1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 17 #include <rte_crypto.h> 18 #include <rte_cryptodev.h> 19 #include <rte_cryptodev_pmd.h> 20 #include <rte_string_fns.h> 21 22 #ifdef RTE_CRYPTO_SCHEDULER 23 #include <rte_cryptodev_scheduler.h> 24 #include <rte_cryptodev_scheduler_operations.h> 25 #endif 26 27 #include <rte_lcore.h> 28 29 #include "test.h" 30 #include "test_cryptodev.h" 31 32 #include "test_cryptodev_blockcipher.h" 33 #include "test_cryptodev_aes_test_vectors.h" 34 #include "test_cryptodev_des_test_vectors.h" 35 #include "test_cryptodev_hash_test_vectors.h" 36 #include "test_cryptodev_kasumi_test_vectors.h" 37 #include "test_cryptodev_kasumi_hash_test_vectors.h" 38 #include "test_cryptodev_snow3g_test_vectors.h" 39 #include "test_cryptodev_snow3g_hash_test_vectors.h" 40 #include "test_cryptodev_zuc_test_vectors.h" 41 #include "test_cryptodev_aead_test_vectors.h" 42 #include "test_cryptodev_hmac_test_vectors.h" 43 #include "test_cryptodev_mixed_test_vectors.h" 44 #ifdef RTE_LIB_SECURITY 45 #include "test_cryptodev_security_pdcp_test_vectors.h" 46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 47 #include "test_cryptodev_security_pdcp_test_func.h" 48 #include "test_cryptodev_security_docsis_test_vectors.h" 49 50 #define SDAP_DISABLED 0 51 #define SDAP_ENABLED 1 52 #endif 53 54 #define VDEV_ARGS_SIZE 100 55 #define MAX_NB_SESSIONS 4 56 57 #define MAX_DRV_SERVICE_CTX_SIZE 256 58 59 #define MAX_RAW_DEQUEUE_COUNT 65535 60 61 #define IN_PLACE 0 62 #define OUT_OF_PLACE 1 63 64 #ifndef ARRAY_SIZE 65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 66 #endif 67 68 static int gbl_driver_id; 69 70 static enum rte_security_session_action_type gbl_action_type = 71 RTE_SECURITY_ACTION_TYPE_NONE; 72 73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 74 75 struct crypto_testsuite_params { 76 struct rte_mempool *mbuf_pool; 77 struct rte_mempool *large_mbuf_pool; 78 struct rte_mempool *op_mpool; 79 struct rte_mempool *session_mpool; 80 struct rte_mempool *session_priv_mpool; 81 struct rte_cryptodev_config conf; 82 struct rte_cryptodev_qp_conf qp_conf; 83 84 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 85 uint8_t valid_dev_count; 86 }; 87 88 struct crypto_unittest_params { 89 struct rte_crypto_sym_xform cipher_xform; 90 struct rte_crypto_sym_xform auth_xform; 91 struct rte_crypto_sym_xform aead_xform; 92 #ifdef RTE_LIB_SECURITY 93 struct rte_security_docsis_xform docsis_xform; 94 #endif 95 96 union { 97 struct rte_cryptodev_sym_session *sess; 98 #ifdef RTE_LIB_SECURITY 99 struct rte_security_session *sec_session; 100 #endif 101 }; 102 #ifdef RTE_LIB_SECURITY 103 enum rte_security_session_action_type type; 104 #endif 105 struct rte_crypto_op *op; 106 107 struct rte_mbuf *obuf, *ibuf; 108 109 uint8_t *digest; 110 }; 111 112 #define ALIGN_POW2_ROUNDUP(num, align) \ 113 (((num) + (align) - 1) & ~((align) - 1)) 114 115 /* 116 * Forward declarations. 117 */ 118 static int 119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 120 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 121 uint8_t *hmac_key); 122 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 125 struct crypto_unittest_params *ut_params, 126 struct crypto_testsuite_params *ts_param, 127 const uint8_t *cipher, 128 const uint8_t *digest, 129 const uint8_t *iv); 130 131 static struct rte_mbuf * 132 setup_test_string(struct rte_mempool *mpool, 133 const char *string, size_t len, uint8_t blocksize) 134 { 135 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 136 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 137 138 memset(m->buf_addr, 0, m->buf_len); 139 if (m) { 140 char *dst = rte_pktmbuf_append(m, t_len); 141 142 if (!dst) { 143 rte_pktmbuf_free(m); 144 return NULL; 145 } 146 if (string != NULL) 147 rte_memcpy(dst, string, t_len); 148 else 149 memset(dst, 0, t_len); 150 } 151 152 return m; 153 } 154 155 /* Get number of bytes in X bits (rounding up) */ 156 static uint32_t 157 ceil_byte_length(uint32_t num_bits) 158 { 159 if (num_bits % 8) 160 return ((num_bits >> 3) + 1); 161 else 162 return (num_bits >> 3); 163 } 164 165 static void 166 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 167 uint8_t is_op_success) 168 { 169 struct rte_crypto_op *op = user_data; 170 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 171 RTE_CRYPTO_OP_STATUS_ERROR; 172 } 173 174 void 175 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 176 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 177 uint8_t len_in_bits, uint8_t cipher_iv_len) 178 { 179 struct rte_crypto_sym_op *sop = op->sym; 180 struct rte_crypto_op *ret_op = NULL; 181 struct rte_crypto_vec data_vec[UINT8_MAX]; 182 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 183 union rte_crypto_sym_ofs ofs; 184 struct rte_crypto_sym_vec vec; 185 struct rte_crypto_sgl sgl; 186 uint32_t max_len; 187 union rte_cryptodev_session_ctx sess; 188 uint32_t count = 0; 189 struct rte_crypto_raw_dp_ctx *ctx; 190 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 191 auth_len = 0; 192 int32_t n; 193 uint32_t n_success; 194 int ctx_service_size; 195 int32_t status = 0; 196 int enqueue_status, dequeue_status; 197 198 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 199 if (ctx_service_size < 0) { 200 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 201 return; 202 } 203 204 ctx = malloc(ctx_service_size); 205 if (!ctx) { 206 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 207 return; 208 } 209 210 /* Both are enums, setting crypto_sess will suit any session type */ 211 sess.crypto_sess = op->sym->session; 212 213 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 214 op->sess_type, sess, 0) < 0) { 215 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 216 goto exit; 217 } 218 219 cipher_iv.iova = 0; 220 cipher_iv.va = NULL; 221 aad_auth_iv.iova = 0; 222 aad_auth_iv.va = NULL; 223 digest.iova = 0; 224 digest.va = NULL; 225 sgl.vec = data_vec; 226 vec.num = 1; 227 vec.sgl = &sgl; 228 vec.iv = &cipher_iv; 229 vec.digest = &digest; 230 vec.aad = &aad_auth_iv; 231 vec.status = &status; 232 233 ofs.raw = 0; 234 235 if (is_cipher && is_auth) { 236 cipher_offset = sop->cipher.data.offset; 237 cipher_len = sop->cipher.data.length; 238 auth_offset = sop->auth.data.offset; 239 auth_len = sop->auth.data.length; 240 max_len = RTE_MAX(cipher_offset + cipher_len, 241 auth_offset + auth_len); 242 if (len_in_bits) { 243 max_len = max_len >> 3; 244 cipher_offset = cipher_offset >> 3; 245 auth_offset = auth_offset >> 3; 246 cipher_len = cipher_len >> 3; 247 auth_len = auth_len >> 3; 248 } 249 ofs.ofs.cipher.head = cipher_offset; 250 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 251 ofs.ofs.auth.head = auth_offset; 252 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 253 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 254 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 255 aad_auth_iv.va = rte_crypto_op_ctod_offset( 256 op, void *, IV_OFFSET + cipher_iv_len); 257 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 258 cipher_iv_len); 259 digest.va = (void *)sop->auth.digest.data; 260 digest.iova = sop->auth.digest.phys_addr; 261 262 } else if (is_cipher) { 263 cipher_offset = sop->cipher.data.offset; 264 cipher_len = sop->cipher.data.length; 265 max_len = cipher_len + cipher_offset; 266 if (len_in_bits) { 267 max_len = max_len >> 3; 268 cipher_offset = cipher_offset >> 3; 269 cipher_len = cipher_len >> 3; 270 } 271 ofs.ofs.cipher.head = cipher_offset; 272 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 273 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 274 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 275 276 } else if (is_auth) { 277 auth_offset = sop->auth.data.offset; 278 auth_len = sop->auth.data.length; 279 max_len = auth_len + auth_offset; 280 if (len_in_bits) { 281 max_len = max_len >> 3; 282 auth_offset = auth_offset >> 3; 283 auth_len = auth_len >> 3; 284 } 285 ofs.ofs.auth.head = auth_offset; 286 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 287 aad_auth_iv.va = rte_crypto_op_ctod_offset( 288 op, void *, IV_OFFSET + cipher_iv_len); 289 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 290 cipher_iv_len); 291 digest.va = (void *)sop->auth.digest.data; 292 digest.iova = sop->auth.digest.phys_addr; 293 294 } else { /* aead */ 295 cipher_offset = sop->aead.data.offset; 296 cipher_len = sop->aead.data.length; 297 max_len = cipher_len + cipher_offset; 298 if (len_in_bits) { 299 max_len = max_len >> 3; 300 cipher_offset = cipher_offset >> 3; 301 cipher_len = cipher_len >> 3; 302 } 303 ofs.ofs.cipher.head = cipher_offset; 304 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 305 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 306 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 307 aad_auth_iv.va = (void *)sop->aead.aad.data; 308 aad_auth_iv.iova = sop->aead.aad.phys_addr; 309 digest.va = (void *)sop->aead.digest.data; 310 digest.iova = sop->aead.digest.phys_addr; 311 } 312 313 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 314 data_vec, RTE_DIM(data_vec)); 315 if (n < 0 || n > sop->m_src->nb_segs) { 316 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 317 goto exit; 318 } 319 320 sgl.num = n; 321 322 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 323 &enqueue_status) < 1) { 324 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 325 goto exit; 326 } 327 328 if (enqueue_status == 0) { 329 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 330 if (status < 0) { 331 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 332 goto exit; 333 } 334 } else if (enqueue_status < 0) { 335 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 336 goto exit; 337 } 338 339 n = n_success = 0; 340 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 341 n = rte_cryptodev_raw_dequeue_burst(ctx, 342 NULL, 1, post_process_raw_dp_op, 343 (void **)&ret_op, 0, &n_success, 344 &dequeue_status); 345 if (dequeue_status < 0) { 346 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 347 goto exit; 348 } 349 if (n == 0) 350 rte_pause(); 351 } 352 353 if (n == 1 && dequeue_status == 0) { 354 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 355 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 356 goto exit; 357 } 358 } 359 360 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 361 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 362 RTE_CRYPTO_OP_STATUS_SUCCESS; 363 364 exit: 365 free(ctx); 366 } 367 368 static void 369 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 370 { 371 int32_t n, st; 372 struct rte_crypto_sym_op *sop; 373 union rte_crypto_sym_ofs ofs; 374 struct rte_crypto_sgl sgl; 375 struct rte_crypto_sym_vec symvec; 376 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 377 struct rte_crypto_vec vec[UINT8_MAX]; 378 379 sop = op->sym; 380 381 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 382 sop->aead.data.length, vec, RTE_DIM(vec)); 383 384 if (n < 0 || n != sop->m_src->nb_segs) { 385 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 386 return; 387 } 388 389 sgl.vec = vec; 390 sgl.num = n; 391 symvec.sgl = &sgl; 392 symvec.iv = &iv_ptr; 393 symvec.digest = &digest_ptr; 394 symvec.aad = &aad_ptr; 395 symvec.status = &st; 396 symvec.num = 1; 397 398 /* for CPU crypto the IOVA address is not required */ 399 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 400 digest_ptr.va = (void *)sop->aead.digest.data; 401 aad_ptr.va = (void *)sop->aead.aad.data; 402 403 ofs.raw = 0; 404 405 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 406 &symvec); 407 408 if (n != 1) 409 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 410 else 411 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 412 } 413 414 static void 415 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 416 { 417 int32_t n, st; 418 struct rte_crypto_sym_op *sop; 419 union rte_crypto_sym_ofs ofs; 420 struct rte_crypto_sgl sgl; 421 struct rte_crypto_sym_vec symvec; 422 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 423 struct rte_crypto_vec vec[UINT8_MAX]; 424 425 sop = op->sym; 426 427 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 428 sop->auth.data.length, vec, RTE_DIM(vec)); 429 430 if (n < 0 || n != sop->m_src->nb_segs) { 431 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 432 return; 433 } 434 435 sgl.vec = vec; 436 sgl.num = n; 437 symvec.sgl = &sgl; 438 symvec.iv = &iv_ptr; 439 symvec.digest = &digest_ptr; 440 symvec.status = &st; 441 symvec.num = 1; 442 443 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 444 digest_ptr.va = (void *)sop->auth.digest.data; 445 446 ofs.raw = 0; 447 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 448 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 449 (sop->cipher.data.offset + sop->cipher.data.length); 450 451 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 452 &symvec); 453 454 if (n != 1) 455 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 456 else 457 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 458 } 459 460 static struct rte_crypto_op * 461 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 462 { 463 464 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 465 466 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 467 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 468 return NULL; 469 } 470 471 op = NULL; 472 473 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 474 rte_pause(); 475 476 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 477 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 478 return NULL; 479 } 480 481 return op; 482 } 483 484 static struct crypto_testsuite_params testsuite_params = { NULL }; 485 static struct crypto_unittest_params unittest_params; 486 487 static int 488 testsuite_setup(void) 489 { 490 struct crypto_testsuite_params *ts_params = &testsuite_params; 491 struct rte_cryptodev_info info; 492 uint32_t i = 0, nb_devs, dev_id; 493 int ret; 494 uint16_t qp_id; 495 496 memset(ts_params, 0, sizeof(*ts_params)); 497 498 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 499 if (ts_params->mbuf_pool == NULL) { 500 /* Not already created so create */ 501 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 502 "CRYPTO_MBUFPOOL", 503 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 504 rte_socket_id()); 505 if (ts_params->mbuf_pool == NULL) { 506 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 507 return TEST_FAILED; 508 } 509 } 510 511 ts_params->large_mbuf_pool = rte_mempool_lookup( 512 "CRYPTO_LARGE_MBUFPOOL"); 513 if (ts_params->large_mbuf_pool == NULL) { 514 /* Not already created so create */ 515 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 516 "CRYPTO_LARGE_MBUFPOOL", 517 1, 0, 0, UINT16_MAX, 518 rte_socket_id()); 519 if (ts_params->large_mbuf_pool == NULL) { 520 RTE_LOG(ERR, USER1, 521 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 522 return TEST_FAILED; 523 } 524 } 525 526 ts_params->op_mpool = rte_crypto_op_pool_create( 527 "MBUF_CRYPTO_SYM_OP_POOL", 528 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 529 NUM_MBUFS, MBUF_CACHE_SIZE, 530 DEFAULT_NUM_XFORMS * 531 sizeof(struct rte_crypto_sym_xform) + 532 MAXIMUM_IV_LENGTH, 533 rte_socket_id()); 534 if (ts_params->op_mpool == NULL) { 535 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 536 return TEST_FAILED; 537 } 538 539 /* Create an AESNI MB device if required */ 540 if (gbl_driver_id == rte_cryptodev_driver_id_get( 541 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) { 542 nb_devs = rte_cryptodev_device_count_by_driver( 543 rte_cryptodev_driver_id_get( 544 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 545 if (nb_devs < 1) { 546 ret = rte_vdev_init( 547 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 548 549 TEST_ASSERT(ret == 0, 550 "Failed to create instance of" 551 " pmd : %s", 552 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 553 } 554 } 555 556 /* Create an AESNI GCM device if required */ 557 if (gbl_driver_id == rte_cryptodev_driver_id_get( 558 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) { 559 nb_devs = rte_cryptodev_device_count_by_driver( 560 rte_cryptodev_driver_id_get( 561 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))); 562 if (nb_devs < 1) { 563 TEST_ASSERT_SUCCESS(rte_vdev_init( 564 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 565 "Failed to create instance of" 566 " pmd : %s", 567 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 568 } 569 } 570 571 /* Create a SNOW 3G device if required */ 572 if (gbl_driver_id == rte_cryptodev_driver_id_get( 573 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) { 574 nb_devs = rte_cryptodev_device_count_by_driver( 575 rte_cryptodev_driver_id_get( 576 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))); 577 if (nb_devs < 1) { 578 TEST_ASSERT_SUCCESS(rte_vdev_init( 579 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 580 "Failed to create instance of" 581 " pmd : %s", 582 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 583 } 584 } 585 586 /* Create a KASUMI device if required */ 587 if (gbl_driver_id == rte_cryptodev_driver_id_get( 588 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) { 589 nb_devs = rte_cryptodev_device_count_by_driver( 590 rte_cryptodev_driver_id_get( 591 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))); 592 if (nb_devs < 1) { 593 TEST_ASSERT_SUCCESS(rte_vdev_init( 594 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 595 "Failed to create instance of" 596 " pmd : %s", 597 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 598 } 599 } 600 601 /* Create a ZUC device if required */ 602 if (gbl_driver_id == rte_cryptodev_driver_id_get( 603 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) { 604 nb_devs = rte_cryptodev_device_count_by_driver( 605 rte_cryptodev_driver_id_get( 606 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))); 607 if (nb_devs < 1) { 608 TEST_ASSERT_SUCCESS(rte_vdev_init( 609 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 610 "Failed to create instance of" 611 " pmd : %s", 612 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 613 } 614 } 615 616 /* Create a NULL device if required */ 617 if (gbl_driver_id == rte_cryptodev_driver_id_get( 618 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) { 619 nb_devs = rte_cryptodev_device_count_by_driver( 620 rte_cryptodev_driver_id_get( 621 RTE_STR(CRYPTODEV_NAME_NULL_PMD))); 622 if (nb_devs < 1) { 623 ret = rte_vdev_init( 624 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 625 626 TEST_ASSERT(ret == 0, 627 "Failed to create instance of" 628 " pmd : %s", 629 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 630 } 631 } 632 633 /* Create an OPENSSL device if required */ 634 if (gbl_driver_id == rte_cryptodev_driver_id_get( 635 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 636 nb_devs = rte_cryptodev_device_count_by_driver( 637 rte_cryptodev_driver_id_get( 638 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 639 if (nb_devs < 1) { 640 ret = rte_vdev_init( 641 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 642 NULL); 643 644 TEST_ASSERT(ret == 0, "Failed to create " 645 "instance of pmd : %s", 646 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 647 } 648 } 649 650 /* Create a ARMv8 device if required */ 651 if (gbl_driver_id == rte_cryptodev_driver_id_get( 652 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) { 653 nb_devs = rte_cryptodev_device_count_by_driver( 654 rte_cryptodev_driver_id_get( 655 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))); 656 if (nb_devs < 1) { 657 ret = rte_vdev_init( 658 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 659 NULL); 660 661 TEST_ASSERT(ret == 0, "Failed to create " 662 "instance of pmd : %s", 663 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 664 } 665 } 666 667 /* Create a MVSAM device if required */ 668 if (gbl_driver_id == rte_cryptodev_driver_id_get( 669 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) { 670 nb_devs = rte_cryptodev_device_count_by_driver( 671 rte_cryptodev_driver_id_get( 672 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))); 673 if (nb_devs < 1) { 674 ret = rte_vdev_init( 675 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD), 676 NULL); 677 678 TEST_ASSERT(ret == 0, "Failed to create " 679 "instance of pmd : %s", 680 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 681 } 682 } 683 684 /* Create an CCP device if required */ 685 if (gbl_driver_id == rte_cryptodev_driver_id_get( 686 RTE_STR(CRYPTODEV_NAME_CCP_PMD))) { 687 nb_devs = rte_cryptodev_device_count_by_driver( 688 rte_cryptodev_driver_id_get( 689 RTE_STR(CRYPTODEV_NAME_CCP_PMD))); 690 if (nb_devs < 1) { 691 ret = rte_vdev_init( 692 RTE_STR(CRYPTODEV_NAME_CCP_PMD), 693 NULL); 694 695 TEST_ASSERT(ret == 0, "Failed to create " 696 "instance of pmd : %s", 697 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 698 } 699 } 700 701 #ifdef RTE_CRYPTO_SCHEDULER 702 char vdev_args[VDEV_ARGS_SIZE] = {""}; 703 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 704 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 705 uint16_t worker_core_count = 0; 706 uint16_t socket_id = 0; 707 708 if (gbl_driver_id == rte_cryptodev_driver_id_get( 709 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 710 711 /* Identify the Worker Cores 712 * Use 2 worker cores for the device args 713 */ 714 RTE_LCORE_FOREACH_WORKER(i) { 715 if (worker_core_count > 1) 716 break; 717 snprintf(vdev_args, sizeof(vdev_args), 718 "%s%d", temp_str, i); 719 strcpy(temp_str, vdev_args); 720 strlcat(temp_str, ";", sizeof(temp_str)); 721 worker_core_count++; 722 socket_id = rte_lcore_to_socket_id(i); 723 } 724 if (worker_core_count != 2) { 725 RTE_LOG(ERR, USER1, 726 "Cryptodev scheduler test require at least " 727 "two worker cores to run. " 728 "Please use the correct coremask.\n"); 729 return TEST_FAILED; 730 } 731 strcpy(temp_str, vdev_args); 732 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 733 temp_str, socket_id); 734 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 735 nb_devs = rte_cryptodev_device_count_by_driver( 736 rte_cryptodev_driver_id_get( 737 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 738 if (nb_devs < 1) { 739 ret = rte_vdev_init( 740 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 741 vdev_args); 742 TEST_ASSERT(ret == 0, 743 "Failed to create instance %u of" 744 " pmd : %s", 745 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 746 } 747 } 748 #endif /* RTE_CRYPTO_SCHEDULER */ 749 750 nb_devs = rte_cryptodev_count(); 751 if (nb_devs < 1) { 752 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 753 return TEST_SKIPPED; 754 } 755 756 /* Create list of valid crypto devs */ 757 for (i = 0; i < nb_devs; i++) { 758 rte_cryptodev_info_get(i, &info); 759 if (info.driver_id == gbl_driver_id) 760 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 761 } 762 763 if (ts_params->valid_dev_count < 1) 764 return TEST_FAILED; 765 766 /* Set up all the qps on the first of the valid devices found */ 767 768 dev_id = ts_params->valid_devs[0]; 769 770 rte_cryptodev_info_get(dev_id, &info); 771 772 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 773 ts_params->conf.socket_id = SOCKET_ID_ANY; 774 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 775 776 unsigned int session_size = 777 rte_cryptodev_sym_get_private_session_size(dev_id); 778 779 #ifdef RTE_LIB_SECURITY 780 unsigned int security_session_size = rte_security_session_get_size( 781 rte_cryptodev_get_sec_ctx(dev_id)); 782 783 if (session_size < security_session_size) 784 session_size = security_session_size; 785 #endif 786 /* 787 * Create mempool with maximum number of sessions. 788 */ 789 if (info.sym.max_nb_sessions != 0 && 790 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 791 RTE_LOG(ERR, USER1, "Device does not support " 792 "at least %u sessions\n", 793 MAX_NB_SESSIONS); 794 return TEST_FAILED; 795 } 796 797 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 798 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 799 SOCKET_ID_ANY); 800 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 801 "session mempool allocation failed"); 802 803 ts_params->session_priv_mpool = rte_mempool_create( 804 "test_sess_mp_priv", 805 MAX_NB_SESSIONS, 806 session_size, 807 0, 0, NULL, NULL, NULL, 808 NULL, SOCKET_ID_ANY, 809 0); 810 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 811 "session mempool allocation failed"); 812 813 814 815 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 816 &ts_params->conf), 817 "Failed to configure cryptodev %u with %u qps", 818 dev_id, ts_params->conf.nb_queue_pairs); 819 820 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 821 ts_params->qp_conf.mp_session = ts_params->session_mpool; 822 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 823 824 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 825 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 826 dev_id, qp_id, &ts_params->qp_conf, 827 rte_cryptodev_socket_id(dev_id)), 828 "Failed to setup queue pair %u on cryptodev %u", 829 qp_id, dev_id); 830 } 831 832 return TEST_SUCCESS; 833 } 834 835 static void 836 testsuite_teardown(void) 837 { 838 struct crypto_testsuite_params *ts_params = &testsuite_params; 839 int res; 840 841 if (ts_params->mbuf_pool != NULL) { 842 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 843 rte_mempool_avail_count(ts_params->mbuf_pool)); 844 } 845 846 if (ts_params->op_mpool != NULL) { 847 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 848 rte_mempool_avail_count(ts_params->op_mpool)); 849 } 850 851 /* Free session mempools */ 852 if (ts_params->session_priv_mpool != NULL) { 853 rte_mempool_free(ts_params->session_priv_mpool); 854 ts_params->session_priv_mpool = NULL; 855 } 856 857 if (ts_params->session_mpool != NULL) { 858 rte_mempool_free(ts_params->session_mpool); 859 ts_params->session_mpool = NULL; 860 } 861 862 res = rte_cryptodev_close(ts_params->valid_devs[0]); 863 if (res) 864 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 865 } 866 867 static int 868 dev_configure_and_start(uint64_t ff_disable) 869 { 870 struct crypto_testsuite_params *ts_params = &testsuite_params; 871 struct crypto_unittest_params *ut_params = &unittest_params; 872 873 uint16_t qp_id; 874 875 /* Clear unit test parameters before running test */ 876 memset(ut_params, 0, sizeof(*ut_params)); 877 878 /* Reconfigure device to default parameters */ 879 ts_params->conf.socket_id = SOCKET_ID_ANY; 880 ts_params->conf.ff_disable = ff_disable; 881 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 882 ts_params->qp_conf.mp_session = ts_params->session_mpool; 883 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 884 885 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 886 &ts_params->conf), 887 "Failed to configure cryptodev %u", 888 ts_params->valid_devs[0]); 889 890 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 891 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 892 ts_params->valid_devs[0], qp_id, 893 &ts_params->qp_conf, 894 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 895 "Failed to setup queue pair %u on cryptodev %u", 896 qp_id, ts_params->valid_devs[0]); 897 } 898 899 900 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 901 902 /* Start the device */ 903 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 904 "Failed to start cryptodev %u", 905 ts_params->valid_devs[0]); 906 907 return TEST_SUCCESS; 908 } 909 910 static int 911 ut_setup(void) 912 { 913 /* Configure and start the device with security feature disabled */ 914 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 915 } 916 917 static int 918 ut_setup_security(void) 919 { 920 /* Configure and start the device with no features disabled */ 921 return dev_configure_and_start(0); 922 } 923 924 static void 925 ut_teardown(void) 926 { 927 struct crypto_testsuite_params *ts_params = &testsuite_params; 928 struct crypto_unittest_params *ut_params = &unittest_params; 929 struct rte_cryptodev_stats stats; 930 931 /* free crypto session structure */ 932 #ifdef RTE_LIB_SECURITY 933 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 934 if (ut_params->sec_session) { 935 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 936 (ts_params->valid_devs[0]), 937 ut_params->sec_session); 938 ut_params->sec_session = NULL; 939 } 940 } else 941 #endif 942 { 943 if (ut_params->sess) { 944 rte_cryptodev_sym_session_clear( 945 ts_params->valid_devs[0], 946 ut_params->sess); 947 rte_cryptodev_sym_session_free(ut_params->sess); 948 ut_params->sess = NULL; 949 } 950 } 951 952 /* free crypto operation structure */ 953 if (ut_params->op) 954 rte_crypto_op_free(ut_params->op); 955 956 /* 957 * free mbuf - both obuf and ibuf are usually the same, 958 * so check if they point at the same address is necessary, 959 * to avoid freeing the mbuf twice. 960 */ 961 if (ut_params->obuf) { 962 rte_pktmbuf_free(ut_params->obuf); 963 if (ut_params->ibuf == ut_params->obuf) 964 ut_params->ibuf = 0; 965 ut_params->obuf = 0; 966 } 967 if (ut_params->ibuf) { 968 rte_pktmbuf_free(ut_params->ibuf); 969 ut_params->ibuf = 0; 970 } 971 972 if (ts_params->mbuf_pool != NULL) 973 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 974 rte_mempool_avail_count(ts_params->mbuf_pool)); 975 976 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 977 978 /* Stop the device */ 979 rte_cryptodev_stop(ts_params->valid_devs[0]); 980 } 981 982 static int 983 test_device_configure_invalid_dev_id(void) 984 { 985 struct crypto_testsuite_params *ts_params = &testsuite_params; 986 uint16_t dev_id, num_devs = 0; 987 988 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 989 "Need at least %d devices for test", 1); 990 991 /* valid dev_id values */ 992 dev_id = ts_params->valid_devs[0]; 993 994 /* Stop the device in case it's started so it can be configured */ 995 rte_cryptodev_stop(dev_id); 996 997 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 998 "Failed test for rte_cryptodev_configure: " 999 "invalid dev_num %u", dev_id); 1000 1001 /* invalid dev_id values */ 1002 dev_id = num_devs; 1003 1004 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1005 "Failed test for rte_cryptodev_configure: " 1006 "invalid dev_num %u", dev_id); 1007 1008 dev_id = 0xff; 1009 1010 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1011 "Failed test for rte_cryptodev_configure:" 1012 "invalid dev_num %u", dev_id); 1013 1014 return TEST_SUCCESS; 1015 } 1016 1017 static int 1018 test_device_configure_invalid_queue_pair_ids(void) 1019 { 1020 struct crypto_testsuite_params *ts_params = &testsuite_params; 1021 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1022 1023 /* Stop the device in case it's started so it can be configured */ 1024 rte_cryptodev_stop(ts_params->valid_devs[0]); 1025 1026 /* valid - max value queue pairs */ 1027 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1028 1029 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1030 &ts_params->conf), 1031 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1032 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1033 1034 /* valid - one queue pairs */ 1035 ts_params->conf.nb_queue_pairs = 1; 1036 1037 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1038 &ts_params->conf), 1039 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1040 ts_params->valid_devs[0], 1041 ts_params->conf.nb_queue_pairs); 1042 1043 1044 /* invalid - zero queue pairs */ 1045 ts_params->conf.nb_queue_pairs = 0; 1046 1047 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1048 &ts_params->conf), 1049 "Failed test for rte_cryptodev_configure, dev_id %u," 1050 " invalid qps: %u", 1051 ts_params->valid_devs[0], 1052 ts_params->conf.nb_queue_pairs); 1053 1054 1055 /* invalid - max value supported by field queue pairs */ 1056 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1057 1058 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1059 &ts_params->conf), 1060 "Failed test for rte_cryptodev_configure, dev_id %u," 1061 " invalid qps: %u", 1062 ts_params->valid_devs[0], 1063 ts_params->conf.nb_queue_pairs); 1064 1065 1066 /* invalid - max value + 1 queue pairs */ 1067 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1068 1069 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1070 &ts_params->conf), 1071 "Failed test for rte_cryptodev_configure, dev_id %u," 1072 " invalid qps: %u", 1073 ts_params->valid_devs[0], 1074 ts_params->conf.nb_queue_pairs); 1075 1076 /* revert to original testsuite value */ 1077 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1078 1079 return TEST_SUCCESS; 1080 } 1081 1082 static int 1083 test_queue_pair_descriptor_setup(void) 1084 { 1085 struct crypto_testsuite_params *ts_params = &testsuite_params; 1086 struct rte_cryptodev_qp_conf qp_conf = { 1087 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1088 }; 1089 uint16_t qp_id; 1090 1091 /* Stop the device in case it's started so it can be configured */ 1092 rte_cryptodev_stop(ts_params->valid_devs[0]); 1093 1094 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1095 &ts_params->conf), 1096 "Failed to configure cryptodev %u", 1097 ts_params->valid_devs[0]); 1098 1099 /* 1100 * Test various ring sizes on this device. memzones can't be 1101 * freed so are re-used if ring is released and re-created. 1102 */ 1103 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1104 qp_conf.mp_session = ts_params->session_mpool; 1105 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1106 1107 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1108 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1109 ts_params->valid_devs[0], qp_id, &qp_conf, 1110 rte_cryptodev_socket_id( 1111 ts_params->valid_devs[0])), 1112 "Failed test for " 1113 "rte_cryptodev_queue_pair_setup: num_inflights " 1114 "%u on qp %u on cryptodev %u", 1115 qp_conf.nb_descriptors, qp_id, 1116 ts_params->valid_devs[0]); 1117 } 1118 1119 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1120 1121 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1122 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1123 ts_params->valid_devs[0], qp_id, &qp_conf, 1124 rte_cryptodev_socket_id( 1125 ts_params->valid_devs[0])), 1126 "Failed test for" 1127 " rte_cryptodev_queue_pair_setup: num_inflights" 1128 " %u on qp %u on cryptodev %u", 1129 qp_conf.nb_descriptors, qp_id, 1130 ts_params->valid_devs[0]); 1131 } 1132 1133 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1134 1135 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1136 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1137 ts_params->valid_devs[0], qp_id, &qp_conf, 1138 rte_cryptodev_socket_id( 1139 ts_params->valid_devs[0])), 1140 "Failed test for " 1141 "rte_cryptodev_queue_pair_setup: num_inflights" 1142 " %u on qp %u on cryptodev %u", 1143 qp_conf.nb_descriptors, qp_id, 1144 ts_params->valid_devs[0]); 1145 } 1146 1147 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1148 1149 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1150 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1151 ts_params->valid_devs[0], qp_id, &qp_conf, 1152 rte_cryptodev_socket_id( 1153 ts_params->valid_devs[0])), 1154 "Failed test for" 1155 " rte_cryptodev_queue_pair_setup:" 1156 "num_inflights %u on qp %u on cryptodev %u", 1157 qp_conf.nb_descriptors, qp_id, 1158 ts_params->valid_devs[0]); 1159 } 1160 1161 /* test invalid queue pair id */ 1162 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1163 1164 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1165 1166 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1167 ts_params->valid_devs[0], 1168 qp_id, &qp_conf, 1169 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1170 "Failed test for rte_cryptodev_queue_pair_setup:" 1171 "invalid qp %u on cryptodev %u", 1172 qp_id, ts_params->valid_devs[0]); 1173 1174 qp_id = 0xffff; /*invalid*/ 1175 1176 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1177 ts_params->valid_devs[0], 1178 qp_id, &qp_conf, 1179 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1180 "Failed test for rte_cryptodev_queue_pair_setup:" 1181 "invalid qp %u on cryptodev %u", 1182 qp_id, ts_params->valid_devs[0]); 1183 1184 return TEST_SUCCESS; 1185 } 1186 1187 /* ***** Plaintext data for tests ***** */ 1188 1189 const char catch_22_quote_1[] = 1190 "There was only one catch and that was Catch-22, which " 1191 "specified that a concern for one's safety in the face of " 1192 "dangers that were real and immediate was the process of a " 1193 "rational mind. Orr was crazy and could be grounded. All he " 1194 "had to do was ask; and as soon as he did, he would no longer " 1195 "be crazy and would have to fly more missions. Orr would be " 1196 "crazy to fly more missions and sane if he didn't, but if he " 1197 "was sane he had to fly them. If he flew them he was crazy " 1198 "and didn't have to; but if he didn't want to he was sane and " 1199 "had to. Yossarian was moved very deeply by the absolute " 1200 "simplicity of this clause of Catch-22 and let out a " 1201 "respectful whistle. \"That's some catch, that Catch-22\", he " 1202 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1203 1204 const char catch_22_quote[] = 1205 "What a lousy earth! He wondered how many people were " 1206 "destitute that same night even in his own prosperous country, " 1207 "how many homes were shanties, how many husbands were drunk " 1208 "and wives socked, and how many children were bullied, abused, " 1209 "or abandoned. How many families hungered for food they could " 1210 "not afford to buy? How many hearts were broken? How many " 1211 "suicides would take place that same night, how many people " 1212 "would go insane? How many cockroaches and landlords would " 1213 "triumph? How many winners were losers, successes failures, " 1214 "and rich men poor men? How many wise guys were stupid? How " 1215 "many happy endings were unhappy endings? How many honest men " 1216 "were liars, brave men cowards, loyal men traitors, how many " 1217 "sainted men were corrupt, how many people in positions of " 1218 "trust had sold their souls to bodyguards, how many had never " 1219 "had souls? How many straight-and-narrow paths were crooked " 1220 "paths? How many best families were worst families and how " 1221 "many good people were bad people? When you added them all up " 1222 "and then subtracted, you might be left with only the children, " 1223 "and perhaps with Albert Einstein and an old violinist or " 1224 "sculptor somewhere."; 1225 1226 #define QUOTE_480_BYTES (480) 1227 #define QUOTE_512_BYTES (512) 1228 #define QUOTE_768_BYTES (768) 1229 #define QUOTE_1024_BYTES (1024) 1230 1231 1232 1233 /* ***** SHA1 Hash Tests ***** */ 1234 1235 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1236 1237 static uint8_t hmac_sha1_key[] = { 1238 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1239 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1240 0xDE, 0xF4, 0xDE, 0xAD }; 1241 1242 /* ***** SHA224 Hash Tests ***** */ 1243 1244 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1245 1246 1247 /* ***** AES-CBC Cipher Tests ***** */ 1248 1249 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1250 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1251 1252 static uint8_t aes_cbc_key[] = { 1253 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1254 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1255 1256 static uint8_t aes_cbc_iv[] = { 1257 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1258 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1259 1260 1261 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1262 1263 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1264 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1265 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1266 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1267 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1268 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1269 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1270 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1271 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1272 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1273 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1274 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1275 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1276 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1277 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1278 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1279 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1280 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1281 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1282 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1283 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1284 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1285 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1286 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1287 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1288 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1289 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1290 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1291 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1292 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1293 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1294 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1295 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1296 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1297 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1298 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1299 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1300 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1301 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1302 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1303 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1304 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1305 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1306 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1307 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1308 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1309 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1310 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1311 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1312 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1313 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1314 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1315 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1316 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1317 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1318 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1319 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1320 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1321 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1322 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1323 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1324 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1325 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1326 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1327 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1328 }; 1329 1330 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1331 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1332 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1333 0x18, 0x8c, 0x1d, 0x32 1334 }; 1335 1336 1337 /* Multisession Vector context Test */ 1338 /*Begin Session 0 */ 1339 static uint8_t ms_aes_cbc_key0[] = { 1340 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1341 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1342 }; 1343 1344 static uint8_t ms_aes_cbc_iv0[] = { 1345 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1346 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1347 }; 1348 1349 static const uint8_t ms_aes_cbc_cipher0[] = { 1350 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1351 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1352 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1353 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1354 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1355 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1356 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1357 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1358 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1359 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1360 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1361 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1362 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1363 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1364 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1365 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1366 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1367 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1368 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1369 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1370 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1371 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1372 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1373 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1374 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1375 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1376 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1377 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1378 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1379 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1380 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1381 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1382 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1383 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1384 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1385 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1386 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1387 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1388 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1389 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1390 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1391 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1392 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1393 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1394 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1395 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1396 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1397 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1398 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1399 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1400 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1401 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1402 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1403 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1404 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1405 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1406 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1407 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1408 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1409 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1410 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1411 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1412 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1413 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1414 }; 1415 1416 1417 static uint8_t ms_hmac_key0[] = { 1418 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1419 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1420 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1421 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1422 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1423 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1424 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1425 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1426 }; 1427 1428 static const uint8_t ms_hmac_digest0[] = { 1429 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1430 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1431 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1432 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1433 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1434 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1435 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1436 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1437 }; 1438 1439 /* End Session 0 */ 1440 /* Begin session 1 */ 1441 1442 static uint8_t ms_aes_cbc_key1[] = { 1443 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1444 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1445 }; 1446 1447 static uint8_t ms_aes_cbc_iv1[] = { 1448 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1449 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1450 }; 1451 1452 static const uint8_t ms_aes_cbc_cipher1[] = { 1453 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1454 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1455 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1456 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1457 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1458 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1459 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1460 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1461 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1462 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1463 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1464 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1465 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1466 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1467 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1468 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1469 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1470 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1471 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1472 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1473 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1474 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1475 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1476 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1477 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1478 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1479 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1480 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1481 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1482 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1483 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1484 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1485 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1486 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1487 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1488 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1489 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1490 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1491 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1492 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1493 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1494 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1495 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1496 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1497 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1498 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1499 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1500 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1501 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1502 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1503 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1504 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1505 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1506 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1507 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1508 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1509 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1510 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1511 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1512 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1513 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1514 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1515 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1516 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1517 1518 }; 1519 1520 static uint8_t ms_hmac_key1[] = { 1521 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1522 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1523 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1524 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1525 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1526 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1527 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1528 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1529 }; 1530 1531 static const uint8_t ms_hmac_digest1[] = { 1532 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1533 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1534 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1535 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1536 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1537 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1538 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1539 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1540 }; 1541 /* End Session 1 */ 1542 /* Begin Session 2 */ 1543 static uint8_t ms_aes_cbc_key2[] = { 1544 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1545 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1546 }; 1547 1548 static uint8_t ms_aes_cbc_iv2[] = { 1549 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1550 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1551 }; 1552 1553 static const uint8_t ms_aes_cbc_cipher2[] = { 1554 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1555 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1556 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1557 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1558 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1559 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1560 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1561 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1562 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1563 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1564 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1565 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1566 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1567 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1568 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1569 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1570 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1571 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1572 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1573 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1574 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1575 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1576 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1577 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1578 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1579 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1580 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1581 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1582 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1583 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1584 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1585 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1586 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1587 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1588 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1589 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1590 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1591 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1592 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1593 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1594 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1595 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1596 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1597 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1598 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1599 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1600 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1601 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1602 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1603 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1604 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1605 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1606 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1607 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1608 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1609 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1610 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1611 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1612 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1613 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1614 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1615 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1616 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1617 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1618 }; 1619 1620 static uint8_t ms_hmac_key2[] = { 1621 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1622 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1623 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1624 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1625 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1626 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1627 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1628 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1629 }; 1630 1631 static const uint8_t ms_hmac_digest2[] = { 1632 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1633 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1634 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1635 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1636 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1637 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1638 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1639 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1640 }; 1641 1642 /* End Session 2 */ 1643 1644 1645 static int 1646 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1647 { 1648 struct crypto_testsuite_params *ts_params = &testsuite_params; 1649 struct crypto_unittest_params *ut_params = &unittest_params; 1650 1651 /* Verify the capabilities */ 1652 struct rte_cryptodev_sym_capability_idx cap_idx; 1653 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1654 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 1655 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1656 &cap_idx) == NULL) 1657 return -ENOTSUP; 1658 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1659 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 1660 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1661 &cap_idx) == NULL) 1662 return -ENOTSUP; 1663 1664 /* Generate test mbuf data and space for digest */ 1665 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1666 catch_22_quote, QUOTE_512_BYTES, 0); 1667 1668 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1669 DIGEST_BYTE_LENGTH_SHA1); 1670 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1671 1672 /* Setup Cipher Parameters */ 1673 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1674 ut_params->cipher_xform.next = &ut_params->auth_xform; 1675 1676 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1677 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1678 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1679 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1680 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1681 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1682 1683 /* Setup HMAC Parameters */ 1684 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1685 1686 ut_params->auth_xform.next = NULL; 1687 1688 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1689 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1690 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1691 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1692 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1693 1694 ut_params->sess = rte_cryptodev_sym_session_create( 1695 ts_params->session_mpool); 1696 1697 /* Create crypto session*/ 1698 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 1699 ut_params->sess, &ut_params->cipher_xform, 1700 ts_params->session_priv_mpool); 1701 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1702 1703 /* Generate crypto op data structure */ 1704 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1705 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1706 TEST_ASSERT_NOT_NULL(ut_params->op, 1707 "Failed to allocate symmetric crypto operation struct"); 1708 1709 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1710 1711 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1712 1713 /* set crypto operation source mbuf */ 1714 sym_op->m_src = ut_params->ibuf; 1715 1716 /* Set crypto operation authentication parameters */ 1717 sym_op->auth.digest.data = ut_params->digest; 1718 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1719 ut_params->ibuf, QUOTE_512_BYTES); 1720 1721 sym_op->auth.data.offset = 0; 1722 sym_op->auth.data.length = QUOTE_512_BYTES; 1723 1724 /* Copy IV at the end of the crypto operation */ 1725 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1726 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 1727 1728 /* Set crypto operation cipher parameters */ 1729 sym_op->cipher.data.offset = 0; 1730 sym_op->cipher.data.length = QUOTE_512_BYTES; 1731 1732 /* Process crypto operation */ 1733 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1734 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1735 ut_params->op); 1736 else 1737 TEST_ASSERT_NOT_NULL( 1738 process_crypto_request(ts_params->valid_devs[0], 1739 ut_params->op), 1740 "failed to process sym crypto op"); 1741 1742 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1743 "crypto op processing failed"); 1744 1745 /* Validate obuf */ 1746 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 1747 uint8_t *); 1748 1749 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1750 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1751 QUOTE_512_BYTES, 1752 "ciphertext data not as expected"); 1753 1754 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1755 1756 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1757 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1758 gbl_driver_id == rte_cryptodev_driver_id_get( 1759 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 1760 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1761 DIGEST_BYTE_LENGTH_SHA1, 1762 "Generated digest data not as expected"); 1763 1764 return TEST_SUCCESS; 1765 } 1766 1767 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1768 1769 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1770 1771 static uint8_t hmac_sha512_key[] = { 1772 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1773 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1774 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1775 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1776 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1777 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1778 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1779 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1780 1781 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1782 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1783 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1784 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1785 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1786 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1787 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1788 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1789 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1790 1791 1792 1793 static int 1794 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1795 struct crypto_unittest_params *ut_params, 1796 uint8_t *cipher_key, 1797 uint8_t *hmac_key); 1798 1799 static int 1800 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1801 struct crypto_unittest_params *ut_params, 1802 struct crypto_testsuite_params *ts_params, 1803 const uint8_t *cipher, 1804 const uint8_t *digest, 1805 const uint8_t *iv); 1806 1807 1808 static int 1809 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1810 struct crypto_unittest_params *ut_params, 1811 uint8_t *cipher_key, 1812 uint8_t *hmac_key) 1813 { 1814 1815 /* Setup Cipher Parameters */ 1816 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1817 ut_params->cipher_xform.next = NULL; 1818 1819 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1820 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1821 ut_params->cipher_xform.cipher.key.data = cipher_key; 1822 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1823 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1824 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1825 1826 /* Setup HMAC Parameters */ 1827 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1828 ut_params->auth_xform.next = &ut_params->cipher_xform; 1829 1830 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1831 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1832 ut_params->auth_xform.auth.key.data = hmac_key; 1833 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1834 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1835 1836 return TEST_SUCCESS; 1837 } 1838 1839 1840 static int 1841 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1842 struct crypto_unittest_params *ut_params, 1843 struct crypto_testsuite_params *ts_params, 1844 const uint8_t *cipher, 1845 const uint8_t *digest, 1846 const uint8_t *iv) 1847 { 1848 /* Generate test mbuf data and digest */ 1849 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1850 (const char *) 1851 cipher, 1852 QUOTE_512_BYTES, 0); 1853 1854 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1855 DIGEST_BYTE_LENGTH_SHA512); 1856 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1857 1858 rte_memcpy(ut_params->digest, 1859 digest, 1860 DIGEST_BYTE_LENGTH_SHA512); 1861 1862 /* Generate Crypto op data structure */ 1863 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1864 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1865 TEST_ASSERT_NOT_NULL(ut_params->op, 1866 "Failed to allocate symmetric crypto operation struct"); 1867 1868 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1869 1870 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1871 1872 /* set crypto operation source mbuf */ 1873 sym_op->m_src = ut_params->ibuf; 1874 1875 sym_op->auth.digest.data = ut_params->digest; 1876 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1877 ut_params->ibuf, QUOTE_512_BYTES); 1878 1879 sym_op->auth.data.offset = 0; 1880 sym_op->auth.data.length = QUOTE_512_BYTES; 1881 1882 /* Copy IV at the end of the crypto operation */ 1883 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1884 iv, CIPHER_IV_LENGTH_AES_CBC); 1885 1886 sym_op->cipher.data.offset = 0; 1887 sym_op->cipher.data.length = QUOTE_512_BYTES; 1888 1889 /* Process crypto operation */ 1890 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1891 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1892 ut_params->op); 1893 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1894 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 1895 ut_params->op, 1, 1, 0, 0); 1896 else 1897 TEST_ASSERT_NOT_NULL( 1898 process_crypto_request(ts_params->valid_devs[0], 1899 ut_params->op), 1900 "failed to process sym crypto op"); 1901 1902 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1903 "crypto op processing failed"); 1904 1905 ut_params->obuf = ut_params->op->sym->m_src; 1906 1907 /* Validate obuf */ 1908 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1909 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 1910 catch_22_quote, 1911 QUOTE_512_BYTES, 1912 "Plaintext data not as expected"); 1913 1914 /* Validate obuf */ 1915 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1916 "Digest verification failed"); 1917 1918 return TEST_SUCCESS; 1919 } 1920 1921 static int 1922 test_blockcipher(enum blockcipher_test_type test_type) 1923 { 1924 struct crypto_testsuite_params *ts_params = &testsuite_params; 1925 int status; 1926 1927 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1928 ts_params->op_mpool, 1929 ts_params->session_mpool, ts_params->session_priv_mpool, 1930 ts_params->valid_devs[0], 1931 test_type); 1932 1933 if (status == -ENOTSUP) 1934 return status; 1935 1936 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1937 1938 return TEST_SUCCESS; 1939 } 1940 1941 static int 1942 test_AES_cipheronly_all(void) 1943 { 1944 return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE); 1945 } 1946 1947 static int 1948 test_AES_docsis_all(void) 1949 { 1950 /* Data-path service does not support DOCSIS yet */ 1951 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1952 return -ENOTSUP; 1953 return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE); 1954 } 1955 1956 static int 1957 test_DES_docsis_all(void) 1958 { 1959 /* Data-path service does not support DOCSIS yet */ 1960 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1961 return -ENOTSUP; 1962 return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE); 1963 } 1964 1965 static int 1966 test_DES_cipheronly_all(void) 1967 { 1968 return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE); 1969 } 1970 1971 static int 1972 test_authonly_all(void) 1973 { 1974 return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE); 1975 } 1976 1977 static int 1978 test_AES_chain_all(void) 1979 { 1980 return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE); 1981 } 1982 1983 static int 1984 test_3DES_chain_all(void) 1985 { 1986 return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE); 1987 } 1988 1989 static int 1990 test_3DES_cipheronly_all(void) 1991 { 1992 return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE); 1993 } 1994 1995 /* ***** SNOW 3G Tests ***** */ 1996 static int 1997 create_wireless_algo_hash_session(uint8_t dev_id, 1998 const uint8_t *key, const uint8_t key_len, 1999 const uint8_t iv_len, const uint8_t auth_len, 2000 enum rte_crypto_auth_operation op, 2001 enum rte_crypto_auth_algorithm algo) 2002 { 2003 uint8_t hash_key[key_len]; 2004 int status; 2005 2006 struct crypto_testsuite_params *ts_params = &testsuite_params; 2007 struct crypto_unittest_params *ut_params = &unittest_params; 2008 2009 memcpy(hash_key, key, key_len); 2010 2011 debug_hexdump(stdout, "key:", key, key_len); 2012 2013 /* Setup Authentication Parameters */ 2014 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2015 ut_params->auth_xform.next = NULL; 2016 2017 ut_params->auth_xform.auth.op = op; 2018 ut_params->auth_xform.auth.algo = algo; 2019 ut_params->auth_xform.auth.key.length = key_len; 2020 ut_params->auth_xform.auth.key.data = hash_key; 2021 ut_params->auth_xform.auth.digest_length = auth_len; 2022 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2023 ut_params->auth_xform.auth.iv.length = iv_len; 2024 ut_params->sess = rte_cryptodev_sym_session_create( 2025 ts_params->session_mpool); 2026 2027 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2028 &ut_params->auth_xform, 2029 ts_params->session_priv_mpool); 2030 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2031 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2032 return 0; 2033 } 2034 2035 static int 2036 create_wireless_algo_cipher_session(uint8_t dev_id, 2037 enum rte_crypto_cipher_operation op, 2038 enum rte_crypto_cipher_algorithm algo, 2039 const uint8_t *key, const uint8_t key_len, 2040 uint8_t iv_len) 2041 { 2042 uint8_t cipher_key[key_len]; 2043 int status; 2044 struct crypto_testsuite_params *ts_params = &testsuite_params; 2045 struct crypto_unittest_params *ut_params = &unittest_params; 2046 2047 memcpy(cipher_key, key, key_len); 2048 2049 /* Setup Cipher Parameters */ 2050 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2051 ut_params->cipher_xform.next = NULL; 2052 2053 ut_params->cipher_xform.cipher.algo = algo; 2054 ut_params->cipher_xform.cipher.op = op; 2055 ut_params->cipher_xform.cipher.key.data = cipher_key; 2056 ut_params->cipher_xform.cipher.key.length = key_len; 2057 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2058 ut_params->cipher_xform.cipher.iv.length = iv_len; 2059 2060 debug_hexdump(stdout, "key:", key, key_len); 2061 2062 /* Create Crypto session */ 2063 ut_params->sess = rte_cryptodev_sym_session_create( 2064 ts_params->session_mpool); 2065 2066 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2067 &ut_params->cipher_xform, 2068 ts_params->session_priv_mpool); 2069 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2070 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2071 return 0; 2072 } 2073 2074 static int 2075 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2076 unsigned int cipher_len, 2077 unsigned int cipher_offset) 2078 { 2079 struct crypto_testsuite_params *ts_params = &testsuite_params; 2080 struct crypto_unittest_params *ut_params = &unittest_params; 2081 2082 /* Generate Crypto op data structure */ 2083 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2084 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2085 TEST_ASSERT_NOT_NULL(ut_params->op, 2086 "Failed to allocate pktmbuf offload"); 2087 2088 /* Set crypto operation data parameters */ 2089 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2090 2091 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2092 2093 /* set crypto operation source mbuf */ 2094 sym_op->m_src = ut_params->ibuf; 2095 2096 /* iv */ 2097 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2098 iv, iv_len); 2099 sym_op->cipher.data.length = cipher_len; 2100 sym_op->cipher.data.offset = cipher_offset; 2101 return 0; 2102 } 2103 2104 static int 2105 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2106 unsigned int cipher_len, 2107 unsigned int cipher_offset) 2108 { 2109 struct crypto_testsuite_params *ts_params = &testsuite_params; 2110 struct crypto_unittest_params *ut_params = &unittest_params; 2111 2112 /* Generate Crypto op data structure */ 2113 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2114 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2115 TEST_ASSERT_NOT_NULL(ut_params->op, 2116 "Failed to allocate pktmbuf offload"); 2117 2118 /* Set crypto operation data parameters */ 2119 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2120 2121 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2122 2123 /* set crypto operation source mbuf */ 2124 sym_op->m_src = ut_params->ibuf; 2125 sym_op->m_dst = ut_params->obuf; 2126 2127 /* iv */ 2128 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2129 iv, iv_len); 2130 sym_op->cipher.data.length = cipher_len; 2131 sym_op->cipher.data.offset = cipher_offset; 2132 return 0; 2133 } 2134 2135 static int 2136 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2137 enum rte_crypto_cipher_operation cipher_op, 2138 enum rte_crypto_auth_operation auth_op, 2139 enum rte_crypto_auth_algorithm auth_algo, 2140 enum rte_crypto_cipher_algorithm cipher_algo, 2141 const uint8_t *key, uint8_t key_len, 2142 uint8_t auth_iv_len, uint8_t auth_len, 2143 uint8_t cipher_iv_len) 2144 2145 { 2146 uint8_t cipher_auth_key[key_len]; 2147 int status; 2148 2149 struct crypto_testsuite_params *ts_params = &testsuite_params; 2150 struct crypto_unittest_params *ut_params = &unittest_params; 2151 2152 memcpy(cipher_auth_key, key, key_len); 2153 2154 /* Setup Authentication Parameters */ 2155 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2156 ut_params->auth_xform.next = NULL; 2157 2158 ut_params->auth_xform.auth.op = auth_op; 2159 ut_params->auth_xform.auth.algo = auth_algo; 2160 ut_params->auth_xform.auth.key.length = key_len; 2161 /* Hash key = cipher key */ 2162 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2163 ut_params->auth_xform.auth.digest_length = auth_len; 2164 /* Auth IV will be after cipher IV */ 2165 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2166 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2167 2168 /* Setup Cipher Parameters */ 2169 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2170 ut_params->cipher_xform.next = &ut_params->auth_xform; 2171 2172 ut_params->cipher_xform.cipher.algo = cipher_algo; 2173 ut_params->cipher_xform.cipher.op = cipher_op; 2174 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2175 ut_params->cipher_xform.cipher.key.length = key_len; 2176 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2177 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2178 2179 debug_hexdump(stdout, "key:", key, key_len); 2180 2181 /* Create Crypto session*/ 2182 ut_params->sess = rte_cryptodev_sym_session_create( 2183 ts_params->session_mpool); 2184 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2185 2186 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2187 &ut_params->cipher_xform, 2188 ts_params->session_priv_mpool); 2189 if (status == -ENOTSUP) 2190 return status; 2191 2192 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2193 return 0; 2194 } 2195 2196 static int 2197 create_wireless_cipher_auth_session(uint8_t dev_id, 2198 enum rte_crypto_cipher_operation cipher_op, 2199 enum rte_crypto_auth_operation auth_op, 2200 enum rte_crypto_auth_algorithm auth_algo, 2201 enum rte_crypto_cipher_algorithm cipher_algo, 2202 const struct wireless_test_data *tdata) 2203 { 2204 const uint8_t key_len = tdata->key.len; 2205 uint8_t cipher_auth_key[key_len]; 2206 int status; 2207 2208 struct crypto_testsuite_params *ts_params = &testsuite_params; 2209 struct crypto_unittest_params *ut_params = &unittest_params; 2210 const uint8_t *key = tdata->key.data; 2211 const uint8_t auth_len = tdata->digest.len; 2212 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2213 uint8_t auth_iv_len = tdata->auth_iv.len; 2214 2215 memcpy(cipher_auth_key, key, key_len); 2216 2217 /* Setup Authentication Parameters */ 2218 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2219 ut_params->auth_xform.next = NULL; 2220 2221 ut_params->auth_xform.auth.op = auth_op; 2222 ut_params->auth_xform.auth.algo = auth_algo; 2223 ut_params->auth_xform.auth.key.length = key_len; 2224 /* Hash key = cipher key */ 2225 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2226 ut_params->auth_xform.auth.digest_length = auth_len; 2227 /* Auth IV will be after cipher IV */ 2228 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2229 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2230 2231 /* Setup Cipher Parameters */ 2232 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2233 ut_params->cipher_xform.next = &ut_params->auth_xform; 2234 2235 ut_params->cipher_xform.cipher.algo = cipher_algo; 2236 ut_params->cipher_xform.cipher.op = cipher_op; 2237 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2238 ut_params->cipher_xform.cipher.key.length = key_len; 2239 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2240 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2241 2242 2243 debug_hexdump(stdout, "key:", key, key_len); 2244 2245 /* Create Crypto session*/ 2246 ut_params->sess = rte_cryptodev_sym_session_create( 2247 ts_params->session_mpool); 2248 2249 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2250 &ut_params->cipher_xform, 2251 ts_params->session_priv_mpool); 2252 if (status == -ENOTSUP) 2253 return status; 2254 2255 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2256 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2257 return 0; 2258 } 2259 2260 static int 2261 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2262 const struct wireless_test_data *tdata) 2263 { 2264 return create_wireless_cipher_auth_session(dev_id, 2265 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2266 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2267 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2268 } 2269 2270 static int 2271 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2272 enum rte_crypto_cipher_operation cipher_op, 2273 enum rte_crypto_auth_operation auth_op, 2274 enum rte_crypto_auth_algorithm auth_algo, 2275 enum rte_crypto_cipher_algorithm cipher_algo, 2276 const uint8_t *key, const uint8_t key_len, 2277 uint8_t auth_iv_len, uint8_t auth_len, 2278 uint8_t cipher_iv_len) 2279 { 2280 uint8_t auth_cipher_key[key_len]; 2281 int status; 2282 struct crypto_testsuite_params *ts_params = &testsuite_params; 2283 struct crypto_unittest_params *ut_params = &unittest_params; 2284 2285 memcpy(auth_cipher_key, key, key_len); 2286 2287 /* Setup Authentication Parameters */ 2288 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2289 ut_params->auth_xform.auth.op = auth_op; 2290 ut_params->auth_xform.next = &ut_params->cipher_xform; 2291 ut_params->auth_xform.auth.algo = auth_algo; 2292 ut_params->auth_xform.auth.key.length = key_len; 2293 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2294 ut_params->auth_xform.auth.digest_length = auth_len; 2295 /* Auth IV will be after cipher IV */ 2296 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2297 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2298 2299 /* Setup Cipher Parameters */ 2300 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2301 ut_params->cipher_xform.next = NULL; 2302 ut_params->cipher_xform.cipher.algo = cipher_algo; 2303 ut_params->cipher_xform.cipher.op = cipher_op; 2304 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2305 ut_params->cipher_xform.cipher.key.length = key_len; 2306 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2307 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2308 2309 debug_hexdump(stdout, "key:", key, key_len); 2310 2311 /* Create Crypto session*/ 2312 ut_params->sess = rte_cryptodev_sym_session_create( 2313 ts_params->session_mpool); 2314 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2315 2316 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2317 ut_params->auth_xform.next = NULL; 2318 ut_params->cipher_xform.next = &ut_params->auth_xform; 2319 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2320 &ut_params->cipher_xform, 2321 ts_params->session_priv_mpool); 2322 2323 } else 2324 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2325 &ut_params->auth_xform, 2326 ts_params->session_priv_mpool); 2327 2328 if (status == -ENOTSUP) 2329 return status; 2330 2331 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2332 2333 return 0; 2334 } 2335 2336 static int 2337 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2338 unsigned int auth_tag_len, 2339 const uint8_t *iv, unsigned int iv_len, 2340 unsigned int data_pad_len, 2341 enum rte_crypto_auth_operation op, 2342 unsigned int auth_len, unsigned int auth_offset) 2343 { 2344 struct crypto_testsuite_params *ts_params = &testsuite_params; 2345 2346 struct crypto_unittest_params *ut_params = &unittest_params; 2347 2348 /* Generate Crypto op data structure */ 2349 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2350 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2351 TEST_ASSERT_NOT_NULL(ut_params->op, 2352 "Failed to allocate pktmbuf offload"); 2353 2354 /* Set crypto operation data parameters */ 2355 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2356 2357 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2358 2359 /* set crypto operation source mbuf */ 2360 sym_op->m_src = ut_params->ibuf; 2361 2362 /* iv */ 2363 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2364 iv, iv_len); 2365 /* digest */ 2366 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2367 ut_params->ibuf, auth_tag_len); 2368 2369 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2370 "no room to append auth tag"); 2371 ut_params->digest = sym_op->auth.digest.data; 2372 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2373 ut_params->ibuf, data_pad_len); 2374 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2375 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2376 else 2377 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2378 2379 debug_hexdump(stdout, "digest:", 2380 sym_op->auth.digest.data, 2381 auth_tag_len); 2382 2383 sym_op->auth.data.length = auth_len; 2384 sym_op->auth.data.offset = auth_offset; 2385 2386 return 0; 2387 } 2388 2389 static int 2390 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2391 enum rte_crypto_auth_operation op) 2392 { 2393 struct crypto_testsuite_params *ts_params = &testsuite_params; 2394 struct crypto_unittest_params *ut_params = &unittest_params; 2395 2396 const uint8_t *auth_tag = tdata->digest.data; 2397 const unsigned int auth_tag_len = tdata->digest.len; 2398 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2399 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2400 2401 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2402 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2403 const uint8_t *auth_iv = tdata->auth_iv.data; 2404 const uint8_t auth_iv_len = tdata->auth_iv.len; 2405 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2406 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2407 2408 /* Generate Crypto op data structure */ 2409 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2410 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2411 TEST_ASSERT_NOT_NULL(ut_params->op, 2412 "Failed to allocate pktmbuf offload"); 2413 /* Set crypto operation data parameters */ 2414 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2415 2416 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2417 2418 /* set crypto operation source mbuf */ 2419 sym_op->m_src = ut_params->ibuf; 2420 2421 /* digest */ 2422 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2423 ut_params->ibuf, auth_tag_len); 2424 2425 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2426 "no room to append auth tag"); 2427 ut_params->digest = sym_op->auth.digest.data; 2428 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2429 ut_params->ibuf, data_pad_len); 2430 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2431 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2432 else 2433 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2434 2435 debug_hexdump(stdout, "digest:", 2436 sym_op->auth.digest.data, 2437 auth_tag_len); 2438 2439 /* Copy cipher and auth IVs at the end of the crypto operation */ 2440 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2441 IV_OFFSET); 2442 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2443 iv_ptr += cipher_iv_len; 2444 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2445 2446 sym_op->cipher.data.length = cipher_len; 2447 sym_op->cipher.data.offset = 0; 2448 sym_op->auth.data.length = auth_len; 2449 sym_op->auth.data.offset = 0; 2450 2451 return 0; 2452 } 2453 2454 static int 2455 create_zuc_cipher_hash_generate_operation( 2456 const struct wireless_test_data *tdata) 2457 { 2458 return create_wireless_cipher_hash_operation(tdata, 2459 RTE_CRYPTO_AUTH_OP_GENERATE); 2460 } 2461 2462 static int 2463 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2464 const unsigned auth_tag_len, 2465 const uint8_t *auth_iv, uint8_t auth_iv_len, 2466 unsigned data_pad_len, 2467 enum rte_crypto_auth_operation op, 2468 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2469 const unsigned cipher_len, const unsigned cipher_offset, 2470 const unsigned auth_len, const unsigned auth_offset) 2471 { 2472 struct crypto_testsuite_params *ts_params = &testsuite_params; 2473 struct crypto_unittest_params *ut_params = &unittest_params; 2474 2475 enum rte_crypto_cipher_algorithm cipher_algo = 2476 ut_params->cipher_xform.cipher.algo; 2477 enum rte_crypto_auth_algorithm auth_algo = 2478 ut_params->auth_xform.auth.algo; 2479 2480 /* Generate Crypto op data structure */ 2481 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2482 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2483 TEST_ASSERT_NOT_NULL(ut_params->op, 2484 "Failed to allocate pktmbuf offload"); 2485 /* Set crypto operation data parameters */ 2486 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2487 2488 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2489 2490 /* set crypto operation source mbuf */ 2491 sym_op->m_src = ut_params->ibuf; 2492 2493 /* digest */ 2494 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2495 ut_params->ibuf, auth_tag_len); 2496 2497 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2498 "no room to append auth tag"); 2499 ut_params->digest = sym_op->auth.digest.data; 2500 2501 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2502 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2503 ut_params->ibuf, data_pad_len); 2504 } else { 2505 struct rte_mbuf *m = ut_params->ibuf; 2506 unsigned int offset = data_pad_len; 2507 2508 while (offset > m->data_len && m->next != NULL) { 2509 offset -= m->data_len; 2510 m = m->next; 2511 } 2512 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2513 m, offset); 2514 } 2515 2516 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2517 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2518 else 2519 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2520 2521 debug_hexdump(stdout, "digest:", 2522 sym_op->auth.digest.data, 2523 auth_tag_len); 2524 2525 /* Copy cipher and auth IVs at the end of the crypto operation */ 2526 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2527 IV_OFFSET); 2528 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2529 iv_ptr += cipher_iv_len; 2530 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2531 2532 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2533 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2534 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2535 sym_op->cipher.data.length = cipher_len; 2536 sym_op->cipher.data.offset = cipher_offset; 2537 } else { 2538 sym_op->cipher.data.length = cipher_len >> 3; 2539 sym_op->cipher.data.offset = cipher_offset >> 3; 2540 } 2541 2542 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2543 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2544 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2545 sym_op->auth.data.length = auth_len; 2546 sym_op->auth.data.offset = auth_offset; 2547 } else { 2548 sym_op->auth.data.length = auth_len >> 3; 2549 sym_op->auth.data.offset = auth_offset >> 3; 2550 } 2551 2552 return 0; 2553 } 2554 2555 static int 2556 create_wireless_algo_auth_cipher_operation( 2557 const uint8_t *auth_tag, unsigned int auth_tag_len, 2558 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2559 const uint8_t *auth_iv, uint8_t auth_iv_len, 2560 unsigned int data_pad_len, 2561 unsigned int cipher_len, unsigned int cipher_offset, 2562 unsigned int auth_len, unsigned int auth_offset, 2563 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2564 { 2565 struct crypto_testsuite_params *ts_params = &testsuite_params; 2566 struct crypto_unittest_params *ut_params = &unittest_params; 2567 2568 enum rte_crypto_cipher_algorithm cipher_algo = 2569 ut_params->cipher_xform.cipher.algo; 2570 enum rte_crypto_auth_algorithm auth_algo = 2571 ut_params->auth_xform.auth.algo; 2572 2573 /* Generate Crypto op data structure */ 2574 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2575 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2576 TEST_ASSERT_NOT_NULL(ut_params->op, 2577 "Failed to allocate pktmbuf offload"); 2578 2579 /* Set crypto operation data parameters */ 2580 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2581 2582 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2583 2584 /* set crypto operation mbufs */ 2585 sym_op->m_src = ut_params->ibuf; 2586 if (op_mode == OUT_OF_PLACE) 2587 sym_op->m_dst = ut_params->obuf; 2588 2589 /* digest */ 2590 if (!do_sgl) { 2591 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2592 (op_mode == IN_PLACE ? 2593 ut_params->ibuf : ut_params->obuf), 2594 uint8_t *, data_pad_len); 2595 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2596 (op_mode == IN_PLACE ? 2597 ut_params->ibuf : ut_params->obuf), 2598 data_pad_len); 2599 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2600 } else { 2601 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2602 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2603 sym_op->m_src : sym_op->m_dst); 2604 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2605 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2606 sgl_buf = sgl_buf->next; 2607 } 2608 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 2609 uint8_t *, remaining_off); 2610 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 2611 remaining_off); 2612 memset(sym_op->auth.digest.data, 0, remaining_off); 2613 while (sgl_buf->next != NULL) { 2614 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 2615 0, rte_pktmbuf_data_len(sgl_buf)); 2616 sgl_buf = sgl_buf->next; 2617 } 2618 } 2619 2620 /* Copy digest for the verification */ 2621 if (verify) 2622 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2623 2624 /* Copy cipher and auth IVs at the end of the crypto operation */ 2625 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 2626 ut_params->op, uint8_t *, IV_OFFSET); 2627 2628 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2629 iv_ptr += cipher_iv_len; 2630 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2631 2632 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2633 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2634 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2635 sym_op->cipher.data.length = cipher_len; 2636 sym_op->cipher.data.offset = cipher_offset; 2637 } else { 2638 sym_op->cipher.data.length = cipher_len >> 3; 2639 sym_op->cipher.data.offset = cipher_offset >> 3; 2640 } 2641 2642 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2643 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2644 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2645 sym_op->auth.data.length = auth_len; 2646 sym_op->auth.data.offset = auth_offset; 2647 } else { 2648 sym_op->auth.data.length = auth_len >> 3; 2649 sym_op->auth.data.offset = auth_offset >> 3; 2650 } 2651 2652 return 0; 2653 } 2654 2655 static int 2656 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2657 { 2658 struct crypto_testsuite_params *ts_params = &testsuite_params; 2659 struct crypto_unittest_params *ut_params = &unittest_params; 2660 2661 int retval; 2662 unsigned plaintext_pad_len; 2663 unsigned plaintext_len; 2664 uint8_t *plaintext; 2665 struct rte_cryptodev_info dev_info; 2666 2667 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2668 uint64_t feat_flags = dev_info.feature_flags; 2669 2670 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2671 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2672 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2673 return -ENOTSUP; 2674 } 2675 2676 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2677 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2678 printf("Device doesn't support RAW data-path APIs.\n"); 2679 return -ENOTSUP; 2680 } 2681 2682 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2683 return -ENOTSUP; 2684 2685 /* Verify the capabilities */ 2686 struct rte_cryptodev_sym_capability_idx cap_idx; 2687 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2688 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2689 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2690 &cap_idx) == NULL) 2691 return -ENOTSUP; 2692 2693 /* Create SNOW 3G session */ 2694 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2695 tdata->key.data, tdata->key.len, 2696 tdata->auth_iv.len, tdata->digest.len, 2697 RTE_CRYPTO_AUTH_OP_GENERATE, 2698 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2699 if (retval < 0) 2700 return retval; 2701 2702 /* alloc mbuf and set payload */ 2703 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2704 2705 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2706 rte_pktmbuf_tailroom(ut_params->ibuf)); 2707 2708 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2709 /* Append data which is padded to a multiple of */ 2710 /* the algorithms block size */ 2711 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2712 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2713 plaintext_pad_len); 2714 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2715 2716 /* Create SNOW 3G operation */ 2717 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2718 tdata->auth_iv.data, tdata->auth_iv.len, 2719 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2720 tdata->validAuthLenInBits.len, 2721 0); 2722 if (retval < 0) 2723 return retval; 2724 2725 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2726 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2727 ut_params->op, 0, 1, 1, 0); 2728 else 2729 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2730 ut_params->op); 2731 ut_params->obuf = ut_params->op->sym->m_src; 2732 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2733 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2734 + plaintext_pad_len; 2735 2736 /* Validate obuf */ 2737 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2738 ut_params->digest, 2739 tdata->digest.data, 2740 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2741 "SNOW 3G Generated auth tag not as expected"); 2742 2743 return 0; 2744 } 2745 2746 static int 2747 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2748 { 2749 struct crypto_testsuite_params *ts_params = &testsuite_params; 2750 struct crypto_unittest_params *ut_params = &unittest_params; 2751 2752 int retval; 2753 unsigned plaintext_pad_len; 2754 unsigned plaintext_len; 2755 uint8_t *plaintext; 2756 struct rte_cryptodev_info dev_info; 2757 2758 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2759 uint64_t feat_flags = dev_info.feature_flags; 2760 2761 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2762 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2763 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2764 return -ENOTSUP; 2765 } 2766 2767 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2768 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2769 printf("Device doesn't support RAW data-path APIs.\n"); 2770 return -ENOTSUP; 2771 } 2772 2773 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2774 return -ENOTSUP; 2775 2776 /* Verify the capabilities */ 2777 struct rte_cryptodev_sym_capability_idx cap_idx; 2778 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2779 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2780 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2781 &cap_idx) == NULL) 2782 return -ENOTSUP; 2783 2784 /* Create SNOW 3G session */ 2785 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2786 tdata->key.data, tdata->key.len, 2787 tdata->auth_iv.len, tdata->digest.len, 2788 RTE_CRYPTO_AUTH_OP_VERIFY, 2789 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2790 if (retval < 0) 2791 return retval; 2792 /* alloc mbuf and set payload */ 2793 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2794 2795 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2796 rte_pktmbuf_tailroom(ut_params->ibuf)); 2797 2798 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2799 /* Append data which is padded to a multiple of */ 2800 /* the algorithms block size */ 2801 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2802 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2803 plaintext_pad_len); 2804 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2805 2806 /* Create SNOW 3G operation */ 2807 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2808 tdata->digest.len, 2809 tdata->auth_iv.data, tdata->auth_iv.len, 2810 plaintext_pad_len, 2811 RTE_CRYPTO_AUTH_OP_VERIFY, 2812 tdata->validAuthLenInBits.len, 2813 0); 2814 if (retval < 0) 2815 return retval; 2816 2817 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2818 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2819 ut_params->op, 0, 1, 1, 0); 2820 else 2821 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2822 ut_params->op); 2823 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2824 ut_params->obuf = ut_params->op->sym->m_src; 2825 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2826 + plaintext_pad_len; 2827 2828 /* Validate obuf */ 2829 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2830 return 0; 2831 else 2832 return -1; 2833 2834 return 0; 2835 } 2836 2837 static int 2838 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2839 { 2840 struct crypto_testsuite_params *ts_params = &testsuite_params; 2841 struct crypto_unittest_params *ut_params = &unittest_params; 2842 2843 int retval; 2844 unsigned plaintext_pad_len; 2845 unsigned plaintext_len; 2846 uint8_t *plaintext; 2847 struct rte_cryptodev_info dev_info; 2848 2849 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2850 uint64_t feat_flags = dev_info.feature_flags; 2851 2852 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2853 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2854 printf("Device doesn't support RAW data-path APIs.\n"); 2855 return -ENOTSUP; 2856 } 2857 2858 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2859 return -ENOTSUP; 2860 2861 /* Verify the capabilities */ 2862 struct rte_cryptodev_sym_capability_idx cap_idx; 2863 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2864 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2865 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2866 &cap_idx) == NULL) 2867 return -ENOTSUP; 2868 2869 /* Create KASUMI session */ 2870 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2871 tdata->key.data, tdata->key.len, 2872 0, tdata->digest.len, 2873 RTE_CRYPTO_AUTH_OP_GENERATE, 2874 RTE_CRYPTO_AUTH_KASUMI_F9); 2875 if (retval < 0) 2876 return retval; 2877 2878 /* alloc mbuf and set payload */ 2879 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2880 2881 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2882 rte_pktmbuf_tailroom(ut_params->ibuf)); 2883 2884 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2885 /* Append data which is padded to a multiple of */ 2886 /* the algorithms block size */ 2887 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2888 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2889 plaintext_pad_len); 2890 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2891 2892 /* Create KASUMI operation */ 2893 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2894 NULL, 0, 2895 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2896 tdata->plaintext.len, 2897 0); 2898 if (retval < 0) 2899 return retval; 2900 2901 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2902 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2903 ut_params->op); 2904 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2905 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2906 ut_params->op, 0, 1, 1, 0); 2907 else 2908 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2909 ut_params->op); 2910 2911 ut_params->obuf = ut_params->op->sym->m_src; 2912 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2913 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2914 + plaintext_pad_len; 2915 2916 /* Validate obuf */ 2917 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2918 ut_params->digest, 2919 tdata->digest.data, 2920 DIGEST_BYTE_LENGTH_KASUMI_F9, 2921 "KASUMI Generated auth tag not as expected"); 2922 2923 return 0; 2924 } 2925 2926 static int 2927 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2928 { 2929 struct crypto_testsuite_params *ts_params = &testsuite_params; 2930 struct crypto_unittest_params *ut_params = &unittest_params; 2931 2932 int retval; 2933 unsigned plaintext_pad_len; 2934 unsigned plaintext_len; 2935 uint8_t *plaintext; 2936 struct rte_cryptodev_info dev_info; 2937 2938 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2939 uint64_t feat_flags = dev_info.feature_flags; 2940 2941 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2942 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2943 printf("Device doesn't support RAW data-path APIs.\n"); 2944 return -ENOTSUP; 2945 } 2946 2947 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2948 return -ENOTSUP; 2949 2950 /* Verify the capabilities */ 2951 struct rte_cryptodev_sym_capability_idx cap_idx; 2952 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2953 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2954 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2955 &cap_idx) == NULL) 2956 return -ENOTSUP; 2957 2958 /* Create KASUMI session */ 2959 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2960 tdata->key.data, tdata->key.len, 2961 0, tdata->digest.len, 2962 RTE_CRYPTO_AUTH_OP_VERIFY, 2963 RTE_CRYPTO_AUTH_KASUMI_F9); 2964 if (retval < 0) 2965 return retval; 2966 /* alloc mbuf and set payload */ 2967 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2968 2969 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2970 rte_pktmbuf_tailroom(ut_params->ibuf)); 2971 2972 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2973 /* Append data which is padded to a multiple */ 2974 /* of the algorithms block size */ 2975 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2976 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2977 plaintext_pad_len); 2978 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2979 2980 /* Create KASUMI operation */ 2981 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2982 tdata->digest.len, 2983 NULL, 0, 2984 plaintext_pad_len, 2985 RTE_CRYPTO_AUTH_OP_VERIFY, 2986 tdata->plaintext.len, 2987 0); 2988 if (retval < 0) 2989 return retval; 2990 2991 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2992 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2993 ut_params->op, 0, 1, 1, 0); 2994 else 2995 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2996 ut_params->op); 2997 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2998 ut_params->obuf = ut_params->op->sym->m_src; 2999 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3000 + plaintext_pad_len; 3001 3002 /* Validate obuf */ 3003 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3004 return 0; 3005 else 3006 return -1; 3007 3008 return 0; 3009 } 3010 3011 static int 3012 test_snow3g_hash_generate_test_case_1(void) 3013 { 3014 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3015 } 3016 3017 static int 3018 test_snow3g_hash_generate_test_case_2(void) 3019 { 3020 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3021 } 3022 3023 static int 3024 test_snow3g_hash_generate_test_case_3(void) 3025 { 3026 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3027 } 3028 3029 static int 3030 test_snow3g_hash_generate_test_case_4(void) 3031 { 3032 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3033 } 3034 3035 static int 3036 test_snow3g_hash_generate_test_case_5(void) 3037 { 3038 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3039 } 3040 3041 static int 3042 test_snow3g_hash_generate_test_case_6(void) 3043 { 3044 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3045 } 3046 3047 static int 3048 test_snow3g_hash_verify_test_case_1(void) 3049 { 3050 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3051 3052 } 3053 3054 static int 3055 test_snow3g_hash_verify_test_case_2(void) 3056 { 3057 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3058 } 3059 3060 static int 3061 test_snow3g_hash_verify_test_case_3(void) 3062 { 3063 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3064 } 3065 3066 static int 3067 test_snow3g_hash_verify_test_case_4(void) 3068 { 3069 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3070 } 3071 3072 static int 3073 test_snow3g_hash_verify_test_case_5(void) 3074 { 3075 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3076 } 3077 3078 static int 3079 test_snow3g_hash_verify_test_case_6(void) 3080 { 3081 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3082 } 3083 3084 static int 3085 test_kasumi_hash_generate_test_case_1(void) 3086 { 3087 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3088 } 3089 3090 static int 3091 test_kasumi_hash_generate_test_case_2(void) 3092 { 3093 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3094 } 3095 3096 static int 3097 test_kasumi_hash_generate_test_case_3(void) 3098 { 3099 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3100 } 3101 3102 static int 3103 test_kasumi_hash_generate_test_case_4(void) 3104 { 3105 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3106 } 3107 3108 static int 3109 test_kasumi_hash_generate_test_case_5(void) 3110 { 3111 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3112 } 3113 3114 static int 3115 test_kasumi_hash_generate_test_case_6(void) 3116 { 3117 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3118 } 3119 3120 static int 3121 test_kasumi_hash_verify_test_case_1(void) 3122 { 3123 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3124 } 3125 3126 static int 3127 test_kasumi_hash_verify_test_case_2(void) 3128 { 3129 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3130 } 3131 3132 static int 3133 test_kasumi_hash_verify_test_case_3(void) 3134 { 3135 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3136 } 3137 3138 static int 3139 test_kasumi_hash_verify_test_case_4(void) 3140 { 3141 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3142 } 3143 3144 static int 3145 test_kasumi_hash_verify_test_case_5(void) 3146 { 3147 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3148 } 3149 3150 static int 3151 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3152 { 3153 struct crypto_testsuite_params *ts_params = &testsuite_params; 3154 struct crypto_unittest_params *ut_params = &unittest_params; 3155 3156 int retval; 3157 uint8_t *plaintext, *ciphertext; 3158 unsigned plaintext_pad_len; 3159 unsigned plaintext_len; 3160 struct rte_cryptodev_info dev_info; 3161 3162 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3163 uint64_t feat_flags = dev_info.feature_flags; 3164 3165 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3166 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3167 printf("Device doesn't support RAW data-path APIs.\n"); 3168 return -ENOTSUP; 3169 } 3170 3171 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3172 return -ENOTSUP; 3173 3174 /* Verify the capabilities */ 3175 struct rte_cryptodev_sym_capability_idx cap_idx; 3176 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3177 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3178 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3179 &cap_idx) == NULL) 3180 return -ENOTSUP; 3181 3182 /* Create KASUMI session */ 3183 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3184 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3185 RTE_CRYPTO_CIPHER_KASUMI_F8, 3186 tdata->key.data, tdata->key.len, 3187 tdata->cipher_iv.len); 3188 if (retval < 0) 3189 return retval; 3190 3191 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3192 3193 /* Clear mbuf payload */ 3194 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3195 rte_pktmbuf_tailroom(ut_params->ibuf)); 3196 3197 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3198 /* Append data which is padded to a multiple */ 3199 /* of the algorithms block size */ 3200 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3201 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3202 plaintext_pad_len); 3203 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3204 3205 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3206 3207 /* Create KASUMI operation */ 3208 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3209 tdata->cipher_iv.len, 3210 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3211 tdata->validCipherOffsetInBits.len); 3212 if (retval < 0) 3213 return retval; 3214 3215 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3216 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3217 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3218 else 3219 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3220 ut_params->op); 3221 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3222 3223 ut_params->obuf = ut_params->op->sym->m_dst; 3224 if (ut_params->obuf) 3225 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3226 else 3227 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3228 3229 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3230 3231 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3232 (tdata->validCipherOffsetInBits.len >> 3); 3233 /* Validate obuf */ 3234 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3235 ciphertext, 3236 reference_ciphertext, 3237 tdata->validCipherLenInBits.len, 3238 "KASUMI Ciphertext data not as expected"); 3239 return 0; 3240 } 3241 3242 static int 3243 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3244 { 3245 struct crypto_testsuite_params *ts_params = &testsuite_params; 3246 struct crypto_unittest_params *ut_params = &unittest_params; 3247 3248 int retval; 3249 3250 unsigned int plaintext_pad_len; 3251 unsigned int plaintext_len; 3252 3253 uint8_t buffer[10000]; 3254 const uint8_t *ciphertext; 3255 3256 struct rte_cryptodev_info dev_info; 3257 3258 /* Verify the capabilities */ 3259 struct rte_cryptodev_sym_capability_idx cap_idx; 3260 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3261 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3262 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3263 &cap_idx) == NULL) 3264 return -ENOTSUP; 3265 3266 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3267 3268 uint64_t feat_flags = dev_info.feature_flags; 3269 3270 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3271 printf("Device doesn't support in-place scatter-gather. " 3272 "Test Skipped.\n"); 3273 return -ENOTSUP; 3274 } 3275 3276 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3277 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3278 printf("Device doesn't support RAW data-path APIs.\n"); 3279 return -ENOTSUP; 3280 } 3281 3282 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3283 return -ENOTSUP; 3284 3285 /* Create KASUMI session */ 3286 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3287 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3288 RTE_CRYPTO_CIPHER_KASUMI_F8, 3289 tdata->key.data, tdata->key.len, 3290 tdata->cipher_iv.len); 3291 if (retval < 0) 3292 return retval; 3293 3294 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3295 3296 3297 /* Append data which is padded to a multiple */ 3298 /* of the algorithms block size */ 3299 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3300 3301 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3302 plaintext_pad_len, 10, 0); 3303 3304 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3305 3306 /* Create KASUMI operation */ 3307 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3308 tdata->cipher_iv.len, 3309 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3310 tdata->validCipherOffsetInBits.len); 3311 if (retval < 0) 3312 return retval; 3313 3314 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3315 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3316 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3317 else 3318 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3319 ut_params->op); 3320 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3321 3322 ut_params->obuf = ut_params->op->sym->m_dst; 3323 3324 if (ut_params->obuf) 3325 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3326 plaintext_len, buffer); 3327 else 3328 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3329 tdata->validCipherOffsetInBits.len >> 3, 3330 plaintext_len, buffer); 3331 3332 /* Validate obuf */ 3333 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3334 3335 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3336 (tdata->validCipherOffsetInBits.len >> 3); 3337 /* Validate obuf */ 3338 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3339 ciphertext, 3340 reference_ciphertext, 3341 tdata->validCipherLenInBits.len, 3342 "KASUMI Ciphertext data not as expected"); 3343 return 0; 3344 } 3345 3346 static int 3347 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3348 { 3349 struct crypto_testsuite_params *ts_params = &testsuite_params; 3350 struct crypto_unittest_params *ut_params = &unittest_params; 3351 3352 int retval; 3353 uint8_t *plaintext, *ciphertext; 3354 unsigned plaintext_pad_len; 3355 unsigned plaintext_len; 3356 3357 /* Verify the capabilities */ 3358 struct rte_cryptodev_sym_capability_idx cap_idx; 3359 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3360 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3361 /* Data-path service does not support OOP */ 3362 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3363 &cap_idx) == NULL) 3364 return -ENOTSUP; 3365 3366 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3367 return -ENOTSUP; 3368 3369 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3370 return -ENOTSUP; 3371 3372 /* Create KASUMI session */ 3373 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3374 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3375 RTE_CRYPTO_CIPHER_KASUMI_F8, 3376 tdata->key.data, tdata->key.len, 3377 tdata->cipher_iv.len); 3378 if (retval < 0) 3379 return retval; 3380 3381 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3382 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3383 3384 /* Clear mbuf payload */ 3385 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3386 rte_pktmbuf_tailroom(ut_params->ibuf)); 3387 3388 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3389 /* Append data which is padded to a multiple */ 3390 /* of the algorithms block size */ 3391 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3392 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3393 plaintext_pad_len); 3394 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3395 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3396 3397 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3398 3399 /* Create KASUMI operation */ 3400 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3401 tdata->cipher_iv.len, 3402 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3403 tdata->validCipherOffsetInBits.len); 3404 if (retval < 0) 3405 return retval; 3406 3407 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3408 ut_params->op); 3409 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3410 3411 ut_params->obuf = ut_params->op->sym->m_dst; 3412 if (ut_params->obuf) 3413 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3414 else 3415 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3416 3417 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3418 3419 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3420 (tdata->validCipherOffsetInBits.len >> 3); 3421 /* Validate obuf */ 3422 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3423 ciphertext, 3424 reference_ciphertext, 3425 tdata->validCipherLenInBits.len, 3426 "KASUMI Ciphertext data not as expected"); 3427 return 0; 3428 } 3429 3430 static int 3431 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3432 { 3433 struct crypto_testsuite_params *ts_params = &testsuite_params; 3434 struct crypto_unittest_params *ut_params = &unittest_params; 3435 3436 int retval; 3437 unsigned int plaintext_pad_len; 3438 unsigned int plaintext_len; 3439 3440 const uint8_t *ciphertext; 3441 uint8_t buffer[2048]; 3442 3443 struct rte_cryptodev_info dev_info; 3444 3445 /* Verify the capabilities */ 3446 struct rte_cryptodev_sym_capability_idx cap_idx; 3447 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3448 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3449 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3450 &cap_idx) == NULL) 3451 return -ENOTSUP; 3452 3453 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3454 return -ENOTSUP; 3455 3456 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3457 return -ENOTSUP; 3458 3459 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3460 3461 uint64_t feat_flags = dev_info.feature_flags; 3462 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3463 printf("Device doesn't support out-of-place scatter-gather " 3464 "in both input and output mbufs. " 3465 "Test Skipped.\n"); 3466 return -ENOTSUP; 3467 } 3468 3469 /* Create KASUMI session */ 3470 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3471 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3472 RTE_CRYPTO_CIPHER_KASUMI_F8, 3473 tdata->key.data, tdata->key.len, 3474 tdata->cipher_iv.len); 3475 if (retval < 0) 3476 return retval; 3477 3478 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3479 /* Append data which is padded to a multiple */ 3480 /* of the algorithms block size */ 3481 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3482 3483 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3484 plaintext_pad_len, 10, 0); 3485 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3486 plaintext_pad_len, 3, 0); 3487 3488 /* Append data which is padded to a multiple */ 3489 /* of the algorithms block size */ 3490 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3491 3492 /* Create KASUMI operation */ 3493 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3494 tdata->cipher_iv.len, 3495 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3496 tdata->validCipherOffsetInBits.len); 3497 if (retval < 0) 3498 return retval; 3499 3500 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3501 ut_params->op); 3502 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3503 3504 ut_params->obuf = ut_params->op->sym->m_dst; 3505 if (ut_params->obuf) 3506 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3507 plaintext_pad_len, buffer); 3508 else 3509 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3510 tdata->validCipherOffsetInBits.len >> 3, 3511 plaintext_pad_len, buffer); 3512 3513 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3514 (tdata->validCipherOffsetInBits.len >> 3); 3515 /* Validate obuf */ 3516 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3517 ciphertext, 3518 reference_ciphertext, 3519 tdata->validCipherLenInBits.len, 3520 "KASUMI Ciphertext data not as expected"); 3521 return 0; 3522 } 3523 3524 3525 static int 3526 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3527 { 3528 struct crypto_testsuite_params *ts_params = &testsuite_params; 3529 struct crypto_unittest_params *ut_params = &unittest_params; 3530 3531 int retval; 3532 uint8_t *ciphertext, *plaintext; 3533 unsigned ciphertext_pad_len; 3534 unsigned ciphertext_len; 3535 3536 /* Verify the capabilities */ 3537 struct rte_cryptodev_sym_capability_idx cap_idx; 3538 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3539 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3540 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3541 &cap_idx) == NULL) 3542 return -ENOTSUP; 3543 3544 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3545 return -ENOTSUP; 3546 3547 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3548 return -ENOTSUP; 3549 3550 /* Create KASUMI session */ 3551 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3552 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3553 RTE_CRYPTO_CIPHER_KASUMI_F8, 3554 tdata->key.data, tdata->key.len, 3555 tdata->cipher_iv.len); 3556 if (retval < 0) 3557 return retval; 3558 3559 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3560 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3561 3562 /* Clear mbuf payload */ 3563 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3564 rte_pktmbuf_tailroom(ut_params->ibuf)); 3565 3566 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3567 /* Append data which is padded to a multiple */ 3568 /* of the algorithms block size */ 3569 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3570 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3571 ciphertext_pad_len); 3572 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3573 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3574 3575 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3576 3577 /* Create KASUMI operation */ 3578 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3579 tdata->cipher_iv.len, 3580 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3581 tdata->validCipherOffsetInBits.len); 3582 if (retval < 0) 3583 return retval; 3584 3585 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3586 ut_params->op); 3587 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3588 3589 ut_params->obuf = ut_params->op->sym->m_dst; 3590 if (ut_params->obuf) 3591 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3592 else 3593 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3594 3595 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3596 3597 const uint8_t *reference_plaintext = tdata->plaintext.data + 3598 (tdata->validCipherOffsetInBits.len >> 3); 3599 /* Validate obuf */ 3600 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3601 plaintext, 3602 reference_plaintext, 3603 tdata->validCipherLenInBits.len, 3604 "KASUMI Plaintext data not as expected"); 3605 return 0; 3606 } 3607 3608 static int 3609 test_kasumi_decryption(const struct kasumi_test_data *tdata) 3610 { 3611 struct crypto_testsuite_params *ts_params = &testsuite_params; 3612 struct crypto_unittest_params *ut_params = &unittest_params; 3613 3614 int retval; 3615 uint8_t *ciphertext, *plaintext; 3616 unsigned ciphertext_pad_len; 3617 unsigned ciphertext_len; 3618 struct rte_cryptodev_info dev_info; 3619 3620 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3621 uint64_t feat_flags = dev_info.feature_flags; 3622 3623 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3624 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3625 printf("Device doesn't support RAW data-path APIs.\n"); 3626 return -ENOTSUP; 3627 } 3628 3629 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3630 return -ENOTSUP; 3631 3632 /* Verify the capabilities */ 3633 struct rte_cryptodev_sym_capability_idx cap_idx; 3634 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3635 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3636 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3637 &cap_idx) == NULL) 3638 return -ENOTSUP; 3639 3640 /* Create KASUMI session */ 3641 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3642 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3643 RTE_CRYPTO_CIPHER_KASUMI_F8, 3644 tdata->key.data, tdata->key.len, 3645 tdata->cipher_iv.len); 3646 if (retval < 0) 3647 return retval; 3648 3649 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3650 3651 /* Clear mbuf payload */ 3652 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3653 rte_pktmbuf_tailroom(ut_params->ibuf)); 3654 3655 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3656 /* Append data which is padded to a multiple */ 3657 /* of the algorithms block size */ 3658 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3659 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3660 ciphertext_pad_len); 3661 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3662 3663 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3664 3665 /* Create KASUMI operation */ 3666 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3667 tdata->cipher_iv.len, 3668 tdata->ciphertext.len, 3669 tdata->validCipherOffsetInBits.len); 3670 if (retval < 0) 3671 return retval; 3672 3673 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3674 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3675 ut_params->op, 1, 0, 1, 0); 3676 else 3677 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3678 ut_params->op); 3679 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3680 3681 ut_params->obuf = ut_params->op->sym->m_dst; 3682 if (ut_params->obuf) 3683 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3684 else 3685 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3686 3687 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3688 3689 const uint8_t *reference_plaintext = tdata->plaintext.data + 3690 (tdata->validCipherOffsetInBits.len >> 3); 3691 /* Validate obuf */ 3692 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3693 plaintext, 3694 reference_plaintext, 3695 tdata->validCipherLenInBits.len, 3696 "KASUMI Plaintext data not as expected"); 3697 return 0; 3698 } 3699 3700 static int 3701 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3702 { 3703 struct crypto_testsuite_params *ts_params = &testsuite_params; 3704 struct crypto_unittest_params *ut_params = &unittest_params; 3705 3706 int retval; 3707 uint8_t *plaintext, *ciphertext; 3708 unsigned plaintext_pad_len; 3709 unsigned plaintext_len; 3710 struct rte_cryptodev_info dev_info; 3711 3712 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3713 uint64_t feat_flags = dev_info.feature_flags; 3714 3715 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3716 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3717 printf("Device doesn't support RAW data-path APIs.\n"); 3718 return -ENOTSUP; 3719 } 3720 3721 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3722 return -ENOTSUP; 3723 3724 /* Verify the capabilities */ 3725 struct rte_cryptodev_sym_capability_idx cap_idx; 3726 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3727 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3728 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3729 &cap_idx) == NULL) 3730 return -ENOTSUP; 3731 3732 /* Create SNOW 3G session */ 3733 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3734 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3735 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3736 tdata->key.data, tdata->key.len, 3737 tdata->cipher_iv.len); 3738 if (retval < 0) 3739 return retval; 3740 3741 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3742 3743 /* Clear mbuf payload */ 3744 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3745 rte_pktmbuf_tailroom(ut_params->ibuf)); 3746 3747 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3748 /* Append data which is padded to a multiple of */ 3749 /* the algorithms block size */ 3750 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3751 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3752 plaintext_pad_len); 3753 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3754 3755 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3756 3757 /* Create SNOW 3G operation */ 3758 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3759 tdata->cipher_iv.len, 3760 tdata->validCipherLenInBits.len, 3761 0); 3762 if (retval < 0) 3763 return retval; 3764 3765 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3766 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3767 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3768 else 3769 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3770 ut_params->op); 3771 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3772 3773 ut_params->obuf = ut_params->op->sym->m_dst; 3774 if (ut_params->obuf) 3775 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3776 else 3777 ciphertext = plaintext; 3778 3779 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3780 3781 /* Validate obuf */ 3782 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3783 ciphertext, 3784 tdata->ciphertext.data, 3785 tdata->validDataLenInBits.len, 3786 "SNOW 3G Ciphertext data not as expected"); 3787 return 0; 3788 } 3789 3790 3791 static int 3792 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3793 { 3794 struct crypto_testsuite_params *ts_params = &testsuite_params; 3795 struct crypto_unittest_params *ut_params = &unittest_params; 3796 uint8_t *plaintext, *ciphertext; 3797 3798 int retval; 3799 unsigned plaintext_pad_len; 3800 unsigned plaintext_len; 3801 3802 /* Verify the capabilities */ 3803 struct rte_cryptodev_sym_capability_idx cap_idx; 3804 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3805 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3806 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3807 &cap_idx) == NULL) 3808 return -ENOTSUP; 3809 3810 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3811 return -ENOTSUP; 3812 3813 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3814 return -ENOTSUP; 3815 3816 /* Create SNOW 3G session */ 3817 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3818 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3819 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3820 tdata->key.data, tdata->key.len, 3821 tdata->cipher_iv.len); 3822 if (retval < 0) 3823 return retval; 3824 3825 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3826 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3827 3828 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3829 "Failed to allocate input buffer in mempool"); 3830 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3831 "Failed to allocate output buffer in mempool"); 3832 3833 /* Clear mbuf payload */ 3834 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3835 rte_pktmbuf_tailroom(ut_params->ibuf)); 3836 3837 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3838 /* Append data which is padded to a multiple of */ 3839 /* the algorithms block size */ 3840 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3841 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3842 plaintext_pad_len); 3843 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3844 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3845 3846 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3847 3848 /* Create SNOW 3G operation */ 3849 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3850 tdata->cipher_iv.len, 3851 tdata->validCipherLenInBits.len, 3852 0); 3853 if (retval < 0) 3854 return retval; 3855 3856 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3857 ut_params->op); 3858 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3859 3860 ut_params->obuf = ut_params->op->sym->m_dst; 3861 if (ut_params->obuf) 3862 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3863 else 3864 ciphertext = plaintext; 3865 3866 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3867 3868 /* Validate obuf */ 3869 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3870 ciphertext, 3871 tdata->ciphertext.data, 3872 tdata->validDataLenInBits.len, 3873 "SNOW 3G Ciphertext data not as expected"); 3874 return 0; 3875 } 3876 3877 static int 3878 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3879 { 3880 struct crypto_testsuite_params *ts_params = &testsuite_params; 3881 struct crypto_unittest_params *ut_params = &unittest_params; 3882 3883 int retval; 3884 unsigned int plaintext_pad_len; 3885 unsigned int plaintext_len; 3886 uint8_t buffer[10000]; 3887 const uint8_t *ciphertext; 3888 3889 struct rte_cryptodev_info dev_info; 3890 3891 /* Verify the capabilities */ 3892 struct rte_cryptodev_sym_capability_idx cap_idx; 3893 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3894 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3895 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3896 &cap_idx) == NULL) 3897 return -ENOTSUP; 3898 3899 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3900 return -ENOTSUP; 3901 3902 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3903 return -ENOTSUP; 3904 3905 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3906 3907 uint64_t feat_flags = dev_info.feature_flags; 3908 3909 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3910 printf("Device doesn't support out-of-place scatter-gather " 3911 "in both input and output mbufs. " 3912 "Test Skipped.\n"); 3913 return -ENOTSUP; 3914 } 3915 3916 /* Create SNOW 3G session */ 3917 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3918 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3919 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3920 tdata->key.data, tdata->key.len, 3921 tdata->cipher_iv.len); 3922 if (retval < 0) 3923 return retval; 3924 3925 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3926 /* Append data which is padded to a multiple of */ 3927 /* the algorithms block size */ 3928 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3929 3930 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3931 plaintext_pad_len, 10, 0); 3932 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3933 plaintext_pad_len, 3, 0); 3934 3935 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3936 "Failed to allocate input buffer in mempool"); 3937 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3938 "Failed to allocate output buffer in mempool"); 3939 3940 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3941 3942 /* Create SNOW 3G operation */ 3943 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3944 tdata->cipher_iv.len, 3945 tdata->validCipherLenInBits.len, 3946 0); 3947 if (retval < 0) 3948 return retval; 3949 3950 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3951 ut_params->op); 3952 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3953 3954 ut_params->obuf = ut_params->op->sym->m_dst; 3955 if (ut_params->obuf) 3956 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3957 plaintext_len, buffer); 3958 else 3959 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 3960 plaintext_len, buffer); 3961 3962 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3963 3964 /* Validate obuf */ 3965 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3966 ciphertext, 3967 tdata->ciphertext.data, 3968 tdata->validDataLenInBits.len, 3969 "SNOW 3G Ciphertext data not as expected"); 3970 3971 return 0; 3972 } 3973 3974 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3975 static void 3976 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3977 { 3978 uint8_t curr_byte, prev_byte; 3979 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3980 uint8_t lower_byte_mask = (1 << offset) - 1; 3981 unsigned i; 3982 3983 prev_byte = buffer[0]; 3984 buffer[0] >>= offset; 3985 3986 for (i = 1; i < length_in_bytes; i++) { 3987 curr_byte = buffer[i]; 3988 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 3989 (curr_byte >> offset); 3990 prev_byte = curr_byte; 3991 } 3992 } 3993 3994 static int 3995 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 3996 { 3997 struct crypto_testsuite_params *ts_params = &testsuite_params; 3998 struct crypto_unittest_params *ut_params = &unittest_params; 3999 uint8_t *plaintext, *ciphertext; 4000 int retval; 4001 uint32_t plaintext_len; 4002 uint32_t plaintext_pad_len; 4003 uint8_t extra_offset = 4; 4004 uint8_t *expected_ciphertext_shifted; 4005 struct rte_cryptodev_info dev_info; 4006 4007 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4008 uint64_t feat_flags = dev_info.feature_flags; 4009 4010 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4011 ((tdata->validDataLenInBits.len % 8) != 0)) { 4012 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4013 return -ENOTSUP; 4014 } 4015 4016 /* Verify the capabilities */ 4017 struct rte_cryptodev_sym_capability_idx cap_idx; 4018 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4019 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4020 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4021 &cap_idx) == NULL) 4022 return -ENOTSUP; 4023 4024 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4025 return -ENOTSUP; 4026 4027 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4028 return -ENOTSUP; 4029 4030 /* Create SNOW 3G session */ 4031 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4032 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4033 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4034 tdata->key.data, tdata->key.len, 4035 tdata->cipher_iv.len); 4036 if (retval < 0) 4037 return retval; 4038 4039 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4040 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4041 4042 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4043 "Failed to allocate input buffer in mempool"); 4044 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4045 "Failed to allocate output buffer in mempool"); 4046 4047 /* Clear mbuf payload */ 4048 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4049 rte_pktmbuf_tailroom(ut_params->ibuf)); 4050 4051 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4052 /* 4053 * Append data which is padded to a 4054 * multiple of the algorithms block size 4055 */ 4056 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4057 4058 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4059 plaintext_pad_len); 4060 4061 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4062 4063 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4064 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4065 4066 #ifdef RTE_APP_TEST_DEBUG 4067 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4068 #endif 4069 /* Create SNOW 3G operation */ 4070 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4071 tdata->cipher_iv.len, 4072 tdata->validCipherLenInBits.len, 4073 extra_offset); 4074 if (retval < 0) 4075 return retval; 4076 4077 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4078 ut_params->op); 4079 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4080 4081 ut_params->obuf = ut_params->op->sym->m_dst; 4082 if (ut_params->obuf) 4083 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4084 else 4085 ciphertext = plaintext; 4086 4087 #ifdef RTE_APP_TEST_DEBUG 4088 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4089 #endif 4090 4091 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4092 4093 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4094 "failed to reserve memory for ciphertext shifted\n"); 4095 4096 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4097 ceil_byte_length(tdata->ciphertext.len)); 4098 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4099 extra_offset); 4100 /* Validate obuf */ 4101 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4102 ciphertext, 4103 expected_ciphertext_shifted, 4104 tdata->validDataLenInBits.len, 4105 extra_offset, 4106 "SNOW 3G Ciphertext data not as expected"); 4107 return 0; 4108 } 4109 4110 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4111 { 4112 struct crypto_testsuite_params *ts_params = &testsuite_params; 4113 struct crypto_unittest_params *ut_params = &unittest_params; 4114 4115 int retval; 4116 4117 uint8_t *plaintext, *ciphertext; 4118 unsigned ciphertext_pad_len; 4119 unsigned ciphertext_len; 4120 struct rte_cryptodev_info dev_info; 4121 4122 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4123 uint64_t feat_flags = dev_info.feature_flags; 4124 4125 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4126 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4127 printf("Device doesn't support RAW data-path APIs.\n"); 4128 return -ENOTSUP; 4129 } 4130 4131 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4132 return -ENOTSUP; 4133 4134 /* Verify the capabilities */ 4135 struct rte_cryptodev_sym_capability_idx cap_idx; 4136 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4137 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4138 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4139 &cap_idx) == NULL) 4140 return -ENOTSUP; 4141 4142 /* Create SNOW 3G session */ 4143 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4144 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4145 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4146 tdata->key.data, tdata->key.len, 4147 tdata->cipher_iv.len); 4148 if (retval < 0) 4149 return retval; 4150 4151 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4152 4153 /* Clear mbuf payload */ 4154 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4155 rte_pktmbuf_tailroom(ut_params->ibuf)); 4156 4157 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4158 /* Append data which is padded to a multiple of */ 4159 /* the algorithms block size */ 4160 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4161 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4162 ciphertext_pad_len); 4163 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4164 4165 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4166 4167 /* Create SNOW 3G operation */ 4168 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4169 tdata->cipher_iv.len, 4170 tdata->validCipherLenInBits.len, 4171 tdata->cipher.offset_bits); 4172 if (retval < 0) 4173 return retval; 4174 4175 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4176 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4177 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4178 else 4179 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4180 ut_params->op); 4181 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4182 ut_params->obuf = ut_params->op->sym->m_dst; 4183 if (ut_params->obuf) 4184 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4185 else 4186 plaintext = ciphertext; 4187 4188 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4189 4190 /* Validate obuf */ 4191 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4192 tdata->plaintext.data, 4193 tdata->validDataLenInBits.len, 4194 "SNOW 3G Plaintext data not as expected"); 4195 return 0; 4196 } 4197 4198 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4199 { 4200 struct crypto_testsuite_params *ts_params = &testsuite_params; 4201 struct crypto_unittest_params *ut_params = &unittest_params; 4202 4203 int retval; 4204 4205 uint8_t *plaintext, *ciphertext; 4206 unsigned ciphertext_pad_len; 4207 unsigned ciphertext_len; 4208 4209 /* Verify the capabilities */ 4210 struct rte_cryptodev_sym_capability_idx cap_idx; 4211 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4212 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4213 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4214 &cap_idx) == NULL) 4215 return -ENOTSUP; 4216 4217 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4218 return -ENOTSUP; 4219 4220 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4221 return -ENOTSUP; 4222 4223 /* Create SNOW 3G session */ 4224 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4225 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4226 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4227 tdata->key.data, tdata->key.len, 4228 tdata->cipher_iv.len); 4229 if (retval < 0) 4230 return retval; 4231 4232 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4233 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4234 4235 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4236 "Failed to allocate input buffer"); 4237 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4238 "Failed to allocate output buffer"); 4239 4240 /* Clear mbuf payload */ 4241 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4242 rte_pktmbuf_tailroom(ut_params->ibuf)); 4243 4244 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4245 rte_pktmbuf_tailroom(ut_params->obuf)); 4246 4247 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4248 /* Append data which is padded to a multiple of */ 4249 /* the algorithms block size */ 4250 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4251 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4252 ciphertext_pad_len); 4253 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4254 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4255 4256 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4257 4258 /* Create SNOW 3G operation */ 4259 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4260 tdata->cipher_iv.len, 4261 tdata->validCipherLenInBits.len, 4262 0); 4263 if (retval < 0) 4264 return retval; 4265 4266 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4267 ut_params->op); 4268 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4269 ut_params->obuf = ut_params->op->sym->m_dst; 4270 if (ut_params->obuf) 4271 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4272 else 4273 plaintext = ciphertext; 4274 4275 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4276 4277 /* Validate obuf */ 4278 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4279 tdata->plaintext.data, 4280 tdata->validDataLenInBits.len, 4281 "SNOW 3G Plaintext data not as expected"); 4282 return 0; 4283 } 4284 4285 static int 4286 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4287 { 4288 struct crypto_testsuite_params *ts_params = &testsuite_params; 4289 struct crypto_unittest_params *ut_params = &unittest_params; 4290 4291 int retval; 4292 4293 uint8_t *plaintext, *ciphertext; 4294 unsigned int plaintext_pad_len; 4295 unsigned int plaintext_len; 4296 4297 struct rte_cryptodev_info dev_info; 4298 struct rte_cryptodev_sym_capability_idx cap_idx; 4299 4300 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4301 uint64_t feat_flags = dev_info.feature_flags; 4302 4303 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4304 ((tdata->validAuthLenInBits.len % 8 != 0) || 4305 (tdata->validDataLenInBits.len % 8 != 0))) { 4306 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4307 return -ENOTSUP; 4308 } 4309 4310 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4311 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4312 printf("Device doesn't support RAW data-path APIs.\n"); 4313 return -ENOTSUP; 4314 } 4315 4316 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4317 return -ENOTSUP; 4318 4319 /* Check if device supports ZUC EEA3 */ 4320 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4321 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4322 4323 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4324 &cap_idx) == NULL) 4325 return -ENOTSUP; 4326 4327 /* Check if device supports ZUC EIA3 */ 4328 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4329 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4330 4331 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4332 &cap_idx) == NULL) 4333 return -ENOTSUP; 4334 4335 /* Create ZUC session */ 4336 retval = create_zuc_cipher_auth_encrypt_generate_session( 4337 ts_params->valid_devs[0], 4338 tdata); 4339 if (retval < 0) 4340 return retval; 4341 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4342 4343 /* clear mbuf payload */ 4344 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4345 rte_pktmbuf_tailroom(ut_params->ibuf)); 4346 4347 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4348 /* Append data which is padded to a multiple of */ 4349 /* the algorithms block size */ 4350 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4351 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4352 plaintext_pad_len); 4353 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4354 4355 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4356 4357 /* Create ZUC operation */ 4358 retval = create_zuc_cipher_hash_generate_operation(tdata); 4359 if (retval < 0) 4360 return retval; 4361 4362 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4363 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4364 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4365 else 4366 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4367 ut_params->op); 4368 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4369 ut_params->obuf = ut_params->op->sym->m_src; 4370 if (ut_params->obuf) 4371 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4372 else 4373 ciphertext = plaintext; 4374 4375 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4376 /* Validate obuf */ 4377 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4378 ciphertext, 4379 tdata->ciphertext.data, 4380 tdata->validDataLenInBits.len, 4381 "ZUC Ciphertext data not as expected"); 4382 4383 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4384 + plaintext_pad_len; 4385 4386 /* Validate obuf */ 4387 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4388 ut_params->digest, 4389 tdata->digest.data, 4390 4, 4391 "ZUC Generated auth tag not as expected"); 4392 return 0; 4393 } 4394 4395 static int 4396 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4397 { 4398 struct crypto_testsuite_params *ts_params = &testsuite_params; 4399 struct crypto_unittest_params *ut_params = &unittest_params; 4400 4401 int retval; 4402 4403 uint8_t *plaintext, *ciphertext; 4404 unsigned plaintext_pad_len; 4405 unsigned plaintext_len; 4406 struct rte_cryptodev_info dev_info; 4407 4408 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4409 uint64_t feat_flags = dev_info.feature_flags; 4410 4411 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4412 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4413 printf("Device doesn't support RAW data-path APIs.\n"); 4414 return -ENOTSUP; 4415 } 4416 4417 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4418 return -ENOTSUP; 4419 4420 /* Verify the capabilities */ 4421 struct rte_cryptodev_sym_capability_idx cap_idx; 4422 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4423 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4424 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4425 &cap_idx) == NULL) 4426 return -ENOTSUP; 4427 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4428 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4429 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4430 &cap_idx) == NULL) 4431 return -ENOTSUP; 4432 4433 /* Create SNOW 3G session */ 4434 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4435 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4436 RTE_CRYPTO_AUTH_OP_GENERATE, 4437 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4438 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4439 tdata->key.data, tdata->key.len, 4440 tdata->auth_iv.len, tdata->digest.len, 4441 tdata->cipher_iv.len); 4442 if (retval < 0) 4443 return retval; 4444 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4445 4446 /* clear mbuf payload */ 4447 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4448 rte_pktmbuf_tailroom(ut_params->ibuf)); 4449 4450 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4451 /* Append data which is padded to a multiple of */ 4452 /* the algorithms block size */ 4453 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4454 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4455 plaintext_pad_len); 4456 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4457 4458 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4459 4460 /* Create SNOW 3G operation */ 4461 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4462 tdata->digest.len, tdata->auth_iv.data, 4463 tdata->auth_iv.len, 4464 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4465 tdata->cipher_iv.data, tdata->cipher_iv.len, 4466 tdata->validCipherLenInBits.len, 4467 0, 4468 tdata->validAuthLenInBits.len, 4469 0 4470 ); 4471 if (retval < 0) 4472 return retval; 4473 4474 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4475 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4476 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4477 else 4478 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4479 ut_params->op); 4480 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4481 ut_params->obuf = ut_params->op->sym->m_src; 4482 if (ut_params->obuf) 4483 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4484 else 4485 ciphertext = plaintext; 4486 4487 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4488 /* Validate obuf */ 4489 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4490 ciphertext, 4491 tdata->ciphertext.data, 4492 tdata->validDataLenInBits.len, 4493 "SNOW 3G Ciphertext data not as expected"); 4494 4495 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4496 + plaintext_pad_len; 4497 4498 /* Validate obuf */ 4499 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4500 ut_params->digest, 4501 tdata->digest.data, 4502 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4503 "SNOW 3G Generated auth tag not as expected"); 4504 return 0; 4505 } 4506 4507 static int 4508 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4509 uint8_t op_mode, uint8_t verify) 4510 { 4511 struct crypto_testsuite_params *ts_params = &testsuite_params; 4512 struct crypto_unittest_params *ut_params = &unittest_params; 4513 4514 int retval; 4515 4516 uint8_t *plaintext = NULL, *ciphertext = NULL; 4517 unsigned int plaintext_pad_len; 4518 unsigned int plaintext_len; 4519 unsigned int ciphertext_pad_len; 4520 unsigned int ciphertext_len; 4521 4522 struct rte_cryptodev_info dev_info; 4523 4524 /* Verify the capabilities */ 4525 struct rte_cryptodev_sym_capability_idx cap_idx; 4526 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4527 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4528 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4529 &cap_idx) == NULL) 4530 return -ENOTSUP; 4531 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4532 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4533 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4534 &cap_idx) == NULL) 4535 return -ENOTSUP; 4536 4537 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4538 return -ENOTSUP; 4539 4540 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4541 4542 uint64_t feat_flags = dev_info.feature_flags; 4543 4544 if (op_mode == OUT_OF_PLACE) { 4545 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4546 printf("Device doesn't support digest encrypted.\n"); 4547 return -ENOTSUP; 4548 } 4549 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4550 return -ENOTSUP; 4551 } 4552 4553 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4554 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4555 printf("Device doesn't support RAW data-path APIs.\n"); 4556 return -ENOTSUP; 4557 } 4558 4559 /* Create SNOW 3G session */ 4560 retval = create_wireless_algo_auth_cipher_session( 4561 ts_params->valid_devs[0], 4562 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4563 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4564 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4565 : RTE_CRYPTO_AUTH_OP_GENERATE), 4566 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4567 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4568 tdata->key.data, tdata->key.len, 4569 tdata->auth_iv.len, tdata->digest.len, 4570 tdata->cipher_iv.len); 4571 4572 if (retval < 0) 4573 return retval; 4574 4575 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4576 if (op_mode == OUT_OF_PLACE) 4577 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4578 4579 /* clear mbuf payload */ 4580 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4581 rte_pktmbuf_tailroom(ut_params->ibuf)); 4582 if (op_mode == OUT_OF_PLACE) 4583 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4584 rte_pktmbuf_tailroom(ut_params->obuf)); 4585 4586 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4587 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4588 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4589 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4590 4591 if (verify) { 4592 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4593 ciphertext_pad_len); 4594 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4595 if (op_mode == OUT_OF_PLACE) 4596 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4597 debug_hexdump(stdout, "ciphertext:", ciphertext, 4598 ciphertext_len); 4599 } else { 4600 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4601 plaintext_pad_len); 4602 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4603 if (op_mode == OUT_OF_PLACE) 4604 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4605 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4606 } 4607 4608 /* Create SNOW 3G operation */ 4609 retval = create_wireless_algo_auth_cipher_operation( 4610 tdata->digest.data, tdata->digest.len, 4611 tdata->cipher_iv.data, tdata->cipher_iv.len, 4612 tdata->auth_iv.data, tdata->auth_iv.len, 4613 (tdata->digest.offset_bytes == 0 ? 4614 (verify ? ciphertext_pad_len : plaintext_pad_len) 4615 : tdata->digest.offset_bytes), 4616 tdata->validCipherLenInBits.len, 4617 tdata->cipher.offset_bits, 4618 tdata->validAuthLenInBits.len, 4619 tdata->auth.offset_bits, 4620 op_mode, 0, verify); 4621 4622 if (retval < 0) 4623 return retval; 4624 4625 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4626 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4627 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4628 else 4629 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4630 ut_params->op); 4631 4632 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4633 4634 ut_params->obuf = (op_mode == IN_PLACE ? 4635 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4636 4637 if (verify) { 4638 if (ut_params->obuf) 4639 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4640 uint8_t *); 4641 else 4642 plaintext = ciphertext + 4643 (tdata->cipher.offset_bits >> 3); 4644 4645 debug_hexdump(stdout, "plaintext:", plaintext, 4646 (tdata->plaintext.len >> 3) - tdata->digest.len); 4647 debug_hexdump(stdout, "plaintext expected:", 4648 tdata->plaintext.data, 4649 (tdata->plaintext.len >> 3) - tdata->digest.len); 4650 } else { 4651 if (ut_params->obuf) 4652 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4653 uint8_t *); 4654 else 4655 ciphertext = plaintext; 4656 4657 debug_hexdump(stdout, "ciphertext:", ciphertext, 4658 ciphertext_len); 4659 debug_hexdump(stdout, "ciphertext expected:", 4660 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4661 4662 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4663 + (tdata->digest.offset_bytes == 0 ? 4664 plaintext_pad_len : tdata->digest.offset_bytes); 4665 4666 debug_hexdump(stdout, "digest:", ut_params->digest, 4667 tdata->digest.len); 4668 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 4669 tdata->digest.len); 4670 } 4671 4672 /* Validate obuf */ 4673 if (verify) { 4674 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4675 plaintext, 4676 tdata->plaintext.data, 4677 tdata->plaintext.len >> 3, 4678 "SNOW 3G Plaintext data not as expected"); 4679 } else { 4680 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4681 ciphertext, 4682 tdata->ciphertext.data, 4683 tdata->validDataLenInBits.len, 4684 "SNOW 3G Ciphertext data not as expected"); 4685 4686 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4687 ut_params->digest, 4688 tdata->digest.data, 4689 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4690 "SNOW 3G Generated auth tag not as expected"); 4691 } 4692 return 0; 4693 } 4694 4695 static int 4696 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 4697 uint8_t op_mode, uint8_t verify) 4698 { 4699 struct crypto_testsuite_params *ts_params = &testsuite_params; 4700 struct crypto_unittest_params *ut_params = &unittest_params; 4701 4702 int retval; 4703 4704 const uint8_t *plaintext = NULL; 4705 const uint8_t *ciphertext = NULL; 4706 const uint8_t *digest = NULL; 4707 unsigned int plaintext_pad_len; 4708 unsigned int plaintext_len; 4709 unsigned int ciphertext_pad_len; 4710 unsigned int ciphertext_len; 4711 uint8_t buffer[10000]; 4712 uint8_t digest_buffer[10000]; 4713 4714 struct rte_cryptodev_info dev_info; 4715 4716 /* Verify the capabilities */ 4717 struct rte_cryptodev_sym_capability_idx cap_idx; 4718 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4719 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4720 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4721 &cap_idx) == NULL) 4722 return -ENOTSUP; 4723 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4724 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4725 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4726 &cap_idx) == NULL) 4727 return -ENOTSUP; 4728 4729 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4730 return -ENOTSUP; 4731 4732 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4733 4734 uint64_t feat_flags = dev_info.feature_flags; 4735 4736 if (op_mode == IN_PLACE) { 4737 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4738 printf("Device doesn't support in-place scatter-gather " 4739 "in both input and output mbufs.\n"); 4740 return -ENOTSUP; 4741 } 4742 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4743 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4744 printf("Device doesn't support RAW data-path APIs.\n"); 4745 return -ENOTSUP; 4746 } 4747 } else { 4748 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4749 return -ENOTSUP; 4750 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4751 printf("Device doesn't support out-of-place scatter-gather " 4752 "in both input and output mbufs.\n"); 4753 return -ENOTSUP; 4754 } 4755 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4756 printf("Device doesn't support digest encrypted.\n"); 4757 return -ENOTSUP; 4758 } 4759 } 4760 4761 /* Create SNOW 3G session */ 4762 retval = create_wireless_algo_auth_cipher_session( 4763 ts_params->valid_devs[0], 4764 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4765 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4766 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4767 : RTE_CRYPTO_AUTH_OP_GENERATE), 4768 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4769 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4770 tdata->key.data, tdata->key.len, 4771 tdata->auth_iv.len, tdata->digest.len, 4772 tdata->cipher_iv.len); 4773 4774 if (retval < 0) 4775 return retval; 4776 4777 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4778 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4779 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4780 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4781 4782 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4783 plaintext_pad_len, 15, 0); 4784 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4785 "Failed to allocate input buffer in mempool"); 4786 4787 if (op_mode == OUT_OF_PLACE) { 4788 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4789 plaintext_pad_len, 15, 0); 4790 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4791 "Failed to allocate output buffer in mempool"); 4792 } 4793 4794 if (verify) { 4795 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4796 tdata->ciphertext.data); 4797 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4798 ciphertext_len, buffer); 4799 debug_hexdump(stdout, "ciphertext:", ciphertext, 4800 ciphertext_len); 4801 } else { 4802 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4803 tdata->plaintext.data); 4804 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4805 plaintext_len, buffer); 4806 debug_hexdump(stdout, "plaintext:", plaintext, 4807 plaintext_len); 4808 } 4809 memset(buffer, 0, sizeof(buffer)); 4810 4811 /* Create SNOW 3G operation */ 4812 retval = create_wireless_algo_auth_cipher_operation( 4813 tdata->digest.data, tdata->digest.len, 4814 tdata->cipher_iv.data, tdata->cipher_iv.len, 4815 tdata->auth_iv.data, tdata->auth_iv.len, 4816 (tdata->digest.offset_bytes == 0 ? 4817 (verify ? ciphertext_pad_len : plaintext_pad_len) 4818 : tdata->digest.offset_bytes), 4819 tdata->validCipherLenInBits.len, 4820 tdata->cipher.offset_bits, 4821 tdata->validAuthLenInBits.len, 4822 tdata->auth.offset_bits, 4823 op_mode, 1, verify); 4824 4825 if (retval < 0) 4826 return retval; 4827 4828 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4829 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4830 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4831 else 4832 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4833 ut_params->op); 4834 4835 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4836 4837 ut_params->obuf = (op_mode == IN_PLACE ? 4838 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4839 4840 if (verify) { 4841 if (ut_params->obuf) 4842 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4843 plaintext_len, buffer); 4844 else 4845 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4846 plaintext_len, buffer); 4847 4848 debug_hexdump(stdout, "plaintext:", plaintext, 4849 (tdata->plaintext.len >> 3) - tdata->digest.len); 4850 debug_hexdump(stdout, "plaintext expected:", 4851 tdata->plaintext.data, 4852 (tdata->plaintext.len >> 3) - tdata->digest.len); 4853 } else { 4854 if (ut_params->obuf) 4855 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4856 ciphertext_len, buffer); 4857 else 4858 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4859 ciphertext_len, buffer); 4860 4861 debug_hexdump(stdout, "ciphertext:", ciphertext, 4862 ciphertext_len); 4863 debug_hexdump(stdout, "ciphertext expected:", 4864 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4865 4866 if (ut_params->obuf) 4867 digest = rte_pktmbuf_read(ut_params->obuf, 4868 (tdata->digest.offset_bytes == 0 ? 4869 plaintext_pad_len : tdata->digest.offset_bytes), 4870 tdata->digest.len, digest_buffer); 4871 else 4872 digest = rte_pktmbuf_read(ut_params->ibuf, 4873 (tdata->digest.offset_bytes == 0 ? 4874 plaintext_pad_len : tdata->digest.offset_bytes), 4875 tdata->digest.len, digest_buffer); 4876 4877 debug_hexdump(stdout, "digest:", digest, 4878 tdata->digest.len); 4879 debug_hexdump(stdout, "digest expected:", 4880 tdata->digest.data, tdata->digest.len); 4881 } 4882 4883 /* Validate obuf */ 4884 if (verify) { 4885 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4886 plaintext, 4887 tdata->plaintext.data, 4888 tdata->plaintext.len >> 3, 4889 "SNOW 3G Plaintext data not as expected"); 4890 } else { 4891 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4892 ciphertext, 4893 tdata->ciphertext.data, 4894 tdata->validDataLenInBits.len, 4895 "SNOW 3G Ciphertext data not as expected"); 4896 4897 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4898 digest, 4899 tdata->digest.data, 4900 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4901 "SNOW 3G Generated auth tag not as expected"); 4902 } 4903 return 0; 4904 } 4905 4906 static int 4907 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 4908 uint8_t op_mode, uint8_t verify) 4909 { 4910 struct crypto_testsuite_params *ts_params = &testsuite_params; 4911 struct crypto_unittest_params *ut_params = &unittest_params; 4912 4913 int retval; 4914 4915 uint8_t *plaintext = NULL, *ciphertext = NULL; 4916 unsigned int plaintext_pad_len; 4917 unsigned int plaintext_len; 4918 unsigned int ciphertext_pad_len; 4919 unsigned int ciphertext_len; 4920 4921 struct rte_cryptodev_info dev_info; 4922 4923 /* Verify the capabilities */ 4924 struct rte_cryptodev_sym_capability_idx cap_idx; 4925 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4926 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4927 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4928 &cap_idx) == NULL) 4929 return -ENOTSUP; 4930 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4931 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4932 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4933 &cap_idx) == NULL) 4934 return -ENOTSUP; 4935 4936 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4937 4938 uint64_t feat_flags = dev_info.feature_flags; 4939 4940 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4941 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4942 printf("Device doesn't support RAW data-path APIs.\n"); 4943 return -ENOTSUP; 4944 } 4945 4946 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4947 return -ENOTSUP; 4948 4949 if (op_mode == OUT_OF_PLACE) { 4950 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4951 return -ENOTSUP; 4952 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4953 printf("Device doesn't support digest encrypted.\n"); 4954 return -ENOTSUP; 4955 } 4956 } 4957 4958 /* Create KASUMI session */ 4959 retval = create_wireless_algo_auth_cipher_session( 4960 ts_params->valid_devs[0], 4961 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4962 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4963 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4964 : RTE_CRYPTO_AUTH_OP_GENERATE), 4965 RTE_CRYPTO_AUTH_KASUMI_F9, 4966 RTE_CRYPTO_CIPHER_KASUMI_F8, 4967 tdata->key.data, tdata->key.len, 4968 0, tdata->digest.len, 4969 tdata->cipher_iv.len); 4970 4971 if (retval < 0) 4972 return retval; 4973 4974 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4975 if (op_mode == OUT_OF_PLACE) 4976 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4977 4978 /* clear mbuf payload */ 4979 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4980 rte_pktmbuf_tailroom(ut_params->ibuf)); 4981 if (op_mode == OUT_OF_PLACE) 4982 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4983 rte_pktmbuf_tailroom(ut_params->obuf)); 4984 4985 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4986 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4987 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4988 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4989 4990 if (verify) { 4991 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4992 ciphertext_pad_len); 4993 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4994 if (op_mode == OUT_OF_PLACE) 4995 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4996 debug_hexdump(stdout, "ciphertext:", ciphertext, 4997 ciphertext_len); 4998 } else { 4999 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5000 plaintext_pad_len); 5001 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5002 if (op_mode == OUT_OF_PLACE) 5003 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5004 debug_hexdump(stdout, "plaintext:", plaintext, 5005 plaintext_len); 5006 } 5007 5008 /* Create KASUMI operation */ 5009 retval = create_wireless_algo_auth_cipher_operation( 5010 tdata->digest.data, tdata->digest.len, 5011 tdata->cipher_iv.data, tdata->cipher_iv.len, 5012 NULL, 0, 5013 (tdata->digest.offset_bytes == 0 ? 5014 (verify ? ciphertext_pad_len : plaintext_pad_len) 5015 : tdata->digest.offset_bytes), 5016 tdata->validCipherLenInBits.len, 5017 tdata->validCipherOffsetInBits.len, 5018 tdata->validAuthLenInBits.len, 5019 0, 5020 op_mode, 0, verify); 5021 5022 if (retval < 0) 5023 return retval; 5024 5025 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5026 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5027 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5028 else 5029 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5030 ut_params->op); 5031 5032 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5033 5034 ut_params->obuf = (op_mode == IN_PLACE ? 5035 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5036 5037 5038 if (verify) { 5039 if (ut_params->obuf) 5040 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5041 uint8_t *); 5042 else 5043 plaintext = ciphertext; 5044 5045 debug_hexdump(stdout, "plaintext:", plaintext, 5046 (tdata->plaintext.len >> 3) - tdata->digest.len); 5047 debug_hexdump(stdout, "plaintext expected:", 5048 tdata->plaintext.data, 5049 (tdata->plaintext.len >> 3) - tdata->digest.len); 5050 } else { 5051 if (ut_params->obuf) 5052 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5053 uint8_t *); 5054 else 5055 ciphertext = plaintext; 5056 5057 debug_hexdump(stdout, "ciphertext:", ciphertext, 5058 ciphertext_len); 5059 debug_hexdump(stdout, "ciphertext expected:", 5060 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5061 5062 ut_params->digest = rte_pktmbuf_mtod( 5063 ut_params->obuf, uint8_t *) + 5064 (tdata->digest.offset_bytes == 0 ? 5065 plaintext_pad_len : tdata->digest.offset_bytes); 5066 5067 debug_hexdump(stdout, "digest:", ut_params->digest, 5068 tdata->digest.len); 5069 debug_hexdump(stdout, "digest expected:", 5070 tdata->digest.data, tdata->digest.len); 5071 } 5072 5073 /* Validate obuf */ 5074 if (verify) { 5075 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5076 plaintext, 5077 tdata->plaintext.data, 5078 tdata->plaintext.len >> 3, 5079 "KASUMI Plaintext data not as expected"); 5080 } else { 5081 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5082 ciphertext, 5083 tdata->ciphertext.data, 5084 tdata->ciphertext.len >> 3, 5085 "KASUMI Ciphertext data not as expected"); 5086 5087 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5088 ut_params->digest, 5089 tdata->digest.data, 5090 DIGEST_BYTE_LENGTH_KASUMI_F9, 5091 "KASUMI Generated auth tag not as expected"); 5092 } 5093 return 0; 5094 } 5095 5096 static int 5097 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5098 uint8_t op_mode, uint8_t verify) 5099 { 5100 struct crypto_testsuite_params *ts_params = &testsuite_params; 5101 struct crypto_unittest_params *ut_params = &unittest_params; 5102 5103 int retval; 5104 5105 const uint8_t *plaintext = NULL; 5106 const uint8_t *ciphertext = NULL; 5107 const uint8_t *digest = NULL; 5108 unsigned int plaintext_pad_len; 5109 unsigned int plaintext_len; 5110 unsigned int ciphertext_pad_len; 5111 unsigned int ciphertext_len; 5112 uint8_t buffer[10000]; 5113 uint8_t digest_buffer[10000]; 5114 5115 struct rte_cryptodev_info dev_info; 5116 5117 /* Verify the capabilities */ 5118 struct rte_cryptodev_sym_capability_idx cap_idx; 5119 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5120 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5121 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5122 &cap_idx) == NULL) 5123 return -ENOTSUP; 5124 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5125 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5126 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5127 &cap_idx) == NULL) 5128 return -ENOTSUP; 5129 5130 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5131 return -ENOTSUP; 5132 5133 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5134 5135 uint64_t feat_flags = dev_info.feature_flags; 5136 5137 if (op_mode == IN_PLACE) { 5138 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5139 printf("Device doesn't support in-place scatter-gather " 5140 "in both input and output mbufs.\n"); 5141 return -ENOTSUP; 5142 } 5143 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5144 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5145 printf("Device doesn't support RAW data-path APIs.\n"); 5146 return -ENOTSUP; 5147 } 5148 } else { 5149 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5150 return -ENOTSUP; 5151 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5152 printf("Device doesn't support out-of-place scatter-gather " 5153 "in both input and output mbufs.\n"); 5154 return -ENOTSUP; 5155 } 5156 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5157 printf("Device doesn't support digest encrypted.\n"); 5158 return -ENOTSUP; 5159 } 5160 } 5161 5162 /* Create KASUMI session */ 5163 retval = create_wireless_algo_auth_cipher_session( 5164 ts_params->valid_devs[0], 5165 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5166 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5167 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5168 : RTE_CRYPTO_AUTH_OP_GENERATE), 5169 RTE_CRYPTO_AUTH_KASUMI_F9, 5170 RTE_CRYPTO_CIPHER_KASUMI_F8, 5171 tdata->key.data, tdata->key.len, 5172 0, tdata->digest.len, 5173 tdata->cipher_iv.len); 5174 5175 if (retval < 0) 5176 return retval; 5177 5178 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5179 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5180 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5181 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5182 5183 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5184 plaintext_pad_len, 15, 0); 5185 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5186 "Failed to allocate input buffer in mempool"); 5187 5188 if (op_mode == OUT_OF_PLACE) { 5189 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5190 plaintext_pad_len, 15, 0); 5191 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5192 "Failed to allocate output buffer in mempool"); 5193 } 5194 5195 if (verify) { 5196 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5197 tdata->ciphertext.data); 5198 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5199 ciphertext_len, buffer); 5200 debug_hexdump(stdout, "ciphertext:", ciphertext, 5201 ciphertext_len); 5202 } else { 5203 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5204 tdata->plaintext.data); 5205 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5206 plaintext_len, buffer); 5207 debug_hexdump(stdout, "plaintext:", plaintext, 5208 plaintext_len); 5209 } 5210 memset(buffer, 0, sizeof(buffer)); 5211 5212 /* Create KASUMI operation */ 5213 retval = create_wireless_algo_auth_cipher_operation( 5214 tdata->digest.data, tdata->digest.len, 5215 tdata->cipher_iv.data, tdata->cipher_iv.len, 5216 NULL, 0, 5217 (tdata->digest.offset_bytes == 0 ? 5218 (verify ? ciphertext_pad_len : plaintext_pad_len) 5219 : tdata->digest.offset_bytes), 5220 tdata->validCipherLenInBits.len, 5221 tdata->validCipherOffsetInBits.len, 5222 tdata->validAuthLenInBits.len, 5223 0, 5224 op_mode, 1, verify); 5225 5226 if (retval < 0) 5227 return retval; 5228 5229 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5230 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5231 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5232 else 5233 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5234 ut_params->op); 5235 5236 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5237 5238 ut_params->obuf = (op_mode == IN_PLACE ? 5239 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5240 5241 if (verify) { 5242 if (ut_params->obuf) 5243 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5244 plaintext_len, buffer); 5245 else 5246 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5247 plaintext_len, buffer); 5248 5249 debug_hexdump(stdout, "plaintext:", plaintext, 5250 (tdata->plaintext.len >> 3) - tdata->digest.len); 5251 debug_hexdump(stdout, "plaintext expected:", 5252 tdata->plaintext.data, 5253 (tdata->plaintext.len >> 3) - tdata->digest.len); 5254 } else { 5255 if (ut_params->obuf) 5256 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5257 ciphertext_len, buffer); 5258 else 5259 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5260 ciphertext_len, buffer); 5261 5262 debug_hexdump(stdout, "ciphertext:", ciphertext, 5263 ciphertext_len); 5264 debug_hexdump(stdout, "ciphertext expected:", 5265 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5266 5267 if (ut_params->obuf) 5268 digest = rte_pktmbuf_read(ut_params->obuf, 5269 (tdata->digest.offset_bytes == 0 ? 5270 plaintext_pad_len : tdata->digest.offset_bytes), 5271 tdata->digest.len, digest_buffer); 5272 else 5273 digest = rte_pktmbuf_read(ut_params->ibuf, 5274 (tdata->digest.offset_bytes == 0 ? 5275 plaintext_pad_len : tdata->digest.offset_bytes), 5276 tdata->digest.len, digest_buffer); 5277 5278 debug_hexdump(stdout, "digest:", digest, 5279 tdata->digest.len); 5280 debug_hexdump(stdout, "digest expected:", 5281 tdata->digest.data, tdata->digest.len); 5282 } 5283 5284 /* Validate obuf */ 5285 if (verify) { 5286 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5287 plaintext, 5288 tdata->plaintext.data, 5289 tdata->plaintext.len >> 3, 5290 "KASUMI Plaintext data not as expected"); 5291 } else { 5292 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5293 ciphertext, 5294 tdata->ciphertext.data, 5295 tdata->validDataLenInBits.len, 5296 "KASUMI Ciphertext data not as expected"); 5297 5298 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5299 digest, 5300 tdata->digest.data, 5301 DIGEST_BYTE_LENGTH_KASUMI_F9, 5302 "KASUMI Generated auth tag not as expected"); 5303 } 5304 return 0; 5305 } 5306 5307 static int 5308 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5309 { 5310 struct crypto_testsuite_params *ts_params = &testsuite_params; 5311 struct crypto_unittest_params *ut_params = &unittest_params; 5312 5313 int retval; 5314 5315 uint8_t *plaintext, *ciphertext; 5316 unsigned plaintext_pad_len; 5317 unsigned plaintext_len; 5318 struct rte_cryptodev_info dev_info; 5319 5320 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5321 uint64_t feat_flags = dev_info.feature_flags; 5322 5323 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5324 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5325 printf("Device doesn't support RAW data-path APIs.\n"); 5326 return -ENOTSUP; 5327 } 5328 5329 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5330 return -ENOTSUP; 5331 5332 /* Verify the capabilities */ 5333 struct rte_cryptodev_sym_capability_idx cap_idx; 5334 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5335 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5336 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5337 &cap_idx) == NULL) 5338 return -ENOTSUP; 5339 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5340 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5341 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5342 &cap_idx) == NULL) 5343 return -ENOTSUP; 5344 5345 /* Create KASUMI session */ 5346 retval = create_wireless_algo_cipher_auth_session( 5347 ts_params->valid_devs[0], 5348 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5349 RTE_CRYPTO_AUTH_OP_GENERATE, 5350 RTE_CRYPTO_AUTH_KASUMI_F9, 5351 RTE_CRYPTO_CIPHER_KASUMI_F8, 5352 tdata->key.data, tdata->key.len, 5353 0, tdata->digest.len, 5354 tdata->cipher_iv.len); 5355 if (retval < 0) 5356 return retval; 5357 5358 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5359 5360 /* clear mbuf payload */ 5361 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5362 rte_pktmbuf_tailroom(ut_params->ibuf)); 5363 5364 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5365 /* Append data which is padded to a multiple of */ 5366 /* the algorithms block size */ 5367 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5368 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5369 plaintext_pad_len); 5370 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5371 5372 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5373 5374 /* Create KASUMI operation */ 5375 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5376 tdata->digest.len, NULL, 0, 5377 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5378 tdata->cipher_iv.data, tdata->cipher_iv.len, 5379 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5380 tdata->validCipherOffsetInBits.len, 5381 tdata->validAuthLenInBits.len, 5382 0 5383 ); 5384 if (retval < 0) 5385 return retval; 5386 5387 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5388 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5389 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5390 else 5391 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5392 ut_params->op); 5393 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5394 5395 if (ut_params->op->sym->m_dst) 5396 ut_params->obuf = ut_params->op->sym->m_dst; 5397 else 5398 ut_params->obuf = ut_params->op->sym->m_src; 5399 5400 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5401 tdata->validCipherOffsetInBits.len >> 3); 5402 5403 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5404 + plaintext_pad_len; 5405 5406 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5407 (tdata->validCipherOffsetInBits.len >> 3); 5408 /* Validate obuf */ 5409 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5410 ciphertext, 5411 reference_ciphertext, 5412 tdata->validCipherLenInBits.len, 5413 "KASUMI Ciphertext data not as expected"); 5414 5415 /* Validate obuf */ 5416 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5417 ut_params->digest, 5418 tdata->digest.data, 5419 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5420 "KASUMI Generated auth tag not as expected"); 5421 return 0; 5422 } 5423 5424 static int 5425 test_zuc_encryption(const struct wireless_test_data *tdata) 5426 { 5427 struct crypto_testsuite_params *ts_params = &testsuite_params; 5428 struct crypto_unittest_params *ut_params = &unittest_params; 5429 5430 int retval; 5431 uint8_t *plaintext, *ciphertext; 5432 unsigned plaintext_pad_len; 5433 unsigned plaintext_len; 5434 struct rte_cryptodev_info dev_info; 5435 5436 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5437 uint64_t feat_flags = dev_info.feature_flags; 5438 5439 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5440 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5441 printf("Device doesn't support RAW data-path APIs.\n"); 5442 return -ENOTSUP; 5443 } 5444 5445 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5446 return -ENOTSUP; 5447 5448 struct rte_cryptodev_sym_capability_idx cap_idx; 5449 5450 /* Check if device supports ZUC EEA3 */ 5451 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5452 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5453 5454 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5455 &cap_idx) == NULL) 5456 return -ENOTSUP; 5457 5458 /* Create ZUC session */ 5459 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5460 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5461 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5462 tdata->key.data, tdata->key.len, 5463 tdata->cipher_iv.len); 5464 if (retval < 0) 5465 return retval; 5466 5467 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5468 5469 /* Clear mbuf payload */ 5470 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5471 rte_pktmbuf_tailroom(ut_params->ibuf)); 5472 5473 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5474 /* Append data which is padded to a multiple */ 5475 /* of the algorithms block size */ 5476 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5477 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5478 plaintext_pad_len); 5479 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5480 5481 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5482 5483 /* Create ZUC operation */ 5484 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5485 tdata->cipher_iv.len, 5486 tdata->plaintext.len, 5487 0); 5488 if (retval < 0) 5489 return retval; 5490 5491 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5492 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5493 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5494 else 5495 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5496 ut_params->op); 5497 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5498 5499 ut_params->obuf = ut_params->op->sym->m_dst; 5500 if (ut_params->obuf) 5501 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5502 else 5503 ciphertext = plaintext; 5504 5505 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5506 5507 /* Validate obuf */ 5508 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5509 ciphertext, 5510 tdata->ciphertext.data, 5511 tdata->validCipherLenInBits.len, 5512 "ZUC Ciphertext data not as expected"); 5513 return 0; 5514 } 5515 5516 static int 5517 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 5518 { 5519 struct crypto_testsuite_params *ts_params = &testsuite_params; 5520 struct crypto_unittest_params *ut_params = &unittest_params; 5521 5522 int retval; 5523 5524 unsigned int plaintext_pad_len; 5525 unsigned int plaintext_len; 5526 const uint8_t *ciphertext; 5527 uint8_t ciphertext_buffer[2048]; 5528 struct rte_cryptodev_info dev_info; 5529 5530 struct rte_cryptodev_sym_capability_idx cap_idx; 5531 5532 /* Check if device supports ZUC EEA3 */ 5533 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5534 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5535 5536 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5537 &cap_idx) == NULL) 5538 return -ENOTSUP; 5539 5540 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5541 return -ENOTSUP; 5542 5543 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5544 5545 uint64_t feat_flags = dev_info.feature_flags; 5546 5547 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5548 printf("Device doesn't support in-place scatter-gather. " 5549 "Test Skipped.\n"); 5550 return -ENOTSUP; 5551 } 5552 5553 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5554 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5555 printf("Device doesn't support RAW data-path APIs.\n"); 5556 return -ENOTSUP; 5557 } 5558 5559 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5560 5561 /* Append data which is padded to a multiple */ 5562 /* of the algorithms block size */ 5563 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5564 5565 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5566 plaintext_pad_len, 10, 0); 5567 5568 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5569 tdata->plaintext.data); 5570 5571 /* Create ZUC session */ 5572 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5573 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5574 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5575 tdata->key.data, tdata->key.len, 5576 tdata->cipher_iv.len); 5577 if (retval < 0) 5578 return retval; 5579 5580 /* Clear mbuf payload */ 5581 5582 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 5583 5584 /* Create ZUC operation */ 5585 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5586 tdata->cipher_iv.len, tdata->plaintext.len, 5587 0); 5588 if (retval < 0) 5589 return retval; 5590 5591 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5592 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5593 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5594 else 5595 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5596 ut_params->op); 5597 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5598 5599 ut_params->obuf = ut_params->op->sym->m_dst; 5600 if (ut_params->obuf) 5601 ciphertext = rte_pktmbuf_read(ut_params->obuf, 5602 0, plaintext_len, ciphertext_buffer); 5603 else 5604 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 5605 0, plaintext_len, ciphertext_buffer); 5606 5607 /* Validate obuf */ 5608 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5609 5610 /* Validate obuf */ 5611 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5612 ciphertext, 5613 tdata->ciphertext.data, 5614 tdata->validCipherLenInBits.len, 5615 "ZUC Ciphertext data not as expected"); 5616 5617 return 0; 5618 } 5619 5620 static int 5621 test_zuc_authentication(const struct wireless_test_data *tdata) 5622 { 5623 struct crypto_testsuite_params *ts_params = &testsuite_params; 5624 struct crypto_unittest_params *ut_params = &unittest_params; 5625 5626 int retval; 5627 unsigned plaintext_pad_len; 5628 unsigned plaintext_len; 5629 uint8_t *plaintext; 5630 5631 struct rte_cryptodev_sym_capability_idx cap_idx; 5632 struct rte_cryptodev_info dev_info; 5633 5634 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5635 uint64_t feat_flags = dev_info.feature_flags; 5636 5637 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5638 (tdata->validAuthLenInBits.len % 8 != 0)) { 5639 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5640 return -ENOTSUP; 5641 } 5642 5643 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5644 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5645 printf("Device doesn't support RAW data-path APIs.\n"); 5646 return -ENOTSUP; 5647 } 5648 5649 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5650 return -ENOTSUP; 5651 5652 /* Check if device supports ZUC EIA3 */ 5653 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5654 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5655 5656 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5657 &cap_idx) == NULL) 5658 return -ENOTSUP; 5659 5660 /* Create ZUC session */ 5661 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 5662 tdata->key.data, tdata->key.len, 5663 tdata->auth_iv.len, tdata->digest.len, 5664 RTE_CRYPTO_AUTH_OP_GENERATE, 5665 RTE_CRYPTO_AUTH_ZUC_EIA3); 5666 if (retval < 0) 5667 return retval; 5668 5669 /* alloc mbuf and set payload */ 5670 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5671 5672 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5673 rte_pktmbuf_tailroom(ut_params->ibuf)); 5674 5675 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5676 /* Append data which is padded to a multiple of */ 5677 /* the algorithms block size */ 5678 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5679 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5680 plaintext_pad_len); 5681 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5682 5683 /* Create ZUC operation */ 5684 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 5685 tdata->auth_iv.data, tdata->auth_iv.len, 5686 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5687 tdata->validAuthLenInBits.len, 5688 0); 5689 if (retval < 0) 5690 return retval; 5691 5692 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5693 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5694 ut_params->op, 0, 1, 1, 0); 5695 else 5696 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5697 ut_params->op); 5698 ut_params->obuf = ut_params->op->sym->m_src; 5699 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5700 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5701 + plaintext_pad_len; 5702 5703 /* Validate obuf */ 5704 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5705 ut_params->digest, 5706 tdata->digest.data, 5707 tdata->digest.len, 5708 "ZUC Generated auth tag not as expected"); 5709 5710 return 0; 5711 } 5712 5713 static int 5714 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 5715 uint8_t op_mode, uint8_t verify) 5716 { 5717 struct crypto_testsuite_params *ts_params = &testsuite_params; 5718 struct crypto_unittest_params *ut_params = &unittest_params; 5719 5720 int retval; 5721 5722 uint8_t *plaintext = NULL, *ciphertext = NULL; 5723 unsigned int plaintext_pad_len; 5724 unsigned int plaintext_len; 5725 unsigned int ciphertext_pad_len; 5726 unsigned int ciphertext_len; 5727 5728 struct rte_cryptodev_info dev_info; 5729 struct rte_cryptodev_sym_capability_idx cap_idx; 5730 5731 /* Check if device supports ZUC EIA3 */ 5732 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5733 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5734 5735 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5736 &cap_idx) == NULL) 5737 return -ENOTSUP; 5738 5739 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5740 5741 uint64_t feat_flags = dev_info.feature_flags; 5742 5743 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5744 printf("Device doesn't support digest encrypted.\n"); 5745 return -ENOTSUP; 5746 } 5747 if (op_mode == IN_PLACE) { 5748 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5749 printf("Device doesn't support in-place scatter-gather " 5750 "in both input and output mbufs.\n"); 5751 return -ENOTSUP; 5752 } 5753 5754 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5755 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5756 printf("Device doesn't support RAW data-path APIs.\n"); 5757 return -ENOTSUP; 5758 } 5759 } else { 5760 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5761 return -ENOTSUP; 5762 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5763 printf("Device doesn't support out-of-place scatter-gather " 5764 "in both input and output mbufs.\n"); 5765 return -ENOTSUP; 5766 } 5767 } 5768 5769 /* Create ZUC session */ 5770 retval = create_wireless_algo_auth_cipher_session( 5771 ts_params->valid_devs[0], 5772 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5773 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5774 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5775 : RTE_CRYPTO_AUTH_OP_GENERATE), 5776 RTE_CRYPTO_AUTH_ZUC_EIA3, 5777 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5778 tdata->key.data, tdata->key.len, 5779 tdata->auth_iv.len, tdata->digest.len, 5780 tdata->cipher_iv.len); 5781 5782 if (retval < 0) 5783 return retval; 5784 5785 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5786 if (op_mode == OUT_OF_PLACE) 5787 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5788 5789 /* clear mbuf payload */ 5790 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5791 rte_pktmbuf_tailroom(ut_params->ibuf)); 5792 if (op_mode == OUT_OF_PLACE) 5793 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5794 rte_pktmbuf_tailroom(ut_params->obuf)); 5795 5796 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5797 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5798 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5799 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5800 5801 if (verify) { 5802 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5803 ciphertext_pad_len); 5804 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5805 if (op_mode == OUT_OF_PLACE) 5806 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5807 debug_hexdump(stdout, "ciphertext:", ciphertext, 5808 ciphertext_len); 5809 } else { 5810 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5811 plaintext_pad_len); 5812 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5813 if (op_mode == OUT_OF_PLACE) 5814 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5815 debug_hexdump(stdout, "plaintext:", plaintext, 5816 plaintext_len); 5817 } 5818 5819 /* Create ZUC operation */ 5820 retval = create_wireless_algo_auth_cipher_operation( 5821 tdata->digest.data, tdata->digest.len, 5822 tdata->cipher_iv.data, tdata->cipher_iv.len, 5823 tdata->auth_iv.data, tdata->auth_iv.len, 5824 (tdata->digest.offset_bytes == 0 ? 5825 (verify ? ciphertext_pad_len : plaintext_pad_len) 5826 : tdata->digest.offset_bytes), 5827 tdata->validCipherLenInBits.len, 5828 tdata->validCipherOffsetInBits.len, 5829 tdata->validAuthLenInBits.len, 5830 0, 5831 op_mode, 0, verify); 5832 5833 if (retval < 0) 5834 return retval; 5835 5836 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5837 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5838 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5839 else 5840 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5841 ut_params->op); 5842 5843 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5844 5845 ut_params->obuf = (op_mode == IN_PLACE ? 5846 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5847 5848 5849 if (verify) { 5850 if (ut_params->obuf) 5851 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5852 uint8_t *); 5853 else 5854 plaintext = ciphertext; 5855 5856 debug_hexdump(stdout, "plaintext:", plaintext, 5857 (tdata->plaintext.len >> 3) - tdata->digest.len); 5858 debug_hexdump(stdout, "plaintext expected:", 5859 tdata->plaintext.data, 5860 (tdata->plaintext.len >> 3) - tdata->digest.len); 5861 } else { 5862 if (ut_params->obuf) 5863 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5864 uint8_t *); 5865 else 5866 ciphertext = plaintext; 5867 5868 debug_hexdump(stdout, "ciphertext:", ciphertext, 5869 ciphertext_len); 5870 debug_hexdump(stdout, "ciphertext expected:", 5871 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5872 5873 ut_params->digest = rte_pktmbuf_mtod( 5874 ut_params->obuf, uint8_t *) + 5875 (tdata->digest.offset_bytes == 0 ? 5876 plaintext_pad_len : tdata->digest.offset_bytes); 5877 5878 debug_hexdump(stdout, "digest:", ut_params->digest, 5879 tdata->digest.len); 5880 debug_hexdump(stdout, "digest expected:", 5881 tdata->digest.data, tdata->digest.len); 5882 } 5883 5884 /* Validate obuf */ 5885 if (verify) { 5886 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5887 plaintext, 5888 tdata->plaintext.data, 5889 tdata->plaintext.len >> 3, 5890 "ZUC Plaintext data not as expected"); 5891 } else { 5892 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5893 ciphertext, 5894 tdata->ciphertext.data, 5895 tdata->ciphertext.len >> 3, 5896 "ZUC Ciphertext data not as expected"); 5897 5898 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5899 ut_params->digest, 5900 tdata->digest.data, 5901 DIGEST_BYTE_LENGTH_KASUMI_F9, 5902 "ZUC Generated auth tag not as expected"); 5903 } 5904 return 0; 5905 } 5906 5907 static int 5908 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 5909 uint8_t op_mode, uint8_t verify) 5910 { 5911 struct crypto_testsuite_params *ts_params = &testsuite_params; 5912 struct crypto_unittest_params *ut_params = &unittest_params; 5913 5914 int retval; 5915 5916 const uint8_t *plaintext = NULL; 5917 const uint8_t *ciphertext = NULL; 5918 const uint8_t *digest = NULL; 5919 unsigned int plaintext_pad_len; 5920 unsigned int plaintext_len; 5921 unsigned int ciphertext_pad_len; 5922 unsigned int ciphertext_len; 5923 uint8_t buffer[10000]; 5924 uint8_t digest_buffer[10000]; 5925 5926 struct rte_cryptodev_info dev_info; 5927 struct rte_cryptodev_sym_capability_idx cap_idx; 5928 5929 /* Check if device supports ZUC EIA3 */ 5930 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5931 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5932 5933 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5934 &cap_idx) == NULL) 5935 return -ENOTSUP; 5936 5937 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5938 5939 uint64_t feat_flags = dev_info.feature_flags; 5940 5941 if (op_mode == IN_PLACE) { 5942 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5943 printf("Device doesn't support in-place scatter-gather " 5944 "in both input and output mbufs.\n"); 5945 return -ENOTSUP; 5946 } 5947 5948 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5949 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5950 printf("Device doesn't support RAW data-path APIs.\n"); 5951 return -ENOTSUP; 5952 } 5953 } else { 5954 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5955 return -ENOTSUP; 5956 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5957 printf("Device doesn't support out-of-place scatter-gather " 5958 "in both input and output mbufs.\n"); 5959 return -ENOTSUP; 5960 } 5961 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5962 printf("Device doesn't support digest encrypted.\n"); 5963 return -ENOTSUP; 5964 } 5965 } 5966 5967 /* Create ZUC session */ 5968 retval = create_wireless_algo_auth_cipher_session( 5969 ts_params->valid_devs[0], 5970 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5971 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5972 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5973 : RTE_CRYPTO_AUTH_OP_GENERATE), 5974 RTE_CRYPTO_AUTH_ZUC_EIA3, 5975 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5976 tdata->key.data, tdata->key.len, 5977 tdata->auth_iv.len, tdata->digest.len, 5978 tdata->cipher_iv.len); 5979 5980 if (retval < 0) 5981 return retval; 5982 5983 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5984 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5985 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5986 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5987 5988 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5989 plaintext_pad_len, 15, 0); 5990 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5991 "Failed to allocate input buffer in mempool"); 5992 5993 if (op_mode == OUT_OF_PLACE) { 5994 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5995 plaintext_pad_len, 15, 0); 5996 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5997 "Failed to allocate output buffer in mempool"); 5998 } 5999 6000 if (verify) { 6001 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6002 tdata->ciphertext.data); 6003 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6004 ciphertext_len, buffer); 6005 debug_hexdump(stdout, "ciphertext:", ciphertext, 6006 ciphertext_len); 6007 } else { 6008 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6009 tdata->plaintext.data); 6010 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6011 plaintext_len, buffer); 6012 debug_hexdump(stdout, "plaintext:", plaintext, 6013 plaintext_len); 6014 } 6015 memset(buffer, 0, sizeof(buffer)); 6016 6017 /* Create ZUC operation */ 6018 retval = create_wireless_algo_auth_cipher_operation( 6019 tdata->digest.data, tdata->digest.len, 6020 tdata->cipher_iv.data, tdata->cipher_iv.len, 6021 NULL, 0, 6022 (tdata->digest.offset_bytes == 0 ? 6023 (verify ? ciphertext_pad_len : plaintext_pad_len) 6024 : tdata->digest.offset_bytes), 6025 tdata->validCipherLenInBits.len, 6026 tdata->validCipherOffsetInBits.len, 6027 tdata->validAuthLenInBits.len, 6028 0, 6029 op_mode, 1, verify); 6030 6031 if (retval < 0) 6032 return retval; 6033 6034 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6035 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6036 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6037 else 6038 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6039 ut_params->op); 6040 6041 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6042 6043 ut_params->obuf = (op_mode == IN_PLACE ? 6044 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6045 6046 if (verify) { 6047 if (ut_params->obuf) 6048 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6049 plaintext_len, buffer); 6050 else 6051 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6052 plaintext_len, buffer); 6053 6054 debug_hexdump(stdout, "plaintext:", plaintext, 6055 (tdata->plaintext.len >> 3) - tdata->digest.len); 6056 debug_hexdump(stdout, "plaintext expected:", 6057 tdata->plaintext.data, 6058 (tdata->plaintext.len >> 3) - tdata->digest.len); 6059 } else { 6060 if (ut_params->obuf) 6061 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6062 ciphertext_len, buffer); 6063 else 6064 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6065 ciphertext_len, buffer); 6066 6067 debug_hexdump(stdout, "ciphertext:", ciphertext, 6068 ciphertext_len); 6069 debug_hexdump(stdout, "ciphertext expected:", 6070 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6071 6072 if (ut_params->obuf) 6073 digest = rte_pktmbuf_read(ut_params->obuf, 6074 (tdata->digest.offset_bytes == 0 ? 6075 plaintext_pad_len : tdata->digest.offset_bytes), 6076 tdata->digest.len, digest_buffer); 6077 else 6078 digest = rte_pktmbuf_read(ut_params->ibuf, 6079 (tdata->digest.offset_bytes == 0 ? 6080 plaintext_pad_len : tdata->digest.offset_bytes), 6081 tdata->digest.len, digest_buffer); 6082 6083 debug_hexdump(stdout, "digest:", digest, 6084 tdata->digest.len); 6085 debug_hexdump(stdout, "digest expected:", 6086 tdata->digest.data, tdata->digest.len); 6087 } 6088 6089 /* Validate obuf */ 6090 if (verify) { 6091 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6092 plaintext, 6093 tdata->plaintext.data, 6094 tdata->plaintext.len >> 3, 6095 "ZUC Plaintext data not as expected"); 6096 } else { 6097 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6098 ciphertext, 6099 tdata->ciphertext.data, 6100 tdata->validDataLenInBits.len, 6101 "ZUC Ciphertext data not as expected"); 6102 6103 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6104 digest, 6105 tdata->digest.data, 6106 DIGEST_BYTE_LENGTH_KASUMI_F9, 6107 "ZUC Generated auth tag not as expected"); 6108 } 6109 return 0; 6110 } 6111 6112 static int 6113 test_kasumi_encryption_test_case_1(void) 6114 { 6115 return test_kasumi_encryption(&kasumi_test_case_1); 6116 } 6117 6118 static int 6119 test_kasumi_encryption_test_case_1_sgl(void) 6120 { 6121 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6122 } 6123 6124 static int 6125 test_kasumi_encryption_test_case_1_oop(void) 6126 { 6127 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6128 } 6129 6130 static int 6131 test_kasumi_encryption_test_case_1_oop_sgl(void) 6132 { 6133 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6134 } 6135 6136 static int 6137 test_kasumi_encryption_test_case_2(void) 6138 { 6139 return test_kasumi_encryption(&kasumi_test_case_2); 6140 } 6141 6142 static int 6143 test_kasumi_encryption_test_case_3(void) 6144 { 6145 return test_kasumi_encryption(&kasumi_test_case_3); 6146 } 6147 6148 static int 6149 test_kasumi_encryption_test_case_4(void) 6150 { 6151 return test_kasumi_encryption(&kasumi_test_case_4); 6152 } 6153 6154 static int 6155 test_kasumi_encryption_test_case_5(void) 6156 { 6157 return test_kasumi_encryption(&kasumi_test_case_5); 6158 } 6159 6160 static int 6161 test_kasumi_decryption_test_case_1(void) 6162 { 6163 return test_kasumi_decryption(&kasumi_test_case_1); 6164 } 6165 6166 static int 6167 test_kasumi_decryption_test_case_1_oop(void) 6168 { 6169 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6170 } 6171 6172 static int 6173 test_kasumi_decryption_test_case_2(void) 6174 { 6175 return test_kasumi_decryption(&kasumi_test_case_2); 6176 } 6177 6178 static int 6179 test_kasumi_decryption_test_case_3(void) 6180 { 6181 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6182 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6183 return -ENOTSUP; 6184 return test_kasumi_decryption(&kasumi_test_case_3); 6185 } 6186 6187 static int 6188 test_kasumi_decryption_test_case_4(void) 6189 { 6190 return test_kasumi_decryption(&kasumi_test_case_4); 6191 } 6192 6193 static int 6194 test_kasumi_decryption_test_case_5(void) 6195 { 6196 return test_kasumi_decryption(&kasumi_test_case_5); 6197 } 6198 static int 6199 test_snow3g_encryption_test_case_1(void) 6200 { 6201 return test_snow3g_encryption(&snow3g_test_case_1); 6202 } 6203 6204 static int 6205 test_snow3g_encryption_test_case_1_oop(void) 6206 { 6207 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6208 } 6209 6210 static int 6211 test_snow3g_encryption_test_case_1_oop_sgl(void) 6212 { 6213 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6214 } 6215 6216 6217 static int 6218 test_snow3g_encryption_test_case_1_offset_oop(void) 6219 { 6220 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6221 } 6222 6223 static int 6224 test_snow3g_encryption_test_case_2(void) 6225 { 6226 return test_snow3g_encryption(&snow3g_test_case_2); 6227 } 6228 6229 static int 6230 test_snow3g_encryption_test_case_3(void) 6231 { 6232 return test_snow3g_encryption(&snow3g_test_case_3); 6233 } 6234 6235 static int 6236 test_snow3g_encryption_test_case_4(void) 6237 { 6238 return test_snow3g_encryption(&snow3g_test_case_4); 6239 } 6240 6241 static int 6242 test_snow3g_encryption_test_case_5(void) 6243 { 6244 return test_snow3g_encryption(&snow3g_test_case_5); 6245 } 6246 6247 static int 6248 test_snow3g_decryption_test_case_1(void) 6249 { 6250 return test_snow3g_decryption(&snow3g_test_case_1); 6251 } 6252 6253 static int 6254 test_snow3g_decryption_test_case_1_oop(void) 6255 { 6256 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6257 } 6258 6259 static int 6260 test_snow3g_decryption_test_case_2(void) 6261 { 6262 return test_snow3g_decryption(&snow3g_test_case_2); 6263 } 6264 6265 static int 6266 test_snow3g_decryption_test_case_3(void) 6267 { 6268 return test_snow3g_decryption(&snow3g_test_case_3); 6269 } 6270 6271 static int 6272 test_snow3g_decryption_test_case_4(void) 6273 { 6274 return test_snow3g_decryption(&snow3g_test_case_4); 6275 } 6276 6277 static int 6278 test_snow3g_decryption_test_case_5(void) 6279 { 6280 return test_snow3g_decryption(&snow3g_test_case_5); 6281 } 6282 6283 /* 6284 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6285 * Pattern digest from snow3g_test_data must be allocated as 6286 * 4 last bytes in plaintext. 6287 */ 6288 static void 6289 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6290 struct snow3g_hash_test_data *output) 6291 { 6292 if ((pattern != NULL) && (output != NULL)) { 6293 output->key.len = pattern->key.len; 6294 6295 memcpy(output->key.data, 6296 pattern->key.data, pattern->key.len); 6297 6298 output->auth_iv.len = pattern->auth_iv.len; 6299 6300 memcpy(output->auth_iv.data, 6301 pattern->auth_iv.data, pattern->auth_iv.len); 6302 6303 output->plaintext.len = pattern->plaintext.len; 6304 6305 memcpy(output->plaintext.data, 6306 pattern->plaintext.data, pattern->plaintext.len >> 3); 6307 6308 output->digest.len = pattern->digest.len; 6309 6310 memcpy(output->digest.data, 6311 &pattern->plaintext.data[pattern->digest.offset_bytes], 6312 pattern->digest.len); 6313 6314 output->validAuthLenInBits.len = 6315 pattern->validAuthLenInBits.len; 6316 } 6317 } 6318 6319 /* 6320 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6321 */ 6322 static int 6323 test_snow3g_decryption_with_digest_test_case_1(void) 6324 { 6325 struct snow3g_hash_test_data snow3g_hash_data; 6326 struct rte_cryptodev_info dev_info; 6327 struct crypto_testsuite_params *ts_params = &testsuite_params; 6328 6329 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6330 uint64_t feat_flags = dev_info.feature_flags; 6331 6332 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6333 printf("Device doesn't support encrypted digest operations.\n"); 6334 return -ENOTSUP; 6335 } 6336 6337 /* 6338 * Function prepare data for hash veryfication test case. 6339 * Digest is allocated in 4 last bytes in plaintext, pattern. 6340 */ 6341 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6342 6343 return test_snow3g_decryption(&snow3g_test_case_7) & 6344 test_snow3g_authentication_verify(&snow3g_hash_data); 6345 } 6346 6347 static int 6348 test_snow3g_cipher_auth_test_case_1(void) 6349 { 6350 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6351 } 6352 6353 static int 6354 test_snow3g_auth_cipher_test_case_1(void) 6355 { 6356 return test_snow3g_auth_cipher( 6357 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6358 } 6359 6360 static int 6361 test_snow3g_auth_cipher_test_case_2(void) 6362 { 6363 return test_snow3g_auth_cipher( 6364 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6365 } 6366 6367 static int 6368 test_snow3g_auth_cipher_test_case_2_oop(void) 6369 { 6370 return test_snow3g_auth_cipher( 6371 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6372 } 6373 6374 static int 6375 test_snow3g_auth_cipher_part_digest_enc(void) 6376 { 6377 return test_snow3g_auth_cipher( 6378 &snow3g_auth_cipher_partial_digest_encryption, 6379 IN_PLACE, 0); 6380 } 6381 6382 static int 6383 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6384 { 6385 return test_snow3g_auth_cipher( 6386 &snow3g_auth_cipher_partial_digest_encryption, 6387 OUT_OF_PLACE, 0); 6388 } 6389 6390 static int 6391 test_snow3g_auth_cipher_test_case_3_sgl(void) 6392 { 6393 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6394 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6395 return -ENOTSUP; 6396 return test_snow3g_auth_cipher_sgl( 6397 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6398 } 6399 6400 static int 6401 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6402 { 6403 return test_snow3g_auth_cipher_sgl( 6404 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6405 } 6406 6407 static int 6408 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6409 { 6410 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6411 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6412 return -ENOTSUP; 6413 return test_snow3g_auth_cipher_sgl( 6414 &snow3g_auth_cipher_partial_digest_encryption, 6415 IN_PLACE, 0); 6416 } 6417 6418 static int 6419 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6420 { 6421 return test_snow3g_auth_cipher_sgl( 6422 &snow3g_auth_cipher_partial_digest_encryption, 6423 OUT_OF_PLACE, 0); 6424 } 6425 6426 static int 6427 test_snow3g_auth_cipher_verify_test_case_1(void) 6428 { 6429 return test_snow3g_auth_cipher( 6430 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6431 } 6432 6433 static int 6434 test_snow3g_auth_cipher_verify_test_case_2(void) 6435 { 6436 return test_snow3g_auth_cipher( 6437 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6438 } 6439 6440 static int 6441 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6442 { 6443 return test_snow3g_auth_cipher( 6444 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6445 } 6446 6447 static int 6448 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6449 { 6450 return test_snow3g_auth_cipher( 6451 &snow3g_auth_cipher_partial_digest_encryption, 6452 IN_PLACE, 1); 6453 } 6454 6455 static int 6456 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6457 { 6458 return test_snow3g_auth_cipher( 6459 &snow3g_auth_cipher_partial_digest_encryption, 6460 OUT_OF_PLACE, 1); 6461 } 6462 6463 static int 6464 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 6465 { 6466 return test_snow3g_auth_cipher_sgl( 6467 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 6468 } 6469 6470 static int 6471 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 6472 { 6473 return test_snow3g_auth_cipher_sgl( 6474 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 6475 } 6476 6477 static int 6478 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 6479 { 6480 return test_snow3g_auth_cipher_sgl( 6481 &snow3g_auth_cipher_partial_digest_encryption, 6482 IN_PLACE, 1); 6483 } 6484 6485 static int 6486 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 6487 { 6488 return test_snow3g_auth_cipher_sgl( 6489 &snow3g_auth_cipher_partial_digest_encryption, 6490 OUT_OF_PLACE, 1); 6491 } 6492 6493 static int 6494 test_snow3g_auth_cipher_with_digest_test_case_1(void) 6495 { 6496 return test_snow3g_auth_cipher( 6497 &snow3g_test_case_7, IN_PLACE, 0); 6498 } 6499 6500 static int 6501 test_kasumi_auth_cipher_test_case_1(void) 6502 { 6503 return test_kasumi_auth_cipher( 6504 &kasumi_test_case_3, IN_PLACE, 0); 6505 } 6506 6507 static int 6508 test_kasumi_auth_cipher_test_case_2(void) 6509 { 6510 return test_kasumi_auth_cipher( 6511 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6512 } 6513 6514 static int 6515 test_kasumi_auth_cipher_test_case_2_oop(void) 6516 { 6517 return test_kasumi_auth_cipher( 6518 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6519 } 6520 6521 static int 6522 test_kasumi_auth_cipher_test_case_2_sgl(void) 6523 { 6524 return test_kasumi_auth_cipher_sgl( 6525 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6526 } 6527 6528 static int 6529 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 6530 { 6531 return test_kasumi_auth_cipher_sgl( 6532 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6533 } 6534 6535 static int 6536 test_kasumi_auth_cipher_verify_test_case_1(void) 6537 { 6538 return test_kasumi_auth_cipher( 6539 &kasumi_test_case_3, IN_PLACE, 1); 6540 } 6541 6542 static int 6543 test_kasumi_auth_cipher_verify_test_case_2(void) 6544 { 6545 return test_kasumi_auth_cipher( 6546 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6547 } 6548 6549 static int 6550 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 6551 { 6552 return test_kasumi_auth_cipher( 6553 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6554 } 6555 6556 static int 6557 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 6558 { 6559 return test_kasumi_auth_cipher_sgl( 6560 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6561 } 6562 6563 static int 6564 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 6565 { 6566 return test_kasumi_auth_cipher_sgl( 6567 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6568 } 6569 6570 static int 6571 test_kasumi_cipher_auth_test_case_1(void) 6572 { 6573 return test_kasumi_cipher_auth(&kasumi_test_case_6); 6574 } 6575 6576 static int 6577 test_zuc_encryption_test_case_1(void) 6578 { 6579 return test_zuc_encryption(&zuc_test_case_cipher_193b); 6580 } 6581 6582 static int 6583 test_zuc_encryption_test_case_2(void) 6584 { 6585 return test_zuc_encryption(&zuc_test_case_cipher_800b); 6586 } 6587 6588 static int 6589 test_zuc_encryption_test_case_3(void) 6590 { 6591 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 6592 } 6593 6594 static int 6595 test_zuc_encryption_test_case_4(void) 6596 { 6597 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 6598 } 6599 6600 static int 6601 test_zuc_encryption_test_case_5(void) 6602 { 6603 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 6604 } 6605 6606 static int 6607 test_zuc_encryption_test_case_6_sgl(void) 6608 { 6609 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 6610 } 6611 6612 static int 6613 test_zuc_hash_generate_test_case_1(void) 6614 { 6615 return test_zuc_authentication(&zuc_test_case_auth_1b); 6616 } 6617 6618 static int 6619 test_zuc_hash_generate_test_case_2(void) 6620 { 6621 return test_zuc_authentication(&zuc_test_case_auth_90b); 6622 } 6623 6624 static int 6625 test_zuc_hash_generate_test_case_3(void) 6626 { 6627 return test_zuc_authentication(&zuc_test_case_auth_577b); 6628 } 6629 6630 static int 6631 test_zuc_hash_generate_test_case_4(void) 6632 { 6633 return test_zuc_authentication(&zuc_test_case_auth_2079b); 6634 } 6635 6636 static int 6637 test_zuc_hash_generate_test_case_5(void) 6638 { 6639 return test_zuc_authentication(&zuc_test_auth_5670b); 6640 } 6641 6642 static int 6643 test_zuc_hash_generate_test_case_6(void) 6644 { 6645 return test_zuc_authentication(&zuc_test_case_auth_128b); 6646 } 6647 6648 static int 6649 test_zuc_hash_generate_test_case_7(void) 6650 { 6651 return test_zuc_authentication(&zuc_test_case_auth_2080b); 6652 } 6653 6654 static int 6655 test_zuc_hash_generate_test_case_8(void) 6656 { 6657 return test_zuc_authentication(&zuc_test_case_auth_584b); 6658 } 6659 6660 static int 6661 test_zuc_cipher_auth_test_case_1(void) 6662 { 6663 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 6664 } 6665 6666 static int 6667 test_zuc_cipher_auth_test_case_2(void) 6668 { 6669 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 6670 } 6671 6672 static int 6673 test_zuc_auth_cipher_test_case_1(void) 6674 { 6675 return test_zuc_auth_cipher( 6676 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6677 } 6678 6679 static int 6680 test_zuc_auth_cipher_test_case_1_oop(void) 6681 { 6682 return test_zuc_auth_cipher( 6683 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6684 } 6685 6686 static int 6687 test_zuc_auth_cipher_test_case_1_sgl(void) 6688 { 6689 return test_zuc_auth_cipher_sgl( 6690 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6691 } 6692 6693 static int 6694 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 6695 { 6696 return test_zuc_auth_cipher_sgl( 6697 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6698 } 6699 6700 static int 6701 test_zuc_auth_cipher_verify_test_case_1(void) 6702 { 6703 return test_zuc_auth_cipher( 6704 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6705 } 6706 6707 static int 6708 test_zuc_auth_cipher_verify_test_case_1_oop(void) 6709 { 6710 return test_zuc_auth_cipher( 6711 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6712 } 6713 6714 static int 6715 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 6716 { 6717 return test_zuc_auth_cipher_sgl( 6718 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6719 } 6720 6721 static int 6722 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 6723 { 6724 return test_zuc_auth_cipher_sgl( 6725 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6726 } 6727 6728 static int 6729 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 6730 { 6731 uint8_t dev_id = testsuite_params.valid_devs[0]; 6732 6733 struct rte_cryptodev_sym_capability_idx cap_idx; 6734 6735 /* Check if device supports particular cipher algorithm */ 6736 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6737 cap_idx.algo.cipher = tdata->cipher_algo; 6738 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6739 return -ENOTSUP; 6740 6741 /* Check if device supports particular hash algorithm */ 6742 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6743 cap_idx.algo.auth = tdata->auth_algo; 6744 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6745 return -ENOTSUP; 6746 6747 return 0; 6748 } 6749 6750 static int 6751 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 6752 uint8_t op_mode, uint8_t verify) 6753 { 6754 struct crypto_testsuite_params *ts_params = &testsuite_params; 6755 struct crypto_unittest_params *ut_params = &unittest_params; 6756 6757 int retval; 6758 6759 uint8_t *plaintext = NULL, *ciphertext = NULL; 6760 unsigned int plaintext_pad_len; 6761 unsigned int plaintext_len; 6762 unsigned int ciphertext_pad_len; 6763 unsigned int ciphertext_len; 6764 6765 struct rte_cryptodev_info dev_info; 6766 struct rte_crypto_op *op; 6767 6768 /* Check if device supports particular algorithms separately */ 6769 if (test_mixed_check_if_unsupported(tdata)) 6770 return -ENOTSUP; 6771 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6772 return -ENOTSUP; 6773 6774 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6775 6776 uint64_t feat_flags = dev_info.feature_flags; 6777 6778 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6779 printf("Device doesn't support digest encrypted.\n"); 6780 return -ENOTSUP; 6781 } 6782 6783 /* Create the session */ 6784 if (verify) 6785 retval = create_wireless_algo_cipher_auth_session( 6786 ts_params->valid_devs[0], 6787 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6788 RTE_CRYPTO_AUTH_OP_VERIFY, 6789 tdata->auth_algo, 6790 tdata->cipher_algo, 6791 tdata->auth_key.data, tdata->auth_key.len, 6792 tdata->auth_iv.len, tdata->digest_enc.len, 6793 tdata->cipher_iv.len); 6794 else 6795 retval = create_wireless_algo_auth_cipher_session( 6796 ts_params->valid_devs[0], 6797 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6798 RTE_CRYPTO_AUTH_OP_GENERATE, 6799 tdata->auth_algo, 6800 tdata->cipher_algo, 6801 tdata->auth_key.data, tdata->auth_key.len, 6802 tdata->auth_iv.len, tdata->digest_enc.len, 6803 tdata->cipher_iv.len); 6804 if (retval < 0) 6805 return retval; 6806 6807 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6808 if (op_mode == OUT_OF_PLACE) 6809 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6810 6811 /* clear mbuf payload */ 6812 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6813 rte_pktmbuf_tailroom(ut_params->ibuf)); 6814 if (op_mode == OUT_OF_PLACE) { 6815 6816 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6817 rte_pktmbuf_tailroom(ut_params->obuf)); 6818 } 6819 6820 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6821 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6822 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6823 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6824 6825 if (verify) { 6826 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6827 ciphertext_pad_len); 6828 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6829 if (op_mode == OUT_OF_PLACE) 6830 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6831 debug_hexdump(stdout, "ciphertext:", ciphertext, 6832 ciphertext_len); 6833 } else { 6834 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6835 plaintext_pad_len); 6836 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6837 if (op_mode == OUT_OF_PLACE) 6838 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6839 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6840 } 6841 6842 /* Create the operation */ 6843 retval = create_wireless_algo_auth_cipher_operation( 6844 tdata->digest_enc.data, tdata->digest_enc.len, 6845 tdata->cipher_iv.data, tdata->cipher_iv.len, 6846 tdata->auth_iv.data, tdata->auth_iv.len, 6847 (tdata->digest_enc.offset == 0 ? 6848 plaintext_pad_len 6849 : tdata->digest_enc.offset), 6850 tdata->validCipherLen.len_bits, 6851 tdata->cipher.offset_bits, 6852 tdata->validAuthLen.len_bits, 6853 tdata->auth.offset_bits, 6854 op_mode, 0, verify); 6855 6856 if (retval < 0) 6857 return retval; 6858 6859 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 6860 6861 /* Check if the op failed because the device doesn't */ 6862 /* support this particular combination of algorithms */ 6863 if (op == NULL && ut_params->op->status == 6864 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6865 printf("Device doesn't support this mixed combination. " 6866 "Test Skipped.\n"); 6867 return -ENOTSUP; 6868 } 6869 ut_params->op = op; 6870 6871 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6872 6873 ut_params->obuf = (op_mode == IN_PLACE ? 6874 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6875 6876 if (verify) { 6877 if (ut_params->obuf) 6878 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6879 uint8_t *); 6880 else 6881 plaintext = ciphertext + 6882 (tdata->cipher.offset_bits >> 3); 6883 6884 debug_hexdump(stdout, "plaintext:", plaintext, 6885 tdata->plaintext.len_bits >> 3); 6886 debug_hexdump(stdout, "plaintext expected:", 6887 tdata->plaintext.data, 6888 tdata->plaintext.len_bits >> 3); 6889 } else { 6890 if (ut_params->obuf) 6891 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6892 uint8_t *); 6893 else 6894 ciphertext = plaintext; 6895 6896 debug_hexdump(stdout, "ciphertext:", ciphertext, 6897 ciphertext_len); 6898 debug_hexdump(stdout, "ciphertext expected:", 6899 tdata->ciphertext.data, 6900 tdata->ciphertext.len_bits >> 3); 6901 6902 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6903 + (tdata->digest_enc.offset == 0 ? 6904 plaintext_pad_len : tdata->digest_enc.offset); 6905 6906 debug_hexdump(stdout, "digest:", ut_params->digest, 6907 tdata->digest_enc.len); 6908 debug_hexdump(stdout, "digest expected:", 6909 tdata->digest_enc.data, 6910 tdata->digest_enc.len); 6911 } 6912 6913 /* Validate obuf */ 6914 if (verify) { 6915 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6916 plaintext, 6917 tdata->plaintext.data, 6918 tdata->plaintext.len_bits >> 3, 6919 "Plaintext data not as expected"); 6920 } else { 6921 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6922 ciphertext, 6923 tdata->ciphertext.data, 6924 tdata->validDataLen.len_bits, 6925 "Ciphertext data not as expected"); 6926 6927 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6928 ut_params->digest, 6929 tdata->digest_enc.data, 6930 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6931 "Generated auth tag not as expected"); 6932 } 6933 6934 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6935 "crypto op processing failed"); 6936 6937 return 0; 6938 } 6939 6940 static int 6941 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 6942 uint8_t op_mode, uint8_t verify) 6943 { 6944 struct crypto_testsuite_params *ts_params = &testsuite_params; 6945 struct crypto_unittest_params *ut_params = &unittest_params; 6946 6947 int retval; 6948 6949 const uint8_t *plaintext = NULL; 6950 const uint8_t *ciphertext = NULL; 6951 const uint8_t *digest = NULL; 6952 unsigned int plaintext_pad_len; 6953 unsigned int plaintext_len; 6954 unsigned int ciphertext_pad_len; 6955 unsigned int ciphertext_len; 6956 uint8_t buffer[10000]; 6957 uint8_t digest_buffer[10000]; 6958 6959 struct rte_cryptodev_info dev_info; 6960 struct rte_crypto_op *op; 6961 6962 /* Check if device supports particular algorithms */ 6963 if (test_mixed_check_if_unsupported(tdata)) 6964 return -ENOTSUP; 6965 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6966 return -ENOTSUP; 6967 6968 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6969 6970 uint64_t feat_flags = dev_info.feature_flags; 6971 6972 if (op_mode == IN_PLACE) { 6973 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6974 printf("Device doesn't support in-place scatter-gather " 6975 "in both input and output mbufs.\n"); 6976 return -ENOTSUP; 6977 } 6978 } else { 6979 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6980 printf("Device doesn't support out-of-place scatter-gather " 6981 "in both input and output mbufs.\n"); 6982 return -ENOTSUP; 6983 } 6984 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6985 printf("Device doesn't support digest encrypted.\n"); 6986 return -ENOTSUP; 6987 } 6988 } 6989 6990 /* Create the session */ 6991 if (verify) 6992 retval = create_wireless_algo_cipher_auth_session( 6993 ts_params->valid_devs[0], 6994 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6995 RTE_CRYPTO_AUTH_OP_VERIFY, 6996 tdata->auth_algo, 6997 tdata->cipher_algo, 6998 tdata->auth_key.data, tdata->auth_key.len, 6999 tdata->auth_iv.len, tdata->digest_enc.len, 7000 tdata->cipher_iv.len); 7001 else 7002 retval = create_wireless_algo_auth_cipher_session( 7003 ts_params->valid_devs[0], 7004 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7005 RTE_CRYPTO_AUTH_OP_GENERATE, 7006 tdata->auth_algo, 7007 tdata->cipher_algo, 7008 tdata->auth_key.data, tdata->auth_key.len, 7009 tdata->auth_iv.len, tdata->digest_enc.len, 7010 tdata->cipher_iv.len); 7011 if (retval < 0) 7012 return retval; 7013 7014 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7015 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7016 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7017 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7018 7019 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7020 ciphertext_pad_len, 15, 0); 7021 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7022 "Failed to allocate input buffer in mempool"); 7023 7024 if (op_mode == OUT_OF_PLACE) { 7025 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7026 plaintext_pad_len, 15, 0); 7027 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7028 "Failed to allocate output buffer in mempool"); 7029 } 7030 7031 if (verify) { 7032 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7033 tdata->ciphertext.data); 7034 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7035 ciphertext_len, buffer); 7036 debug_hexdump(stdout, "ciphertext:", ciphertext, 7037 ciphertext_len); 7038 } else { 7039 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7040 tdata->plaintext.data); 7041 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7042 plaintext_len, buffer); 7043 debug_hexdump(stdout, "plaintext:", plaintext, 7044 plaintext_len); 7045 } 7046 memset(buffer, 0, sizeof(buffer)); 7047 7048 /* Create the operation */ 7049 retval = create_wireless_algo_auth_cipher_operation( 7050 tdata->digest_enc.data, tdata->digest_enc.len, 7051 tdata->cipher_iv.data, tdata->cipher_iv.len, 7052 tdata->auth_iv.data, tdata->auth_iv.len, 7053 (tdata->digest_enc.offset == 0 ? 7054 plaintext_pad_len 7055 : tdata->digest_enc.offset), 7056 tdata->validCipherLen.len_bits, 7057 tdata->cipher.offset_bits, 7058 tdata->validAuthLen.len_bits, 7059 tdata->auth.offset_bits, 7060 op_mode, 1, verify); 7061 7062 if (retval < 0) 7063 return retval; 7064 7065 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7066 7067 /* Check if the op failed because the device doesn't */ 7068 /* support this particular combination of algorithms */ 7069 if (op == NULL && ut_params->op->status == 7070 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7071 printf("Device doesn't support this mixed combination. " 7072 "Test Skipped.\n"); 7073 return -ENOTSUP; 7074 } 7075 ut_params->op = op; 7076 7077 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7078 7079 ut_params->obuf = (op_mode == IN_PLACE ? 7080 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7081 7082 if (verify) { 7083 if (ut_params->obuf) 7084 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7085 plaintext_len, buffer); 7086 else 7087 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7088 plaintext_len, buffer); 7089 7090 debug_hexdump(stdout, "plaintext:", plaintext, 7091 (tdata->plaintext.len_bits >> 3) - 7092 tdata->digest_enc.len); 7093 debug_hexdump(stdout, "plaintext expected:", 7094 tdata->plaintext.data, 7095 (tdata->plaintext.len_bits >> 3) - 7096 tdata->digest_enc.len); 7097 } else { 7098 if (ut_params->obuf) 7099 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7100 ciphertext_len, buffer); 7101 else 7102 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7103 ciphertext_len, buffer); 7104 7105 debug_hexdump(stdout, "ciphertext:", ciphertext, 7106 ciphertext_len); 7107 debug_hexdump(stdout, "ciphertext expected:", 7108 tdata->ciphertext.data, 7109 tdata->ciphertext.len_bits >> 3); 7110 7111 if (ut_params->obuf) 7112 digest = rte_pktmbuf_read(ut_params->obuf, 7113 (tdata->digest_enc.offset == 0 ? 7114 plaintext_pad_len : 7115 tdata->digest_enc.offset), 7116 tdata->digest_enc.len, digest_buffer); 7117 else 7118 digest = rte_pktmbuf_read(ut_params->ibuf, 7119 (tdata->digest_enc.offset == 0 ? 7120 plaintext_pad_len : 7121 tdata->digest_enc.offset), 7122 tdata->digest_enc.len, digest_buffer); 7123 7124 debug_hexdump(stdout, "digest:", digest, 7125 tdata->digest_enc.len); 7126 debug_hexdump(stdout, "digest expected:", 7127 tdata->digest_enc.data, tdata->digest_enc.len); 7128 } 7129 7130 /* Validate obuf */ 7131 if (verify) { 7132 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7133 plaintext, 7134 tdata->plaintext.data, 7135 tdata->plaintext.len_bits >> 3, 7136 "Plaintext data not as expected"); 7137 } else { 7138 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7139 ciphertext, 7140 tdata->ciphertext.data, 7141 tdata->validDataLen.len_bits, 7142 "Ciphertext data not as expected"); 7143 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7144 digest, 7145 tdata->digest_enc.data, 7146 tdata->digest_enc.len, 7147 "Generated auth tag not as expected"); 7148 } 7149 7150 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7151 "crypto op processing failed"); 7152 7153 return 0; 7154 } 7155 7156 /** AUTH AES CMAC + CIPHER AES CTR */ 7157 7158 static int 7159 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7160 { 7161 return test_mixed_auth_cipher( 7162 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7163 } 7164 7165 static int 7166 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7167 { 7168 return test_mixed_auth_cipher( 7169 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7170 } 7171 7172 static int 7173 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7174 { 7175 return test_mixed_auth_cipher_sgl( 7176 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7177 } 7178 7179 static int 7180 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7181 { 7182 return test_mixed_auth_cipher_sgl( 7183 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7184 } 7185 7186 static int 7187 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7188 { 7189 return test_mixed_auth_cipher( 7190 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7191 } 7192 7193 static int 7194 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7195 { 7196 return test_mixed_auth_cipher( 7197 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7198 } 7199 7200 static int 7201 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7202 { 7203 return test_mixed_auth_cipher_sgl( 7204 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7205 } 7206 7207 static int 7208 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7209 { 7210 return test_mixed_auth_cipher_sgl( 7211 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7212 } 7213 7214 /** MIXED AUTH + CIPHER */ 7215 7216 static int 7217 test_auth_zuc_cipher_snow_test_case_1(void) 7218 { 7219 return test_mixed_auth_cipher( 7220 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7221 } 7222 7223 static int 7224 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7225 { 7226 return test_mixed_auth_cipher( 7227 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7228 } 7229 7230 static int 7231 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7232 { 7233 return test_mixed_auth_cipher( 7234 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7235 } 7236 7237 static int 7238 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7239 { 7240 return test_mixed_auth_cipher( 7241 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7242 } 7243 7244 static int 7245 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7246 { 7247 return test_mixed_auth_cipher( 7248 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7249 } 7250 7251 static int 7252 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7253 { 7254 return test_mixed_auth_cipher( 7255 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7256 } 7257 7258 static int 7259 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7260 { 7261 return test_mixed_auth_cipher( 7262 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7263 } 7264 7265 static int 7266 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7267 { 7268 return test_mixed_auth_cipher( 7269 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7270 } 7271 7272 static int 7273 test_auth_snow_cipher_zuc_test_case_1(void) 7274 { 7275 return test_mixed_auth_cipher( 7276 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7277 } 7278 7279 static int 7280 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7281 { 7282 return test_mixed_auth_cipher( 7283 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7284 } 7285 7286 static int 7287 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7288 { 7289 return test_mixed_auth_cipher( 7290 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7291 } 7292 7293 static int 7294 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7295 { 7296 return test_mixed_auth_cipher( 7297 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7298 } 7299 7300 static int 7301 test_auth_null_cipher_snow_test_case_1(void) 7302 { 7303 return test_mixed_auth_cipher( 7304 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7305 } 7306 7307 static int 7308 test_verify_auth_null_cipher_snow_test_case_1(void) 7309 { 7310 return test_mixed_auth_cipher( 7311 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7312 } 7313 7314 static int 7315 test_auth_null_cipher_zuc_test_case_1(void) 7316 { 7317 return test_mixed_auth_cipher( 7318 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7319 } 7320 7321 static int 7322 test_verify_auth_null_cipher_zuc_test_case_1(void) 7323 { 7324 return test_mixed_auth_cipher( 7325 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7326 } 7327 7328 static int 7329 test_auth_snow_cipher_null_test_case_1(void) 7330 { 7331 return test_mixed_auth_cipher( 7332 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7333 } 7334 7335 static int 7336 test_verify_auth_snow_cipher_null_test_case_1(void) 7337 { 7338 return test_mixed_auth_cipher( 7339 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7340 } 7341 7342 static int 7343 test_auth_zuc_cipher_null_test_case_1(void) 7344 { 7345 return test_mixed_auth_cipher( 7346 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7347 } 7348 7349 static int 7350 test_verify_auth_zuc_cipher_null_test_case_1(void) 7351 { 7352 return test_mixed_auth_cipher( 7353 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7354 } 7355 7356 static int 7357 test_auth_null_cipher_aes_ctr_test_case_1(void) 7358 { 7359 return test_mixed_auth_cipher( 7360 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7361 } 7362 7363 static int 7364 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7365 { 7366 return test_mixed_auth_cipher( 7367 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7368 } 7369 7370 static int 7371 test_auth_aes_cmac_cipher_null_test_case_1(void) 7372 { 7373 return test_mixed_auth_cipher( 7374 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7375 } 7376 7377 static int 7378 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7379 { 7380 return test_mixed_auth_cipher( 7381 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7382 } 7383 7384 /* ***** AEAD algorithm Tests ***** */ 7385 7386 static int 7387 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7388 enum rte_crypto_aead_operation op, 7389 const uint8_t *key, const uint8_t key_len, 7390 const uint16_t aad_len, const uint8_t auth_len, 7391 uint8_t iv_len) 7392 { 7393 uint8_t aead_key[key_len]; 7394 7395 struct crypto_testsuite_params *ts_params = &testsuite_params; 7396 struct crypto_unittest_params *ut_params = &unittest_params; 7397 7398 memcpy(aead_key, key, key_len); 7399 7400 /* Setup AEAD Parameters */ 7401 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7402 ut_params->aead_xform.next = NULL; 7403 ut_params->aead_xform.aead.algo = algo; 7404 ut_params->aead_xform.aead.op = op; 7405 ut_params->aead_xform.aead.key.data = aead_key; 7406 ut_params->aead_xform.aead.key.length = key_len; 7407 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7408 ut_params->aead_xform.aead.iv.length = iv_len; 7409 ut_params->aead_xform.aead.digest_length = auth_len; 7410 ut_params->aead_xform.aead.aad_length = aad_len; 7411 7412 debug_hexdump(stdout, "key:", key, key_len); 7413 7414 /* Create Crypto session*/ 7415 ut_params->sess = rte_cryptodev_sym_session_create( 7416 ts_params->session_mpool); 7417 7418 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 7419 &ut_params->aead_xform, 7420 ts_params->session_priv_mpool); 7421 7422 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 7423 7424 return 0; 7425 } 7426 7427 static int 7428 create_aead_xform(struct rte_crypto_op *op, 7429 enum rte_crypto_aead_algorithm algo, 7430 enum rte_crypto_aead_operation aead_op, 7431 uint8_t *key, const uint8_t key_len, 7432 const uint8_t aad_len, const uint8_t auth_len, 7433 uint8_t iv_len) 7434 { 7435 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 7436 "failed to allocate space for crypto transform"); 7437 7438 struct rte_crypto_sym_op *sym_op = op->sym; 7439 7440 /* Setup AEAD Parameters */ 7441 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 7442 sym_op->xform->next = NULL; 7443 sym_op->xform->aead.algo = algo; 7444 sym_op->xform->aead.op = aead_op; 7445 sym_op->xform->aead.key.data = key; 7446 sym_op->xform->aead.key.length = key_len; 7447 sym_op->xform->aead.iv.offset = IV_OFFSET; 7448 sym_op->xform->aead.iv.length = iv_len; 7449 sym_op->xform->aead.digest_length = auth_len; 7450 sym_op->xform->aead.aad_length = aad_len; 7451 7452 debug_hexdump(stdout, "key:", key, key_len); 7453 7454 return 0; 7455 } 7456 7457 static int 7458 create_aead_operation(enum rte_crypto_aead_operation op, 7459 const struct aead_test_data *tdata) 7460 { 7461 struct crypto_testsuite_params *ts_params = &testsuite_params; 7462 struct crypto_unittest_params *ut_params = &unittest_params; 7463 7464 uint8_t *plaintext, *ciphertext; 7465 unsigned int aad_pad_len, plaintext_pad_len; 7466 7467 /* Generate Crypto op data structure */ 7468 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7469 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7470 TEST_ASSERT_NOT_NULL(ut_params->op, 7471 "Failed to allocate symmetric crypto operation struct"); 7472 7473 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 7474 7475 /* Append aad data */ 7476 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 7477 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 7478 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7479 aad_pad_len); 7480 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7481 "no room to append aad"); 7482 7483 sym_op->aead.aad.phys_addr = 7484 rte_pktmbuf_iova(ut_params->ibuf); 7485 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 7486 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 7487 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7488 tdata->aad.len); 7489 7490 /* Append IV at the end of the crypto operation*/ 7491 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7492 uint8_t *, IV_OFFSET); 7493 7494 /* Copy IV 1 byte after the IV pointer, according to the API */ 7495 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 7496 debug_hexdump(stdout, "iv:", iv_ptr, 7497 tdata->iv.len); 7498 } else { 7499 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 7500 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7501 aad_pad_len); 7502 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7503 "no room to append aad"); 7504 7505 sym_op->aead.aad.phys_addr = 7506 rte_pktmbuf_iova(ut_params->ibuf); 7507 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 7508 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7509 tdata->aad.len); 7510 7511 /* Append IV at the end of the crypto operation*/ 7512 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7513 uint8_t *, IV_OFFSET); 7514 7515 if (tdata->iv.len == 0) { 7516 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 7517 debug_hexdump(stdout, "iv:", iv_ptr, 7518 AES_GCM_J0_LENGTH); 7519 } else { 7520 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 7521 debug_hexdump(stdout, "iv:", iv_ptr, 7522 tdata->iv.len); 7523 } 7524 } 7525 7526 /* Append plaintext/ciphertext */ 7527 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7528 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7529 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7530 plaintext_pad_len); 7531 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 7532 7533 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 7534 debug_hexdump(stdout, "plaintext:", plaintext, 7535 tdata->plaintext.len); 7536 7537 if (ut_params->obuf) { 7538 ciphertext = (uint8_t *)rte_pktmbuf_append( 7539 ut_params->obuf, 7540 plaintext_pad_len + aad_pad_len); 7541 TEST_ASSERT_NOT_NULL(ciphertext, 7542 "no room to append ciphertext"); 7543 7544 memset(ciphertext + aad_pad_len, 0, 7545 tdata->ciphertext.len); 7546 } 7547 } else { 7548 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 7549 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7550 plaintext_pad_len); 7551 TEST_ASSERT_NOT_NULL(ciphertext, 7552 "no room to append ciphertext"); 7553 7554 memcpy(ciphertext, tdata->ciphertext.data, 7555 tdata->ciphertext.len); 7556 debug_hexdump(stdout, "ciphertext:", ciphertext, 7557 tdata->ciphertext.len); 7558 7559 if (ut_params->obuf) { 7560 plaintext = (uint8_t *)rte_pktmbuf_append( 7561 ut_params->obuf, 7562 plaintext_pad_len + aad_pad_len); 7563 TEST_ASSERT_NOT_NULL(plaintext, 7564 "no room to append plaintext"); 7565 7566 memset(plaintext + aad_pad_len, 0, 7567 tdata->plaintext.len); 7568 } 7569 } 7570 7571 /* Append digest data */ 7572 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7573 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7574 ut_params->obuf ? ut_params->obuf : 7575 ut_params->ibuf, 7576 tdata->auth_tag.len); 7577 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7578 "no room to append digest"); 7579 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 7580 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7581 ut_params->obuf ? ut_params->obuf : 7582 ut_params->ibuf, 7583 plaintext_pad_len + 7584 aad_pad_len); 7585 } else { 7586 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7587 ut_params->ibuf, tdata->auth_tag.len); 7588 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7589 "no room to append digest"); 7590 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7591 ut_params->ibuf, 7592 plaintext_pad_len + aad_pad_len); 7593 7594 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 7595 tdata->auth_tag.len); 7596 debug_hexdump(stdout, "digest:", 7597 sym_op->aead.digest.data, 7598 tdata->auth_tag.len); 7599 } 7600 7601 sym_op->aead.data.length = tdata->plaintext.len; 7602 sym_op->aead.data.offset = aad_pad_len; 7603 7604 return 0; 7605 } 7606 7607 static int 7608 test_authenticated_encryption(const struct aead_test_data *tdata) 7609 { 7610 struct crypto_testsuite_params *ts_params = &testsuite_params; 7611 struct crypto_unittest_params *ut_params = &unittest_params; 7612 7613 int retval; 7614 uint8_t *ciphertext, *auth_tag; 7615 uint16_t plaintext_pad_len; 7616 uint32_t i; 7617 struct rte_cryptodev_info dev_info; 7618 7619 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7620 uint64_t feat_flags = dev_info.feature_flags; 7621 7622 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 7623 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 7624 printf("Device doesn't support RAW data-path APIs.\n"); 7625 return -ENOTSUP; 7626 } 7627 7628 /* Verify the capabilities */ 7629 struct rte_cryptodev_sym_capability_idx cap_idx; 7630 const struct rte_cryptodev_symmetric_capability *capability; 7631 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7632 cap_idx.algo.aead = tdata->algo; 7633 capability = rte_cryptodev_sym_capability_get( 7634 ts_params->valid_devs[0], &cap_idx); 7635 if (capability == NULL) 7636 return -ENOTSUP; 7637 if (rte_cryptodev_sym_capability_check_aead( 7638 capability, tdata->key.len, tdata->auth_tag.len, 7639 tdata->aad.len, tdata->iv.len)) 7640 return -ENOTSUP; 7641 7642 /* Create AEAD session */ 7643 retval = create_aead_session(ts_params->valid_devs[0], 7644 tdata->algo, 7645 RTE_CRYPTO_AEAD_OP_ENCRYPT, 7646 tdata->key.data, tdata->key.len, 7647 tdata->aad.len, tdata->auth_tag.len, 7648 tdata->iv.len); 7649 if (retval < 0) 7650 return retval; 7651 7652 if (tdata->aad.len > MBUF_SIZE) { 7653 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7654 /* Populate full size of add data */ 7655 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7656 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7657 } else 7658 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7659 7660 /* clear mbuf payload */ 7661 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7662 rte_pktmbuf_tailroom(ut_params->ibuf)); 7663 7664 /* Create AEAD operation */ 7665 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 7666 if (retval < 0) 7667 return retval; 7668 7669 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7670 7671 ut_params->op->sym->m_src = ut_params->ibuf; 7672 7673 /* Process crypto operation */ 7674 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7675 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7676 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7677 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 7678 ut_params->op, 0, 0, 0, 0); 7679 else 7680 TEST_ASSERT_NOT_NULL( 7681 process_crypto_request(ts_params->valid_devs[0], 7682 ut_params->op), "failed to process sym crypto op"); 7683 7684 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7685 "crypto op processing failed"); 7686 7687 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7688 7689 if (ut_params->op->sym->m_dst) { 7690 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7691 uint8_t *); 7692 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7693 uint8_t *, plaintext_pad_len); 7694 } else { 7695 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7696 uint8_t *, 7697 ut_params->op->sym->cipher.data.offset); 7698 auth_tag = ciphertext + plaintext_pad_len; 7699 } 7700 7701 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 7702 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 7703 7704 /* Validate obuf */ 7705 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7706 ciphertext, 7707 tdata->ciphertext.data, 7708 tdata->ciphertext.len, 7709 "Ciphertext data not as expected"); 7710 7711 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7712 auth_tag, 7713 tdata->auth_tag.data, 7714 tdata->auth_tag.len, 7715 "Generated auth tag not as expected"); 7716 7717 return 0; 7718 7719 } 7720 7721 #ifdef RTE_LIB_SECURITY 7722 static int 7723 security_proto_supported(enum rte_security_session_action_type action, 7724 enum rte_security_session_protocol proto) 7725 { 7726 struct crypto_testsuite_params *ts_params = &testsuite_params; 7727 7728 const struct rte_security_capability *capabilities; 7729 const struct rte_security_capability *capability; 7730 uint16_t i = 0; 7731 7732 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7733 rte_cryptodev_get_sec_ctx( 7734 ts_params->valid_devs[0]); 7735 7736 7737 capabilities = rte_security_capabilities_get(ctx); 7738 7739 if (capabilities == NULL) 7740 return -ENOTSUP; 7741 7742 while ((capability = &capabilities[i++])->action != 7743 RTE_SECURITY_ACTION_TYPE_NONE) { 7744 if (capability->action == action && 7745 capability->protocol == proto) 7746 return 0; 7747 } 7748 7749 return -ENOTSUP; 7750 } 7751 7752 /* Basic algorithm run function for async inplace mode. 7753 * Creates a session from input parameters and runs one operation 7754 * on input_vec. Checks the output of the crypto operation against 7755 * output_vec. 7756 */ 7757 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 7758 enum rte_crypto_auth_operation opa, 7759 const uint8_t *input_vec, unsigned int input_vec_len, 7760 const uint8_t *output_vec, 7761 unsigned int output_vec_len, 7762 enum rte_crypto_cipher_algorithm cipher_alg, 7763 const uint8_t *cipher_key, uint32_t cipher_key_len, 7764 enum rte_crypto_auth_algorithm auth_alg, 7765 const uint8_t *auth_key, uint32_t auth_key_len, 7766 uint8_t bearer, enum rte_security_pdcp_domain domain, 7767 uint8_t packet_direction, uint8_t sn_size, 7768 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 7769 { 7770 struct crypto_testsuite_params *ts_params = &testsuite_params; 7771 struct crypto_unittest_params *ut_params = &unittest_params; 7772 uint8_t *plaintext; 7773 int ret = TEST_SUCCESS; 7774 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7775 rte_cryptodev_get_sec_ctx( 7776 ts_params->valid_devs[0]); 7777 7778 /* Verify the capabilities */ 7779 struct rte_security_capability_idx sec_cap_idx; 7780 7781 sec_cap_idx.action = ut_params->type; 7782 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7783 sec_cap_idx.pdcp.domain = domain; 7784 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7785 return -ENOTSUP; 7786 7787 /* Generate test mbuf data */ 7788 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7789 7790 /* clear mbuf payload */ 7791 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7792 rte_pktmbuf_tailroom(ut_params->ibuf)); 7793 7794 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7795 input_vec_len); 7796 memcpy(plaintext, input_vec, input_vec_len); 7797 7798 /* Out of place support */ 7799 if (oop) { 7800 /* 7801 * For out-op-place we need to alloc another mbuf 7802 */ 7803 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7804 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 7805 } 7806 7807 /* Setup Cipher Parameters */ 7808 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7809 ut_params->cipher_xform.cipher.algo = cipher_alg; 7810 ut_params->cipher_xform.cipher.op = opc; 7811 ut_params->cipher_xform.cipher.key.data = cipher_key; 7812 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 7813 ut_params->cipher_xform.cipher.iv.length = 7814 packet_direction ? 4 : 0; 7815 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 7816 7817 /* Setup HMAC Parameters if ICV header is required */ 7818 if (auth_alg != 0) { 7819 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7820 ut_params->auth_xform.next = NULL; 7821 ut_params->auth_xform.auth.algo = auth_alg; 7822 ut_params->auth_xform.auth.op = opa; 7823 ut_params->auth_xform.auth.key.data = auth_key; 7824 ut_params->auth_xform.auth.key.length = auth_key_len; 7825 7826 ut_params->cipher_xform.next = &ut_params->auth_xform; 7827 } else { 7828 ut_params->cipher_xform.next = NULL; 7829 } 7830 7831 struct rte_security_session_conf sess_conf = { 7832 .action_type = ut_params->type, 7833 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7834 {.pdcp = { 7835 .bearer = bearer, 7836 .domain = domain, 7837 .pkt_dir = packet_direction, 7838 .sn_size = sn_size, 7839 .hfn = packet_direction ? 0 : hfn, 7840 /** 7841 * hfn can be set as pdcp_test_hfn[i] 7842 * if hfn_ovrd is not set. Here, PDCP 7843 * packet direction is just used to 7844 * run half of the cases with session 7845 * HFN and other half with per packet 7846 * HFN. 7847 */ 7848 .hfn_threshold = hfn_threshold, 7849 .hfn_ovrd = packet_direction ? 1 : 0, 7850 .sdap_enabled = sdap, 7851 } }, 7852 .crypto_xform = &ut_params->cipher_xform 7853 }; 7854 7855 /* Create security session */ 7856 ut_params->sec_session = rte_security_session_create(ctx, 7857 &sess_conf, ts_params->session_mpool, 7858 ts_params->session_priv_mpool); 7859 7860 if (!ut_params->sec_session) { 7861 printf("TestCase %s()-%d line %d failed %s: ", 7862 __func__, i, __LINE__, "Failed to allocate session"); 7863 ret = TEST_FAILED; 7864 goto on_err; 7865 } 7866 7867 /* Generate crypto op data structure */ 7868 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7869 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7870 if (!ut_params->op) { 7871 printf("TestCase %s()-%d line %d failed %s: ", 7872 __func__, i, __LINE__, 7873 "Failed to allocate symmetric crypto operation struct"); 7874 ret = TEST_FAILED; 7875 goto on_err; 7876 } 7877 7878 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 7879 uint32_t *, IV_OFFSET); 7880 *per_pkt_hfn = packet_direction ? hfn : 0; 7881 7882 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7883 7884 /* set crypto operation source mbuf */ 7885 ut_params->op->sym->m_src = ut_params->ibuf; 7886 if (oop) 7887 ut_params->op->sym->m_dst = ut_params->obuf; 7888 7889 /* Process crypto operation */ 7890 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7891 == NULL) { 7892 printf("TestCase %s()-%d line %d failed %s: ", 7893 __func__, i, __LINE__, 7894 "failed to process sym crypto op"); 7895 ret = TEST_FAILED; 7896 goto on_err; 7897 } 7898 7899 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7900 printf("TestCase %s()-%d line %d failed %s: ", 7901 __func__, i, __LINE__, "crypto op processing failed"); 7902 ret = TEST_FAILED; 7903 goto on_err; 7904 } 7905 7906 /* Validate obuf */ 7907 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7908 uint8_t *); 7909 if (oop) { 7910 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7911 uint8_t *); 7912 } 7913 7914 if (memcmp(ciphertext, output_vec, output_vec_len)) { 7915 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7916 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 7917 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 7918 ret = TEST_FAILED; 7919 goto on_err; 7920 } 7921 7922 on_err: 7923 rte_crypto_op_free(ut_params->op); 7924 ut_params->op = NULL; 7925 7926 if (ut_params->sec_session) 7927 rte_security_session_destroy(ctx, ut_params->sec_session); 7928 ut_params->sec_session = NULL; 7929 7930 rte_pktmbuf_free(ut_params->ibuf); 7931 ut_params->ibuf = NULL; 7932 if (oop) { 7933 rte_pktmbuf_free(ut_params->obuf); 7934 ut_params->obuf = NULL; 7935 } 7936 7937 return ret; 7938 } 7939 7940 static int 7941 test_pdcp_proto_SGL(int i, int oop, 7942 enum rte_crypto_cipher_operation opc, 7943 enum rte_crypto_auth_operation opa, 7944 uint8_t *input_vec, 7945 unsigned int input_vec_len, 7946 uint8_t *output_vec, 7947 unsigned int output_vec_len, 7948 uint32_t fragsz, 7949 uint32_t fragsz_oop) 7950 { 7951 struct crypto_testsuite_params *ts_params = &testsuite_params; 7952 struct crypto_unittest_params *ut_params = &unittest_params; 7953 uint8_t *plaintext; 7954 struct rte_mbuf *buf, *buf_oop = NULL; 7955 int ret = TEST_SUCCESS; 7956 int to_trn = 0; 7957 int to_trn_tbl[16]; 7958 int segs = 1; 7959 unsigned int trn_data = 0; 7960 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7961 rte_cryptodev_get_sec_ctx( 7962 ts_params->valid_devs[0]); 7963 7964 /* Verify the capabilities */ 7965 struct rte_security_capability_idx sec_cap_idx; 7966 7967 sec_cap_idx.action = ut_params->type; 7968 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7969 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7970 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7971 return -ENOTSUP; 7972 7973 if (fragsz > input_vec_len) 7974 fragsz = input_vec_len; 7975 7976 uint16_t plaintext_len = fragsz; 7977 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 7978 7979 if (fragsz_oop > output_vec_len) 7980 frag_size_oop = output_vec_len; 7981 7982 int ecx = 0; 7983 if (input_vec_len % fragsz != 0) { 7984 if (input_vec_len / fragsz + 1 > 16) 7985 return 1; 7986 } else if (input_vec_len / fragsz > 16) 7987 return 1; 7988 7989 /* Out of place support */ 7990 if (oop) { 7991 /* 7992 * For out-op-place we need to alloc another mbuf 7993 */ 7994 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7995 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 7996 buf_oop = ut_params->obuf; 7997 } 7998 7999 /* Generate test mbuf data */ 8000 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8001 8002 /* clear mbuf payload */ 8003 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8004 rte_pktmbuf_tailroom(ut_params->ibuf)); 8005 8006 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8007 plaintext_len); 8008 memcpy(plaintext, input_vec, plaintext_len); 8009 trn_data += plaintext_len; 8010 8011 buf = ut_params->ibuf; 8012 8013 /* 8014 * Loop until no more fragments 8015 */ 8016 8017 while (trn_data < input_vec_len) { 8018 ++segs; 8019 to_trn = (input_vec_len - trn_data < fragsz) ? 8020 (input_vec_len - trn_data) : fragsz; 8021 8022 to_trn_tbl[ecx++] = to_trn; 8023 8024 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8025 buf = buf->next; 8026 8027 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8028 rte_pktmbuf_tailroom(buf)); 8029 8030 /* OOP */ 8031 if (oop && !fragsz_oop) { 8032 buf_oop->next = 8033 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8034 buf_oop = buf_oop->next; 8035 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8036 0, rte_pktmbuf_tailroom(buf_oop)); 8037 rte_pktmbuf_append(buf_oop, to_trn); 8038 } 8039 8040 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8041 to_trn); 8042 8043 memcpy(plaintext, input_vec + trn_data, to_trn); 8044 trn_data += to_trn; 8045 } 8046 8047 ut_params->ibuf->nb_segs = segs; 8048 8049 segs = 1; 8050 if (fragsz_oop && oop) { 8051 to_trn = 0; 8052 ecx = 0; 8053 8054 trn_data = frag_size_oop; 8055 while (trn_data < output_vec_len) { 8056 ++segs; 8057 to_trn = 8058 (output_vec_len - trn_data < 8059 frag_size_oop) ? 8060 (output_vec_len - trn_data) : 8061 frag_size_oop; 8062 8063 to_trn_tbl[ecx++] = to_trn; 8064 8065 buf_oop->next = 8066 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8067 buf_oop = buf_oop->next; 8068 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8069 0, rte_pktmbuf_tailroom(buf_oop)); 8070 rte_pktmbuf_append(buf_oop, to_trn); 8071 8072 trn_data += to_trn; 8073 } 8074 ut_params->obuf->nb_segs = segs; 8075 } 8076 8077 /* Setup Cipher Parameters */ 8078 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8079 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8080 ut_params->cipher_xform.cipher.op = opc; 8081 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8082 ut_params->cipher_xform.cipher.key.length = 8083 pdcp_test_params[i].cipher_key_len; 8084 ut_params->cipher_xform.cipher.iv.length = 0; 8085 8086 /* Setup HMAC Parameters if ICV header is required */ 8087 if (pdcp_test_params[i].auth_alg != 0) { 8088 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8089 ut_params->auth_xform.next = NULL; 8090 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8091 ut_params->auth_xform.auth.op = opa; 8092 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8093 ut_params->auth_xform.auth.key.length = 8094 pdcp_test_params[i].auth_key_len; 8095 8096 ut_params->cipher_xform.next = &ut_params->auth_xform; 8097 } else { 8098 ut_params->cipher_xform.next = NULL; 8099 } 8100 8101 struct rte_security_session_conf sess_conf = { 8102 .action_type = ut_params->type, 8103 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8104 {.pdcp = { 8105 .bearer = pdcp_test_bearer[i], 8106 .domain = pdcp_test_params[i].domain, 8107 .pkt_dir = pdcp_test_packet_direction[i], 8108 .sn_size = pdcp_test_data_sn_size[i], 8109 .hfn = pdcp_test_hfn[i], 8110 .hfn_threshold = pdcp_test_hfn_threshold[i], 8111 .hfn_ovrd = 0, 8112 } }, 8113 .crypto_xform = &ut_params->cipher_xform 8114 }; 8115 8116 /* Create security session */ 8117 ut_params->sec_session = rte_security_session_create(ctx, 8118 &sess_conf, ts_params->session_mpool, 8119 ts_params->session_priv_mpool); 8120 8121 if (!ut_params->sec_session) { 8122 printf("TestCase %s()-%d line %d failed %s: ", 8123 __func__, i, __LINE__, "Failed to allocate session"); 8124 ret = TEST_FAILED; 8125 goto on_err; 8126 } 8127 8128 /* Generate crypto op data structure */ 8129 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8130 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8131 if (!ut_params->op) { 8132 printf("TestCase %s()-%d line %d failed %s: ", 8133 __func__, i, __LINE__, 8134 "Failed to allocate symmetric crypto operation struct"); 8135 ret = TEST_FAILED; 8136 goto on_err; 8137 } 8138 8139 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8140 8141 /* set crypto operation source mbuf */ 8142 ut_params->op->sym->m_src = ut_params->ibuf; 8143 if (oop) 8144 ut_params->op->sym->m_dst = ut_params->obuf; 8145 8146 /* Process crypto operation */ 8147 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8148 == NULL) { 8149 printf("TestCase %s()-%d line %d failed %s: ", 8150 __func__, i, __LINE__, 8151 "failed to process sym crypto op"); 8152 ret = TEST_FAILED; 8153 goto on_err; 8154 } 8155 8156 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8157 printf("TestCase %s()-%d line %d failed %s: ", 8158 __func__, i, __LINE__, "crypto op processing failed"); 8159 ret = TEST_FAILED; 8160 goto on_err; 8161 } 8162 8163 /* Validate obuf */ 8164 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8165 uint8_t *); 8166 if (oop) { 8167 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8168 uint8_t *); 8169 } 8170 if (fragsz_oop) 8171 fragsz = frag_size_oop; 8172 if (memcmp(ciphertext, output_vec, fragsz)) { 8173 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8174 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8175 rte_hexdump(stdout, "reference", output_vec, fragsz); 8176 ret = TEST_FAILED; 8177 goto on_err; 8178 } 8179 8180 buf = ut_params->op->sym->m_src->next; 8181 if (oop) 8182 buf = ut_params->op->sym->m_dst->next; 8183 8184 unsigned int off = fragsz; 8185 8186 ecx = 0; 8187 while (buf) { 8188 ciphertext = rte_pktmbuf_mtod(buf, 8189 uint8_t *); 8190 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8191 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8192 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8193 rte_hexdump(stdout, "reference", output_vec + off, 8194 to_trn_tbl[ecx]); 8195 ret = TEST_FAILED; 8196 goto on_err; 8197 } 8198 off += to_trn_tbl[ecx++]; 8199 buf = buf->next; 8200 } 8201 on_err: 8202 rte_crypto_op_free(ut_params->op); 8203 ut_params->op = NULL; 8204 8205 if (ut_params->sec_session) 8206 rte_security_session_destroy(ctx, ut_params->sec_session); 8207 ut_params->sec_session = NULL; 8208 8209 rte_pktmbuf_free(ut_params->ibuf); 8210 ut_params->ibuf = NULL; 8211 if (oop) { 8212 rte_pktmbuf_free(ut_params->obuf); 8213 ut_params->obuf = NULL; 8214 } 8215 8216 return ret; 8217 } 8218 8219 int 8220 test_pdcp_proto_cplane_encap(int i) 8221 { 8222 return test_pdcp_proto( 8223 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8224 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8225 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8226 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8227 pdcp_test_params[i].cipher_key_len, 8228 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8229 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8230 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8231 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8232 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8233 } 8234 8235 int 8236 test_pdcp_proto_uplane_encap(int i) 8237 { 8238 return test_pdcp_proto( 8239 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8240 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8241 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8242 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8243 pdcp_test_params[i].cipher_key_len, 8244 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8245 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8246 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8247 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8248 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8249 } 8250 8251 int 8252 test_pdcp_proto_uplane_encap_with_int(int i) 8253 { 8254 return test_pdcp_proto( 8255 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8256 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8257 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8258 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8259 pdcp_test_params[i].cipher_key_len, 8260 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8261 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8262 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8263 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8264 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8265 } 8266 8267 int 8268 test_pdcp_proto_cplane_decap(int i) 8269 { 8270 return test_pdcp_proto( 8271 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8272 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8273 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8274 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8275 pdcp_test_params[i].cipher_key_len, 8276 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8277 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8278 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8279 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8280 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8281 } 8282 8283 int 8284 test_pdcp_proto_uplane_decap(int i) 8285 { 8286 return test_pdcp_proto( 8287 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8288 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8289 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8290 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8291 pdcp_test_params[i].cipher_key_len, 8292 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8293 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8294 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8295 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8296 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8297 } 8298 8299 int 8300 test_pdcp_proto_uplane_decap_with_int(int i) 8301 { 8302 return test_pdcp_proto( 8303 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8304 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8305 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8306 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8307 pdcp_test_params[i].cipher_key_len, 8308 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8309 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8310 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8311 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8312 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8313 } 8314 8315 static int 8316 test_PDCP_PROTO_SGL_in_place_32B(void) 8317 { 8318 /* i can be used for running any PDCP case 8319 * In this case it is uplane 12-bit AES-SNOW DL encap 8320 */ 8321 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8322 return test_pdcp_proto_SGL(i, IN_PLACE, 8323 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8324 RTE_CRYPTO_AUTH_OP_GENERATE, 8325 pdcp_test_data_in[i], 8326 pdcp_test_data_in_len[i], 8327 pdcp_test_data_out[i], 8328 pdcp_test_data_in_len[i]+4, 8329 32, 0); 8330 } 8331 static int 8332 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8333 { 8334 /* i can be used for running any PDCP case 8335 * In this case it is uplane 18-bit NULL-NULL DL encap 8336 */ 8337 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8338 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8339 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8340 RTE_CRYPTO_AUTH_OP_GENERATE, 8341 pdcp_test_data_in[i], 8342 pdcp_test_data_in_len[i], 8343 pdcp_test_data_out[i], 8344 pdcp_test_data_in_len[i]+4, 8345 32, 128); 8346 } 8347 static int 8348 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8349 { 8350 /* i can be used for running any PDCP case 8351 * In this case it is uplane 18-bit AES DL encap 8352 */ 8353 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8354 + DOWNLINK; 8355 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8356 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8357 RTE_CRYPTO_AUTH_OP_GENERATE, 8358 pdcp_test_data_in[i], 8359 pdcp_test_data_in_len[i], 8360 pdcp_test_data_out[i], 8361 pdcp_test_data_in_len[i], 8362 32, 40); 8363 } 8364 static int 8365 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8366 { 8367 /* i can be used for running any PDCP case 8368 * In this case it is cplane 12-bit AES-ZUC DL encap 8369 */ 8370 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8371 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8372 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8373 RTE_CRYPTO_AUTH_OP_GENERATE, 8374 pdcp_test_data_in[i], 8375 pdcp_test_data_in_len[i], 8376 pdcp_test_data_out[i], 8377 pdcp_test_data_in_len[i]+4, 8378 128, 32); 8379 } 8380 8381 static int 8382 test_PDCP_SDAP_PROTO_encap_all(void) 8383 { 8384 int i = 0, size = 0; 8385 int err, all_err = TEST_SUCCESS; 8386 const struct pdcp_sdap_test *cur_test; 8387 8388 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8389 8390 for (i = 0; i < size; i++) { 8391 cur_test = &list_pdcp_sdap_tests[i]; 8392 err = test_pdcp_proto( 8393 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8394 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 8395 cur_test->in_len, cur_test->data_out, 8396 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8397 cur_test->param.cipher_alg, cur_test->cipher_key, 8398 cur_test->param.cipher_key_len, 8399 cur_test->param.auth_alg, 8400 cur_test->auth_key, cur_test->param.auth_key_len, 8401 cur_test->bearer, cur_test->param.domain, 8402 cur_test->packet_direction, cur_test->sn_size, 8403 cur_test->hfn, 8404 cur_test->hfn_threshold, SDAP_ENABLED); 8405 if (err) { 8406 printf("\t%d) %s: Encapsulation failed\n", 8407 cur_test->test_idx, 8408 cur_test->param.name); 8409 err = TEST_FAILED; 8410 } else { 8411 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 8412 cur_test->param.name); 8413 err = TEST_SUCCESS; 8414 } 8415 all_err += err; 8416 } 8417 8418 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8419 8420 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8421 } 8422 8423 static int 8424 test_PDCP_SDAP_PROTO_decap_all(void) 8425 { 8426 int i = 0, size = 0; 8427 int err, all_err = TEST_SUCCESS; 8428 const struct pdcp_sdap_test *cur_test; 8429 8430 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8431 8432 for (i = 0; i < size; i++) { 8433 cur_test = &list_pdcp_sdap_tests[i]; 8434 err = test_pdcp_proto( 8435 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 8436 RTE_CRYPTO_AUTH_OP_VERIFY, 8437 cur_test->data_out, 8438 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8439 cur_test->data_in, cur_test->in_len, 8440 cur_test->param.cipher_alg, 8441 cur_test->cipher_key, cur_test->param.cipher_key_len, 8442 cur_test->param.auth_alg, cur_test->auth_key, 8443 cur_test->param.auth_key_len, cur_test->bearer, 8444 cur_test->param.domain, cur_test->packet_direction, 8445 cur_test->sn_size, cur_test->hfn, 8446 cur_test->hfn_threshold, SDAP_ENABLED); 8447 if (err) { 8448 printf("\t%d) %s: Decapsulation failed\n", 8449 cur_test->test_idx, 8450 cur_test->param.name); 8451 err = TEST_FAILED; 8452 } else { 8453 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 8454 cur_test->param.name); 8455 err = TEST_SUCCESS; 8456 } 8457 all_err += err; 8458 } 8459 8460 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8461 8462 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8463 } 8464 8465 static int 8466 test_PDCP_PROTO_all(void) 8467 { 8468 struct crypto_testsuite_params *ts_params = &testsuite_params; 8469 struct crypto_unittest_params *ut_params = &unittest_params; 8470 struct rte_cryptodev_info dev_info; 8471 int status; 8472 8473 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8474 uint64_t feat_flags = dev_info.feature_flags; 8475 8476 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8477 return -ENOTSUP; 8478 8479 /* Set action type */ 8480 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8481 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8482 gbl_action_type; 8483 8484 if (security_proto_supported(ut_params->type, 8485 RTE_SECURITY_PROTOCOL_PDCP) < 0) 8486 return -ENOTSUP; 8487 8488 status = test_PDCP_PROTO_cplane_encap_all(); 8489 status += test_PDCP_PROTO_cplane_decap_all(); 8490 status += test_PDCP_PROTO_uplane_encap_all(); 8491 status += test_PDCP_PROTO_uplane_decap_all(); 8492 status += test_PDCP_PROTO_SGL_in_place_32B(); 8493 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 8494 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 8495 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 8496 status += test_PDCP_SDAP_PROTO_encap_all(); 8497 status += test_PDCP_SDAP_PROTO_decap_all(); 8498 8499 if (status) 8500 return TEST_FAILED; 8501 else 8502 return TEST_SUCCESS; 8503 } 8504 8505 static int 8506 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td) 8507 { 8508 struct crypto_testsuite_params *ts_params = &testsuite_params; 8509 struct crypto_unittest_params *ut_params = &unittest_params; 8510 uint8_t *plaintext, *ciphertext; 8511 uint8_t *iv_ptr; 8512 int32_t cipher_len, crc_len; 8513 uint32_t crc_data_len; 8514 int ret = TEST_SUCCESS; 8515 8516 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8517 rte_cryptodev_get_sec_ctx( 8518 ts_params->valid_devs[0]); 8519 8520 /* Verify the capabilities */ 8521 struct rte_security_capability_idx sec_cap_idx; 8522 const struct rte_security_capability *sec_cap; 8523 const struct rte_cryptodev_capabilities *crypto_cap; 8524 const struct rte_cryptodev_symmetric_capability *sym_cap; 8525 int j = 0; 8526 8527 sec_cap_idx.action = ut_params->type; 8528 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8529 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 8530 8531 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8532 if (sec_cap == NULL) 8533 return -ENOTSUP; 8534 8535 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8536 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8537 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8538 crypto_cap->sym.xform_type == 8539 RTE_CRYPTO_SYM_XFORM_CIPHER && 8540 crypto_cap->sym.cipher.algo == 8541 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8542 sym_cap = &crypto_cap->sym; 8543 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8544 d_td->key.len, 8545 d_td->iv.len) == 0) 8546 break; 8547 } 8548 } 8549 8550 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8551 return -ENOTSUP; 8552 8553 /* Setup source mbuf payload */ 8554 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8555 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8556 rte_pktmbuf_tailroom(ut_params->ibuf)); 8557 8558 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8559 d_td->ciphertext.len); 8560 8561 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 8562 8563 /* Setup cipher session parameters */ 8564 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8565 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8566 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 8567 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8568 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8569 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8570 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8571 ut_params->cipher_xform.next = NULL; 8572 8573 /* Setup DOCSIS session parameters */ 8574 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 8575 8576 struct rte_security_session_conf sess_conf = { 8577 .action_type = ut_params->type, 8578 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8579 .docsis = ut_params->docsis_xform, 8580 .crypto_xform = &ut_params->cipher_xform, 8581 }; 8582 8583 /* Create security session */ 8584 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8585 ts_params->session_mpool, 8586 ts_params->session_priv_mpool); 8587 8588 if (!ut_params->sec_session) { 8589 printf("TestCase %s(%d) line %d: %s\n", 8590 __func__, i, __LINE__, "failed to allocate session"); 8591 ret = TEST_FAILED; 8592 goto on_err; 8593 } 8594 8595 /* Generate crypto op data structure */ 8596 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8597 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8598 if (!ut_params->op) { 8599 printf("TestCase %s(%d) line %d: %s\n", 8600 __func__, i, __LINE__, 8601 "failed to allocate symmetric crypto operation"); 8602 ret = TEST_FAILED; 8603 goto on_err; 8604 } 8605 8606 /* Setup CRC operation parameters */ 8607 crc_len = d_td->ciphertext.no_crc == false ? 8608 (d_td->ciphertext.len - 8609 d_td->ciphertext.crc_offset - 8610 RTE_ETHER_CRC_LEN) : 8611 0; 8612 crc_len = crc_len > 0 ? crc_len : 0; 8613 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 8614 ut_params->op->sym->auth.data.length = crc_len; 8615 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 8616 8617 /* Setup cipher operation parameters */ 8618 cipher_len = d_td->ciphertext.no_cipher == false ? 8619 (d_td->ciphertext.len - 8620 d_td->ciphertext.cipher_offset) : 8621 0; 8622 cipher_len = cipher_len > 0 ? cipher_len : 0; 8623 ut_params->op->sym->cipher.data.length = cipher_len; 8624 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 8625 8626 /* Setup cipher IV */ 8627 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8628 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8629 8630 /* Attach session to operation */ 8631 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8632 8633 /* Set crypto operation mbufs */ 8634 ut_params->op->sym->m_src = ut_params->ibuf; 8635 ut_params->op->sym->m_dst = NULL; 8636 8637 /* Process crypto operation */ 8638 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8639 NULL) { 8640 printf("TestCase %s(%d) line %d: %s\n", 8641 __func__, i, __LINE__, 8642 "failed to process security crypto op"); 8643 ret = TEST_FAILED; 8644 goto on_err; 8645 } 8646 8647 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8648 printf("TestCase %s(%d) line %d: %s\n", 8649 __func__, i, __LINE__, "crypto op processing failed"); 8650 ret = TEST_FAILED; 8651 goto on_err; 8652 } 8653 8654 /* Validate plaintext */ 8655 plaintext = ciphertext; 8656 8657 if (memcmp(plaintext, d_td->plaintext.data, 8658 d_td->plaintext.len - crc_data_len)) { 8659 printf("TestCase %s(%d) line %d: %s\n", 8660 __func__, i, __LINE__, "plaintext not as expected\n"); 8661 rte_hexdump(stdout, "expected", d_td->plaintext.data, 8662 d_td->plaintext.len); 8663 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 8664 ret = TEST_FAILED; 8665 goto on_err; 8666 } 8667 8668 on_err: 8669 rte_crypto_op_free(ut_params->op); 8670 ut_params->op = NULL; 8671 8672 if (ut_params->sec_session) 8673 rte_security_session_destroy(ctx, ut_params->sec_session); 8674 ut_params->sec_session = NULL; 8675 8676 rte_pktmbuf_free(ut_params->ibuf); 8677 ut_params->ibuf = NULL; 8678 8679 return ret; 8680 } 8681 8682 static int 8683 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td) 8684 { 8685 struct crypto_testsuite_params *ts_params = &testsuite_params; 8686 struct crypto_unittest_params *ut_params = &unittest_params; 8687 uint8_t *plaintext, *ciphertext; 8688 uint8_t *iv_ptr; 8689 int32_t cipher_len, crc_len; 8690 int ret = TEST_SUCCESS; 8691 8692 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8693 rte_cryptodev_get_sec_ctx( 8694 ts_params->valid_devs[0]); 8695 8696 /* Verify the capabilities */ 8697 struct rte_security_capability_idx sec_cap_idx; 8698 const struct rte_security_capability *sec_cap; 8699 const struct rte_cryptodev_capabilities *crypto_cap; 8700 const struct rte_cryptodev_symmetric_capability *sym_cap; 8701 int j = 0; 8702 8703 sec_cap_idx.action = ut_params->type; 8704 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8705 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8706 8707 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8708 if (sec_cap == NULL) 8709 return -ENOTSUP; 8710 8711 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8712 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8713 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8714 crypto_cap->sym.xform_type == 8715 RTE_CRYPTO_SYM_XFORM_CIPHER && 8716 crypto_cap->sym.cipher.algo == 8717 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8718 sym_cap = &crypto_cap->sym; 8719 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8720 d_td->key.len, 8721 d_td->iv.len) == 0) 8722 break; 8723 } 8724 } 8725 8726 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8727 return -ENOTSUP; 8728 8729 /* Setup source mbuf payload */ 8730 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8731 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8732 rte_pktmbuf_tailroom(ut_params->ibuf)); 8733 8734 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8735 d_td->plaintext.len); 8736 8737 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 8738 8739 /* Setup cipher session parameters */ 8740 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8741 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8742 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 8743 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8744 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8745 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8746 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8747 ut_params->cipher_xform.next = NULL; 8748 8749 /* Setup DOCSIS session parameters */ 8750 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8751 8752 struct rte_security_session_conf sess_conf = { 8753 .action_type = ut_params->type, 8754 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8755 .docsis = ut_params->docsis_xform, 8756 .crypto_xform = &ut_params->cipher_xform, 8757 }; 8758 8759 /* Create security session */ 8760 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8761 ts_params->session_mpool, 8762 ts_params->session_priv_mpool); 8763 8764 if (!ut_params->sec_session) { 8765 printf("TestCase %s(%d) line %d: %s\n", 8766 __func__, i, __LINE__, "failed to allocate session"); 8767 ret = TEST_FAILED; 8768 goto on_err; 8769 } 8770 8771 /* Generate crypto op data structure */ 8772 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8773 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8774 if (!ut_params->op) { 8775 printf("TestCase %s(%d) line %d: %s\n", 8776 __func__, i, __LINE__, 8777 "failed to allocate security crypto operation"); 8778 ret = TEST_FAILED; 8779 goto on_err; 8780 } 8781 8782 /* Setup CRC operation parameters */ 8783 crc_len = d_td->plaintext.no_crc == false ? 8784 (d_td->plaintext.len - 8785 d_td->plaintext.crc_offset - 8786 RTE_ETHER_CRC_LEN) : 8787 0; 8788 crc_len = crc_len > 0 ? crc_len : 0; 8789 ut_params->op->sym->auth.data.length = crc_len; 8790 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 8791 8792 /* Setup cipher operation parameters */ 8793 cipher_len = d_td->plaintext.no_cipher == false ? 8794 (d_td->plaintext.len - 8795 d_td->plaintext.cipher_offset) : 8796 0; 8797 cipher_len = cipher_len > 0 ? cipher_len : 0; 8798 ut_params->op->sym->cipher.data.length = cipher_len; 8799 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 8800 8801 /* Setup cipher IV */ 8802 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8803 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8804 8805 /* Attach session to operation */ 8806 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8807 8808 /* Set crypto operation mbufs */ 8809 ut_params->op->sym->m_src = ut_params->ibuf; 8810 ut_params->op->sym->m_dst = NULL; 8811 8812 /* Process crypto operation */ 8813 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8814 NULL) { 8815 printf("TestCase %s(%d) line %d: %s\n", 8816 __func__, i, __LINE__, 8817 "failed to process security crypto op"); 8818 ret = TEST_FAILED; 8819 goto on_err; 8820 } 8821 8822 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8823 printf("TestCase %s(%d) line %d: %s\n", 8824 __func__, i, __LINE__, "crypto op processing failed"); 8825 ret = TEST_FAILED; 8826 goto on_err; 8827 } 8828 8829 /* Validate ciphertext */ 8830 ciphertext = plaintext; 8831 8832 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 8833 printf("TestCase %s(%d) line %d: %s\n", 8834 __func__, i, __LINE__, "ciphertext not as expected\n"); 8835 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 8836 d_td->ciphertext.len); 8837 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 8838 ret = TEST_FAILED; 8839 goto on_err; 8840 } 8841 8842 on_err: 8843 rte_crypto_op_free(ut_params->op); 8844 ut_params->op = NULL; 8845 8846 if (ut_params->sec_session) 8847 rte_security_session_destroy(ctx, ut_params->sec_session); 8848 ut_params->sec_session = NULL; 8849 8850 rte_pktmbuf_free(ut_params->ibuf); 8851 ut_params->ibuf = NULL; 8852 8853 return ret; 8854 } 8855 8856 #define TEST_DOCSIS_COUNT(func) do { \ 8857 int ret = func; \ 8858 if (ret == TEST_SUCCESS) { \ 8859 printf("\t%2d)", n++); \ 8860 printf("+++++ PASSED:" #func"\n"); \ 8861 p++; \ 8862 } else if (ret == -ENOTSUP) { \ 8863 printf("\t%2d)", n++); \ 8864 printf("~~~~~ UNSUPP:" #func"\n"); \ 8865 u++; \ 8866 } else { \ 8867 printf("\t%2d)", n++); \ 8868 printf("----- FAILED:" #func"\n"); \ 8869 f++; \ 8870 } \ 8871 } while (0) 8872 8873 static int 8874 test_DOCSIS_PROTO_uplink_all(void) 8875 { 8876 int p = 0, u = 0, f = 0, n = 0; 8877 8878 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1)); 8879 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2)); 8880 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3)); 8881 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4)); 8882 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5)); 8883 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6)); 8884 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7)); 8885 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8)); 8886 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9)); 8887 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10)); 8888 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11)); 8889 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12)); 8890 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13)); 8891 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14)); 8892 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15)); 8893 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16)); 8894 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17)); 8895 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18)); 8896 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19)); 8897 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20)); 8898 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21)); 8899 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22)); 8900 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23)); 8901 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24)); 8902 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25)); 8903 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26)); 8904 8905 if (f) 8906 printf("## %s: %d passed out of %d (%d unsupported)\n", 8907 __func__, p, n, u); 8908 8909 return f; 8910 }; 8911 8912 static int 8913 test_DOCSIS_PROTO_downlink_all(void) 8914 { 8915 int p = 0, u = 0, f = 0, n = 0; 8916 8917 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1)); 8918 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2)); 8919 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3)); 8920 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4)); 8921 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5)); 8922 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6)); 8923 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7)); 8924 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8)); 8925 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9)); 8926 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10)); 8927 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11)); 8928 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12)); 8929 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13)); 8930 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14)); 8931 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15)); 8932 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16)); 8933 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17)); 8934 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18)); 8935 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19)); 8936 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20)); 8937 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21)); 8938 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22)); 8939 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23)); 8940 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24)); 8941 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25)); 8942 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26)); 8943 8944 if (f) 8945 printf("## %s: %d passed out of %d (%d unsupported)\n", 8946 __func__, p, n, u); 8947 8948 return f; 8949 }; 8950 8951 static int 8952 test_DOCSIS_PROTO_all(void) 8953 { 8954 struct crypto_testsuite_params *ts_params = &testsuite_params; 8955 struct crypto_unittest_params *ut_params = &unittest_params; 8956 struct rte_cryptodev_info dev_info; 8957 int status; 8958 8959 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8960 uint64_t feat_flags = dev_info.feature_flags; 8961 8962 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8963 return -ENOTSUP; 8964 8965 /* Set action type */ 8966 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8967 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8968 gbl_action_type; 8969 8970 if (security_proto_supported(ut_params->type, 8971 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 8972 return -ENOTSUP; 8973 8974 status = test_DOCSIS_PROTO_uplink_all(); 8975 status += test_DOCSIS_PROTO_downlink_all(); 8976 8977 if (status) 8978 return TEST_FAILED; 8979 else 8980 return TEST_SUCCESS; 8981 } 8982 #endif 8983 8984 static int 8985 test_AES_GCM_authenticated_encryption_test_case_1(void) 8986 { 8987 return test_authenticated_encryption(&gcm_test_case_1); 8988 } 8989 8990 static int 8991 test_AES_GCM_authenticated_encryption_test_case_2(void) 8992 { 8993 return test_authenticated_encryption(&gcm_test_case_2); 8994 } 8995 8996 static int 8997 test_AES_GCM_authenticated_encryption_test_case_3(void) 8998 { 8999 return test_authenticated_encryption(&gcm_test_case_3); 9000 } 9001 9002 static int 9003 test_AES_GCM_authenticated_encryption_test_case_4(void) 9004 { 9005 return test_authenticated_encryption(&gcm_test_case_4); 9006 } 9007 9008 static int 9009 test_AES_GCM_authenticated_encryption_test_case_5(void) 9010 { 9011 return test_authenticated_encryption(&gcm_test_case_5); 9012 } 9013 9014 static int 9015 test_AES_GCM_authenticated_encryption_test_case_6(void) 9016 { 9017 return test_authenticated_encryption(&gcm_test_case_6); 9018 } 9019 9020 static int 9021 test_AES_GCM_authenticated_encryption_test_case_7(void) 9022 { 9023 return test_authenticated_encryption(&gcm_test_case_7); 9024 } 9025 9026 static int 9027 test_AES_GCM_authenticated_encryption_test_case_8(void) 9028 { 9029 return test_authenticated_encryption(&gcm_test_case_8); 9030 } 9031 9032 static int 9033 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 9034 { 9035 return test_authenticated_encryption(&gcm_J0_test_case_1); 9036 } 9037 9038 static int 9039 test_AES_GCM_auth_encryption_test_case_192_1(void) 9040 { 9041 return test_authenticated_encryption(&gcm_test_case_192_1); 9042 } 9043 9044 static int 9045 test_AES_GCM_auth_encryption_test_case_192_2(void) 9046 { 9047 return test_authenticated_encryption(&gcm_test_case_192_2); 9048 } 9049 9050 static int 9051 test_AES_GCM_auth_encryption_test_case_192_3(void) 9052 { 9053 return test_authenticated_encryption(&gcm_test_case_192_3); 9054 } 9055 9056 static int 9057 test_AES_GCM_auth_encryption_test_case_192_4(void) 9058 { 9059 return test_authenticated_encryption(&gcm_test_case_192_4); 9060 } 9061 9062 static int 9063 test_AES_GCM_auth_encryption_test_case_192_5(void) 9064 { 9065 return test_authenticated_encryption(&gcm_test_case_192_5); 9066 } 9067 9068 static int 9069 test_AES_GCM_auth_encryption_test_case_192_6(void) 9070 { 9071 return test_authenticated_encryption(&gcm_test_case_192_6); 9072 } 9073 9074 static int 9075 test_AES_GCM_auth_encryption_test_case_192_7(void) 9076 { 9077 return test_authenticated_encryption(&gcm_test_case_192_7); 9078 } 9079 9080 static int 9081 test_AES_GCM_auth_encryption_test_case_256_1(void) 9082 { 9083 return test_authenticated_encryption(&gcm_test_case_256_1); 9084 } 9085 9086 static int 9087 test_AES_GCM_auth_encryption_test_case_256_2(void) 9088 { 9089 return test_authenticated_encryption(&gcm_test_case_256_2); 9090 } 9091 9092 static int 9093 test_AES_GCM_auth_encryption_test_case_256_3(void) 9094 { 9095 return test_authenticated_encryption(&gcm_test_case_256_3); 9096 } 9097 9098 static int 9099 test_AES_GCM_auth_encryption_test_case_256_4(void) 9100 { 9101 return test_authenticated_encryption(&gcm_test_case_256_4); 9102 } 9103 9104 static int 9105 test_AES_GCM_auth_encryption_test_case_256_5(void) 9106 { 9107 return test_authenticated_encryption(&gcm_test_case_256_5); 9108 } 9109 9110 static int 9111 test_AES_GCM_auth_encryption_test_case_256_6(void) 9112 { 9113 return test_authenticated_encryption(&gcm_test_case_256_6); 9114 } 9115 9116 static int 9117 test_AES_GCM_auth_encryption_test_case_256_7(void) 9118 { 9119 return test_authenticated_encryption(&gcm_test_case_256_7); 9120 } 9121 9122 static int 9123 test_AES_GCM_auth_encryption_test_case_aad_1(void) 9124 { 9125 return test_authenticated_encryption(&gcm_test_case_aad_1); 9126 } 9127 9128 static int 9129 test_AES_GCM_auth_encryption_test_case_aad_2(void) 9130 { 9131 return test_authenticated_encryption(&gcm_test_case_aad_2); 9132 } 9133 9134 static int 9135 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 9136 { 9137 struct aead_test_data tdata; 9138 int res; 9139 9140 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9141 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9142 tdata.iv.data[0] += 1; 9143 res = test_authenticated_encryption(&tdata); 9144 if (res == -ENOTSUP) 9145 return res; 9146 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9147 return TEST_SUCCESS; 9148 } 9149 9150 static int 9151 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 9152 { 9153 struct aead_test_data tdata; 9154 int res; 9155 9156 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9157 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9158 tdata.plaintext.data[0] += 1; 9159 res = test_authenticated_encryption(&tdata); 9160 if (res == -ENOTSUP) 9161 return res; 9162 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9163 return TEST_SUCCESS; 9164 } 9165 9166 static int 9167 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 9168 { 9169 struct aead_test_data tdata; 9170 int res; 9171 9172 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9173 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9174 tdata.ciphertext.data[0] += 1; 9175 res = test_authenticated_encryption(&tdata); 9176 if (res == -ENOTSUP) 9177 return res; 9178 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9179 return TEST_SUCCESS; 9180 } 9181 9182 static int 9183 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 9184 { 9185 struct aead_test_data tdata; 9186 int res; 9187 9188 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9189 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9190 tdata.aad.len += 1; 9191 res = test_authenticated_encryption(&tdata); 9192 if (res == -ENOTSUP) 9193 return res; 9194 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9195 return TEST_SUCCESS; 9196 } 9197 9198 static int 9199 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 9200 { 9201 struct aead_test_data tdata; 9202 uint8_t aad[gcm_test_case_7.aad.len]; 9203 int res; 9204 9205 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9206 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9207 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9208 aad[0] += 1; 9209 tdata.aad.data = aad; 9210 res = test_authenticated_encryption(&tdata); 9211 if (res == -ENOTSUP) 9212 return res; 9213 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9214 return TEST_SUCCESS; 9215 } 9216 9217 static int 9218 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 9219 { 9220 struct aead_test_data tdata; 9221 int res; 9222 9223 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9224 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9225 tdata.auth_tag.data[0] += 1; 9226 res = test_authenticated_encryption(&tdata); 9227 if (res == -ENOTSUP) 9228 return res; 9229 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9230 return TEST_SUCCESS; 9231 } 9232 9233 static int 9234 test_authenticated_decryption(const struct aead_test_data *tdata) 9235 { 9236 struct crypto_testsuite_params *ts_params = &testsuite_params; 9237 struct crypto_unittest_params *ut_params = &unittest_params; 9238 9239 int retval; 9240 uint8_t *plaintext; 9241 uint32_t i; 9242 struct rte_cryptodev_info dev_info; 9243 9244 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9245 uint64_t feat_flags = dev_info.feature_flags; 9246 9247 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9248 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9249 printf("Device doesn't support RAW data-path APIs.\n"); 9250 return -ENOTSUP; 9251 } 9252 9253 /* Verify the capabilities */ 9254 struct rte_cryptodev_sym_capability_idx cap_idx; 9255 const struct rte_cryptodev_symmetric_capability *capability; 9256 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9257 cap_idx.algo.aead = tdata->algo; 9258 capability = rte_cryptodev_sym_capability_get( 9259 ts_params->valid_devs[0], &cap_idx); 9260 if (capability == NULL) 9261 return -ENOTSUP; 9262 if (rte_cryptodev_sym_capability_check_aead( 9263 capability, tdata->key.len, tdata->auth_tag.len, 9264 tdata->aad.len, tdata->iv.len)) 9265 return -ENOTSUP; 9266 9267 /* Create AEAD session */ 9268 retval = create_aead_session(ts_params->valid_devs[0], 9269 tdata->algo, 9270 RTE_CRYPTO_AEAD_OP_DECRYPT, 9271 tdata->key.data, tdata->key.len, 9272 tdata->aad.len, tdata->auth_tag.len, 9273 tdata->iv.len); 9274 if (retval < 0) 9275 return retval; 9276 9277 /* alloc mbuf and set payload */ 9278 if (tdata->aad.len > MBUF_SIZE) { 9279 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9280 /* Populate full size of add data */ 9281 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9282 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9283 } else 9284 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9285 9286 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9287 rte_pktmbuf_tailroom(ut_params->ibuf)); 9288 9289 /* Create AEAD operation */ 9290 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9291 if (retval < 0) 9292 return retval; 9293 9294 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9295 9296 ut_params->op->sym->m_src = ut_params->ibuf; 9297 9298 /* Process crypto operation */ 9299 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9300 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9301 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9302 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9303 ut_params->op, 0, 0, 0, 0); 9304 else 9305 TEST_ASSERT_NOT_NULL( 9306 process_crypto_request(ts_params->valid_devs[0], 9307 ut_params->op), "failed to process sym crypto op"); 9308 9309 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9310 "crypto op processing failed"); 9311 9312 if (ut_params->op->sym->m_dst) 9313 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9314 uint8_t *); 9315 else 9316 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9317 uint8_t *, 9318 ut_params->op->sym->cipher.data.offset); 9319 9320 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9321 9322 /* Validate obuf */ 9323 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9324 plaintext, 9325 tdata->plaintext.data, 9326 tdata->plaintext.len, 9327 "Plaintext data not as expected"); 9328 9329 TEST_ASSERT_EQUAL(ut_params->op->status, 9330 RTE_CRYPTO_OP_STATUS_SUCCESS, 9331 "Authentication failed"); 9332 9333 return 0; 9334 } 9335 9336 static int 9337 test_AES_GCM_authenticated_decryption_test_case_1(void) 9338 { 9339 return test_authenticated_decryption(&gcm_test_case_1); 9340 } 9341 9342 static int 9343 test_AES_GCM_authenticated_decryption_test_case_2(void) 9344 { 9345 return test_authenticated_decryption(&gcm_test_case_2); 9346 } 9347 9348 static int 9349 test_AES_GCM_authenticated_decryption_test_case_3(void) 9350 { 9351 return test_authenticated_decryption(&gcm_test_case_3); 9352 } 9353 9354 static int 9355 test_AES_GCM_authenticated_decryption_test_case_4(void) 9356 { 9357 return test_authenticated_decryption(&gcm_test_case_4); 9358 } 9359 9360 static int 9361 test_AES_GCM_authenticated_decryption_test_case_5(void) 9362 { 9363 return test_authenticated_decryption(&gcm_test_case_5); 9364 } 9365 9366 static int 9367 test_AES_GCM_authenticated_decryption_test_case_6(void) 9368 { 9369 return test_authenticated_decryption(&gcm_test_case_6); 9370 } 9371 9372 static int 9373 test_AES_GCM_authenticated_decryption_test_case_7(void) 9374 { 9375 return test_authenticated_decryption(&gcm_test_case_7); 9376 } 9377 9378 static int 9379 test_AES_GCM_authenticated_decryption_test_case_8(void) 9380 { 9381 return test_authenticated_decryption(&gcm_test_case_8); 9382 } 9383 9384 static int 9385 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 9386 { 9387 return test_authenticated_decryption(&gcm_J0_test_case_1); 9388 } 9389 9390 static int 9391 test_AES_GCM_auth_decryption_test_case_192_1(void) 9392 { 9393 return test_authenticated_decryption(&gcm_test_case_192_1); 9394 } 9395 9396 static int 9397 test_AES_GCM_auth_decryption_test_case_192_2(void) 9398 { 9399 return test_authenticated_decryption(&gcm_test_case_192_2); 9400 } 9401 9402 static int 9403 test_AES_GCM_auth_decryption_test_case_192_3(void) 9404 { 9405 return test_authenticated_decryption(&gcm_test_case_192_3); 9406 } 9407 9408 static int 9409 test_AES_GCM_auth_decryption_test_case_192_4(void) 9410 { 9411 return test_authenticated_decryption(&gcm_test_case_192_4); 9412 } 9413 9414 static int 9415 test_AES_GCM_auth_decryption_test_case_192_5(void) 9416 { 9417 return test_authenticated_decryption(&gcm_test_case_192_5); 9418 } 9419 9420 static int 9421 test_AES_GCM_auth_decryption_test_case_192_6(void) 9422 { 9423 return test_authenticated_decryption(&gcm_test_case_192_6); 9424 } 9425 9426 static int 9427 test_AES_GCM_auth_decryption_test_case_192_7(void) 9428 { 9429 return test_authenticated_decryption(&gcm_test_case_192_7); 9430 } 9431 9432 static int 9433 test_AES_GCM_auth_decryption_test_case_256_1(void) 9434 { 9435 return test_authenticated_decryption(&gcm_test_case_256_1); 9436 } 9437 9438 static int 9439 test_AES_GCM_auth_decryption_test_case_256_2(void) 9440 { 9441 return test_authenticated_decryption(&gcm_test_case_256_2); 9442 } 9443 9444 static int 9445 test_AES_GCM_auth_decryption_test_case_256_3(void) 9446 { 9447 return test_authenticated_decryption(&gcm_test_case_256_3); 9448 } 9449 9450 static int 9451 test_AES_GCM_auth_decryption_test_case_256_4(void) 9452 { 9453 return test_authenticated_decryption(&gcm_test_case_256_4); 9454 } 9455 9456 static int 9457 test_AES_GCM_auth_decryption_test_case_256_5(void) 9458 { 9459 return test_authenticated_decryption(&gcm_test_case_256_5); 9460 } 9461 9462 static int 9463 test_AES_GCM_auth_decryption_test_case_256_6(void) 9464 { 9465 return test_authenticated_decryption(&gcm_test_case_256_6); 9466 } 9467 9468 static int 9469 test_AES_GCM_auth_decryption_test_case_256_7(void) 9470 { 9471 return test_authenticated_decryption(&gcm_test_case_256_7); 9472 } 9473 9474 static int 9475 test_AES_GCM_auth_decryption_test_case_aad_1(void) 9476 { 9477 return test_authenticated_decryption(&gcm_test_case_aad_1); 9478 } 9479 9480 static int 9481 test_AES_GCM_auth_decryption_test_case_aad_2(void) 9482 { 9483 return test_authenticated_decryption(&gcm_test_case_aad_2); 9484 } 9485 9486 static int 9487 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 9488 { 9489 struct aead_test_data tdata; 9490 int res; 9491 9492 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9493 tdata.iv.data[0] += 1; 9494 res = test_authenticated_decryption(&tdata); 9495 if (res == -ENOTSUP) 9496 return res; 9497 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9498 return TEST_SUCCESS; 9499 } 9500 9501 static int 9502 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 9503 { 9504 struct aead_test_data tdata; 9505 int res; 9506 9507 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9508 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9509 tdata.plaintext.data[0] += 1; 9510 res = test_authenticated_decryption(&tdata); 9511 if (res == -ENOTSUP) 9512 return res; 9513 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9514 return TEST_SUCCESS; 9515 } 9516 9517 static int 9518 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 9519 { 9520 struct aead_test_data tdata; 9521 int res; 9522 9523 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9524 tdata.ciphertext.data[0] += 1; 9525 res = test_authenticated_decryption(&tdata); 9526 if (res == -ENOTSUP) 9527 return res; 9528 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9529 return TEST_SUCCESS; 9530 } 9531 9532 static int 9533 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 9534 { 9535 struct aead_test_data tdata; 9536 int res; 9537 9538 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9539 tdata.aad.len += 1; 9540 res = test_authenticated_decryption(&tdata); 9541 if (res == -ENOTSUP) 9542 return res; 9543 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9544 return TEST_SUCCESS; 9545 } 9546 9547 static int 9548 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 9549 { 9550 struct aead_test_data tdata; 9551 uint8_t aad[gcm_test_case_7.aad.len]; 9552 int res; 9553 9554 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9555 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9556 aad[0] += 1; 9557 tdata.aad.data = aad; 9558 res = test_authenticated_decryption(&tdata); 9559 if (res == -ENOTSUP) 9560 return res; 9561 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9562 return TEST_SUCCESS; 9563 } 9564 9565 static int 9566 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 9567 { 9568 struct aead_test_data tdata; 9569 int res; 9570 9571 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9572 tdata.auth_tag.data[0] += 1; 9573 res = test_authenticated_decryption(&tdata); 9574 if (res == -ENOTSUP) 9575 return res; 9576 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 9577 return TEST_SUCCESS; 9578 } 9579 9580 static int 9581 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 9582 { 9583 struct crypto_testsuite_params *ts_params = &testsuite_params; 9584 struct crypto_unittest_params *ut_params = &unittest_params; 9585 9586 int retval; 9587 uint8_t *ciphertext, *auth_tag; 9588 uint16_t plaintext_pad_len; 9589 9590 /* Verify the capabilities */ 9591 struct rte_cryptodev_sym_capability_idx cap_idx; 9592 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9593 cap_idx.algo.aead = tdata->algo; 9594 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9595 &cap_idx) == NULL) 9596 return -ENOTSUP; 9597 9598 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9599 return -ENOTSUP; 9600 9601 /* not supported with CPU crypto */ 9602 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9603 return -ENOTSUP; 9604 9605 /* Create AEAD session */ 9606 retval = create_aead_session(ts_params->valid_devs[0], 9607 tdata->algo, 9608 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9609 tdata->key.data, tdata->key.len, 9610 tdata->aad.len, tdata->auth_tag.len, 9611 tdata->iv.len); 9612 if (retval < 0) 9613 return retval; 9614 9615 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9616 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9617 9618 /* clear mbuf payload */ 9619 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9620 rte_pktmbuf_tailroom(ut_params->ibuf)); 9621 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9622 rte_pktmbuf_tailroom(ut_params->obuf)); 9623 9624 /* Create AEAD operation */ 9625 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9626 if (retval < 0) 9627 return retval; 9628 9629 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9630 9631 ut_params->op->sym->m_src = ut_params->ibuf; 9632 ut_params->op->sym->m_dst = ut_params->obuf; 9633 9634 /* Process crypto operation */ 9635 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9636 ut_params->op), "failed to process sym crypto op"); 9637 9638 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9639 "crypto op processing failed"); 9640 9641 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9642 9643 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9644 ut_params->op->sym->cipher.data.offset); 9645 auth_tag = ciphertext + plaintext_pad_len; 9646 9647 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9648 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9649 9650 /* Validate obuf */ 9651 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9652 ciphertext, 9653 tdata->ciphertext.data, 9654 tdata->ciphertext.len, 9655 "Ciphertext data not as expected"); 9656 9657 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9658 auth_tag, 9659 tdata->auth_tag.data, 9660 tdata->auth_tag.len, 9661 "Generated auth tag not as expected"); 9662 9663 return 0; 9664 9665 } 9666 9667 static int 9668 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 9669 { 9670 return test_authenticated_encryption_oop(&gcm_test_case_5); 9671 } 9672 9673 static int 9674 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 9675 { 9676 struct crypto_testsuite_params *ts_params = &testsuite_params; 9677 struct crypto_unittest_params *ut_params = &unittest_params; 9678 9679 int retval; 9680 uint8_t *plaintext; 9681 9682 /* Verify the capabilities */ 9683 struct rte_cryptodev_sym_capability_idx cap_idx; 9684 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9685 cap_idx.algo.aead = tdata->algo; 9686 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9687 &cap_idx) == NULL) 9688 return -ENOTSUP; 9689 9690 /* not supported with CPU crypto and raw data-path APIs*/ 9691 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 9692 global_api_test_type == CRYPTODEV_RAW_API_TEST) 9693 return -ENOTSUP; 9694 9695 /* Create AEAD session */ 9696 retval = create_aead_session(ts_params->valid_devs[0], 9697 tdata->algo, 9698 RTE_CRYPTO_AEAD_OP_DECRYPT, 9699 tdata->key.data, tdata->key.len, 9700 tdata->aad.len, tdata->auth_tag.len, 9701 tdata->iv.len); 9702 if (retval < 0) 9703 return retval; 9704 9705 /* alloc mbuf and set payload */ 9706 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9707 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9708 9709 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9710 rte_pktmbuf_tailroom(ut_params->ibuf)); 9711 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9712 rte_pktmbuf_tailroom(ut_params->obuf)); 9713 9714 /* Create AEAD operation */ 9715 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9716 if (retval < 0) 9717 return retval; 9718 9719 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9720 9721 ut_params->op->sym->m_src = ut_params->ibuf; 9722 ut_params->op->sym->m_dst = ut_params->obuf; 9723 9724 /* Process crypto operation */ 9725 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9726 ut_params->op), "failed to process sym crypto op"); 9727 9728 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9729 "crypto op processing failed"); 9730 9731 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9732 ut_params->op->sym->cipher.data.offset); 9733 9734 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9735 9736 /* Validate obuf */ 9737 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9738 plaintext, 9739 tdata->plaintext.data, 9740 tdata->plaintext.len, 9741 "Plaintext data not as expected"); 9742 9743 TEST_ASSERT_EQUAL(ut_params->op->status, 9744 RTE_CRYPTO_OP_STATUS_SUCCESS, 9745 "Authentication failed"); 9746 return 0; 9747 } 9748 9749 static int 9750 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 9751 { 9752 return test_authenticated_decryption_oop(&gcm_test_case_5); 9753 } 9754 9755 static int 9756 test_authenticated_encryption_sessionless( 9757 const struct aead_test_data *tdata) 9758 { 9759 struct crypto_testsuite_params *ts_params = &testsuite_params; 9760 struct crypto_unittest_params *ut_params = &unittest_params; 9761 9762 int retval; 9763 uint8_t *ciphertext, *auth_tag; 9764 uint16_t plaintext_pad_len; 9765 uint8_t key[tdata->key.len + 1]; 9766 struct rte_cryptodev_info dev_info; 9767 9768 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9769 uint64_t feat_flags = dev_info.feature_flags; 9770 9771 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9772 printf("Device doesn't support Sessionless ops.\n"); 9773 return -ENOTSUP; 9774 } 9775 9776 /* not supported with CPU crypto */ 9777 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9778 return -ENOTSUP; 9779 9780 /* Verify the capabilities */ 9781 struct rte_cryptodev_sym_capability_idx cap_idx; 9782 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9783 cap_idx.algo.aead = tdata->algo; 9784 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9785 &cap_idx) == NULL) 9786 return -ENOTSUP; 9787 9788 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9789 9790 /* clear mbuf payload */ 9791 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9792 rte_pktmbuf_tailroom(ut_params->ibuf)); 9793 9794 /* Create AEAD operation */ 9795 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9796 if (retval < 0) 9797 return retval; 9798 9799 /* Create GCM xform */ 9800 memcpy(key, tdata->key.data, tdata->key.len); 9801 retval = create_aead_xform(ut_params->op, 9802 tdata->algo, 9803 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9804 key, tdata->key.len, 9805 tdata->aad.len, tdata->auth_tag.len, 9806 tdata->iv.len); 9807 if (retval < 0) 9808 return retval; 9809 9810 ut_params->op->sym->m_src = ut_params->ibuf; 9811 9812 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9813 RTE_CRYPTO_OP_SESSIONLESS, 9814 "crypto op session type not sessionless"); 9815 9816 /* Process crypto operation */ 9817 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9818 ut_params->op), "failed to process sym crypto op"); 9819 9820 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9821 9822 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9823 "crypto op status not success"); 9824 9825 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9826 9827 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9828 ut_params->op->sym->cipher.data.offset); 9829 auth_tag = ciphertext + plaintext_pad_len; 9830 9831 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9832 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9833 9834 /* Validate obuf */ 9835 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9836 ciphertext, 9837 tdata->ciphertext.data, 9838 tdata->ciphertext.len, 9839 "Ciphertext data not as expected"); 9840 9841 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9842 auth_tag, 9843 tdata->auth_tag.data, 9844 tdata->auth_tag.len, 9845 "Generated auth tag not as expected"); 9846 9847 return 0; 9848 9849 } 9850 9851 static int 9852 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 9853 { 9854 return test_authenticated_encryption_sessionless( 9855 &gcm_test_case_5); 9856 } 9857 9858 static int 9859 test_authenticated_decryption_sessionless( 9860 const struct aead_test_data *tdata) 9861 { 9862 struct crypto_testsuite_params *ts_params = &testsuite_params; 9863 struct crypto_unittest_params *ut_params = &unittest_params; 9864 9865 int retval; 9866 uint8_t *plaintext; 9867 uint8_t key[tdata->key.len + 1]; 9868 struct rte_cryptodev_info dev_info; 9869 9870 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9871 uint64_t feat_flags = dev_info.feature_flags; 9872 9873 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9874 printf("Device doesn't support Sessionless ops.\n"); 9875 return -ENOTSUP; 9876 } 9877 9878 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9879 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9880 printf("Device doesn't support RAW data-path APIs.\n"); 9881 return -ENOTSUP; 9882 } 9883 9884 /* not supported with CPU crypto */ 9885 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9886 return -ENOTSUP; 9887 9888 /* Verify the capabilities */ 9889 struct rte_cryptodev_sym_capability_idx cap_idx; 9890 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9891 cap_idx.algo.aead = tdata->algo; 9892 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9893 &cap_idx) == NULL) 9894 return -ENOTSUP; 9895 9896 /* alloc mbuf and set payload */ 9897 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9898 9899 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9900 rte_pktmbuf_tailroom(ut_params->ibuf)); 9901 9902 /* Create AEAD operation */ 9903 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9904 if (retval < 0) 9905 return retval; 9906 9907 /* Create AEAD xform */ 9908 memcpy(key, tdata->key.data, tdata->key.len); 9909 retval = create_aead_xform(ut_params->op, 9910 tdata->algo, 9911 RTE_CRYPTO_AEAD_OP_DECRYPT, 9912 key, tdata->key.len, 9913 tdata->aad.len, tdata->auth_tag.len, 9914 tdata->iv.len); 9915 if (retval < 0) 9916 return retval; 9917 9918 ut_params->op->sym->m_src = ut_params->ibuf; 9919 9920 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9921 RTE_CRYPTO_OP_SESSIONLESS, 9922 "crypto op session type not sessionless"); 9923 9924 /* Process crypto operation */ 9925 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9926 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9927 ut_params->op, 0, 0, 0, 0); 9928 else 9929 TEST_ASSERT_NOT_NULL(process_crypto_request( 9930 ts_params->valid_devs[0], ut_params->op), 9931 "failed to process sym crypto op"); 9932 9933 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9934 9935 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9936 "crypto op status not success"); 9937 9938 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9939 ut_params->op->sym->cipher.data.offset); 9940 9941 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9942 9943 /* Validate obuf */ 9944 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9945 plaintext, 9946 tdata->plaintext.data, 9947 tdata->plaintext.len, 9948 "Plaintext data not as expected"); 9949 9950 TEST_ASSERT_EQUAL(ut_params->op->status, 9951 RTE_CRYPTO_OP_STATUS_SUCCESS, 9952 "Authentication failed"); 9953 return 0; 9954 } 9955 9956 static int 9957 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 9958 { 9959 return test_authenticated_decryption_sessionless( 9960 &gcm_test_case_5); 9961 } 9962 9963 static int 9964 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 9965 { 9966 return test_authenticated_encryption(&ccm_test_case_128_1); 9967 } 9968 9969 static int 9970 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 9971 { 9972 return test_authenticated_encryption(&ccm_test_case_128_2); 9973 } 9974 9975 static int 9976 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 9977 { 9978 return test_authenticated_encryption(&ccm_test_case_128_3); 9979 } 9980 9981 static int 9982 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 9983 { 9984 return test_authenticated_decryption(&ccm_test_case_128_1); 9985 } 9986 9987 static int 9988 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 9989 { 9990 return test_authenticated_decryption(&ccm_test_case_128_2); 9991 } 9992 9993 static int 9994 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 9995 { 9996 return test_authenticated_decryption(&ccm_test_case_128_3); 9997 } 9998 9999 static int 10000 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 10001 { 10002 return test_authenticated_encryption(&ccm_test_case_192_1); 10003 } 10004 10005 static int 10006 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 10007 { 10008 return test_authenticated_encryption(&ccm_test_case_192_2); 10009 } 10010 10011 static int 10012 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 10013 { 10014 return test_authenticated_encryption(&ccm_test_case_192_3); 10015 } 10016 10017 static int 10018 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 10019 { 10020 return test_authenticated_decryption(&ccm_test_case_192_1); 10021 } 10022 10023 static int 10024 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 10025 { 10026 return test_authenticated_decryption(&ccm_test_case_192_2); 10027 } 10028 10029 static int 10030 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 10031 { 10032 return test_authenticated_decryption(&ccm_test_case_192_3); 10033 } 10034 10035 static int 10036 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 10037 { 10038 return test_authenticated_encryption(&ccm_test_case_256_1); 10039 } 10040 10041 static int 10042 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 10043 { 10044 return test_authenticated_encryption(&ccm_test_case_256_2); 10045 } 10046 10047 static int 10048 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 10049 { 10050 return test_authenticated_encryption(&ccm_test_case_256_3); 10051 } 10052 10053 static int 10054 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 10055 { 10056 return test_authenticated_decryption(&ccm_test_case_256_1); 10057 } 10058 10059 static int 10060 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 10061 { 10062 return test_authenticated_decryption(&ccm_test_case_256_2); 10063 } 10064 10065 static int 10066 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 10067 { 10068 return test_authenticated_decryption(&ccm_test_case_256_3); 10069 } 10070 10071 static int 10072 test_stats(void) 10073 { 10074 struct crypto_testsuite_params *ts_params = &testsuite_params; 10075 struct rte_cryptodev_stats stats; 10076 10077 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10078 return -ENOTSUP; 10079 10080 /* Verify the capabilities */ 10081 struct rte_cryptodev_sym_capability_idx cap_idx; 10082 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10083 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 10084 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10085 &cap_idx) == NULL) 10086 return -ENOTSUP; 10087 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10088 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10089 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10090 &cap_idx) == NULL) 10091 return -ENOTSUP; 10092 10093 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 10094 == -ENOTSUP) 10095 return -ENOTSUP; 10096 10097 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10098 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 10099 &stats) == -ENODEV), 10100 "rte_cryptodev_stats_get invalid dev failed"); 10101 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 10102 "rte_cryptodev_stats_get invalid Param failed"); 10103 10104 /* Test expected values */ 10105 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 10106 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10107 &stats), 10108 "rte_cryptodev_stats_get failed"); 10109 TEST_ASSERT((stats.enqueued_count == 1), 10110 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10111 TEST_ASSERT((stats.dequeued_count == 1), 10112 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10113 TEST_ASSERT((stats.enqueue_err_count == 0), 10114 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10115 TEST_ASSERT((stats.dequeue_err_count == 0), 10116 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10117 10118 /* invalid device but should ignore and not reset device stats*/ 10119 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 10120 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10121 &stats), 10122 "rte_cryptodev_stats_get failed"); 10123 TEST_ASSERT((stats.enqueued_count == 1), 10124 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10125 10126 /* check that a valid reset clears stats */ 10127 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10128 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10129 &stats), 10130 "rte_cryptodev_stats_get failed"); 10131 TEST_ASSERT((stats.enqueued_count == 0), 10132 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10133 TEST_ASSERT((stats.dequeued_count == 0), 10134 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10135 10136 return TEST_SUCCESS; 10137 } 10138 10139 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 10140 struct crypto_unittest_params *ut_params, 10141 enum rte_crypto_auth_operation op, 10142 const struct HMAC_MD5_vector *test_case) 10143 { 10144 uint8_t key[64]; 10145 10146 memcpy(key, test_case->key.data, test_case->key.len); 10147 10148 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10149 ut_params->auth_xform.next = NULL; 10150 ut_params->auth_xform.auth.op = op; 10151 10152 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 10153 10154 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 10155 ut_params->auth_xform.auth.key.length = test_case->key.len; 10156 ut_params->auth_xform.auth.key.data = key; 10157 10158 ut_params->sess = rte_cryptodev_sym_session_create( 10159 ts_params->session_mpool); 10160 10161 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10162 ut_params->sess, &ut_params->auth_xform, 10163 ts_params->session_priv_mpool); 10164 10165 if (ut_params->sess == NULL) 10166 return TEST_FAILED; 10167 10168 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10169 10170 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10171 rte_pktmbuf_tailroom(ut_params->ibuf)); 10172 10173 return 0; 10174 } 10175 10176 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 10177 const struct HMAC_MD5_vector *test_case, 10178 uint8_t **plaintext) 10179 { 10180 uint16_t plaintext_pad_len; 10181 10182 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10183 10184 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10185 16); 10186 10187 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10188 plaintext_pad_len); 10189 memcpy(*plaintext, test_case->plaintext.data, 10190 test_case->plaintext.len); 10191 10192 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10193 ut_params->ibuf, MD5_DIGEST_LEN); 10194 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10195 "no room to append digest"); 10196 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10197 ut_params->ibuf, plaintext_pad_len); 10198 10199 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10200 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 10201 test_case->auth_tag.len); 10202 } 10203 10204 sym_op->auth.data.offset = 0; 10205 sym_op->auth.data.length = test_case->plaintext.len; 10206 10207 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10208 ut_params->op->sym->m_src = ut_params->ibuf; 10209 10210 return 0; 10211 } 10212 10213 static int 10214 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 10215 { 10216 uint16_t plaintext_pad_len; 10217 uint8_t *plaintext, *auth_tag; 10218 10219 struct crypto_testsuite_params *ts_params = &testsuite_params; 10220 struct crypto_unittest_params *ut_params = &unittest_params; 10221 struct rte_cryptodev_info dev_info; 10222 10223 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10224 uint64_t feat_flags = dev_info.feature_flags; 10225 10226 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10227 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10228 printf("Device doesn't support RAW data-path APIs.\n"); 10229 return -ENOTSUP; 10230 } 10231 10232 /* Verify the capabilities */ 10233 struct rte_cryptodev_sym_capability_idx cap_idx; 10234 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10235 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10236 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10237 &cap_idx) == NULL) 10238 return -ENOTSUP; 10239 10240 if (MD5_HMAC_create_session(ts_params, ut_params, 10241 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 10242 return TEST_FAILED; 10243 10244 /* Generate Crypto op data structure */ 10245 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10246 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10247 TEST_ASSERT_NOT_NULL(ut_params->op, 10248 "Failed to allocate symmetric crypto operation struct"); 10249 10250 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10251 16); 10252 10253 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10254 return TEST_FAILED; 10255 10256 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10257 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10258 ut_params->op); 10259 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10260 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10261 ut_params->op, 0, 1, 0, 0); 10262 else 10263 TEST_ASSERT_NOT_NULL( 10264 process_crypto_request(ts_params->valid_devs[0], 10265 ut_params->op), 10266 "failed to process sym crypto op"); 10267 10268 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10269 "crypto op processing failed"); 10270 10271 if (ut_params->op->sym->m_dst) { 10272 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 10273 uint8_t *, plaintext_pad_len); 10274 } else { 10275 auth_tag = plaintext + plaintext_pad_len; 10276 } 10277 10278 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10279 auth_tag, 10280 test_case->auth_tag.data, 10281 test_case->auth_tag.len, 10282 "HMAC_MD5 generated tag not as expected"); 10283 10284 return TEST_SUCCESS; 10285 } 10286 10287 static int 10288 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 10289 { 10290 uint8_t *plaintext; 10291 10292 struct crypto_testsuite_params *ts_params = &testsuite_params; 10293 struct crypto_unittest_params *ut_params = &unittest_params; 10294 struct rte_cryptodev_info dev_info; 10295 10296 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10297 uint64_t feat_flags = dev_info.feature_flags; 10298 10299 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10300 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10301 printf("Device doesn't support RAW data-path APIs.\n"); 10302 return -ENOTSUP; 10303 } 10304 10305 /* Verify the capabilities */ 10306 struct rte_cryptodev_sym_capability_idx cap_idx; 10307 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10308 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10309 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10310 &cap_idx) == NULL) 10311 return -ENOTSUP; 10312 10313 if (MD5_HMAC_create_session(ts_params, ut_params, 10314 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 10315 return TEST_FAILED; 10316 } 10317 10318 /* Generate Crypto op data structure */ 10319 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10320 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10321 TEST_ASSERT_NOT_NULL(ut_params->op, 10322 "Failed to allocate symmetric crypto operation struct"); 10323 10324 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10325 return TEST_FAILED; 10326 10327 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10328 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10329 ut_params->op); 10330 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10331 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10332 ut_params->op, 0, 1, 0, 0); 10333 else 10334 TEST_ASSERT_NOT_NULL( 10335 process_crypto_request(ts_params->valid_devs[0], 10336 ut_params->op), 10337 "failed to process sym crypto op"); 10338 10339 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10340 "HMAC_MD5 crypto op processing failed"); 10341 10342 return TEST_SUCCESS; 10343 } 10344 10345 static int 10346 test_MD5_HMAC_generate_case_1(void) 10347 { 10348 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 10349 } 10350 10351 static int 10352 test_MD5_HMAC_verify_case_1(void) 10353 { 10354 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 10355 } 10356 10357 static int 10358 test_MD5_HMAC_generate_case_2(void) 10359 { 10360 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 10361 } 10362 10363 static int 10364 test_MD5_HMAC_verify_case_2(void) 10365 { 10366 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 10367 } 10368 10369 static int 10370 test_multi_session(void) 10371 { 10372 struct crypto_testsuite_params *ts_params = &testsuite_params; 10373 struct crypto_unittest_params *ut_params = &unittest_params; 10374 10375 struct rte_cryptodev_info dev_info; 10376 struct rte_cryptodev_sym_session **sessions; 10377 10378 uint16_t i; 10379 10380 /* Verify the capabilities */ 10381 struct rte_cryptodev_sym_capability_idx cap_idx; 10382 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10383 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10384 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10385 &cap_idx) == NULL) 10386 return -ENOTSUP; 10387 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10388 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10389 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10390 &cap_idx) == NULL) 10391 return -ENOTSUP; 10392 10393 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 10394 aes_cbc_key, hmac_sha512_key); 10395 10396 10397 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10398 10399 sessions = rte_malloc(NULL, 10400 (sizeof(struct rte_cryptodev_sym_session *) * 10401 MAX_NB_SESSIONS) + 1, 0); 10402 10403 /* Create multiple crypto sessions*/ 10404 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10405 10406 sessions[i] = rte_cryptodev_sym_session_create( 10407 ts_params->session_mpool); 10408 10409 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10410 sessions[i], &ut_params->auth_xform, 10411 ts_params->session_priv_mpool); 10412 TEST_ASSERT_NOT_NULL(sessions[i], 10413 "Session creation failed at session number %u", 10414 i); 10415 10416 /* Attempt to send a request on each session */ 10417 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 10418 sessions[i], 10419 ut_params, 10420 ts_params, 10421 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 10422 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 10423 aes_cbc_iv), 10424 "Failed to perform decrypt on request number %u.", i); 10425 /* free crypto operation structure */ 10426 if (ut_params->op) 10427 rte_crypto_op_free(ut_params->op); 10428 10429 /* 10430 * free mbuf - both obuf and ibuf are usually the same, 10431 * so check if they point at the same address is necessary, 10432 * to avoid freeing the mbuf twice. 10433 */ 10434 if (ut_params->obuf) { 10435 rte_pktmbuf_free(ut_params->obuf); 10436 if (ut_params->ibuf == ut_params->obuf) 10437 ut_params->ibuf = 0; 10438 ut_params->obuf = 0; 10439 } 10440 if (ut_params->ibuf) { 10441 rte_pktmbuf_free(ut_params->ibuf); 10442 ut_params->ibuf = 0; 10443 } 10444 } 10445 10446 /* Next session create should fail */ 10447 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10448 sessions[i], &ut_params->auth_xform, 10449 ts_params->session_priv_mpool); 10450 TEST_ASSERT_NULL(sessions[i], 10451 "Session creation succeeded unexpectedly!"); 10452 10453 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10454 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10455 sessions[i]); 10456 rte_cryptodev_sym_session_free(sessions[i]); 10457 } 10458 10459 rte_free(sessions); 10460 10461 return TEST_SUCCESS; 10462 } 10463 10464 struct multi_session_params { 10465 struct crypto_unittest_params ut_params; 10466 uint8_t *cipher_key; 10467 uint8_t *hmac_key; 10468 const uint8_t *cipher; 10469 const uint8_t *digest; 10470 uint8_t *iv; 10471 }; 10472 10473 #define MB_SESSION_NUMBER 3 10474 10475 static int 10476 test_multi_session_random_usage(void) 10477 { 10478 struct crypto_testsuite_params *ts_params = &testsuite_params; 10479 struct rte_cryptodev_info dev_info; 10480 struct rte_cryptodev_sym_session **sessions; 10481 uint32_t i, j; 10482 struct multi_session_params ut_paramz[] = { 10483 10484 { 10485 .cipher_key = ms_aes_cbc_key0, 10486 .hmac_key = ms_hmac_key0, 10487 .cipher = ms_aes_cbc_cipher0, 10488 .digest = ms_hmac_digest0, 10489 .iv = ms_aes_cbc_iv0 10490 }, 10491 { 10492 .cipher_key = ms_aes_cbc_key1, 10493 .hmac_key = ms_hmac_key1, 10494 .cipher = ms_aes_cbc_cipher1, 10495 .digest = ms_hmac_digest1, 10496 .iv = ms_aes_cbc_iv1 10497 }, 10498 { 10499 .cipher_key = ms_aes_cbc_key2, 10500 .hmac_key = ms_hmac_key2, 10501 .cipher = ms_aes_cbc_cipher2, 10502 .digest = ms_hmac_digest2, 10503 .iv = ms_aes_cbc_iv2 10504 }, 10505 10506 }; 10507 10508 /* Verify the capabilities */ 10509 struct rte_cryptodev_sym_capability_idx cap_idx; 10510 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10511 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10512 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10513 &cap_idx) == NULL) 10514 return -ENOTSUP; 10515 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10516 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10517 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10518 &cap_idx) == NULL) 10519 return -ENOTSUP; 10520 10521 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10522 10523 sessions = rte_malloc(NULL, 10524 (sizeof(struct rte_cryptodev_sym_session *) 10525 * MAX_NB_SESSIONS) + 1, 0); 10526 10527 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10528 sessions[i] = rte_cryptodev_sym_session_create( 10529 ts_params->session_mpool); 10530 10531 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 10532 sizeof(struct crypto_unittest_params)); 10533 10534 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 10535 &ut_paramz[i].ut_params, 10536 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 10537 10538 /* Create multiple crypto sessions*/ 10539 rte_cryptodev_sym_session_init( 10540 ts_params->valid_devs[0], 10541 sessions[i], 10542 &ut_paramz[i].ut_params.auth_xform, 10543 ts_params->session_priv_mpool); 10544 10545 TEST_ASSERT_NOT_NULL(sessions[i], 10546 "Session creation failed at session number %u", 10547 i); 10548 10549 } 10550 10551 srand(time(NULL)); 10552 for (i = 0; i < 40000; i++) { 10553 10554 j = rand() % MB_SESSION_NUMBER; 10555 10556 TEST_ASSERT_SUCCESS( 10557 test_AES_CBC_HMAC_SHA512_decrypt_perform( 10558 sessions[j], 10559 &ut_paramz[j].ut_params, 10560 ts_params, ut_paramz[j].cipher, 10561 ut_paramz[j].digest, 10562 ut_paramz[j].iv), 10563 "Failed to perform decrypt on request number %u.", i); 10564 10565 if (ut_paramz[j].ut_params.op) 10566 rte_crypto_op_free(ut_paramz[j].ut_params.op); 10567 10568 /* 10569 * free mbuf - both obuf and ibuf are usually the same, 10570 * so check if they point at the same address is necessary, 10571 * to avoid freeing the mbuf twice. 10572 */ 10573 if (ut_paramz[j].ut_params.obuf) { 10574 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 10575 if (ut_paramz[j].ut_params.ibuf 10576 == ut_paramz[j].ut_params.obuf) 10577 ut_paramz[j].ut_params.ibuf = 0; 10578 ut_paramz[j].ut_params.obuf = 0; 10579 } 10580 if (ut_paramz[j].ut_params.ibuf) { 10581 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 10582 ut_paramz[j].ut_params.ibuf = 0; 10583 } 10584 } 10585 10586 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10587 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10588 sessions[i]); 10589 rte_cryptodev_sym_session_free(sessions[i]); 10590 } 10591 10592 rte_free(sessions); 10593 10594 return TEST_SUCCESS; 10595 } 10596 10597 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 10598 0xab, 0xab, 0xab, 0xab, 10599 0xab, 0xab, 0xab, 0xab, 10600 0xab, 0xab, 0xab, 0xab}; 10601 10602 static int 10603 test_null_invalid_operation(void) 10604 { 10605 struct crypto_testsuite_params *ts_params = &testsuite_params; 10606 struct crypto_unittest_params *ut_params = &unittest_params; 10607 int ret; 10608 10609 /* This test is for NULL PMD only */ 10610 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10611 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10612 return -ENOTSUP; 10613 10614 /* Setup Cipher Parameters */ 10615 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10616 ut_params->cipher_xform.next = NULL; 10617 10618 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 10619 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10620 10621 ut_params->sess = rte_cryptodev_sym_session_create( 10622 ts_params->session_mpool); 10623 10624 /* Create Crypto session*/ 10625 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10626 ut_params->sess, &ut_params->cipher_xform, 10627 ts_params->session_priv_mpool); 10628 TEST_ASSERT(ret < 0, 10629 "Session creation succeeded unexpectedly"); 10630 10631 10632 /* Setup HMAC Parameters */ 10633 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10634 ut_params->auth_xform.next = NULL; 10635 10636 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 10637 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10638 10639 ut_params->sess = rte_cryptodev_sym_session_create( 10640 ts_params->session_mpool); 10641 10642 /* Create Crypto session*/ 10643 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10644 ut_params->sess, &ut_params->auth_xform, 10645 ts_params->session_priv_mpool); 10646 TEST_ASSERT(ret < 0, 10647 "Session creation succeeded unexpectedly"); 10648 10649 return TEST_SUCCESS; 10650 } 10651 10652 10653 #define NULL_BURST_LENGTH (32) 10654 10655 static int 10656 test_null_burst_operation(void) 10657 { 10658 struct crypto_testsuite_params *ts_params = &testsuite_params; 10659 struct crypto_unittest_params *ut_params = &unittest_params; 10660 10661 unsigned i, burst_len = NULL_BURST_LENGTH; 10662 10663 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 10664 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 10665 10666 /* This test is for NULL PMD only */ 10667 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10668 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10669 return -ENOTSUP; 10670 10671 /* Setup Cipher Parameters */ 10672 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10673 ut_params->cipher_xform.next = &ut_params->auth_xform; 10674 10675 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 10676 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10677 10678 /* Setup HMAC Parameters */ 10679 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10680 ut_params->auth_xform.next = NULL; 10681 10682 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 10683 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10684 10685 ut_params->sess = rte_cryptodev_sym_session_create( 10686 ts_params->session_mpool); 10687 10688 /* Create Crypto session*/ 10689 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10690 ut_params->sess, &ut_params->cipher_xform, 10691 ts_params->session_priv_mpool); 10692 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10693 10694 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 10695 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 10696 burst_len, "failed to generate burst of crypto ops"); 10697 10698 /* Generate an operation for each mbuf in burst */ 10699 for (i = 0; i < burst_len; i++) { 10700 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10701 10702 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 10703 10704 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 10705 sizeof(unsigned)); 10706 *data = i; 10707 10708 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 10709 10710 burst[i]->sym->m_src = m; 10711 } 10712 10713 /* Process crypto operation */ 10714 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 10715 0, burst, burst_len), 10716 burst_len, 10717 "Error enqueuing burst"); 10718 10719 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 10720 0, burst_dequeued, burst_len), 10721 burst_len, 10722 "Error dequeuing burst"); 10723 10724 10725 for (i = 0; i < burst_len; i++) { 10726 TEST_ASSERT_EQUAL( 10727 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 10728 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 10729 uint32_t *), 10730 "data not as expected"); 10731 10732 rte_pktmbuf_free(burst[i]->sym->m_src); 10733 rte_crypto_op_free(burst[i]); 10734 } 10735 10736 return TEST_SUCCESS; 10737 } 10738 10739 static uint16_t 10740 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10741 uint16_t nb_ops, void *user_param) 10742 { 10743 RTE_SET_USED(dev_id); 10744 RTE_SET_USED(qp_id); 10745 RTE_SET_USED(ops); 10746 RTE_SET_USED(user_param); 10747 10748 printf("crypto enqueue callback called\n"); 10749 return nb_ops; 10750 } 10751 10752 static uint16_t 10753 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10754 uint16_t nb_ops, void *user_param) 10755 { 10756 RTE_SET_USED(dev_id); 10757 RTE_SET_USED(qp_id); 10758 RTE_SET_USED(ops); 10759 RTE_SET_USED(user_param); 10760 10761 printf("crypto dequeue callback called\n"); 10762 return nb_ops; 10763 } 10764 10765 /* 10766 * Thread using enqueue/dequeue callback with RCU. 10767 */ 10768 static int 10769 test_enqdeq_callback_thread(void *arg) 10770 { 10771 RTE_SET_USED(arg); 10772 /* DP thread calls rte_cryptodev_enqueue_burst()/ 10773 * rte_cryptodev_dequeue_burst() and invokes callback. 10774 */ 10775 test_null_burst_operation(); 10776 return 0; 10777 } 10778 10779 static int 10780 test_enq_callback_setup(void) 10781 { 10782 struct crypto_testsuite_params *ts_params = &testsuite_params; 10783 struct rte_cryptodev_info dev_info; 10784 struct rte_cryptodev_qp_conf qp_conf = { 10785 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10786 }; 10787 10788 struct rte_cryptodev_cb *cb; 10789 uint16_t qp_id = 0; 10790 10791 /* Stop the device in case it's started so it can be configured */ 10792 rte_cryptodev_stop(ts_params->valid_devs[0]); 10793 10794 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10795 10796 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10797 &ts_params->conf), 10798 "Failed to configure cryptodev %u", 10799 ts_params->valid_devs[0]); 10800 10801 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10802 qp_conf.mp_session = ts_params->session_mpool; 10803 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10804 10805 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10806 ts_params->valid_devs[0], qp_id, &qp_conf, 10807 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10808 "Failed test for " 10809 "rte_cryptodev_queue_pair_setup: num_inflights " 10810 "%u on qp %u on cryptodev %u", 10811 qp_conf.nb_descriptors, qp_id, 10812 ts_params->valid_devs[0]); 10813 10814 /* Test with invalid crypto device */ 10815 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 10816 qp_id, test_enq_callback, NULL); 10817 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10818 "cryptodev %u did not fail", 10819 qp_id, RTE_CRYPTO_MAX_DEVS); 10820 10821 /* Test with invalid queue pair */ 10822 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10823 dev_info.max_nb_queue_pairs + 1, 10824 test_enq_callback, NULL); 10825 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10826 "cryptodev %u did not fail", 10827 dev_info.max_nb_queue_pairs + 1, 10828 ts_params->valid_devs[0]); 10829 10830 /* Test with NULL callback */ 10831 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10832 qp_id, NULL, NULL); 10833 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10834 "cryptodev %u did not fail", 10835 qp_id, ts_params->valid_devs[0]); 10836 10837 /* Test with valid configuration */ 10838 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10839 qp_id, test_enq_callback, NULL); 10840 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10841 "qp %u on cryptodev %u", 10842 qp_id, ts_params->valid_devs[0]); 10843 10844 rte_cryptodev_start(ts_params->valid_devs[0]); 10845 10846 /* Launch a thread */ 10847 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10848 rte_get_next_lcore(-1, 1, 0)); 10849 10850 /* Wait until reader exited. */ 10851 rte_eal_mp_wait_lcore(); 10852 10853 /* Test with invalid crypto device */ 10854 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10855 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10856 "Expected call to fail as crypto device is invalid"); 10857 10858 /* Test with invalid queue pair */ 10859 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10860 ts_params->valid_devs[0], 10861 dev_info.max_nb_queue_pairs + 1, cb), 10862 "Expected call to fail as queue pair is invalid"); 10863 10864 /* Test with NULL callback */ 10865 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10866 ts_params->valid_devs[0], qp_id, NULL), 10867 "Expected call to fail as callback is NULL"); 10868 10869 /* Test with valid configuration */ 10870 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 10871 ts_params->valid_devs[0], qp_id, cb), 10872 "Failed test to remove callback on " 10873 "qp %u on cryptodev %u", 10874 qp_id, ts_params->valid_devs[0]); 10875 10876 return TEST_SUCCESS; 10877 } 10878 10879 static int 10880 test_deq_callback_setup(void) 10881 { 10882 struct crypto_testsuite_params *ts_params = &testsuite_params; 10883 struct rte_cryptodev_info dev_info; 10884 struct rte_cryptodev_qp_conf qp_conf = { 10885 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10886 }; 10887 10888 struct rte_cryptodev_cb *cb; 10889 uint16_t qp_id = 0; 10890 10891 /* Stop the device in case it's started so it can be configured */ 10892 rte_cryptodev_stop(ts_params->valid_devs[0]); 10893 10894 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10895 10896 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10897 &ts_params->conf), 10898 "Failed to configure cryptodev %u", 10899 ts_params->valid_devs[0]); 10900 10901 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10902 qp_conf.mp_session = ts_params->session_mpool; 10903 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10904 10905 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10906 ts_params->valid_devs[0], qp_id, &qp_conf, 10907 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10908 "Failed test for " 10909 "rte_cryptodev_queue_pair_setup: num_inflights " 10910 "%u on qp %u on cryptodev %u", 10911 qp_conf.nb_descriptors, qp_id, 10912 ts_params->valid_devs[0]); 10913 10914 /* Test with invalid crypto device */ 10915 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 10916 qp_id, test_deq_callback, NULL); 10917 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10918 "cryptodev %u did not fail", 10919 qp_id, RTE_CRYPTO_MAX_DEVS); 10920 10921 /* Test with invalid queue pair */ 10922 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10923 dev_info.max_nb_queue_pairs + 1, 10924 test_deq_callback, NULL); 10925 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10926 "cryptodev %u did not fail", 10927 dev_info.max_nb_queue_pairs + 1, 10928 ts_params->valid_devs[0]); 10929 10930 /* Test with NULL callback */ 10931 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10932 qp_id, NULL, NULL); 10933 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10934 "cryptodev %u did not fail", 10935 qp_id, ts_params->valid_devs[0]); 10936 10937 /* Test with valid configuration */ 10938 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10939 qp_id, test_deq_callback, NULL); 10940 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10941 "qp %u on cryptodev %u", 10942 qp_id, ts_params->valid_devs[0]); 10943 10944 rte_cryptodev_start(ts_params->valid_devs[0]); 10945 10946 /* Launch a thread */ 10947 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10948 rte_get_next_lcore(-1, 1, 0)); 10949 10950 /* Wait until reader exited. */ 10951 rte_eal_mp_wait_lcore(); 10952 10953 /* Test with invalid crypto device */ 10954 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10955 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10956 "Expected call to fail as crypto device is invalid"); 10957 10958 /* Test with invalid queue pair */ 10959 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10960 ts_params->valid_devs[0], 10961 dev_info.max_nb_queue_pairs + 1, cb), 10962 "Expected call to fail as queue pair is invalid"); 10963 10964 /* Test with NULL callback */ 10965 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10966 ts_params->valid_devs[0], qp_id, NULL), 10967 "Expected call to fail as callback is NULL"); 10968 10969 /* Test with valid configuration */ 10970 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 10971 ts_params->valid_devs[0], qp_id, cb), 10972 "Failed test to remove callback on " 10973 "qp %u on cryptodev %u", 10974 qp_id, ts_params->valid_devs[0]); 10975 10976 return TEST_SUCCESS; 10977 } 10978 10979 static void 10980 generate_gmac_large_plaintext(uint8_t *data) 10981 { 10982 uint16_t i; 10983 10984 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 10985 memcpy(&data[i], &data[0], 32); 10986 } 10987 10988 static int 10989 create_gmac_operation(enum rte_crypto_auth_operation op, 10990 const struct gmac_test_data *tdata) 10991 { 10992 struct crypto_testsuite_params *ts_params = &testsuite_params; 10993 struct crypto_unittest_params *ut_params = &unittest_params; 10994 struct rte_crypto_sym_op *sym_op; 10995 10996 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10997 10998 /* Generate Crypto op data structure */ 10999 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11000 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11001 TEST_ASSERT_NOT_NULL(ut_params->op, 11002 "Failed to allocate symmetric crypto operation struct"); 11003 11004 sym_op = ut_params->op->sym; 11005 11006 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11007 ut_params->ibuf, tdata->gmac_tag.len); 11008 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11009 "no room to append digest"); 11010 11011 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11012 ut_params->ibuf, plaintext_pad_len); 11013 11014 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11015 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11016 tdata->gmac_tag.len); 11017 debug_hexdump(stdout, "digest:", 11018 sym_op->auth.digest.data, 11019 tdata->gmac_tag.len); 11020 } 11021 11022 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11023 uint8_t *, IV_OFFSET); 11024 11025 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11026 11027 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11028 11029 sym_op->cipher.data.length = 0; 11030 sym_op->cipher.data.offset = 0; 11031 11032 sym_op->auth.data.offset = 0; 11033 sym_op->auth.data.length = tdata->plaintext.len; 11034 11035 return 0; 11036 } 11037 11038 static int 11039 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 11040 const struct gmac_test_data *tdata, 11041 void *digest_mem, uint64_t digest_phys) 11042 { 11043 struct crypto_testsuite_params *ts_params = &testsuite_params; 11044 struct crypto_unittest_params *ut_params = &unittest_params; 11045 struct rte_crypto_sym_op *sym_op; 11046 11047 /* Generate Crypto op data structure */ 11048 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11049 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11050 TEST_ASSERT_NOT_NULL(ut_params->op, 11051 "Failed to allocate symmetric crypto operation struct"); 11052 11053 sym_op = ut_params->op->sym; 11054 11055 sym_op->auth.digest.data = digest_mem; 11056 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11057 "no room to append digest"); 11058 11059 sym_op->auth.digest.phys_addr = digest_phys; 11060 11061 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11062 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11063 tdata->gmac_tag.len); 11064 debug_hexdump(stdout, "digest:", 11065 sym_op->auth.digest.data, 11066 tdata->gmac_tag.len); 11067 } 11068 11069 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11070 uint8_t *, IV_OFFSET); 11071 11072 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11073 11074 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11075 11076 sym_op->cipher.data.length = 0; 11077 sym_op->cipher.data.offset = 0; 11078 11079 sym_op->auth.data.offset = 0; 11080 sym_op->auth.data.length = tdata->plaintext.len; 11081 11082 return 0; 11083 } 11084 11085 static int create_gmac_session(uint8_t dev_id, 11086 const struct gmac_test_data *tdata, 11087 enum rte_crypto_auth_operation auth_op) 11088 { 11089 uint8_t auth_key[tdata->key.len]; 11090 11091 struct crypto_testsuite_params *ts_params = &testsuite_params; 11092 struct crypto_unittest_params *ut_params = &unittest_params; 11093 11094 memcpy(auth_key, tdata->key.data, tdata->key.len); 11095 11096 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11097 ut_params->auth_xform.next = NULL; 11098 11099 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 11100 ut_params->auth_xform.auth.op = auth_op; 11101 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 11102 ut_params->auth_xform.auth.key.length = tdata->key.len; 11103 ut_params->auth_xform.auth.key.data = auth_key; 11104 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11105 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 11106 11107 11108 ut_params->sess = rte_cryptodev_sym_session_create( 11109 ts_params->session_mpool); 11110 11111 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11112 &ut_params->auth_xform, 11113 ts_params->session_priv_mpool); 11114 11115 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11116 11117 return 0; 11118 } 11119 11120 static int 11121 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 11122 { 11123 struct crypto_testsuite_params *ts_params = &testsuite_params; 11124 struct crypto_unittest_params *ut_params = &unittest_params; 11125 struct rte_cryptodev_info dev_info; 11126 11127 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11128 uint64_t feat_flags = dev_info.feature_flags; 11129 11130 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11131 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11132 printf("Device doesn't support RAW data-path APIs.\n"); 11133 return -ENOTSUP; 11134 } 11135 11136 int retval; 11137 11138 uint8_t *auth_tag, *plaintext; 11139 uint16_t plaintext_pad_len; 11140 11141 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11142 "No GMAC length in the source data"); 11143 11144 /* Verify the capabilities */ 11145 struct rte_cryptodev_sym_capability_idx cap_idx; 11146 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11147 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11148 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11149 &cap_idx) == NULL) 11150 return -ENOTSUP; 11151 11152 retval = create_gmac_session(ts_params->valid_devs[0], 11153 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11154 11155 if (retval < 0) 11156 return retval; 11157 11158 if (tdata->plaintext.len > MBUF_SIZE) 11159 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11160 else 11161 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11162 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11163 "Failed to allocate input buffer in mempool"); 11164 11165 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11166 rte_pktmbuf_tailroom(ut_params->ibuf)); 11167 11168 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11169 /* 11170 * Runtime generate the large plain text instead of use hard code 11171 * plain text vector. It is done to avoid create huge source file 11172 * with the test vector. 11173 */ 11174 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11175 generate_gmac_large_plaintext(tdata->plaintext.data); 11176 11177 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11178 plaintext_pad_len); 11179 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11180 11181 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11182 debug_hexdump(stdout, "plaintext:", plaintext, 11183 tdata->plaintext.len); 11184 11185 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 11186 tdata); 11187 11188 if (retval < 0) 11189 return retval; 11190 11191 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11192 11193 ut_params->op->sym->m_src = ut_params->ibuf; 11194 11195 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11196 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11197 ut_params->op); 11198 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11199 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11200 ut_params->op, 0, 1, 0, 0); 11201 else 11202 TEST_ASSERT_NOT_NULL( 11203 process_crypto_request(ts_params->valid_devs[0], 11204 ut_params->op), "failed to process sym crypto op"); 11205 11206 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11207 "crypto op processing failed"); 11208 11209 if (ut_params->op->sym->m_dst) { 11210 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11211 uint8_t *, plaintext_pad_len); 11212 } else { 11213 auth_tag = plaintext + plaintext_pad_len; 11214 } 11215 11216 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11217 11218 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11219 auth_tag, 11220 tdata->gmac_tag.data, 11221 tdata->gmac_tag.len, 11222 "GMAC Generated auth tag not as expected"); 11223 11224 return 0; 11225 } 11226 11227 static int 11228 test_AES_GMAC_authentication_test_case_1(void) 11229 { 11230 return test_AES_GMAC_authentication(&gmac_test_case_1); 11231 } 11232 11233 static int 11234 test_AES_GMAC_authentication_test_case_2(void) 11235 { 11236 return test_AES_GMAC_authentication(&gmac_test_case_2); 11237 } 11238 11239 static int 11240 test_AES_GMAC_authentication_test_case_3(void) 11241 { 11242 return test_AES_GMAC_authentication(&gmac_test_case_3); 11243 } 11244 11245 static int 11246 test_AES_GMAC_authentication_test_case_4(void) 11247 { 11248 return test_AES_GMAC_authentication(&gmac_test_case_4); 11249 } 11250 11251 static int 11252 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 11253 { 11254 struct crypto_testsuite_params *ts_params = &testsuite_params; 11255 struct crypto_unittest_params *ut_params = &unittest_params; 11256 int retval; 11257 uint32_t plaintext_pad_len; 11258 uint8_t *plaintext; 11259 struct rte_cryptodev_info dev_info; 11260 11261 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11262 uint64_t feat_flags = dev_info.feature_flags; 11263 11264 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11265 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11266 printf("Device doesn't support RAW data-path APIs.\n"); 11267 return -ENOTSUP; 11268 } 11269 11270 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11271 "No GMAC length in the source data"); 11272 11273 /* Verify the capabilities */ 11274 struct rte_cryptodev_sym_capability_idx cap_idx; 11275 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11276 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11277 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11278 &cap_idx) == NULL) 11279 return -ENOTSUP; 11280 11281 retval = create_gmac_session(ts_params->valid_devs[0], 11282 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 11283 11284 if (retval < 0) 11285 return retval; 11286 11287 if (tdata->plaintext.len > MBUF_SIZE) 11288 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11289 else 11290 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11291 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11292 "Failed to allocate input buffer in mempool"); 11293 11294 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11295 rte_pktmbuf_tailroom(ut_params->ibuf)); 11296 11297 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11298 11299 /* 11300 * Runtime generate the large plain text instead of use hard code 11301 * plain text vector. It is done to avoid create huge source file 11302 * with the test vector. 11303 */ 11304 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11305 generate_gmac_large_plaintext(tdata->plaintext.data); 11306 11307 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11308 plaintext_pad_len); 11309 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11310 11311 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11312 debug_hexdump(stdout, "plaintext:", plaintext, 11313 tdata->plaintext.len); 11314 11315 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 11316 tdata); 11317 11318 if (retval < 0) 11319 return retval; 11320 11321 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11322 11323 ut_params->op->sym->m_src = ut_params->ibuf; 11324 11325 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11326 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11327 ut_params->op); 11328 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11329 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11330 ut_params->op, 0, 1, 0, 0); 11331 else 11332 TEST_ASSERT_NOT_NULL( 11333 process_crypto_request(ts_params->valid_devs[0], 11334 ut_params->op), "failed to process sym crypto op"); 11335 11336 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11337 "crypto op processing failed"); 11338 11339 return 0; 11340 11341 } 11342 11343 static int 11344 test_AES_GMAC_authentication_verify_test_case_1(void) 11345 { 11346 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 11347 } 11348 11349 static int 11350 test_AES_GMAC_authentication_verify_test_case_2(void) 11351 { 11352 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 11353 } 11354 11355 static int 11356 test_AES_GMAC_authentication_verify_test_case_3(void) 11357 { 11358 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 11359 } 11360 11361 static int 11362 test_AES_GMAC_authentication_verify_test_case_4(void) 11363 { 11364 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 11365 } 11366 11367 static int 11368 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 11369 uint32_t fragsz) 11370 { 11371 struct crypto_testsuite_params *ts_params = &testsuite_params; 11372 struct crypto_unittest_params *ut_params = &unittest_params; 11373 struct rte_cryptodev_info dev_info; 11374 uint64_t feature_flags; 11375 unsigned int trn_data = 0; 11376 void *digest_mem = NULL; 11377 uint32_t segs = 1; 11378 unsigned int to_trn = 0; 11379 struct rte_mbuf *buf = NULL; 11380 uint8_t *auth_tag, *plaintext; 11381 int retval; 11382 11383 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11384 "No GMAC length in the source data"); 11385 11386 /* Verify the capabilities */ 11387 struct rte_cryptodev_sym_capability_idx cap_idx; 11388 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11389 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11390 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11391 &cap_idx) == NULL) 11392 return -ENOTSUP; 11393 11394 /* Check for any input SGL support */ 11395 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11396 feature_flags = dev_info.feature_flags; 11397 11398 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 11399 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 11400 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 11401 return -ENOTSUP; 11402 11403 if (fragsz > tdata->plaintext.len) 11404 fragsz = tdata->plaintext.len; 11405 11406 uint16_t plaintext_len = fragsz; 11407 11408 retval = create_gmac_session(ts_params->valid_devs[0], 11409 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11410 11411 if (retval < 0) 11412 return retval; 11413 11414 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11415 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11416 "Failed to allocate input buffer in mempool"); 11417 11418 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11419 rte_pktmbuf_tailroom(ut_params->ibuf)); 11420 11421 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11422 plaintext_len); 11423 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11424 11425 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 11426 11427 trn_data += plaintext_len; 11428 11429 buf = ut_params->ibuf; 11430 11431 /* 11432 * Loop until no more fragments 11433 */ 11434 11435 while (trn_data < tdata->plaintext.len) { 11436 ++segs; 11437 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 11438 (tdata->plaintext.len - trn_data) : fragsz; 11439 11440 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11441 buf = buf->next; 11442 11443 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 11444 rte_pktmbuf_tailroom(buf)); 11445 11446 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 11447 to_trn); 11448 11449 memcpy(plaintext, tdata->plaintext.data + trn_data, 11450 to_trn); 11451 trn_data += to_trn; 11452 if (trn_data == tdata->plaintext.len) 11453 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 11454 tdata->gmac_tag.len); 11455 } 11456 ut_params->ibuf->nb_segs = segs; 11457 11458 /* 11459 * Place digest at the end of the last buffer 11460 */ 11461 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 11462 11463 if (!digest_mem) { 11464 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11465 + tdata->gmac_tag.len); 11466 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 11467 tdata->plaintext.len); 11468 } 11469 11470 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 11471 tdata, digest_mem, digest_phys); 11472 11473 if (retval < 0) 11474 return retval; 11475 11476 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11477 11478 ut_params->op->sym->m_src = ut_params->ibuf; 11479 11480 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11481 return -ENOTSUP; 11482 11483 TEST_ASSERT_NOT_NULL( 11484 process_crypto_request(ts_params->valid_devs[0], 11485 ut_params->op), "failed to process sym crypto op"); 11486 11487 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11488 "crypto op processing failed"); 11489 11490 auth_tag = digest_mem; 11491 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11492 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11493 auth_tag, 11494 tdata->gmac_tag.data, 11495 tdata->gmac_tag.len, 11496 "GMAC Generated auth tag not as expected"); 11497 11498 return 0; 11499 } 11500 11501 /* Segment size not multiple of block size (16B) */ 11502 static int 11503 test_AES_GMAC_authentication_SGL_40B(void) 11504 { 11505 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 11506 } 11507 11508 static int 11509 test_AES_GMAC_authentication_SGL_80B(void) 11510 { 11511 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 11512 } 11513 11514 static int 11515 test_AES_GMAC_authentication_SGL_2048B(void) 11516 { 11517 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 11518 } 11519 11520 /* Segment size not multiple of block size (16B) */ 11521 static int 11522 test_AES_GMAC_authentication_SGL_2047B(void) 11523 { 11524 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 11525 } 11526 11527 struct test_crypto_vector { 11528 enum rte_crypto_cipher_algorithm crypto_algo; 11529 unsigned int cipher_offset; 11530 unsigned int cipher_len; 11531 11532 struct { 11533 uint8_t data[64]; 11534 unsigned int len; 11535 } cipher_key; 11536 11537 struct { 11538 uint8_t data[64]; 11539 unsigned int len; 11540 } iv; 11541 11542 struct { 11543 const uint8_t *data; 11544 unsigned int len; 11545 } plaintext; 11546 11547 struct { 11548 const uint8_t *data; 11549 unsigned int len; 11550 } ciphertext; 11551 11552 enum rte_crypto_auth_algorithm auth_algo; 11553 unsigned int auth_offset; 11554 11555 struct { 11556 uint8_t data[128]; 11557 unsigned int len; 11558 } auth_key; 11559 11560 struct { 11561 const uint8_t *data; 11562 unsigned int len; 11563 } aad; 11564 11565 struct { 11566 uint8_t data[128]; 11567 unsigned int len; 11568 } digest; 11569 }; 11570 11571 static const struct test_crypto_vector 11572 hmac_sha1_test_crypto_vector = { 11573 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11574 .plaintext = { 11575 .data = plaintext_hash, 11576 .len = 512 11577 }, 11578 .auth_key = { 11579 .data = { 11580 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11581 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11582 0xDE, 0xF4, 0xDE, 0xAD 11583 }, 11584 .len = 20 11585 }, 11586 .digest = { 11587 .data = { 11588 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 11589 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 11590 0x3F, 0x91, 0x64, 0x59 11591 }, 11592 .len = 20 11593 } 11594 }; 11595 11596 static const struct test_crypto_vector 11597 aes128_gmac_test_vector = { 11598 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 11599 .plaintext = { 11600 .data = plaintext_hash, 11601 .len = 512 11602 }, 11603 .iv = { 11604 .data = { 11605 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11606 0x08, 0x09, 0x0A, 0x0B 11607 }, 11608 .len = 12 11609 }, 11610 .auth_key = { 11611 .data = { 11612 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11613 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 11614 }, 11615 .len = 16 11616 }, 11617 .digest = { 11618 .data = { 11619 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 11620 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 11621 }, 11622 .len = 16 11623 } 11624 }; 11625 11626 static const struct test_crypto_vector 11627 aes128cbc_hmac_sha1_test_vector = { 11628 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11629 .cipher_offset = 0, 11630 .cipher_len = 512, 11631 .cipher_key = { 11632 .data = { 11633 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11634 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11635 }, 11636 .len = 16 11637 }, 11638 .iv = { 11639 .data = { 11640 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11641 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11642 }, 11643 .len = 16 11644 }, 11645 .plaintext = { 11646 .data = plaintext_hash, 11647 .len = 512 11648 }, 11649 .ciphertext = { 11650 .data = ciphertext512_aes128cbc, 11651 .len = 512 11652 }, 11653 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11654 .auth_offset = 0, 11655 .auth_key = { 11656 .data = { 11657 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11658 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11659 0xDE, 0xF4, 0xDE, 0xAD 11660 }, 11661 .len = 20 11662 }, 11663 .digest = { 11664 .data = { 11665 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 11666 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11667 0x18, 0x8C, 0x1D, 0x32 11668 }, 11669 .len = 20 11670 } 11671 }; 11672 11673 static const struct test_crypto_vector 11674 aes128cbc_hmac_sha1_aad_test_vector = { 11675 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11676 .cipher_offset = 8, 11677 .cipher_len = 496, 11678 .cipher_key = { 11679 .data = { 11680 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11681 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11682 }, 11683 .len = 16 11684 }, 11685 .iv = { 11686 .data = { 11687 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11688 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11689 }, 11690 .len = 16 11691 }, 11692 .plaintext = { 11693 .data = plaintext_hash, 11694 .len = 512 11695 }, 11696 .ciphertext = { 11697 .data = ciphertext512_aes128cbc_aad, 11698 .len = 512 11699 }, 11700 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11701 .auth_offset = 0, 11702 .auth_key = { 11703 .data = { 11704 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11705 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11706 0xDE, 0xF4, 0xDE, 0xAD 11707 }, 11708 .len = 20 11709 }, 11710 .digest = { 11711 .data = { 11712 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 11713 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 11714 0x62, 0x0F, 0xFB, 0x10 11715 }, 11716 .len = 20 11717 } 11718 }; 11719 11720 static void 11721 data_corruption(uint8_t *data) 11722 { 11723 data[0] += 1; 11724 } 11725 11726 static void 11727 tag_corruption(uint8_t *data, unsigned int tag_offset) 11728 { 11729 data[tag_offset] += 1; 11730 } 11731 11732 static int 11733 create_auth_session(struct crypto_unittest_params *ut_params, 11734 uint8_t dev_id, 11735 const struct test_crypto_vector *reference, 11736 enum rte_crypto_auth_operation auth_op) 11737 { 11738 struct crypto_testsuite_params *ts_params = &testsuite_params; 11739 uint8_t auth_key[reference->auth_key.len + 1]; 11740 11741 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11742 11743 /* Setup Authentication Parameters */ 11744 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11745 ut_params->auth_xform.auth.op = auth_op; 11746 ut_params->auth_xform.next = NULL; 11747 ut_params->auth_xform.auth.algo = reference->auth_algo; 11748 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11749 ut_params->auth_xform.auth.key.data = auth_key; 11750 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11751 11752 /* Create Crypto session*/ 11753 ut_params->sess = rte_cryptodev_sym_session_create( 11754 ts_params->session_mpool); 11755 11756 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11757 &ut_params->auth_xform, 11758 ts_params->session_priv_mpool); 11759 11760 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11761 11762 return 0; 11763 } 11764 11765 static int 11766 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 11767 uint8_t dev_id, 11768 const struct test_crypto_vector *reference, 11769 enum rte_crypto_auth_operation auth_op, 11770 enum rte_crypto_cipher_operation cipher_op) 11771 { 11772 struct crypto_testsuite_params *ts_params = &testsuite_params; 11773 uint8_t cipher_key[reference->cipher_key.len + 1]; 11774 uint8_t auth_key[reference->auth_key.len + 1]; 11775 11776 memcpy(cipher_key, reference->cipher_key.data, 11777 reference->cipher_key.len); 11778 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11779 11780 /* Setup Authentication Parameters */ 11781 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11782 ut_params->auth_xform.auth.op = auth_op; 11783 ut_params->auth_xform.auth.algo = reference->auth_algo; 11784 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11785 ut_params->auth_xform.auth.key.data = auth_key; 11786 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11787 11788 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 11789 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11790 ut_params->auth_xform.auth.iv.length = reference->iv.len; 11791 } else { 11792 ut_params->auth_xform.next = &ut_params->cipher_xform; 11793 11794 /* Setup Cipher Parameters */ 11795 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11796 ut_params->cipher_xform.next = NULL; 11797 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 11798 ut_params->cipher_xform.cipher.op = cipher_op; 11799 ut_params->cipher_xform.cipher.key.data = cipher_key; 11800 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 11801 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11802 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 11803 } 11804 11805 /* Create Crypto session*/ 11806 ut_params->sess = rte_cryptodev_sym_session_create( 11807 ts_params->session_mpool); 11808 11809 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11810 &ut_params->auth_xform, 11811 ts_params->session_priv_mpool); 11812 11813 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11814 11815 return 0; 11816 } 11817 11818 static int 11819 create_auth_operation(struct crypto_testsuite_params *ts_params, 11820 struct crypto_unittest_params *ut_params, 11821 const struct test_crypto_vector *reference, 11822 unsigned int auth_generate) 11823 { 11824 /* Generate Crypto op data structure */ 11825 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11826 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11827 TEST_ASSERT_NOT_NULL(ut_params->op, 11828 "Failed to allocate pktmbuf offload"); 11829 11830 /* Set crypto operation data parameters */ 11831 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11832 11833 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11834 11835 /* set crypto operation source mbuf */ 11836 sym_op->m_src = ut_params->ibuf; 11837 11838 /* digest */ 11839 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11840 ut_params->ibuf, reference->digest.len); 11841 11842 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11843 "no room to append auth tag"); 11844 11845 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11846 ut_params->ibuf, reference->plaintext.len); 11847 11848 if (auth_generate) 11849 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11850 else 11851 memcpy(sym_op->auth.digest.data, 11852 reference->digest.data, 11853 reference->digest.len); 11854 11855 debug_hexdump(stdout, "digest:", 11856 sym_op->auth.digest.data, 11857 reference->digest.len); 11858 11859 sym_op->auth.data.length = reference->plaintext.len; 11860 sym_op->auth.data.offset = 0; 11861 11862 return 0; 11863 } 11864 11865 static int 11866 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 11867 struct crypto_unittest_params *ut_params, 11868 const struct test_crypto_vector *reference, 11869 unsigned int auth_generate) 11870 { 11871 /* Generate Crypto op data structure */ 11872 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11873 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11874 TEST_ASSERT_NOT_NULL(ut_params->op, 11875 "Failed to allocate pktmbuf offload"); 11876 11877 /* Set crypto operation data parameters */ 11878 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11879 11880 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11881 11882 /* set crypto operation source mbuf */ 11883 sym_op->m_src = ut_params->ibuf; 11884 11885 /* digest */ 11886 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11887 ut_params->ibuf, reference->digest.len); 11888 11889 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11890 "no room to append auth tag"); 11891 11892 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11893 ut_params->ibuf, reference->ciphertext.len); 11894 11895 if (auth_generate) 11896 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11897 else 11898 memcpy(sym_op->auth.digest.data, 11899 reference->digest.data, 11900 reference->digest.len); 11901 11902 debug_hexdump(stdout, "digest:", 11903 sym_op->auth.digest.data, 11904 reference->digest.len); 11905 11906 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11907 reference->iv.data, reference->iv.len); 11908 11909 sym_op->cipher.data.length = 0; 11910 sym_op->cipher.data.offset = 0; 11911 11912 sym_op->auth.data.length = reference->plaintext.len; 11913 sym_op->auth.data.offset = 0; 11914 11915 return 0; 11916 } 11917 11918 static int 11919 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 11920 struct crypto_unittest_params *ut_params, 11921 const struct test_crypto_vector *reference, 11922 unsigned int auth_generate) 11923 { 11924 /* Generate Crypto op data structure */ 11925 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11926 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11927 TEST_ASSERT_NOT_NULL(ut_params->op, 11928 "Failed to allocate pktmbuf offload"); 11929 11930 /* Set crypto operation data parameters */ 11931 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11932 11933 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11934 11935 /* set crypto operation source mbuf */ 11936 sym_op->m_src = ut_params->ibuf; 11937 11938 /* digest */ 11939 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11940 ut_params->ibuf, reference->digest.len); 11941 11942 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11943 "no room to append auth tag"); 11944 11945 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11946 ut_params->ibuf, reference->ciphertext.len); 11947 11948 if (auth_generate) 11949 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11950 else 11951 memcpy(sym_op->auth.digest.data, 11952 reference->digest.data, 11953 reference->digest.len); 11954 11955 debug_hexdump(stdout, "digest:", 11956 sym_op->auth.digest.data, 11957 reference->digest.len); 11958 11959 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11960 reference->iv.data, reference->iv.len); 11961 11962 sym_op->cipher.data.length = reference->cipher_len; 11963 sym_op->cipher.data.offset = reference->cipher_offset; 11964 11965 sym_op->auth.data.length = reference->plaintext.len; 11966 sym_op->auth.data.offset = reference->auth_offset; 11967 11968 return 0; 11969 } 11970 11971 static int 11972 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11973 struct crypto_unittest_params *ut_params, 11974 const struct test_crypto_vector *reference) 11975 { 11976 return create_auth_operation(ts_params, ut_params, reference, 0); 11977 } 11978 11979 static int 11980 create_auth_verify_GMAC_operation( 11981 struct crypto_testsuite_params *ts_params, 11982 struct crypto_unittest_params *ut_params, 11983 const struct test_crypto_vector *reference) 11984 { 11985 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 11986 } 11987 11988 static int 11989 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11990 struct crypto_unittest_params *ut_params, 11991 const struct test_crypto_vector *reference) 11992 { 11993 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 11994 } 11995 11996 static int 11997 test_authentication_verify_fail_when_data_corruption( 11998 struct crypto_testsuite_params *ts_params, 11999 struct crypto_unittest_params *ut_params, 12000 const struct test_crypto_vector *reference, 12001 unsigned int data_corrupted) 12002 { 12003 int retval; 12004 12005 uint8_t *plaintext; 12006 struct rte_cryptodev_info dev_info; 12007 12008 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12009 uint64_t feat_flags = dev_info.feature_flags; 12010 12011 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12012 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12013 printf("Device doesn't support RAW data-path APIs.\n"); 12014 return -ENOTSUP; 12015 } 12016 12017 /* Verify the capabilities */ 12018 struct rte_cryptodev_sym_capability_idx cap_idx; 12019 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12020 cap_idx.algo.auth = reference->auth_algo; 12021 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12022 &cap_idx) == NULL) 12023 return -ENOTSUP; 12024 12025 12026 /* Create session */ 12027 retval = create_auth_session(ut_params, 12028 ts_params->valid_devs[0], 12029 reference, 12030 RTE_CRYPTO_AUTH_OP_VERIFY); 12031 if (retval < 0) 12032 return retval; 12033 12034 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12035 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12036 "Failed to allocate input buffer in mempool"); 12037 12038 /* clear mbuf payload */ 12039 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12040 rte_pktmbuf_tailroom(ut_params->ibuf)); 12041 12042 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12043 reference->plaintext.len); 12044 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12045 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12046 12047 debug_hexdump(stdout, "plaintext:", plaintext, 12048 reference->plaintext.len); 12049 12050 /* Create operation */ 12051 retval = create_auth_verify_operation(ts_params, ut_params, reference); 12052 12053 if (retval < 0) 12054 return retval; 12055 12056 if (data_corrupted) 12057 data_corruption(plaintext); 12058 else 12059 tag_corruption(plaintext, reference->plaintext.len); 12060 12061 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12062 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12063 ut_params->op); 12064 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12065 RTE_CRYPTO_OP_STATUS_SUCCESS, 12066 "authentication not failed"); 12067 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12068 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12069 ut_params->op, 0, 1, 0, 0); 12070 else { 12071 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12072 ut_params->op); 12073 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12074 } 12075 12076 return 0; 12077 } 12078 12079 static int 12080 test_authentication_verify_GMAC_fail_when_corruption( 12081 struct crypto_testsuite_params *ts_params, 12082 struct crypto_unittest_params *ut_params, 12083 const struct test_crypto_vector *reference, 12084 unsigned int data_corrupted) 12085 { 12086 int retval; 12087 uint8_t *plaintext; 12088 struct rte_cryptodev_info dev_info; 12089 12090 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12091 uint64_t feat_flags = dev_info.feature_flags; 12092 12093 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12094 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12095 printf("Device doesn't support RAW data-path APIs.\n"); 12096 return -ENOTSUP; 12097 } 12098 12099 /* Verify the capabilities */ 12100 struct rte_cryptodev_sym_capability_idx cap_idx; 12101 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12102 cap_idx.algo.auth = reference->auth_algo; 12103 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12104 &cap_idx) == NULL) 12105 return -ENOTSUP; 12106 12107 /* Create session */ 12108 retval = create_auth_cipher_session(ut_params, 12109 ts_params->valid_devs[0], 12110 reference, 12111 RTE_CRYPTO_AUTH_OP_VERIFY, 12112 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12113 if (retval < 0) 12114 return retval; 12115 12116 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12117 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12118 "Failed to allocate input buffer in mempool"); 12119 12120 /* clear mbuf payload */ 12121 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12122 rte_pktmbuf_tailroom(ut_params->ibuf)); 12123 12124 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12125 reference->plaintext.len); 12126 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12127 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12128 12129 debug_hexdump(stdout, "plaintext:", plaintext, 12130 reference->plaintext.len); 12131 12132 /* Create operation */ 12133 retval = create_auth_verify_GMAC_operation(ts_params, 12134 ut_params, 12135 reference); 12136 12137 if (retval < 0) 12138 return retval; 12139 12140 if (data_corrupted) 12141 data_corruption(plaintext); 12142 else 12143 tag_corruption(plaintext, reference->aad.len); 12144 12145 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12146 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12147 ut_params->op); 12148 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12149 RTE_CRYPTO_OP_STATUS_SUCCESS, 12150 "authentication not failed"); 12151 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12152 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12153 ut_params->op, 0, 1, 0, 0); 12154 else { 12155 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12156 ut_params->op); 12157 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12158 } 12159 12160 return 0; 12161 } 12162 12163 static int 12164 test_authenticated_decryption_fail_when_corruption( 12165 struct crypto_testsuite_params *ts_params, 12166 struct crypto_unittest_params *ut_params, 12167 const struct test_crypto_vector *reference, 12168 unsigned int data_corrupted) 12169 { 12170 int retval; 12171 12172 uint8_t *ciphertext; 12173 struct rte_cryptodev_info dev_info; 12174 12175 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12176 uint64_t feat_flags = dev_info.feature_flags; 12177 12178 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12179 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12180 printf("Device doesn't support RAW data-path APIs.\n"); 12181 return -ENOTSUP; 12182 } 12183 12184 /* Verify the capabilities */ 12185 struct rte_cryptodev_sym_capability_idx cap_idx; 12186 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12187 cap_idx.algo.auth = reference->auth_algo; 12188 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12189 &cap_idx) == NULL) 12190 return -ENOTSUP; 12191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12192 cap_idx.algo.cipher = reference->crypto_algo; 12193 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12194 &cap_idx) == NULL) 12195 return -ENOTSUP; 12196 12197 /* Create session */ 12198 retval = create_auth_cipher_session(ut_params, 12199 ts_params->valid_devs[0], 12200 reference, 12201 RTE_CRYPTO_AUTH_OP_VERIFY, 12202 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12203 if (retval < 0) 12204 return retval; 12205 12206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12207 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12208 "Failed to allocate input buffer in mempool"); 12209 12210 /* clear mbuf payload */ 12211 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12212 rte_pktmbuf_tailroom(ut_params->ibuf)); 12213 12214 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12215 reference->ciphertext.len); 12216 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12217 memcpy(ciphertext, reference->ciphertext.data, 12218 reference->ciphertext.len); 12219 12220 /* Create operation */ 12221 retval = create_cipher_auth_verify_operation(ts_params, 12222 ut_params, 12223 reference); 12224 12225 if (retval < 0) 12226 return retval; 12227 12228 if (data_corrupted) 12229 data_corruption(ciphertext); 12230 else 12231 tag_corruption(ciphertext, reference->ciphertext.len); 12232 12233 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12234 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12235 ut_params->op); 12236 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12237 RTE_CRYPTO_OP_STATUS_SUCCESS, 12238 "authentication not failed"); 12239 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12240 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12241 ut_params->op, 1, 1, 0, 0); 12242 else { 12243 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12244 ut_params->op); 12245 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12246 } 12247 12248 return 0; 12249 } 12250 12251 static int 12252 test_authenticated_encryt_with_esn( 12253 struct crypto_testsuite_params *ts_params, 12254 struct crypto_unittest_params *ut_params, 12255 const struct test_crypto_vector *reference) 12256 { 12257 int retval; 12258 12259 uint8_t *authciphertext, *plaintext, *auth_tag; 12260 uint16_t plaintext_pad_len; 12261 uint8_t cipher_key[reference->cipher_key.len + 1]; 12262 uint8_t auth_key[reference->auth_key.len + 1]; 12263 struct rte_cryptodev_info dev_info; 12264 12265 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12266 uint64_t feat_flags = dev_info.feature_flags; 12267 12268 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12269 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12270 printf("Device doesn't support RAW data-path APIs.\n"); 12271 return -ENOTSUP; 12272 } 12273 12274 /* Verify the capabilities */ 12275 struct rte_cryptodev_sym_capability_idx cap_idx; 12276 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12277 cap_idx.algo.auth = reference->auth_algo; 12278 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12279 &cap_idx) == NULL) 12280 return -ENOTSUP; 12281 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12282 cap_idx.algo.cipher = reference->crypto_algo; 12283 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12284 &cap_idx) == NULL) 12285 return -ENOTSUP; 12286 12287 /* Create session */ 12288 memcpy(cipher_key, reference->cipher_key.data, 12289 reference->cipher_key.len); 12290 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12291 12292 /* Setup Cipher Parameters */ 12293 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12294 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12295 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12296 ut_params->cipher_xform.cipher.key.data = cipher_key; 12297 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12298 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12299 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12300 12301 ut_params->cipher_xform.next = &ut_params->auth_xform; 12302 12303 /* Setup Authentication Parameters */ 12304 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12305 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12306 ut_params->auth_xform.auth.algo = reference->auth_algo; 12307 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12308 ut_params->auth_xform.auth.key.data = auth_key; 12309 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12310 ut_params->auth_xform.next = NULL; 12311 12312 /* Create Crypto session*/ 12313 ut_params->sess = rte_cryptodev_sym_session_create( 12314 ts_params->session_mpool); 12315 12316 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12317 ut_params->sess, 12318 &ut_params->cipher_xform, 12319 ts_params->session_priv_mpool); 12320 12321 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12322 12323 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12324 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12325 "Failed to allocate input buffer in mempool"); 12326 12327 /* clear mbuf payload */ 12328 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12329 rte_pktmbuf_tailroom(ut_params->ibuf)); 12330 12331 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12332 reference->plaintext.len); 12333 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12334 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12335 12336 /* Create operation */ 12337 retval = create_cipher_auth_operation(ts_params, 12338 ut_params, 12339 reference, 0); 12340 12341 if (retval < 0) 12342 return retval; 12343 12344 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12345 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12346 ut_params->op); 12347 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12348 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12349 ut_params->op, 1, 1, 0, 0); 12350 else 12351 ut_params->op = process_crypto_request( 12352 ts_params->valid_devs[0], ut_params->op); 12353 12354 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 12355 12356 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12357 "crypto op processing failed"); 12358 12359 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 12360 12361 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12362 ut_params->op->sym->auth.data.offset); 12363 auth_tag = authciphertext + plaintext_pad_len; 12364 debug_hexdump(stdout, "ciphertext:", authciphertext, 12365 reference->ciphertext.len); 12366 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 12367 12368 /* Validate obuf */ 12369 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12370 authciphertext, 12371 reference->ciphertext.data, 12372 reference->ciphertext.len, 12373 "Ciphertext data not as expected"); 12374 12375 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12376 auth_tag, 12377 reference->digest.data, 12378 reference->digest.len, 12379 "Generated digest not as expected"); 12380 12381 return TEST_SUCCESS; 12382 12383 } 12384 12385 static int 12386 test_authenticated_decrypt_with_esn( 12387 struct crypto_testsuite_params *ts_params, 12388 struct crypto_unittest_params *ut_params, 12389 const struct test_crypto_vector *reference) 12390 { 12391 int retval; 12392 12393 uint8_t *ciphertext; 12394 uint8_t cipher_key[reference->cipher_key.len + 1]; 12395 uint8_t auth_key[reference->auth_key.len + 1]; 12396 struct rte_cryptodev_info dev_info; 12397 12398 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12399 uint64_t feat_flags = dev_info.feature_flags; 12400 12401 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12402 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12403 printf("Device doesn't support RAW data-path APIs.\n"); 12404 return -ENOTSUP; 12405 } 12406 12407 /* Verify the capabilities */ 12408 struct rte_cryptodev_sym_capability_idx cap_idx; 12409 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12410 cap_idx.algo.auth = reference->auth_algo; 12411 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12412 &cap_idx) == NULL) 12413 return -ENOTSUP; 12414 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12415 cap_idx.algo.cipher = reference->crypto_algo; 12416 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12417 &cap_idx) == NULL) 12418 return -ENOTSUP; 12419 12420 /* Create session */ 12421 memcpy(cipher_key, reference->cipher_key.data, 12422 reference->cipher_key.len); 12423 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12424 12425 /* Setup Authentication Parameters */ 12426 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12427 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 12428 ut_params->auth_xform.auth.algo = reference->auth_algo; 12429 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12430 ut_params->auth_xform.auth.key.data = auth_key; 12431 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12432 ut_params->auth_xform.next = &ut_params->cipher_xform; 12433 12434 /* Setup Cipher Parameters */ 12435 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12436 ut_params->cipher_xform.next = NULL; 12437 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12438 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 12439 ut_params->cipher_xform.cipher.key.data = cipher_key; 12440 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12441 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12442 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12443 12444 /* Create Crypto session*/ 12445 ut_params->sess = rte_cryptodev_sym_session_create( 12446 ts_params->session_mpool); 12447 12448 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12449 ut_params->sess, 12450 &ut_params->auth_xform, 12451 ts_params->session_priv_mpool); 12452 12453 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12454 12455 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12456 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12457 "Failed to allocate input buffer in mempool"); 12458 12459 /* clear mbuf payload */ 12460 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12461 rte_pktmbuf_tailroom(ut_params->ibuf)); 12462 12463 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12464 reference->ciphertext.len); 12465 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12466 memcpy(ciphertext, reference->ciphertext.data, 12467 reference->ciphertext.len); 12468 12469 /* Create operation */ 12470 retval = create_cipher_auth_verify_operation(ts_params, 12471 ut_params, 12472 reference); 12473 12474 if (retval < 0) 12475 return retval; 12476 12477 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12478 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12479 ut_params->op); 12480 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12481 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12482 ut_params->op, 1, 1, 0, 0); 12483 else 12484 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12485 ut_params->op); 12486 12487 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12488 TEST_ASSERT_EQUAL(ut_params->op->status, 12489 RTE_CRYPTO_OP_STATUS_SUCCESS, 12490 "crypto op processing passed"); 12491 12492 ut_params->obuf = ut_params->op->sym->m_src; 12493 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 12494 12495 return 0; 12496 } 12497 12498 static int 12499 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 12500 const struct aead_test_data *tdata, 12501 void *digest_mem, uint64_t digest_phys) 12502 { 12503 struct crypto_testsuite_params *ts_params = &testsuite_params; 12504 struct crypto_unittest_params *ut_params = &unittest_params; 12505 12506 const unsigned int auth_tag_len = tdata->auth_tag.len; 12507 const unsigned int iv_len = tdata->iv.len; 12508 unsigned int aad_len = tdata->aad.len; 12509 unsigned int aad_len_pad = 0; 12510 12511 /* Generate Crypto op data structure */ 12512 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12513 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12514 TEST_ASSERT_NOT_NULL(ut_params->op, 12515 "Failed to allocate symmetric crypto operation struct"); 12516 12517 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12518 12519 sym_op->aead.digest.data = digest_mem; 12520 12521 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 12522 "no room to append digest"); 12523 12524 sym_op->aead.digest.phys_addr = digest_phys; 12525 12526 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 12527 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 12528 auth_tag_len); 12529 debug_hexdump(stdout, "digest:", 12530 sym_op->aead.digest.data, 12531 auth_tag_len); 12532 } 12533 12534 /* Append aad data */ 12535 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 12536 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12537 uint8_t *, IV_OFFSET); 12538 12539 /* Copy IV 1 byte after the IV pointer, according to the API */ 12540 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 12541 12542 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 12543 12544 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12545 ut_params->ibuf, aad_len); 12546 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12547 "no room to prepend aad"); 12548 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12549 ut_params->ibuf); 12550 12551 memset(sym_op->aead.aad.data, 0, aad_len); 12552 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 12553 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12554 12555 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12556 debug_hexdump(stdout, "aad:", 12557 sym_op->aead.aad.data, aad_len); 12558 } else { 12559 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12560 uint8_t *, IV_OFFSET); 12561 12562 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 12563 12564 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 12565 12566 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12567 ut_params->ibuf, aad_len_pad); 12568 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12569 "no room to prepend aad"); 12570 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12571 ut_params->ibuf); 12572 12573 memset(sym_op->aead.aad.data, 0, aad_len); 12574 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12575 12576 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12577 debug_hexdump(stdout, "aad:", 12578 sym_op->aead.aad.data, aad_len); 12579 } 12580 12581 sym_op->aead.data.length = tdata->plaintext.len; 12582 sym_op->aead.data.offset = aad_len_pad; 12583 12584 return 0; 12585 } 12586 12587 #define SGL_MAX_NO 16 12588 12589 static int 12590 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 12591 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 12592 { 12593 struct crypto_testsuite_params *ts_params = &testsuite_params; 12594 struct crypto_unittest_params *ut_params = &unittest_params; 12595 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 12596 int retval; 12597 int to_trn = 0; 12598 int to_trn_tbl[SGL_MAX_NO]; 12599 int segs = 1; 12600 unsigned int trn_data = 0; 12601 uint8_t *plaintext, *ciphertext, *auth_tag; 12602 struct rte_cryptodev_info dev_info; 12603 12604 /* Verify the capabilities */ 12605 struct rte_cryptodev_sym_capability_idx cap_idx; 12606 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12607 cap_idx.algo.aead = tdata->algo; 12608 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12609 &cap_idx) == NULL) 12610 return -ENOTSUP; 12611 12612 /* OOP not supported with CPU crypto */ 12613 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12614 return -ENOTSUP; 12615 12616 /* Detailed check for the particular SGL support flag */ 12617 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12618 if (!oop) { 12619 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12620 if (sgl_in && (!(dev_info.feature_flags & 12621 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 12622 return -ENOTSUP; 12623 12624 uint64_t feat_flags = dev_info.feature_flags; 12625 12626 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12627 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12628 printf("Device doesn't support RAW data-path APIs.\n"); 12629 return -ENOTSUP; 12630 } 12631 } else { 12632 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12633 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 12634 tdata->plaintext.len; 12635 /* Raw data path API does not support OOP */ 12636 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12637 return -ENOTSUP; 12638 if (sgl_in && !sgl_out) { 12639 if (!(dev_info.feature_flags & 12640 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 12641 return -ENOTSUP; 12642 } else if (!sgl_in && sgl_out) { 12643 if (!(dev_info.feature_flags & 12644 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 12645 return -ENOTSUP; 12646 } else if (sgl_in && sgl_out) { 12647 if (!(dev_info.feature_flags & 12648 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 12649 return -ENOTSUP; 12650 } 12651 } 12652 12653 if (fragsz > tdata->plaintext.len) 12654 fragsz = tdata->plaintext.len; 12655 12656 uint16_t plaintext_len = fragsz; 12657 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 12658 12659 if (fragsz_oop > tdata->plaintext.len) 12660 frag_size_oop = tdata->plaintext.len; 12661 12662 int ecx = 0; 12663 void *digest_mem = NULL; 12664 12665 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 12666 12667 if (tdata->plaintext.len % fragsz != 0) { 12668 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 12669 return 1; 12670 } else { 12671 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 12672 return 1; 12673 } 12674 12675 /* 12676 * For out-op-place we need to alloc another mbuf 12677 */ 12678 if (oop) { 12679 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12680 rte_pktmbuf_append(ut_params->obuf, 12681 frag_size_oop + prepend_len); 12682 buf_oop = ut_params->obuf; 12683 } 12684 12685 /* Create AEAD session */ 12686 retval = create_aead_session(ts_params->valid_devs[0], 12687 tdata->algo, 12688 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12689 tdata->key.data, tdata->key.len, 12690 tdata->aad.len, tdata->auth_tag.len, 12691 tdata->iv.len); 12692 if (retval < 0) 12693 return retval; 12694 12695 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12696 12697 /* clear mbuf payload */ 12698 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12699 rte_pktmbuf_tailroom(ut_params->ibuf)); 12700 12701 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12702 plaintext_len); 12703 12704 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12705 12706 trn_data += plaintext_len; 12707 12708 buf = ut_params->ibuf; 12709 12710 /* 12711 * Loop until no more fragments 12712 */ 12713 12714 while (trn_data < tdata->plaintext.len) { 12715 ++segs; 12716 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12717 (tdata->plaintext.len - trn_data) : fragsz; 12718 12719 to_trn_tbl[ecx++] = to_trn; 12720 12721 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12722 buf = buf->next; 12723 12724 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12725 rte_pktmbuf_tailroom(buf)); 12726 12727 /* OOP */ 12728 if (oop && !fragsz_oop) { 12729 buf_last_oop = buf_oop->next = 12730 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12731 buf_oop = buf_oop->next; 12732 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12733 0, rte_pktmbuf_tailroom(buf_oop)); 12734 rte_pktmbuf_append(buf_oop, to_trn); 12735 } 12736 12737 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12738 to_trn); 12739 12740 memcpy(plaintext, tdata->plaintext.data + trn_data, 12741 to_trn); 12742 trn_data += to_trn; 12743 if (trn_data == tdata->plaintext.len) { 12744 if (oop) { 12745 if (!fragsz_oop) 12746 digest_mem = rte_pktmbuf_append(buf_oop, 12747 tdata->auth_tag.len); 12748 } else 12749 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12750 tdata->auth_tag.len); 12751 } 12752 } 12753 12754 uint64_t digest_phys = 0; 12755 12756 ut_params->ibuf->nb_segs = segs; 12757 12758 segs = 1; 12759 if (fragsz_oop && oop) { 12760 to_trn = 0; 12761 ecx = 0; 12762 12763 if (frag_size_oop == tdata->plaintext.len) { 12764 digest_mem = rte_pktmbuf_append(ut_params->obuf, 12765 tdata->auth_tag.len); 12766 12767 digest_phys = rte_pktmbuf_iova_offset( 12768 ut_params->obuf, 12769 tdata->plaintext.len + prepend_len); 12770 } 12771 12772 trn_data = frag_size_oop; 12773 while (trn_data < tdata->plaintext.len) { 12774 ++segs; 12775 to_trn = 12776 (tdata->plaintext.len - trn_data < 12777 frag_size_oop) ? 12778 (tdata->plaintext.len - trn_data) : 12779 frag_size_oop; 12780 12781 to_trn_tbl[ecx++] = to_trn; 12782 12783 buf_last_oop = buf_oop->next = 12784 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12785 buf_oop = buf_oop->next; 12786 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12787 0, rte_pktmbuf_tailroom(buf_oop)); 12788 rte_pktmbuf_append(buf_oop, to_trn); 12789 12790 trn_data += to_trn; 12791 12792 if (trn_data == tdata->plaintext.len) { 12793 digest_mem = rte_pktmbuf_append(buf_oop, 12794 tdata->auth_tag.len); 12795 } 12796 } 12797 12798 ut_params->obuf->nb_segs = segs; 12799 } 12800 12801 /* 12802 * Place digest at the end of the last buffer 12803 */ 12804 if (!digest_phys) 12805 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12806 if (oop && buf_last_oop) 12807 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 12808 12809 if (!digest_mem && !oop) { 12810 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12811 + tdata->auth_tag.len); 12812 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12813 tdata->plaintext.len); 12814 } 12815 12816 /* Create AEAD operation */ 12817 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 12818 tdata, digest_mem, digest_phys); 12819 12820 if (retval < 0) 12821 return retval; 12822 12823 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12824 12825 ut_params->op->sym->m_src = ut_params->ibuf; 12826 if (oop) 12827 ut_params->op->sym->m_dst = ut_params->obuf; 12828 12829 /* Process crypto operation */ 12830 if (oop == IN_PLACE && 12831 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12832 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12833 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12834 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12835 ut_params->op, 0, 0, 0, 0); 12836 else 12837 TEST_ASSERT_NOT_NULL( 12838 process_crypto_request(ts_params->valid_devs[0], 12839 ut_params->op), "failed to process sym crypto op"); 12840 12841 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12842 "crypto op processing failed"); 12843 12844 12845 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12846 uint8_t *, prepend_len); 12847 if (oop) { 12848 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12849 uint8_t *, prepend_len); 12850 } 12851 12852 if (fragsz_oop) 12853 fragsz = fragsz_oop; 12854 12855 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12856 ciphertext, 12857 tdata->ciphertext.data, 12858 fragsz, 12859 "Ciphertext data not as expected"); 12860 12861 buf = ut_params->op->sym->m_src->next; 12862 if (oop) 12863 buf = ut_params->op->sym->m_dst->next; 12864 12865 unsigned int off = fragsz; 12866 12867 ecx = 0; 12868 while (buf) { 12869 ciphertext = rte_pktmbuf_mtod(buf, 12870 uint8_t *); 12871 12872 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12873 ciphertext, 12874 tdata->ciphertext.data + off, 12875 to_trn_tbl[ecx], 12876 "Ciphertext data not as expected"); 12877 12878 off += to_trn_tbl[ecx++]; 12879 buf = buf->next; 12880 } 12881 12882 auth_tag = digest_mem; 12883 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12884 auth_tag, 12885 tdata->auth_tag.data, 12886 tdata->auth_tag.len, 12887 "Generated auth tag not as expected"); 12888 12889 return 0; 12890 } 12891 12892 static int 12893 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 12894 { 12895 return test_authenticated_encryption_SGL( 12896 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 12897 } 12898 12899 static int 12900 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 12901 { 12902 return test_authenticated_encryption_SGL( 12903 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 12904 } 12905 12906 static int 12907 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 12908 { 12909 return test_authenticated_encryption_SGL( 12910 &gcm_test_case_8, OUT_OF_PLACE, 400, 12911 gcm_test_case_8.plaintext.len); 12912 } 12913 12914 static int 12915 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 12916 { 12917 /* This test is not for OPENSSL PMD */ 12918 if (gbl_driver_id == rte_cryptodev_driver_id_get( 12919 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 12920 return -ENOTSUP; 12921 12922 return test_authenticated_encryption_SGL( 12923 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 12924 } 12925 12926 static int 12927 test_authentication_verify_fail_when_data_corrupted( 12928 struct crypto_testsuite_params *ts_params, 12929 struct crypto_unittest_params *ut_params, 12930 const struct test_crypto_vector *reference) 12931 { 12932 return test_authentication_verify_fail_when_data_corruption( 12933 ts_params, ut_params, reference, 1); 12934 } 12935 12936 static int 12937 test_authentication_verify_fail_when_tag_corrupted( 12938 struct crypto_testsuite_params *ts_params, 12939 struct crypto_unittest_params *ut_params, 12940 const struct test_crypto_vector *reference) 12941 { 12942 return test_authentication_verify_fail_when_data_corruption( 12943 ts_params, ut_params, reference, 0); 12944 } 12945 12946 static int 12947 test_authentication_verify_GMAC_fail_when_data_corrupted( 12948 struct crypto_testsuite_params *ts_params, 12949 struct crypto_unittest_params *ut_params, 12950 const struct test_crypto_vector *reference) 12951 { 12952 return test_authentication_verify_GMAC_fail_when_corruption( 12953 ts_params, ut_params, reference, 1); 12954 } 12955 12956 static int 12957 test_authentication_verify_GMAC_fail_when_tag_corrupted( 12958 struct crypto_testsuite_params *ts_params, 12959 struct crypto_unittest_params *ut_params, 12960 const struct test_crypto_vector *reference) 12961 { 12962 return test_authentication_verify_GMAC_fail_when_corruption( 12963 ts_params, ut_params, reference, 0); 12964 } 12965 12966 static int 12967 test_authenticated_decryption_fail_when_data_corrupted( 12968 struct crypto_testsuite_params *ts_params, 12969 struct crypto_unittest_params *ut_params, 12970 const struct test_crypto_vector *reference) 12971 { 12972 return test_authenticated_decryption_fail_when_corruption( 12973 ts_params, ut_params, reference, 1); 12974 } 12975 12976 static int 12977 test_authenticated_decryption_fail_when_tag_corrupted( 12978 struct crypto_testsuite_params *ts_params, 12979 struct crypto_unittest_params *ut_params, 12980 const struct test_crypto_vector *reference) 12981 { 12982 return test_authenticated_decryption_fail_when_corruption( 12983 ts_params, ut_params, reference, 0); 12984 } 12985 12986 static int 12987 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 12988 { 12989 return test_authentication_verify_fail_when_data_corrupted( 12990 &testsuite_params, &unittest_params, 12991 &hmac_sha1_test_crypto_vector); 12992 } 12993 12994 static int 12995 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 12996 { 12997 return test_authentication_verify_fail_when_tag_corrupted( 12998 &testsuite_params, &unittest_params, 12999 &hmac_sha1_test_crypto_vector); 13000 } 13001 13002 static int 13003 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 13004 { 13005 return test_authentication_verify_GMAC_fail_when_data_corrupted( 13006 &testsuite_params, &unittest_params, 13007 &aes128_gmac_test_vector); 13008 } 13009 13010 static int 13011 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 13012 { 13013 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 13014 &testsuite_params, &unittest_params, 13015 &aes128_gmac_test_vector); 13016 } 13017 13018 static int 13019 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 13020 { 13021 return test_authenticated_decryption_fail_when_data_corrupted( 13022 &testsuite_params, 13023 &unittest_params, 13024 &aes128cbc_hmac_sha1_test_vector); 13025 } 13026 13027 static int 13028 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 13029 { 13030 return test_authenticated_decryption_fail_when_tag_corrupted( 13031 &testsuite_params, 13032 &unittest_params, 13033 &aes128cbc_hmac_sha1_test_vector); 13034 } 13035 13036 static int 13037 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13038 { 13039 return test_authenticated_encryt_with_esn( 13040 &testsuite_params, 13041 &unittest_params, 13042 &aes128cbc_hmac_sha1_aad_test_vector); 13043 } 13044 13045 static int 13046 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13047 { 13048 return test_authenticated_decrypt_with_esn( 13049 &testsuite_params, 13050 &unittest_params, 13051 &aes128cbc_hmac_sha1_aad_test_vector); 13052 } 13053 13054 static int 13055 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 13056 { 13057 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 13058 } 13059 13060 static int 13061 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 13062 { 13063 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 13064 } 13065 13066 #ifdef RTE_CRYPTO_SCHEDULER 13067 13068 /* global AESNI worker IDs for the scheduler test */ 13069 uint8_t aesni_ids[2]; 13070 13071 static int 13072 test_scheduler_attach_slave_op(void) 13073 { 13074 struct crypto_testsuite_params *ts_params = &testsuite_params; 13075 uint8_t sched_id = ts_params->valid_devs[0]; 13076 uint32_t nb_devs, i, nb_devs_attached = 0; 13077 int ret; 13078 char vdev_name[32]; 13079 13080 /* create 2 AESNI_MB if necessary */ 13081 nb_devs = rte_cryptodev_device_count_by_driver( 13082 rte_cryptodev_driver_id_get( 13083 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 13084 if (nb_devs < 2) { 13085 for (i = nb_devs; i < 2; i++) { 13086 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 13087 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 13088 i); 13089 ret = rte_vdev_init(vdev_name, NULL); 13090 13091 TEST_ASSERT(ret == 0, 13092 "Failed to create instance %u of" 13093 " pmd : %s", 13094 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13095 } 13096 } 13097 13098 /* attach 2 AESNI_MB cdevs */ 13099 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 13100 i++) { 13101 struct rte_cryptodev_info info; 13102 unsigned int session_size; 13103 13104 rte_cryptodev_info_get(i, &info); 13105 if (info.driver_id != rte_cryptodev_driver_id_get( 13106 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 13107 continue; 13108 13109 session_size = rte_cryptodev_sym_get_private_session_size(i); 13110 /* 13111 * Create the session mempool again, since now there are new devices 13112 * to use the mempool. 13113 */ 13114 if (ts_params->session_mpool) { 13115 rte_mempool_free(ts_params->session_mpool); 13116 ts_params->session_mpool = NULL; 13117 } 13118 if (ts_params->session_priv_mpool) { 13119 rte_mempool_free(ts_params->session_priv_mpool); 13120 ts_params->session_priv_mpool = NULL; 13121 } 13122 13123 if (info.sym.max_nb_sessions != 0 && 13124 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 13125 RTE_LOG(ERR, USER1, 13126 "Device does not support " 13127 "at least %u sessions\n", 13128 MAX_NB_SESSIONS); 13129 return TEST_FAILED; 13130 } 13131 /* 13132 * Create mempool with maximum number of sessions, 13133 * to include the session headers 13134 */ 13135 if (ts_params->session_mpool == NULL) { 13136 ts_params->session_mpool = 13137 rte_cryptodev_sym_session_pool_create( 13138 "test_sess_mp", 13139 MAX_NB_SESSIONS, 0, 0, 0, 13140 SOCKET_ID_ANY); 13141 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 13142 "session mempool allocation failed"); 13143 } 13144 13145 /* 13146 * Create mempool with maximum number of sessions, 13147 * to include device specific session private data 13148 */ 13149 if (ts_params->session_priv_mpool == NULL) { 13150 ts_params->session_priv_mpool = rte_mempool_create( 13151 "test_sess_mp_priv", 13152 MAX_NB_SESSIONS, 13153 session_size, 13154 0, 0, NULL, NULL, NULL, 13155 NULL, SOCKET_ID_ANY, 13156 0); 13157 13158 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 13159 "session mempool allocation failed"); 13160 } 13161 13162 ts_params->qp_conf.mp_session = ts_params->session_mpool; 13163 ts_params->qp_conf.mp_session_private = 13164 ts_params->session_priv_mpool; 13165 13166 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 13167 (uint8_t)i); 13168 13169 TEST_ASSERT(ret == 0, 13170 "Failed to attach device %u of pmd : %s", i, 13171 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13172 13173 aesni_ids[nb_devs_attached] = (uint8_t)i; 13174 13175 nb_devs_attached++; 13176 } 13177 13178 return 0; 13179 } 13180 13181 static int 13182 test_scheduler_detach_slave_op(void) 13183 { 13184 struct crypto_testsuite_params *ts_params = &testsuite_params; 13185 uint8_t sched_id = ts_params->valid_devs[0]; 13186 uint32_t i; 13187 int ret; 13188 13189 for (i = 0; i < 2; i++) { 13190 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 13191 aesni_ids[i]); 13192 TEST_ASSERT(ret == 0, 13193 "Failed to detach device %u", aesni_ids[i]); 13194 } 13195 13196 return 0; 13197 } 13198 13199 static int 13200 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 13201 { 13202 struct crypto_testsuite_params *ts_params = &testsuite_params; 13203 uint8_t sched_id = ts_params->valid_devs[0]; 13204 /* set mode */ 13205 return rte_cryptodev_scheduler_mode_set(sched_id, 13206 scheduler_mode); 13207 } 13208 13209 static int 13210 test_scheduler_mode_roundrobin_op(void) 13211 { 13212 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 13213 0, "Failed to set roundrobin mode"); 13214 return 0; 13215 13216 } 13217 13218 static int 13219 test_scheduler_mode_multicore_op(void) 13220 { 13221 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 13222 0, "Failed to set multicore mode"); 13223 13224 return 0; 13225 } 13226 13227 static int 13228 test_scheduler_mode_failover_op(void) 13229 { 13230 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 13231 0, "Failed to set failover mode"); 13232 13233 return 0; 13234 } 13235 13236 static int 13237 test_scheduler_mode_pkt_size_distr_op(void) 13238 { 13239 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 13240 0, "Failed to set pktsize mode"); 13241 13242 return 0; 13243 } 13244 13245 static struct unit_test_suite cryptodev_scheduler_testsuite = { 13246 .suite_name = "Crypto Device Scheduler Unit Test Suite", 13247 .setup = testsuite_setup, 13248 .teardown = testsuite_teardown, 13249 .unit_test_cases = { 13250 /* Multi Core */ 13251 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13252 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op), 13253 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13254 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13255 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13256 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13257 13258 /* Round Robin */ 13259 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13260 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op), 13261 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13262 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13263 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13264 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13265 13266 /* Fail over */ 13267 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13268 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op), 13269 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13270 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13271 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13272 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13273 13274 /* PKT SIZE */ 13275 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13276 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op), 13277 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13278 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13279 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13280 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13281 13282 TEST_CASES_END() /**< NULL terminate unit test array */ 13283 } 13284 }; 13285 13286 #endif /* RTE_CRYPTO_SCHEDULER */ 13287 13288 static struct unit_test_suite cryptodev_testsuite = { 13289 .suite_name = "Crypto Unit Test Suite", 13290 .setup = testsuite_setup, 13291 .teardown = testsuite_teardown, 13292 .unit_test_cases = { 13293 TEST_CASE_ST(ut_setup, ut_teardown, 13294 test_device_configure_invalid_dev_id), 13295 TEST_CASE_ST(ut_setup, ut_teardown, 13296 test_queue_pair_descriptor_setup), 13297 TEST_CASE_ST(ut_setup, ut_teardown, 13298 test_device_configure_invalid_queue_pair_ids), 13299 TEST_CASE_ST(ut_setup, ut_teardown, 13300 test_multi_session), 13301 TEST_CASE_ST(ut_setup, ut_teardown, 13302 test_multi_session_random_usage), 13303 13304 TEST_CASE_ST(ut_setup, ut_teardown, 13305 test_null_invalid_operation), 13306 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 13307 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13308 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13309 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13310 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13311 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all), 13312 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all), 13313 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all), 13314 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13315 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 13316 13317 /** AES CCM Authenticated Encryption 128 bits key */ 13318 TEST_CASE_ST(ut_setup, ut_teardown, 13319 test_AES_CCM_authenticated_encryption_test_case_128_1), 13320 TEST_CASE_ST(ut_setup, ut_teardown, 13321 test_AES_CCM_authenticated_encryption_test_case_128_2), 13322 TEST_CASE_ST(ut_setup, ut_teardown, 13323 test_AES_CCM_authenticated_encryption_test_case_128_3), 13324 13325 /** AES CCM Authenticated Decryption 128 bits key*/ 13326 TEST_CASE_ST(ut_setup, ut_teardown, 13327 test_AES_CCM_authenticated_decryption_test_case_128_1), 13328 TEST_CASE_ST(ut_setup, ut_teardown, 13329 test_AES_CCM_authenticated_decryption_test_case_128_2), 13330 TEST_CASE_ST(ut_setup, ut_teardown, 13331 test_AES_CCM_authenticated_decryption_test_case_128_3), 13332 13333 /** AES CCM Authenticated Encryption 192 bits key */ 13334 TEST_CASE_ST(ut_setup, ut_teardown, 13335 test_AES_CCM_authenticated_encryption_test_case_192_1), 13336 TEST_CASE_ST(ut_setup, ut_teardown, 13337 test_AES_CCM_authenticated_encryption_test_case_192_2), 13338 TEST_CASE_ST(ut_setup, ut_teardown, 13339 test_AES_CCM_authenticated_encryption_test_case_192_3), 13340 13341 /** AES CCM Authenticated Decryption 192 bits key*/ 13342 TEST_CASE_ST(ut_setup, ut_teardown, 13343 test_AES_CCM_authenticated_decryption_test_case_192_1), 13344 TEST_CASE_ST(ut_setup, ut_teardown, 13345 test_AES_CCM_authenticated_decryption_test_case_192_2), 13346 TEST_CASE_ST(ut_setup, ut_teardown, 13347 test_AES_CCM_authenticated_decryption_test_case_192_3), 13348 13349 /** AES CCM Authenticated Encryption 256 bits key */ 13350 TEST_CASE_ST(ut_setup, ut_teardown, 13351 test_AES_CCM_authenticated_encryption_test_case_256_1), 13352 TEST_CASE_ST(ut_setup, ut_teardown, 13353 test_AES_CCM_authenticated_encryption_test_case_256_2), 13354 TEST_CASE_ST(ut_setup, ut_teardown, 13355 test_AES_CCM_authenticated_encryption_test_case_256_3), 13356 13357 /** AES CCM Authenticated Decryption 256 bits key*/ 13358 TEST_CASE_ST(ut_setup, ut_teardown, 13359 test_AES_CCM_authenticated_decryption_test_case_256_1), 13360 TEST_CASE_ST(ut_setup, ut_teardown, 13361 test_AES_CCM_authenticated_decryption_test_case_256_2), 13362 TEST_CASE_ST(ut_setup, ut_teardown, 13363 test_AES_CCM_authenticated_decryption_test_case_256_3), 13364 13365 /** AES GCM Authenticated Encryption */ 13366 TEST_CASE_ST(ut_setup, ut_teardown, 13367 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 13368 TEST_CASE_ST(ut_setup, ut_teardown, 13369 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 13370 TEST_CASE_ST(ut_setup, ut_teardown, 13371 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 13372 TEST_CASE_ST(ut_setup, ut_teardown, 13373 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 13374 TEST_CASE_ST(ut_setup, ut_teardown, 13375 test_AES_GCM_authenticated_encryption_test_case_1), 13376 TEST_CASE_ST(ut_setup, ut_teardown, 13377 test_AES_GCM_authenticated_encryption_test_case_2), 13378 TEST_CASE_ST(ut_setup, ut_teardown, 13379 test_AES_GCM_authenticated_encryption_test_case_3), 13380 TEST_CASE_ST(ut_setup, ut_teardown, 13381 test_AES_GCM_authenticated_encryption_test_case_4), 13382 TEST_CASE_ST(ut_setup, ut_teardown, 13383 test_AES_GCM_authenticated_encryption_test_case_5), 13384 TEST_CASE_ST(ut_setup, ut_teardown, 13385 test_AES_GCM_authenticated_encryption_test_case_6), 13386 TEST_CASE_ST(ut_setup, ut_teardown, 13387 test_AES_GCM_authenticated_encryption_test_case_7), 13388 TEST_CASE_ST(ut_setup, ut_teardown, 13389 test_AES_GCM_authenticated_encryption_test_case_8), 13390 TEST_CASE_ST(ut_setup, ut_teardown, 13391 test_AES_GCM_J0_authenticated_encryption_test_case_1), 13392 13393 /** AES GCM Authenticated Decryption */ 13394 TEST_CASE_ST(ut_setup, ut_teardown, 13395 test_AES_GCM_authenticated_decryption_test_case_1), 13396 TEST_CASE_ST(ut_setup, ut_teardown, 13397 test_AES_GCM_authenticated_decryption_test_case_2), 13398 TEST_CASE_ST(ut_setup, ut_teardown, 13399 test_AES_GCM_authenticated_decryption_test_case_3), 13400 TEST_CASE_ST(ut_setup, ut_teardown, 13401 test_AES_GCM_authenticated_decryption_test_case_4), 13402 TEST_CASE_ST(ut_setup, ut_teardown, 13403 test_AES_GCM_authenticated_decryption_test_case_5), 13404 TEST_CASE_ST(ut_setup, ut_teardown, 13405 test_AES_GCM_authenticated_decryption_test_case_6), 13406 TEST_CASE_ST(ut_setup, ut_teardown, 13407 test_AES_GCM_authenticated_decryption_test_case_7), 13408 TEST_CASE_ST(ut_setup, ut_teardown, 13409 test_AES_GCM_authenticated_decryption_test_case_8), 13410 TEST_CASE_ST(ut_setup, ut_teardown, 13411 test_AES_GCM_J0_authenticated_decryption_test_case_1), 13412 13413 /** AES GCM Authenticated Encryption 192 bits key */ 13414 TEST_CASE_ST(ut_setup, ut_teardown, 13415 test_AES_GCM_auth_encryption_test_case_192_1), 13416 TEST_CASE_ST(ut_setup, ut_teardown, 13417 test_AES_GCM_auth_encryption_test_case_192_2), 13418 TEST_CASE_ST(ut_setup, ut_teardown, 13419 test_AES_GCM_auth_encryption_test_case_192_3), 13420 TEST_CASE_ST(ut_setup, ut_teardown, 13421 test_AES_GCM_auth_encryption_test_case_192_4), 13422 TEST_CASE_ST(ut_setup, ut_teardown, 13423 test_AES_GCM_auth_encryption_test_case_192_5), 13424 TEST_CASE_ST(ut_setup, ut_teardown, 13425 test_AES_GCM_auth_encryption_test_case_192_6), 13426 TEST_CASE_ST(ut_setup, ut_teardown, 13427 test_AES_GCM_auth_encryption_test_case_192_7), 13428 13429 /** AES GCM Authenticated Decryption 192 bits key */ 13430 TEST_CASE_ST(ut_setup, ut_teardown, 13431 test_AES_GCM_auth_decryption_test_case_192_1), 13432 TEST_CASE_ST(ut_setup, ut_teardown, 13433 test_AES_GCM_auth_decryption_test_case_192_2), 13434 TEST_CASE_ST(ut_setup, ut_teardown, 13435 test_AES_GCM_auth_decryption_test_case_192_3), 13436 TEST_CASE_ST(ut_setup, ut_teardown, 13437 test_AES_GCM_auth_decryption_test_case_192_4), 13438 TEST_CASE_ST(ut_setup, ut_teardown, 13439 test_AES_GCM_auth_decryption_test_case_192_5), 13440 TEST_CASE_ST(ut_setup, ut_teardown, 13441 test_AES_GCM_auth_decryption_test_case_192_6), 13442 TEST_CASE_ST(ut_setup, ut_teardown, 13443 test_AES_GCM_auth_decryption_test_case_192_7), 13444 13445 /** AES GCM Authenticated Encryption 256 bits key */ 13446 TEST_CASE_ST(ut_setup, ut_teardown, 13447 test_AES_GCM_auth_encryption_test_case_256_1), 13448 TEST_CASE_ST(ut_setup, ut_teardown, 13449 test_AES_GCM_auth_encryption_test_case_256_2), 13450 TEST_CASE_ST(ut_setup, ut_teardown, 13451 test_AES_GCM_auth_encryption_test_case_256_3), 13452 TEST_CASE_ST(ut_setup, ut_teardown, 13453 test_AES_GCM_auth_encryption_test_case_256_4), 13454 TEST_CASE_ST(ut_setup, ut_teardown, 13455 test_AES_GCM_auth_encryption_test_case_256_5), 13456 TEST_CASE_ST(ut_setup, ut_teardown, 13457 test_AES_GCM_auth_encryption_test_case_256_6), 13458 TEST_CASE_ST(ut_setup, ut_teardown, 13459 test_AES_GCM_auth_encryption_test_case_256_7), 13460 13461 /** AES GCM Authenticated Decryption 256 bits key */ 13462 TEST_CASE_ST(ut_setup, ut_teardown, 13463 test_AES_GCM_auth_decryption_test_case_256_1), 13464 TEST_CASE_ST(ut_setup, ut_teardown, 13465 test_AES_GCM_auth_decryption_test_case_256_2), 13466 TEST_CASE_ST(ut_setup, ut_teardown, 13467 test_AES_GCM_auth_decryption_test_case_256_3), 13468 TEST_CASE_ST(ut_setup, ut_teardown, 13469 test_AES_GCM_auth_decryption_test_case_256_4), 13470 TEST_CASE_ST(ut_setup, ut_teardown, 13471 test_AES_GCM_auth_decryption_test_case_256_5), 13472 TEST_CASE_ST(ut_setup, ut_teardown, 13473 test_AES_GCM_auth_decryption_test_case_256_6), 13474 TEST_CASE_ST(ut_setup, ut_teardown, 13475 test_AES_GCM_auth_decryption_test_case_256_7), 13476 13477 /** AES GCM Authenticated Encryption big aad size */ 13478 TEST_CASE_ST(ut_setup, ut_teardown, 13479 test_AES_GCM_auth_encryption_test_case_aad_1), 13480 TEST_CASE_ST(ut_setup, ut_teardown, 13481 test_AES_GCM_auth_encryption_test_case_aad_2), 13482 13483 /** AES GCM Authenticated Decryption big aad size */ 13484 TEST_CASE_ST(ut_setup, ut_teardown, 13485 test_AES_GCM_auth_decryption_test_case_aad_1), 13486 TEST_CASE_ST(ut_setup, ut_teardown, 13487 test_AES_GCM_auth_decryption_test_case_aad_2), 13488 13489 /** Out of place tests */ 13490 TEST_CASE_ST(ut_setup, ut_teardown, 13491 test_AES_GCM_authenticated_encryption_oop_test_case_1), 13492 TEST_CASE_ST(ut_setup, ut_teardown, 13493 test_AES_GCM_authenticated_decryption_oop_test_case_1), 13494 13495 /** Session-less tests */ 13496 TEST_CASE_ST(ut_setup, ut_teardown, 13497 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 13498 TEST_CASE_ST(ut_setup, ut_teardown, 13499 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 13500 13501 /** AES GMAC Authentication */ 13502 TEST_CASE_ST(ut_setup, ut_teardown, 13503 test_AES_GMAC_authentication_test_case_1), 13504 TEST_CASE_ST(ut_setup, ut_teardown, 13505 test_AES_GMAC_authentication_verify_test_case_1), 13506 TEST_CASE_ST(ut_setup, ut_teardown, 13507 test_AES_GMAC_authentication_test_case_2), 13508 TEST_CASE_ST(ut_setup, ut_teardown, 13509 test_AES_GMAC_authentication_verify_test_case_2), 13510 TEST_CASE_ST(ut_setup, ut_teardown, 13511 test_AES_GMAC_authentication_test_case_3), 13512 TEST_CASE_ST(ut_setup, ut_teardown, 13513 test_AES_GMAC_authentication_verify_test_case_3), 13514 TEST_CASE_ST(ut_setup, ut_teardown, 13515 test_AES_GMAC_authentication_test_case_4), 13516 TEST_CASE_ST(ut_setup, ut_teardown, 13517 test_AES_GMAC_authentication_verify_test_case_4), 13518 TEST_CASE_ST(ut_setup, ut_teardown, 13519 test_AES_GMAC_authentication_SGL_40B), 13520 TEST_CASE_ST(ut_setup, ut_teardown, 13521 test_AES_GMAC_authentication_SGL_80B), 13522 TEST_CASE_ST(ut_setup, ut_teardown, 13523 test_AES_GMAC_authentication_SGL_2048B), 13524 TEST_CASE_ST(ut_setup, ut_teardown, 13525 test_AES_GMAC_authentication_SGL_2047B), 13526 13527 /** Chacha20-Poly1305 */ 13528 TEST_CASE_ST(ut_setup, ut_teardown, 13529 test_chacha20_poly1305_encrypt_test_case_rfc8439), 13530 TEST_CASE_ST(ut_setup, ut_teardown, 13531 test_chacha20_poly1305_decrypt_test_case_rfc8439), 13532 /** SNOW 3G encrypt only (UEA2) */ 13533 TEST_CASE_ST(ut_setup, ut_teardown, 13534 test_snow3g_encryption_test_case_1), 13535 TEST_CASE_ST(ut_setup, ut_teardown, 13536 test_snow3g_encryption_test_case_2), 13537 TEST_CASE_ST(ut_setup, ut_teardown, 13538 test_snow3g_encryption_test_case_3), 13539 TEST_CASE_ST(ut_setup, ut_teardown, 13540 test_snow3g_encryption_test_case_4), 13541 TEST_CASE_ST(ut_setup, ut_teardown, 13542 test_snow3g_encryption_test_case_5), 13543 13544 TEST_CASE_ST(ut_setup, ut_teardown, 13545 test_snow3g_encryption_test_case_1_oop), 13546 TEST_CASE_ST(ut_setup, ut_teardown, 13547 test_snow3g_encryption_test_case_1_oop_sgl), 13548 TEST_CASE_ST(ut_setup, ut_teardown, 13549 test_snow3g_encryption_test_case_1_offset_oop), 13550 TEST_CASE_ST(ut_setup, ut_teardown, 13551 test_snow3g_decryption_test_case_1_oop), 13552 13553 /** SNOW 3G generate auth, then encrypt (UEA2) */ 13554 TEST_CASE_ST(ut_setup, ut_teardown, 13555 test_snow3g_auth_cipher_test_case_1), 13556 TEST_CASE_ST(ut_setup, ut_teardown, 13557 test_snow3g_auth_cipher_test_case_2), 13558 TEST_CASE_ST(ut_setup, ut_teardown, 13559 test_snow3g_auth_cipher_test_case_2_oop), 13560 TEST_CASE_ST(ut_setup, ut_teardown, 13561 test_snow3g_auth_cipher_part_digest_enc), 13562 TEST_CASE_ST(ut_setup, ut_teardown, 13563 test_snow3g_auth_cipher_part_digest_enc_oop), 13564 TEST_CASE_ST(ut_setup, ut_teardown, 13565 test_snow3g_auth_cipher_test_case_3_sgl), 13566 TEST_CASE_ST(ut_setup, ut_teardown, 13567 test_snow3g_auth_cipher_test_case_3_oop_sgl), 13568 TEST_CASE_ST(ut_setup, ut_teardown, 13569 test_snow3g_auth_cipher_part_digest_enc_sgl), 13570 TEST_CASE_ST(ut_setup, ut_teardown, 13571 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 13572 13573 /** SNOW 3G decrypt (UEA2), then verify auth */ 13574 TEST_CASE_ST(ut_setup, ut_teardown, 13575 test_snow3g_auth_cipher_verify_test_case_1), 13576 TEST_CASE_ST(ut_setup, ut_teardown, 13577 test_snow3g_auth_cipher_verify_test_case_2), 13578 TEST_CASE_ST(ut_setup, ut_teardown, 13579 test_snow3g_auth_cipher_verify_test_case_2_oop), 13580 TEST_CASE_ST(ut_setup, ut_teardown, 13581 test_snow3g_auth_cipher_verify_part_digest_enc), 13582 TEST_CASE_ST(ut_setup, ut_teardown, 13583 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 13584 TEST_CASE_ST(ut_setup, ut_teardown, 13585 test_snow3g_auth_cipher_verify_test_case_3_sgl), 13586 TEST_CASE_ST(ut_setup, ut_teardown, 13587 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 13588 TEST_CASE_ST(ut_setup, ut_teardown, 13589 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 13590 TEST_CASE_ST(ut_setup, ut_teardown, 13591 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 13592 13593 /** SNOW 3G decrypt only (UEA2) */ 13594 TEST_CASE_ST(ut_setup, ut_teardown, 13595 test_snow3g_decryption_test_case_1), 13596 TEST_CASE_ST(ut_setup, ut_teardown, 13597 test_snow3g_decryption_test_case_2), 13598 TEST_CASE_ST(ut_setup, ut_teardown, 13599 test_snow3g_decryption_test_case_3), 13600 TEST_CASE_ST(ut_setup, ut_teardown, 13601 test_snow3g_decryption_test_case_4), 13602 TEST_CASE_ST(ut_setup, ut_teardown, 13603 test_snow3g_decryption_test_case_5), 13604 TEST_CASE_ST(ut_setup, ut_teardown, 13605 test_snow3g_decryption_with_digest_test_case_1), 13606 TEST_CASE_ST(ut_setup, ut_teardown, 13607 test_snow3g_hash_generate_test_case_1), 13608 TEST_CASE_ST(ut_setup, ut_teardown, 13609 test_snow3g_hash_generate_test_case_2), 13610 TEST_CASE_ST(ut_setup, ut_teardown, 13611 test_snow3g_hash_generate_test_case_3), 13612 /* Tests with buffers which length is not byte-aligned */ 13613 TEST_CASE_ST(ut_setup, ut_teardown, 13614 test_snow3g_hash_generate_test_case_4), 13615 TEST_CASE_ST(ut_setup, ut_teardown, 13616 test_snow3g_hash_generate_test_case_5), 13617 TEST_CASE_ST(ut_setup, ut_teardown, 13618 test_snow3g_hash_generate_test_case_6), 13619 TEST_CASE_ST(ut_setup, ut_teardown, 13620 test_snow3g_hash_verify_test_case_1), 13621 TEST_CASE_ST(ut_setup, ut_teardown, 13622 test_snow3g_hash_verify_test_case_2), 13623 TEST_CASE_ST(ut_setup, ut_teardown, 13624 test_snow3g_hash_verify_test_case_3), 13625 /* Tests with buffers which length is not byte-aligned */ 13626 TEST_CASE_ST(ut_setup, ut_teardown, 13627 test_snow3g_hash_verify_test_case_4), 13628 TEST_CASE_ST(ut_setup, ut_teardown, 13629 test_snow3g_hash_verify_test_case_5), 13630 TEST_CASE_ST(ut_setup, ut_teardown, 13631 test_snow3g_hash_verify_test_case_6), 13632 TEST_CASE_ST(ut_setup, ut_teardown, 13633 test_snow3g_cipher_auth_test_case_1), 13634 TEST_CASE_ST(ut_setup, ut_teardown, 13635 test_snow3g_auth_cipher_with_digest_test_case_1), 13636 13637 /** ZUC encrypt only (EEA3) */ 13638 TEST_CASE_ST(ut_setup, ut_teardown, 13639 test_zuc_encryption_test_case_1), 13640 TEST_CASE_ST(ut_setup, ut_teardown, 13641 test_zuc_encryption_test_case_2), 13642 TEST_CASE_ST(ut_setup, ut_teardown, 13643 test_zuc_encryption_test_case_3), 13644 TEST_CASE_ST(ut_setup, ut_teardown, 13645 test_zuc_encryption_test_case_4), 13646 TEST_CASE_ST(ut_setup, ut_teardown, 13647 test_zuc_encryption_test_case_5), 13648 TEST_CASE_ST(ut_setup, ut_teardown, 13649 test_zuc_encryption_test_case_6_sgl), 13650 13651 /** ZUC authenticate (EIA3) */ 13652 TEST_CASE_ST(ut_setup, ut_teardown, 13653 test_zuc_hash_generate_test_case_1), 13654 TEST_CASE_ST(ut_setup, ut_teardown, 13655 test_zuc_hash_generate_test_case_2), 13656 TEST_CASE_ST(ut_setup, ut_teardown, 13657 test_zuc_hash_generate_test_case_3), 13658 TEST_CASE_ST(ut_setup, ut_teardown, 13659 test_zuc_hash_generate_test_case_4), 13660 TEST_CASE_ST(ut_setup, ut_teardown, 13661 test_zuc_hash_generate_test_case_5), 13662 TEST_CASE_ST(ut_setup, ut_teardown, 13663 test_zuc_hash_generate_test_case_6), 13664 TEST_CASE_ST(ut_setup, ut_teardown, 13665 test_zuc_hash_generate_test_case_7), 13666 TEST_CASE_ST(ut_setup, ut_teardown, 13667 test_zuc_hash_generate_test_case_8), 13668 13669 /** ZUC alg-chain (EEA3/EIA3) */ 13670 TEST_CASE_ST(ut_setup, ut_teardown, 13671 test_zuc_cipher_auth_test_case_1), 13672 TEST_CASE_ST(ut_setup, ut_teardown, 13673 test_zuc_cipher_auth_test_case_2), 13674 13675 /** ZUC generate auth, then encrypt (EEA3) */ 13676 TEST_CASE_ST(ut_setup, ut_teardown, 13677 test_zuc_auth_cipher_test_case_1), 13678 TEST_CASE_ST(ut_setup, ut_teardown, 13679 test_zuc_auth_cipher_test_case_1_oop), 13680 TEST_CASE_ST(ut_setup, ut_teardown, 13681 test_zuc_auth_cipher_test_case_1_sgl), 13682 TEST_CASE_ST(ut_setup, ut_teardown, 13683 test_zuc_auth_cipher_test_case_1_oop_sgl), 13684 13685 /** ZUC decrypt (EEA3), then verify auth */ 13686 TEST_CASE_ST(ut_setup, ut_teardown, 13687 test_zuc_auth_cipher_verify_test_case_1), 13688 TEST_CASE_ST(ut_setup, ut_teardown, 13689 test_zuc_auth_cipher_verify_test_case_1_oop), 13690 TEST_CASE_ST(ut_setup, ut_teardown, 13691 test_zuc_auth_cipher_verify_test_case_1_sgl), 13692 TEST_CASE_ST(ut_setup, ut_teardown, 13693 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 13694 13695 /** HMAC_MD5 Authentication */ 13696 TEST_CASE_ST(ut_setup, ut_teardown, 13697 test_MD5_HMAC_generate_case_1), 13698 TEST_CASE_ST(ut_setup, ut_teardown, 13699 test_MD5_HMAC_verify_case_1), 13700 TEST_CASE_ST(ut_setup, ut_teardown, 13701 test_MD5_HMAC_generate_case_2), 13702 TEST_CASE_ST(ut_setup, ut_teardown, 13703 test_MD5_HMAC_verify_case_2), 13704 13705 /** KASUMI hash only (UIA1) */ 13706 TEST_CASE_ST(ut_setup, ut_teardown, 13707 test_kasumi_hash_generate_test_case_1), 13708 TEST_CASE_ST(ut_setup, ut_teardown, 13709 test_kasumi_hash_generate_test_case_2), 13710 TEST_CASE_ST(ut_setup, ut_teardown, 13711 test_kasumi_hash_generate_test_case_3), 13712 TEST_CASE_ST(ut_setup, ut_teardown, 13713 test_kasumi_hash_generate_test_case_4), 13714 TEST_CASE_ST(ut_setup, ut_teardown, 13715 test_kasumi_hash_generate_test_case_5), 13716 TEST_CASE_ST(ut_setup, ut_teardown, 13717 test_kasumi_hash_generate_test_case_6), 13718 13719 TEST_CASE_ST(ut_setup, ut_teardown, 13720 test_kasumi_hash_verify_test_case_1), 13721 TEST_CASE_ST(ut_setup, ut_teardown, 13722 test_kasumi_hash_verify_test_case_2), 13723 TEST_CASE_ST(ut_setup, ut_teardown, 13724 test_kasumi_hash_verify_test_case_3), 13725 TEST_CASE_ST(ut_setup, ut_teardown, 13726 test_kasumi_hash_verify_test_case_4), 13727 TEST_CASE_ST(ut_setup, ut_teardown, 13728 test_kasumi_hash_verify_test_case_5), 13729 13730 /** KASUMI encrypt only (UEA1) */ 13731 TEST_CASE_ST(ut_setup, ut_teardown, 13732 test_kasumi_encryption_test_case_1), 13733 TEST_CASE_ST(ut_setup, ut_teardown, 13734 test_kasumi_encryption_test_case_1_sgl), 13735 TEST_CASE_ST(ut_setup, ut_teardown, 13736 test_kasumi_encryption_test_case_1_oop), 13737 TEST_CASE_ST(ut_setup, ut_teardown, 13738 test_kasumi_encryption_test_case_1_oop_sgl), 13739 TEST_CASE_ST(ut_setup, ut_teardown, 13740 test_kasumi_encryption_test_case_2), 13741 TEST_CASE_ST(ut_setup, ut_teardown, 13742 test_kasumi_encryption_test_case_3), 13743 TEST_CASE_ST(ut_setup, ut_teardown, 13744 test_kasumi_encryption_test_case_4), 13745 TEST_CASE_ST(ut_setup, ut_teardown, 13746 test_kasumi_encryption_test_case_5), 13747 13748 /** KASUMI decrypt only (UEA1) */ 13749 TEST_CASE_ST(ut_setup, ut_teardown, 13750 test_kasumi_decryption_test_case_1), 13751 TEST_CASE_ST(ut_setup, ut_teardown, 13752 test_kasumi_decryption_test_case_2), 13753 TEST_CASE_ST(ut_setup, ut_teardown, 13754 test_kasumi_decryption_test_case_3), 13755 TEST_CASE_ST(ut_setup, ut_teardown, 13756 test_kasumi_decryption_test_case_4), 13757 TEST_CASE_ST(ut_setup, ut_teardown, 13758 test_kasumi_decryption_test_case_5), 13759 TEST_CASE_ST(ut_setup, ut_teardown, 13760 test_kasumi_decryption_test_case_1_oop), 13761 13762 TEST_CASE_ST(ut_setup, ut_teardown, 13763 test_kasumi_cipher_auth_test_case_1), 13764 13765 /** KASUMI generate auth, then encrypt (F8) */ 13766 TEST_CASE_ST(ut_setup, ut_teardown, 13767 test_kasumi_auth_cipher_test_case_1), 13768 TEST_CASE_ST(ut_setup, ut_teardown, 13769 test_kasumi_auth_cipher_test_case_2), 13770 TEST_CASE_ST(ut_setup, ut_teardown, 13771 test_kasumi_auth_cipher_test_case_2_oop), 13772 TEST_CASE_ST(ut_setup, ut_teardown, 13773 test_kasumi_auth_cipher_test_case_2_sgl), 13774 TEST_CASE_ST(ut_setup, ut_teardown, 13775 test_kasumi_auth_cipher_test_case_2_oop_sgl), 13776 13777 /** KASUMI decrypt (F8), then verify auth */ 13778 TEST_CASE_ST(ut_setup, ut_teardown, 13779 test_kasumi_auth_cipher_verify_test_case_1), 13780 TEST_CASE_ST(ut_setup, ut_teardown, 13781 test_kasumi_auth_cipher_verify_test_case_2), 13782 TEST_CASE_ST(ut_setup, ut_teardown, 13783 test_kasumi_auth_cipher_verify_test_case_2_oop), 13784 TEST_CASE_ST(ut_setup, ut_teardown, 13785 test_kasumi_auth_cipher_verify_test_case_2_sgl), 13786 TEST_CASE_ST(ut_setup, ut_teardown, 13787 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 13788 13789 /** ESN Testcase */ 13790 TEST_CASE_ST(ut_setup, ut_teardown, 13791 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 13792 TEST_CASE_ST(ut_setup, ut_teardown, 13793 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 13794 13795 /** Negative tests */ 13796 TEST_CASE_ST(ut_setup, ut_teardown, 13797 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13798 TEST_CASE_ST(ut_setup, ut_teardown, 13799 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13800 TEST_CASE_ST(ut_setup, ut_teardown, 13801 test_AES_GCM_auth_encryption_fail_iv_corrupt), 13802 TEST_CASE_ST(ut_setup, ut_teardown, 13803 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 13804 TEST_CASE_ST(ut_setup, ut_teardown, 13805 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 13806 TEST_CASE_ST(ut_setup, ut_teardown, 13807 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 13808 TEST_CASE_ST(ut_setup, ut_teardown, 13809 test_AES_GCM_auth_encryption_fail_aad_corrupt), 13810 TEST_CASE_ST(ut_setup, ut_teardown, 13811 test_AES_GCM_auth_encryption_fail_tag_corrupt), 13812 TEST_CASE_ST(ut_setup, ut_teardown, 13813 test_AES_GCM_auth_decryption_fail_iv_corrupt), 13814 TEST_CASE_ST(ut_setup, ut_teardown, 13815 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 13816 TEST_CASE_ST(ut_setup, ut_teardown, 13817 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 13818 TEST_CASE_ST(ut_setup, ut_teardown, 13819 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 13820 TEST_CASE_ST(ut_setup, ut_teardown, 13821 test_AES_GCM_auth_decryption_fail_aad_corrupt), 13822 TEST_CASE_ST(ut_setup, ut_teardown, 13823 test_AES_GCM_auth_decryption_fail_tag_corrupt), 13824 TEST_CASE_ST(ut_setup, ut_teardown, 13825 authentication_verify_AES128_GMAC_fail_data_corrupt), 13826 TEST_CASE_ST(ut_setup, ut_teardown, 13827 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13828 TEST_CASE_ST(ut_setup, ut_teardown, 13829 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13830 TEST_CASE_ST(ut_setup, ut_teardown, 13831 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13832 13833 /** Mixed CIPHER + HASH algorithms */ 13834 /** AUTH AES CMAC + CIPHER AES CTR */ 13835 TEST_CASE_ST(ut_setup, ut_teardown, 13836 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 13837 TEST_CASE_ST(ut_setup, ut_teardown, 13838 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13839 TEST_CASE_ST(ut_setup, ut_teardown, 13840 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13841 TEST_CASE_ST(ut_setup, ut_teardown, 13842 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13843 TEST_CASE_ST(ut_setup, ut_teardown, 13844 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 13845 TEST_CASE_ST(ut_setup, ut_teardown, 13846 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13847 TEST_CASE_ST(ut_setup, ut_teardown, 13848 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13849 TEST_CASE_ST(ut_setup, ut_teardown, 13850 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13851 13852 /** AUTH ZUC + CIPHER SNOW3G */ 13853 TEST_CASE_ST(ut_setup, ut_teardown, 13854 test_auth_zuc_cipher_snow_test_case_1), 13855 TEST_CASE_ST(ut_setup, ut_teardown, 13856 test_verify_auth_zuc_cipher_snow_test_case_1), 13857 /** AUTH AES CMAC + CIPHER SNOW3G */ 13858 TEST_CASE_ST(ut_setup, ut_teardown, 13859 test_auth_aes_cmac_cipher_snow_test_case_1), 13860 TEST_CASE_ST(ut_setup, ut_teardown, 13861 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 13862 /** AUTH ZUC + CIPHER AES CTR */ 13863 TEST_CASE_ST(ut_setup, ut_teardown, 13864 test_auth_zuc_cipher_aes_ctr_test_case_1), 13865 TEST_CASE_ST(ut_setup, ut_teardown, 13866 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 13867 /** AUTH SNOW3G + CIPHER AES CTR */ 13868 TEST_CASE_ST(ut_setup, ut_teardown, 13869 test_auth_snow_cipher_aes_ctr_test_case_1), 13870 TEST_CASE_ST(ut_setup, ut_teardown, 13871 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 13872 /** AUTH SNOW3G + CIPHER ZUC */ 13873 TEST_CASE_ST(ut_setup, ut_teardown, 13874 test_auth_snow_cipher_zuc_test_case_1), 13875 TEST_CASE_ST(ut_setup, ut_teardown, 13876 test_verify_auth_snow_cipher_zuc_test_case_1), 13877 /** AUTH AES CMAC + CIPHER ZUC */ 13878 TEST_CASE_ST(ut_setup, ut_teardown, 13879 test_auth_aes_cmac_cipher_zuc_test_case_1), 13880 TEST_CASE_ST(ut_setup, ut_teardown, 13881 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 13882 13883 /** AUTH NULL + CIPHER SNOW3G */ 13884 TEST_CASE_ST(ut_setup, ut_teardown, 13885 test_auth_null_cipher_snow_test_case_1), 13886 TEST_CASE_ST(ut_setup, ut_teardown, 13887 test_verify_auth_null_cipher_snow_test_case_1), 13888 /** AUTH NULL + CIPHER ZUC */ 13889 TEST_CASE_ST(ut_setup, ut_teardown, 13890 test_auth_null_cipher_zuc_test_case_1), 13891 TEST_CASE_ST(ut_setup, ut_teardown, 13892 test_verify_auth_null_cipher_zuc_test_case_1), 13893 /** AUTH SNOW3G + CIPHER NULL */ 13894 TEST_CASE_ST(ut_setup, ut_teardown, 13895 test_auth_snow_cipher_null_test_case_1), 13896 TEST_CASE_ST(ut_setup, ut_teardown, 13897 test_verify_auth_snow_cipher_null_test_case_1), 13898 /** AUTH ZUC + CIPHER NULL */ 13899 TEST_CASE_ST(ut_setup, ut_teardown, 13900 test_auth_zuc_cipher_null_test_case_1), 13901 TEST_CASE_ST(ut_setup, ut_teardown, 13902 test_verify_auth_zuc_cipher_null_test_case_1), 13903 /** AUTH NULL + CIPHER AES CTR */ 13904 TEST_CASE_ST(ut_setup, ut_teardown, 13905 test_auth_null_cipher_aes_ctr_test_case_1), 13906 TEST_CASE_ST(ut_setup, ut_teardown, 13907 test_verify_auth_null_cipher_aes_ctr_test_case_1), 13908 /** AUTH AES CMAC + CIPHER NULL */ 13909 TEST_CASE_ST(ut_setup, ut_teardown, 13910 test_auth_aes_cmac_cipher_null_test_case_1), 13911 TEST_CASE_ST(ut_setup, ut_teardown, 13912 test_verify_auth_aes_cmac_cipher_null_test_case_1), 13913 13914 #ifdef RTE_LIB_SECURITY 13915 TEST_CASE_ST(ut_setup_security, ut_teardown, 13916 test_PDCP_PROTO_all), 13917 TEST_CASE_ST(ut_setup_security, ut_teardown, 13918 test_DOCSIS_PROTO_all), 13919 #endif 13920 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 13921 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 13922 TEST_CASES_END() /**< NULL terminate unit test array */ 13923 } 13924 }; 13925 13926 static struct unit_test_suite cryptodev_virtio_testsuite = { 13927 .suite_name = "Crypto VIRTIO Unit Test Suite", 13928 .setup = testsuite_setup, 13929 .teardown = testsuite_teardown, 13930 .unit_test_cases = { 13931 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13932 13933 TEST_CASES_END() /**< NULL terminate unit test array */ 13934 } 13935 }; 13936 13937 static struct unit_test_suite cryptodev_caam_jr_testsuite = { 13938 .suite_name = "Crypto CAAM JR Unit Test Suite", 13939 .setup = testsuite_setup, 13940 .teardown = testsuite_teardown, 13941 .unit_test_cases = { 13942 TEST_CASE_ST(ut_setup, ut_teardown, 13943 test_device_configure_invalid_dev_id), 13944 TEST_CASE_ST(ut_setup, ut_teardown, 13945 test_multi_session), 13946 13947 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13948 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13949 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13950 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13951 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13952 13953 TEST_CASES_END() /**< NULL terminate unit test array */ 13954 } 13955 }; 13956 13957 static struct unit_test_suite cryptodev_mrvl_testsuite = { 13958 .suite_name = "Crypto Device Marvell Component Test Suite", 13959 .setup = testsuite_setup, 13960 .teardown = testsuite_teardown, 13961 .unit_test_cases = { 13962 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13963 TEST_CASE_ST(ut_setup, ut_teardown, 13964 test_multi_session_random_usage), 13965 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13966 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13967 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13968 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13969 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13970 13971 /** Negative tests */ 13972 TEST_CASE_ST(ut_setup, ut_teardown, 13973 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13974 TEST_CASE_ST(ut_setup, ut_teardown, 13975 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13976 TEST_CASE_ST(ut_setup, ut_teardown, 13977 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13978 TEST_CASE_ST(ut_setup, ut_teardown, 13979 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13980 13981 TEST_CASES_END() /**< NULL terminate unit test array */ 13982 } 13983 }; 13984 13985 static struct unit_test_suite cryptodev_ccp_testsuite = { 13986 .suite_name = "Crypto Device CCP Unit Test Suite", 13987 .setup = testsuite_setup, 13988 .teardown = testsuite_teardown, 13989 .unit_test_cases = { 13990 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13991 TEST_CASE_ST(ut_setup, ut_teardown, 13992 test_multi_session_random_usage), 13993 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13994 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13995 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13996 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13997 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13998 13999 /** Negative tests */ 14000 TEST_CASE_ST(ut_setup, ut_teardown, 14001 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14002 TEST_CASE_ST(ut_setup, ut_teardown, 14003 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14004 TEST_CASE_ST(ut_setup, ut_teardown, 14005 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14006 TEST_CASE_ST(ut_setup, ut_teardown, 14007 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14008 14009 TEST_CASES_END() /**< NULL terminate unit test array */ 14010 } 14011 }; 14012 14013 static int 14014 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 14015 { 14016 gbl_driver_id = rte_cryptodev_driver_id_get( 14017 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14018 14019 if (gbl_driver_id == -1) { 14020 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14021 return TEST_SKIPPED; 14022 } 14023 14024 return unit_test_suite_runner(&cryptodev_testsuite); 14025 } 14026 14027 static int 14028 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/) 14029 { 14030 gbl_driver_id = rte_cryptodev_driver_id_get( 14031 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 14032 14033 if (gbl_driver_id == -1) { 14034 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n"); 14035 return TEST_FAILED; 14036 } 14037 14038 return unit_test_suite_runner(&cryptodev_virtio_testsuite); 14039 } 14040 14041 static int 14042 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 14043 { 14044 gbl_driver_id = rte_cryptodev_driver_id_get( 14045 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14046 14047 if (gbl_driver_id == -1) { 14048 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14049 return TEST_SKIPPED; 14050 } 14051 14052 return unit_test_suite_runner(&cryptodev_testsuite); 14053 } 14054 14055 static int 14056 test_cryptodev_cpu_aesni_mb(void) 14057 { 14058 int32_t rc; 14059 enum rte_security_session_action_type at; 14060 14061 gbl_driver_id = rte_cryptodev_driver_id_get( 14062 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14063 14064 if (gbl_driver_id == -1) { 14065 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14066 return TEST_SKIPPED; 14067 } 14068 14069 at = gbl_action_type; 14070 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14071 rc = unit_test_suite_runner(&cryptodev_testsuite); 14072 gbl_action_type = at; 14073 return rc; 14074 } 14075 14076 static int 14077 test_cryptodev_openssl(void) 14078 { 14079 gbl_driver_id = rte_cryptodev_driver_id_get( 14080 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 14081 14082 if (gbl_driver_id == -1) { 14083 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n"); 14084 return TEST_SKIPPED; 14085 } 14086 14087 return unit_test_suite_runner(&cryptodev_testsuite); 14088 } 14089 14090 static int 14091 test_cryptodev_aesni_gcm(void) 14092 { 14093 gbl_driver_id = rte_cryptodev_driver_id_get( 14094 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 14095 14096 if (gbl_driver_id == -1) { 14097 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 14098 return TEST_SKIPPED; 14099 } 14100 14101 return unit_test_suite_runner(&cryptodev_testsuite); 14102 } 14103 14104 static int 14105 test_cryptodev_cpu_aesni_gcm(void) 14106 { 14107 int32_t rc; 14108 enum rte_security_session_action_type at; 14109 14110 gbl_driver_id = rte_cryptodev_driver_id_get( 14111 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 14112 14113 if (gbl_driver_id == -1) { 14114 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 14115 return TEST_SKIPPED; 14116 } 14117 14118 at = gbl_action_type; 14119 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14120 rc = unit_test_suite_runner(&cryptodev_testsuite); 14121 gbl_action_type = at; 14122 return rc; 14123 } 14124 14125 static int 14126 test_cryptodev_null(void) 14127 { 14128 gbl_driver_id = rte_cryptodev_driver_id_get( 14129 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 14130 14131 if (gbl_driver_id == -1) { 14132 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n"); 14133 return TEST_SKIPPED; 14134 } 14135 14136 return unit_test_suite_runner(&cryptodev_testsuite); 14137 } 14138 14139 static int 14140 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 14141 { 14142 gbl_driver_id = rte_cryptodev_driver_id_get( 14143 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 14144 14145 if (gbl_driver_id == -1) { 14146 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n"); 14147 return TEST_SKIPPED; 14148 } 14149 14150 return unit_test_suite_runner(&cryptodev_testsuite); 14151 } 14152 14153 static int 14154 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 14155 { 14156 gbl_driver_id = rte_cryptodev_driver_id_get( 14157 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 14158 14159 if (gbl_driver_id == -1) { 14160 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14161 return TEST_SKIPPED; 14162 } 14163 14164 return unit_test_suite_runner(&cryptodev_testsuite); 14165 } 14166 14167 static int 14168 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 14169 { 14170 gbl_driver_id = rte_cryptodev_driver_id_get( 14171 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 14172 14173 if (gbl_driver_id == -1) { 14174 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14175 return TEST_SKIPPED; 14176 } 14177 14178 return unit_test_suite_runner(&cryptodev_testsuite); 14179 } 14180 14181 static int 14182 test_cryptodev_armv8(void) 14183 { 14184 gbl_driver_id = rte_cryptodev_driver_id_get( 14185 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 14186 14187 if (gbl_driver_id == -1) { 14188 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n"); 14189 return TEST_SKIPPED; 14190 } 14191 14192 return unit_test_suite_runner(&cryptodev_testsuite); 14193 } 14194 14195 static int 14196 test_cryptodev_mrvl(void) 14197 { 14198 gbl_driver_id = rte_cryptodev_driver_id_get( 14199 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 14200 14201 if (gbl_driver_id == -1) { 14202 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n"); 14203 return TEST_SKIPPED; 14204 } 14205 14206 return unit_test_suite_runner(&cryptodev_mrvl_testsuite); 14207 } 14208 14209 #ifdef RTE_CRYPTO_SCHEDULER 14210 14211 static int 14212 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 14213 { 14214 gbl_driver_id = rte_cryptodev_driver_id_get( 14215 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14216 14217 if (gbl_driver_id == -1) { 14218 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 14219 return TEST_SKIPPED; 14220 } 14221 14222 if (rte_cryptodev_driver_id_get( 14223 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 14224 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14225 return TEST_SKIPPED; 14226 } 14227 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 14228 } 14229 14230 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 14231 14232 #endif 14233 14234 static int 14235 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14236 { 14237 gbl_driver_id = rte_cryptodev_driver_id_get( 14238 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 14239 14240 if (gbl_driver_id == -1) { 14241 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n"); 14242 return TEST_SKIPPED; 14243 } 14244 14245 return unit_test_suite_runner(&cryptodev_testsuite); 14246 } 14247 14248 static int 14249 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14250 { 14251 gbl_driver_id = rte_cryptodev_driver_id_get( 14252 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 14253 14254 if (gbl_driver_id == -1) { 14255 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n"); 14256 return TEST_SKIPPED; 14257 } 14258 14259 return unit_test_suite_runner(&cryptodev_testsuite); 14260 } 14261 14262 static int 14263 test_cryptodev_ccp(void) 14264 { 14265 gbl_driver_id = rte_cryptodev_driver_id_get( 14266 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 14267 14268 if (gbl_driver_id == -1) { 14269 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n"); 14270 return TEST_FAILED; 14271 } 14272 14273 return unit_test_suite_runner(&cryptodev_ccp_testsuite); 14274 } 14275 14276 static int 14277 test_cryptodev_octeontx(void) 14278 { 14279 gbl_driver_id = rte_cryptodev_driver_id_get( 14280 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 14281 if (gbl_driver_id == -1) { 14282 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n"); 14283 return TEST_FAILED; 14284 } 14285 return unit_test_suite_runner(&cryptodev_testsuite); 14286 } 14287 14288 static int 14289 test_cryptodev_octeontx2(void) 14290 { 14291 gbl_driver_id = rte_cryptodev_driver_id_get( 14292 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 14293 if (gbl_driver_id == -1) { 14294 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n"); 14295 return TEST_FAILED; 14296 } 14297 return unit_test_suite_runner(&cryptodev_testsuite); 14298 } 14299 14300 static int 14301 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/) 14302 { 14303 gbl_driver_id = rte_cryptodev_driver_id_get( 14304 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 14305 14306 if (gbl_driver_id == -1) { 14307 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n"); 14308 return TEST_FAILED; 14309 } 14310 14311 return unit_test_suite_runner(&cryptodev_caam_jr_testsuite); 14312 } 14313 14314 static int 14315 test_cryptodev_nitrox(void) 14316 { 14317 gbl_driver_id = rte_cryptodev_driver_id_get( 14318 RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 14319 14320 if (gbl_driver_id == -1) { 14321 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n"); 14322 return TEST_FAILED; 14323 } 14324 14325 return unit_test_suite_runner(&cryptodev_testsuite); 14326 } 14327 14328 static int 14329 test_cryptodev_bcmfs(void) 14330 { 14331 gbl_driver_id = rte_cryptodev_driver_id_get( 14332 RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 14333 14334 if (gbl_driver_id == -1) { 14335 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n"); 14336 return TEST_FAILED; 14337 } 14338 14339 return unit_test_suite_runner(&cryptodev_testsuite); 14340 } 14341 14342 static int 14343 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/) 14344 { 14345 int ret; 14346 14347 gbl_driver_id = rte_cryptodev_driver_id_get( 14348 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14349 14350 if (gbl_driver_id == -1) { 14351 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14352 return TEST_SKIPPED; 14353 } 14354 14355 global_api_test_type = CRYPTODEV_RAW_API_TEST; 14356 ret = unit_test_suite_runner(&cryptodev_testsuite); 14357 global_api_test_type = CRYPTODEV_API_TEST; 14358 14359 return ret; 14360 } 14361 14362 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 14363 test_cryptodev_qat_raw_api); 14364 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 14365 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 14366 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 14367 test_cryptodev_cpu_aesni_mb); 14368 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 14369 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 14370 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 14371 test_cryptodev_cpu_aesni_gcm); 14372 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 14373 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 14374 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 14375 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 14376 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 14377 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 14378 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 14379 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 14380 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 14381 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 14382 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 14383 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 14384 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 14385 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 14386 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 14387