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_ip.h> 20 #include <rte_string_fns.h> 21 #include <rte_tcp.h> 22 #include <rte_udp.h> 23 24 #ifdef RTE_CRYPTO_SCHEDULER 25 #include <rte_cryptodev_scheduler.h> 26 #include <rte_cryptodev_scheduler_operations.h> 27 #endif 28 29 #include <rte_lcore.h> 30 31 #include "test.h" 32 #include "test_cryptodev.h" 33 34 #include "test_cryptodev_blockcipher.h" 35 #include "test_cryptodev_aes_test_vectors.h" 36 #include "test_cryptodev_des_test_vectors.h" 37 #include "test_cryptodev_hash_test_vectors.h" 38 #include "test_cryptodev_kasumi_test_vectors.h" 39 #include "test_cryptodev_kasumi_hash_test_vectors.h" 40 #include "test_cryptodev_snow3g_test_vectors.h" 41 #include "test_cryptodev_snow3g_hash_test_vectors.h" 42 #include "test_cryptodev_zuc_test_vectors.h" 43 #include "test_cryptodev_aead_test_vectors.h" 44 #include "test_cryptodev_hmac_test_vectors.h" 45 #include "test_cryptodev_mixed_test_vectors.h" 46 #ifdef RTE_LIB_SECURITY 47 #include "test_cryptodev_security_ipsec.h" 48 #include "test_cryptodev_security_ipsec_test_vectors.h" 49 #include "test_cryptodev_security_pdcp_test_vectors.h" 50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 51 #include "test_cryptodev_security_pdcp_test_func.h" 52 #include "test_cryptodev_security_docsis_test_vectors.h" 53 54 #define SDAP_DISABLED 0 55 #define SDAP_ENABLED 1 56 #endif 57 58 #define VDEV_ARGS_SIZE 100 59 #define MAX_NB_SESSIONS 4 60 61 #define MAX_DRV_SERVICE_CTX_SIZE 256 62 63 #define MAX_RAW_DEQUEUE_COUNT 65535 64 65 #define IN_PLACE 0 66 #define OUT_OF_PLACE 1 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_unittest_params { 76 struct rte_crypto_sym_xform cipher_xform; 77 struct rte_crypto_sym_xform auth_xform; 78 struct rte_crypto_sym_xform aead_xform; 79 #ifdef RTE_LIB_SECURITY 80 struct rte_security_docsis_xform docsis_xform; 81 #endif 82 83 union { 84 struct rte_cryptodev_sym_session *sess; 85 #ifdef RTE_LIB_SECURITY 86 struct rte_security_session *sec_session; 87 #endif 88 }; 89 #ifdef RTE_LIB_SECURITY 90 enum rte_security_session_action_type type; 91 #endif 92 struct rte_crypto_op *op; 93 94 struct rte_mbuf *obuf, *ibuf; 95 96 uint8_t *digest; 97 }; 98 99 #define ALIGN_POW2_ROUNDUP(num, align) \ 100 (((num) + (align) - 1) & ~((align) - 1)) 101 102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 103 for (j = 0; j < num_child_ts; index++, j++) \ 104 parent_ts.unit_test_suites[index] = child_ts[j] 105 106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 107 for (j = 0; j < num_blk_types; index++, j++) \ 108 parent_ts.unit_test_suites[index] = \ 109 build_blockcipher_test_suite(blk_types[j]) 110 111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 112 for (j = index; j < index + num_blk_types; j++) \ 113 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 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 int 132 security_proto_supported(enum rte_security_session_action_type action, 133 enum rte_security_session_protocol proto); 134 135 static int 136 dev_configure_and_start(uint64_t ff_disable); 137 138 static struct rte_mbuf * 139 setup_test_string(struct rte_mempool *mpool, 140 const char *string, size_t len, uint8_t blocksize) 141 { 142 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 143 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 144 145 if (m) { 146 char *dst; 147 148 memset(m->buf_addr, 0, m->buf_len); 149 dst = rte_pktmbuf_append(m, t_len); 150 if (!dst) { 151 rte_pktmbuf_free(m); 152 return NULL; 153 } 154 if (string != NULL) 155 rte_memcpy(dst, string, t_len); 156 else 157 memset(dst, 0, t_len); 158 } 159 160 return m; 161 } 162 163 /* Get number of bytes in X bits (rounding up) */ 164 static uint32_t 165 ceil_byte_length(uint32_t num_bits) 166 { 167 if (num_bits % 8) 168 return ((num_bits >> 3) + 1); 169 else 170 return (num_bits >> 3); 171 } 172 173 static void 174 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 175 uint8_t is_op_success) 176 { 177 struct rte_crypto_op *op = user_data; 178 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 179 RTE_CRYPTO_OP_STATUS_ERROR; 180 } 181 182 static struct crypto_testsuite_params testsuite_params = { NULL }; 183 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 184 static struct crypto_unittest_params unittest_params; 185 186 void 187 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 188 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 189 uint8_t len_in_bits, uint8_t cipher_iv_len) 190 { 191 struct rte_crypto_sym_op *sop = op->sym; 192 struct rte_crypto_op *ret_op = NULL; 193 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 194 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 195 union rte_crypto_sym_ofs ofs; 196 struct rte_crypto_sym_vec vec; 197 struct rte_crypto_sgl sgl, dest_sgl; 198 uint32_t max_len; 199 union rte_cryptodev_session_ctx sess; 200 uint64_t auth_end_iova; 201 uint32_t count = 0; 202 struct rte_crypto_raw_dp_ctx *ctx; 203 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 204 auth_len = 0; 205 int32_t n; 206 uint32_t n_success; 207 int ctx_service_size; 208 int32_t status = 0; 209 int enqueue_status, dequeue_status; 210 struct crypto_unittest_params *ut_params = &unittest_params; 211 int is_sgl = sop->m_src->nb_segs > 1; 212 213 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 214 if (ctx_service_size < 0) { 215 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 216 return; 217 } 218 219 ctx = malloc(ctx_service_size); 220 if (!ctx) { 221 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 222 return; 223 } 224 225 /* Both are enums, setting crypto_sess will suit any session type */ 226 sess.crypto_sess = op->sym->session; 227 228 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 229 op->sess_type, sess, 0) < 0) { 230 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 231 goto exit; 232 } 233 234 cipher_iv.iova = 0; 235 cipher_iv.va = NULL; 236 aad_auth_iv.iova = 0; 237 aad_auth_iv.va = NULL; 238 digest.iova = 0; 239 digest.va = NULL; 240 sgl.vec = data_vec; 241 vec.num = 1; 242 vec.src_sgl = &sgl; 243 vec.iv = &cipher_iv; 244 vec.digest = &digest; 245 vec.aad = &aad_auth_iv; 246 vec.status = &status; 247 248 ofs.raw = 0; 249 250 if (is_cipher && is_auth) { 251 cipher_offset = sop->cipher.data.offset; 252 cipher_len = sop->cipher.data.length; 253 auth_offset = sop->auth.data.offset; 254 auth_len = sop->auth.data.length; 255 max_len = RTE_MAX(cipher_offset + cipher_len, 256 auth_offset + auth_len); 257 if (len_in_bits) { 258 max_len = max_len >> 3; 259 cipher_offset = cipher_offset >> 3; 260 auth_offset = auth_offset >> 3; 261 cipher_len = cipher_len >> 3; 262 auth_len = auth_len >> 3; 263 } 264 ofs.ofs.cipher.head = cipher_offset; 265 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 266 ofs.ofs.auth.head = auth_offset; 267 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 268 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 269 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 270 aad_auth_iv.va = rte_crypto_op_ctod_offset( 271 op, void *, IV_OFFSET + cipher_iv_len); 272 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 273 cipher_iv_len); 274 digest.va = (void *)sop->auth.digest.data; 275 digest.iova = sop->auth.digest.phys_addr; 276 277 if (is_sgl) { 278 uint32_t remaining_off = auth_offset + auth_len; 279 struct rte_mbuf *sgl_buf = sop->m_src; 280 281 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 282 && sgl_buf->next != NULL) { 283 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 284 sgl_buf = sgl_buf->next; 285 } 286 287 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 288 sgl_buf, remaining_off); 289 } else { 290 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 291 auth_offset + auth_len; 292 } 293 /* Then check if digest-encrypted conditions are met */ 294 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 295 (digest.iova == auth_end_iova) && is_sgl) 296 max_len = RTE_MAX(max_len, auth_offset + auth_len + 297 ut_params->auth_xform.auth.digest_length); 298 299 } else if (is_cipher) { 300 cipher_offset = sop->cipher.data.offset; 301 cipher_len = sop->cipher.data.length; 302 max_len = cipher_len + cipher_offset; 303 if (len_in_bits) { 304 max_len = max_len >> 3; 305 cipher_offset = cipher_offset >> 3; 306 cipher_len = cipher_len >> 3; 307 } 308 ofs.ofs.cipher.head = cipher_offset; 309 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 310 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 311 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 312 313 } else if (is_auth) { 314 auth_offset = sop->auth.data.offset; 315 auth_len = sop->auth.data.length; 316 max_len = auth_len + auth_offset; 317 if (len_in_bits) { 318 max_len = max_len >> 3; 319 auth_offset = auth_offset >> 3; 320 auth_len = auth_len >> 3; 321 } 322 ofs.ofs.auth.head = auth_offset; 323 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 324 aad_auth_iv.va = rte_crypto_op_ctod_offset( 325 op, void *, IV_OFFSET + cipher_iv_len); 326 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 327 cipher_iv_len); 328 digest.va = (void *)sop->auth.digest.data; 329 digest.iova = sop->auth.digest.phys_addr; 330 331 } else { /* aead */ 332 cipher_offset = sop->aead.data.offset; 333 cipher_len = sop->aead.data.length; 334 max_len = cipher_len + cipher_offset; 335 if (len_in_bits) { 336 max_len = max_len >> 3; 337 cipher_offset = cipher_offset >> 3; 338 cipher_len = cipher_len >> 3; 339 } 340 ofs.ofs.cipher.head = cipher_offset; 341 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 342 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 343 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 344 aad_auth_iv.va = (void *)sop->aead.aad.data; 345 aad_auth_iv.iova = sop->aead.aad.phys_addr; 346 digest.va = (void *)sop->aead.digest.data; 347 digest.iova = sop->aead.digest.phys_addr; 348 } 349 350 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 351 data_vec, RTE_DIM(data_vec)); 352 if (n < 0 || n > sop->m_src->nb_segs) { 353 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 354 goto exit; 355 } 356 357 sgl.num = n; 358 /* Out of place */ 359 if (sop->m_dst != NULL) { 360 dest_sgl.vec = dest_data_vec; 361 vec.dest_sgl = &dest_sgl; 362 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 363 dest_data_vec, RTE_DIM(dest_data_vec)); 364 if (n < 0 || n > sop->m_dst->nb_segs) { 365 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 366 goto exit; 367 } 368 dest_sgl.num = n; 369 } else 370 vec.dest_sgl = NULL; 371 372 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 373 &enqueue_status) < 1) { 374 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 375 goto exit; 376 } 377 378 if (enqueue_status == 0) { 379 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 380 if (status < 0) { 381 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 382 goto exit; 383 } 384 } else if (enqueue_status < 0) { 385 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 386 goto exit; 387 } 388 389 n = n_success = 0; 390 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 391 n = rte_cryptodev_raw_dequeue_burst(ctx, 392 NULL, 1, post_process_raw_dp_op, 393 (void **)&ret_op, 0, &n_success, 394 &dequeue_status); 395 if (dequeue_status < 0) { 396 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 397 goto exit; 398 } 399 if (n == 0) 400 rte_pause(); 401 } 402 403 if (n == 1 && dequeue_status == 0) { 404 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 405 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 406 goto exit; 407 } 408 } 409 410 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 411 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 412 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 413 RTE_CRYPTO_OP_STATUS_SUCCESS; 414 415 exit: 416 free(ctx); 417 } 418 419 static void 420 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 421 { 422 int32_t n, st; 423 struct rte_crypto_sym_op *sop; 424 union rte_crypto_sym_ofs ofs; 425 struct rte_crypto_sgl sgl; 426 struct rte_crypto_sym_vec symvec; 427 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 428 struct rte_crypto_vec vec[UINT8_MAX]; 429 430 sop = op->sym; 431 432 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 433 sop->aead.data.length, vec, RTE_DIM(vec)); 434 435 if (n < 0 || n != sop->m_src->nb_segs) { 436 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 437 return; 438 } 439 440 sgl.vec = vec; 441 sgl.num = n; 442 symvec.src_sgl = &sgl; 443 symvec.iv = &iv_ptr; 444 symvec.digest = &digest_ptr; 445 symvec.aad = &aad_ptr; 446 symvec.status = &st; 447 symvec.num = 1; 448 449 /* for CPU crypto the IOVA address is not required */ 450 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 451 digest_ptr.va = (void *)sop->aead.digest.data; 452 aad_ptr.va = (void *)sop->aead.aad.data; 453 454 ofs.raw = 0; 455 456 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 457 &symvec); 458 459 if (n != 1) 460 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 461 else 462 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 463 } 464 465 static void 466 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 467 { 468 int32_t n, st; 469 struct rte_crypto_sym_op *sop; 470 union rte_crypto_sym_ofs ofs; 471 struct rte_crypto_sgl sgl; 472 struct rte_crypto_sym_vec symvec; 473 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 474 struct rte_crypto_vec vec[UINT8_MAX]; 475 476 sop = op->sym; 477 478 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 479 sop->auth.data.length, vec, RTE_DIM(vec)); 480 481 if (n < 0 || n != sop->m_src->nb_segs) { 482 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 483 return; 484 } 485 486 sgl.vec = vec; 487 sgl.num = n; 488 symvec.src_sgl = &sgl; 489 symvec.iv = &iv_ptr; 490 symvec.digest = &digest_ptr; 491 symvec.status = &st; 492 symvec.num = 1; 493 494 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 495 digest_ptr.va = (void *)sop->auth.digest.data; 496 497 ofs.raw = 0; 498 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 499 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 500 (sop->cipher.data.offset + sop->cipher.data.length); 501 502 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 503 &symvec); 504 505 if (n != 1) 506 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 507 else 508 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 509 } 510 511 static struct rte_crypto_op * 512 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 513 { 514 515 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 516 517 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 518 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 519 return NULL; 520 } 521 522 op = NULL; 523 524 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 525 rte_pause(); 526 527 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 528 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 529 return NULL; 530 } 531 532 return op; 533 } 534 535 static int 536 testsuite_setup(void) 537 { 538 struct crypto_testsuite_params *ts_params = &testsuite_params; 539 struct rte_cryptodev_info info; 540 uint32_t i = 0, nb_devs, dev_id; 541 uint16_t qp_id; 542 543 memset(ts_params, 0, sizeof(*ts_params)); 544 545 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 546 if (ts_params->mbuf_pool == NULL) { 547 /* Not already created so create */ 548 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 549 "CRYPTO_MBUFPOOL", 550 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 551 rte_socket_id()); 552 if (ts_params->mbuf_pool == NULL) { 553 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 554 return TEST_FAILED; 555 } 556 } 557 558 ts_params->large_mbuf_pool = rte_mempool_lookup( 559 "CRYPTO_LARGE_MBUFPOOL"); 560 if (ts_params->large_mbuf_pool == NULL) { 561 /* Not already created so create */ 562 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 563 "CRYPTO_LARGE_MBUFPOOL", 564 1, 0, 0, UINT16_MAX, 565 rte_socket_id()); 566 if (ts_params->large_mbuf_pool == NULL) { 567 RTE_LOG(ERR, USER1, 568 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 569 return TEST_FAILED; 570 } 571 } 572 573 ts_params->op_mpool = rte_crypto_op_pool_create( 574 "MBUF_CRYPTO_SYM_OP_POOL", 575 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 576 NUM_MBUFS, MBUF_CACHE_SIZE, 577 DEFAULT_NUM_XFORMS * 578 sizeof(struct rte_crypto_sym_xform) + 579 MAXIMUM_IV_LENGTH, 580 rte_socket_id()); 581 if (ts_params->op_mpool == NULL) { 582 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 583 return TEST_FAILED; 584 } 585 586 nb_devs = rte_cryptodev_count(); 587 if (nb_devs < 1) { 588 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 589 return TEST_SKIPPED; 590 } 591 592 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 593 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 594 rte_cryptodev_driver_name_get(gbl_driver_id)); 595 return TEST_SKIPPED; 596 } 597 598 /* Create list of valid crypto devs */ 599 for (i = 0; i < nb_devs; i++) { 600 rte_cryptodev_info_get(i, &info); 601 if (info.driver_id == gbl_driver_id) 602 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 603 } 604 605 if (ts_params->valid_dev_count < 1) 606 return TEST_FAILED; 607 608 /* Set up all the qps on the first of the valid devices found */ 609 610 dev_id = ts_params->valid_devs[0]; 611 612 rte_cryptodev_info_get(dev_id, &info); 613 614 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 615 ts_params->conf.socket_id = SOCKET_ID_ANY; 616 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 617 618 unsigned int session_size = 619 rte_cryptodev_sym_get_private_session_size(dev_id); 620 621 #ifdef RTE_LIB_SECURITY 622 unsigned int security_session_size = rte_security_session_get_size( 623 rte_cryptodev_get_sec_ctx(dev_id)); 624 625 if (session_size < security_session_size) 626 session_size = security_session_size; 627 #endif 628 /* 629 * Create mempool with maximum number of sessions. 630 */ 631 if (info.sym.max_nb_sessions != 0 && 632 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 633 RTE_LOG(ERR, USER1, "Device does not support " 634 "at least %u sessions\n", 635 MAX_NB_SESSIONS); 636 return TEST_FAILED; 637 } 638 639 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 640 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 641 SOCKET_ID_ANY); 642 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 643 "session mempool allocation failed"); 644 645 ts_params->session_priv_mpool = rte_mempool_create( 646 "test_sess_mp_priv", 647 MAX_NB_SESSIONS, 648 session_size, 649 0, 0, NULL, NULL, NULL, 650 NULL, SOCKET_ID_ANY, 651 0); 652 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 653 "session mempool allocation failed"); 654 655 656 657 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 658 &ts_params->conf), 659 "Failed to configure cryptodev %u with %u qps", 660 dev_id, ts_params->conf.nb_queue_pairs); 661 662 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 663 ts_params->qp_conf.mp_session = ts_params->session_mpool; 664 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 665 666 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 667 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 668 dev_id, qp_id, &ts_params->qp_conf, 669 rte_cryptodev_socket_id(dev_id)), 670 "Failed to setup queue pair %u on cryptodev %u", 671 qp_id, dev_id); 672 } 673 674 return TEST_SUCCESS; 675 } 676 677 static void 678 testsuite_teardown(void) 679 { 680 struct crypto_testsuite_params *ts_params = &testsuite_params; 681 int res; 682 683 if (ts_params->mbuf_pool != NULL) { 684 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 685 rte_mempool_avail_count(ts_params->mbuf_pool)); 686 } 687 688 if (ts_params->op_mpool != NULL) { 689 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 690 rte_mempool_avail_count(ts_params->op_mpool)); 691 } 692 693 /* Free session mempools */ 694 if (ts_params->session_priv_mpool != NULL) { 695 rte_mempool_free(ts_params->session_priv_mpool); 696 ts_params->session_priv_mpool = NULL; 697 } 698 699 if (ts_params->session_mpool != NULL) { 700 rte_mempool_free(ts_params->session_mpool); 701 ts_params->session_mpool = NULL; 702 } 703 704 res = rte_cryptodev_close(ts_params->valid_devs[0]); 705 if (res) 706 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 707 } 708 709 static int 710 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 711 const int *algs, uint16_t num_algs) 712 { 713 uint8_t dev_id = testsuite_params.valid_devs[0]; 714 bool some_alg_supported = FALSE; 715 uint16_t i; 716 717 for (i = 0; i < num_algs && !some_alg_supported; i++) { 718 struct rte_cryptodev_sym_capability_idx alg = { 719 type, {algs[i]} 720 }; 721 if (rte_cryptodev_sym_capability_get(dev_id, 722 &alg) != NULL) 723 some_alg_supported = TRUE; 724 } 725 if (!some_alg_supported) 726 return TEST_SKIPPED; 727 728 return 0; 729 } 730 731 int 732 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 733 uint16_t num_ciphers) 734 { 735 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 736 (const int *) ciphers, num_ciphers); 737 } 738 739 int 740 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 741 uint16_t num_auths) 742 { 743 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 744 (const int *) auths, num_auths); 745 } 746 747 int 748 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 749 uint16_t num_aeads) 750 { 751 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 752 (const int *) aeads, num_aeads); 753 } 754 755 static int 756 null_testsuite_setup(void) 757 { 758 struct crypto_testsuite_params *ts_params = &testsuite_params; 759 uint8_t dev_id = ts_params->valid_devs[0]; 760 struct rte_cryptodev_info dev_info; 761 const enum rte_crypto_cipher_algorithm ciphers[] = { 762 RTE_CRYPTO_CIPHER_NULL 763 }; 764 const enum rte_crypto_auth_algorithm auths[] = { 765 RTE_CRYPTO_AUTH_NULL 766 }; 767 768 rte_cryptodev_info_get(dev_id, &dev_info); 769 770 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 771 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 772 "testsuite not met\n"); 773 return TEST_SKIPPED; 774 } 775 776 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 777 && check_auth_capabilities_supported(auths, 778 RTE_DIM(auths)) != 0) { 779 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 780 "testsuite not met\n"); 781 return TEST_SKIPPED; 782 } 783 784 return 0; 785 } 786 787 static int 788 crypto_gen_testsuite_setup(void) 789 { 790 struct crypto_testsuite_params *ts_params = &testsuite_params; 791 uint8_t dev_id = ts_params->valid_devs[0]; 792 struct rte_cryptodev_info dev_info; 793 794 rte_cryptodev_info_get(dev_id, &dev_info); 795 796 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 797 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 798 "testsuite not met\n"); 799 return TEST_SKIPPED; 800 } 801 802 return 0; 803 } 804 805 #ifdef RTE_LIB_SECURITY 806 static int 807 ipsec_proto_testsuite_setup(void) 808 { 809 struct crypto_testsuite_params *ts_params = &testsuite_params; 810 struct crypto_unittest_params *ut_params = &unittest_params; 811 struct rte_cryptodev_info dev_info; 812 int ret = 0; 813 814 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 815 816 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 817 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 818 "testsuite not met\n"); 819 return TEST_SKIPPED; 820 } 821 822 /* Reconfigure to enable security */ 823 ret = dev_configure_and_start(0); 824 if (ret != TEST_SUCCESS) 825 return ret; 826 827 /* Set action type */ 828 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 829 830 if (security_proto_supported( 831 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 832 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 833 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 834 "test not met\n"); 835 ret = TEST_SKIPPED; 836 } 837 838 /* 839 * Stop the device. Device would be started again by individual test 840 * case setup routine. 841 */ 842 rte_cryptodev_stop(ts_params->valid_devs[0]); 843 844 return ret; 845 } 846 847 static int 848 pdcp_proto_testsuite_setup(void) 849 { 850 struct crypto_testsuite_params *ts_params = &testsuite_params; 851 uint8_t dev_id = ts_params->valid_devs[0]; 852 struct rte_cryptodev_info dev_info; 853 const enum rte_crypto_cipher_algorithm ciphers[] = { 854 RTE_CRYPTO_CIPHER_NULL, 855 RTE_CRYPTO_CIPHER_AES_CTR, 856 RTE_CRYPTO_CIPHER_ZUC_EEA3, 857 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 858 }; 859 const enum rte_crypto_auth_algorithm auths[] = { 860 RTE_CRYPTO_AUTH_NULL, 861 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 862 RTE_CRYPTO_AUTH_AES_CMAC, 863 RTE_CRYPTO_AUTH_ZUC_EIA3 864 }; 865 866 rte_cryptodev_info_get(dev_id, &dev_info); 867 868 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 869 !(dev_info.feature_flags & 870 RTE_CRYPTODEV_FF_SECURITY)) { 871 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 872 "testsuite not met\n"); 873 return TEST_SKIPPED; 874 } 875 876 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 877 && check_auth_capabilities_supported(auths, 878 RTE_DIM(auths)) != 0) { 879 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 880 "testsuite not met\n"); 881 return TEST_SKIPPED; 882 } 883 884 return 0; 885 } 886 887 static int 888 docsis_proto_testsuite_setup(void) 889 { 890 struct crypto_testsuite_params *ts_params = &testsuite_params; 891 uint8_t dev_id = ts_params->valid_devs[0]; 892 struct rte_cryptodev_info dev_info; 893 const enum rte_crypto_cipher_algorithm ciphers[] = { 894 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 895 }; 896 897 rte_cryptodev_info_get(dev_id, &dev_info); 898 899 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 900 !(dev_info.feature_flags & 901 RTE_CRYPTODEV_FF_SECURITY)) { 902 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 903 "Proto testsuite not met\n"); 904 return TEST_SKIPPED; 905 } 906 907 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 908 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 909 "testsuite not met\n"); 910 return TEST_SKIPPED; 911 } 912 913 return 0; 914 } 915 #endif 916 917 static int 918 aes_ccm_auth_testsuite_setup(void) 919 { 920 struct crypto_testsuite_params *ts_params = &testsuite_params; 921 uint8_t dev_id = ts_params->valid_devs[0]; 922 struct rte_cryptodev_info dev_info; 923 const enum rte_crypto_aead_algorithm aeads[] = { 924 RTE_CRYPTO_AEAD_AES_CCM 925 }; 926 927 rte_cryptodev_info_get(dev_id, &dev_info); 928 929 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 930 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 931 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 932 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 933 "testsuite not met\n"); 934 return TEST_SKIPPED; 935 } 936 937 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 938 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 939 "testsuite not met\n"); 940 return TEST_SKIPPED; 941 } 942 943 return 0; 944 } 945 946 static int 947 aes_gcm_auth_testsuite_setup(void) 948 { 949 struct crypto_testsuite_params *ts_params = &testsuite_params; 950 uint8_t dev_id = ts_params->valid_devs[0]; 951 struct rte_cryptodev_info dev_info; 952 const enum rte_crypto_aead_algorithm aeads[] = { 953 RTE_CRYPTO_AEAD_AES_GCM 954 }; 955 956 rte_cryptodev_info_get(dev_id, &dev_info); 957 958 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 959 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 960 "testsuite not met\n"); 961 return TEST_SKIPPED; 962 } 963 964 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 965 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 966 "testsuite not met\n"); 967 return TEST_SKIPPED; 968 } 969 970 return 0; 971 } 972 973 static int 974 aes_gmac_auth_testsuite_setup(void) 975 { 976 struct crypto_testsuite_params *ts_params = &testsuite_params; 977 uint8_t dev_id = ts_params->valid_devs[0]; 978 struct rte_cryptodev_info dev_info; 979 const enum rte_crypto_auth_algorithm auths[] = { 980 RTE_CRYPTO_AUTH_AES_GMAC 981 }; 982 983 rte_cryptodev_info_get(dev_id, &dev_info); 984 985 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 986 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 987 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 988 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 989 "testsuite not met\n"); 990 return TEST_SKIPPED; 991 } 992 993 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 994 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 995 "testsuite not met\n"); 996 return TEST_SKIPPED; 997 } 998 999 return 0; 1000 } 1001 1002 static int 1003 chacha20_poly1305_testsuite_setup(void) 1004 { 1005 struct crypto_testsuite_params *ts_params = &testsuite_params; 1006 uint8_t dev_id = ts_params->valid_devs[0]; 1007 struct rte_cryptodev_info dev_info; 1008 const enum rte_crypto_aead_algorithm aeads[] = { 1009 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1010 }; 1011 1012 rte_cryptodev_info_get(dev_id, &dev_info); 1013 1014 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1015 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1016 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1017 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1018 "Chacha20-Poly1305 testsuite not met\n"); 1019 return TEST_SKIPPED; 1020 } 1021 1022 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1023 RTE_LOG(INFO, USER1, "Capability requirements for " 1024 "Chacha20-Poly1305 testsuite not met\n"); 1025 return TEST_SKIPPED; 1026 } 1027 1028 return 0; 1029 } 1030 1031 static int 1032 snow3g_testsuite_setup(void) 1033 { 1034 struct crypto_testsuite_params *ts_params = &testsuite_params; 1035 uint8_t dev_id = ts_params->valid_devs[0]; 1036 struct rte_cryptodev_info dev_info; 1037 const enum rte_crypto_cipher_algorithm ciphers[] = { 1038 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1039 1040 }; 1041 const enum rte_crypto_auth_algorithm auths[] = { 1042 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1043 }; 1044 1045 rte_cryptodev_info_get(dev_id, &dev_info); 1046 1047 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1048 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1049 "testsuite not met\n"); 1050 return TEST_SKIPPED; 1051 } 1052 1053 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1054 && check_auth_capabilities_supported(auths, 1055 RTE_DIM(auths)) != 0) { 1056 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1057 "testsuite not met\n"); 1058 return TEST_SKIPPED; 1059 } 1060 1061 return 0; 1062 } 1063 1064 static int 1065 zuc_testsuite_setup(void) 1066 { 1067 struct crypto_testsuite_params *ts_params = &testsuite_params; 1068 uint8_t dev_id = ts_params->valid_devs[0]; 1069 struct rte_cryptodev_info dev_info; 1070 const enum rte_crypto_cipher_algorithm ciphers[] = { 1071 RTE_CRYPTO_CIPHER_ZUC_EEA3 1072 }; 1073 const enum rte_crypto_auth_algorithm auths[] = { 1074 RTE_CRYPTO_AUTH_ZUC_EIA3 1075 }; 1076 1077 rte_cryptodev_info_get(dev_id, &dev_info); 1078 1079 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1080 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1081 "testsuite not met\n"); 1082 return TEST_SKIPPED; 1083 } 1084 1085 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1086 && check_auth_capabilities_supported(auths, 1087 RTE_DIM(auths)) != 0) { 1088 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1089 "testsuite not met\n"); 1090 return TEST_SKIPPED; 1091 } 1092 1093 return 0; 1094 } 1095 1096 static int 1097 hmac_md5_auth_testsuite_setup(void) 1098 { 1099 struct crypto_testsuite_params *ts_params = &testsuite_params; 1100 uint8_t dev_id = ts_params->valid_devs[0]; 1101 struct rte_cryptodev_info dev_info; 1102 const enum rte_crypto_auth_algorithm auths[] = { 1103 RTE_CRYPTO_AUTH_MD5_HMAC 1104 }; 1105 1106 rte_cryptodev_info_get(dev_id, &dev_info); 1107 1108 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1109 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1110 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1111 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1112 "Auth testsuite not met\n"); 1113 return TEST_SKIPPED; 1114 } 1115 1116 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1117 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1118 "testsuite not met\n"); 1119 return TEST_SKIPPED; 1120 } 1121 1122 return 0; 1123 } 1124 1125 static int 1126 kasumi_testsuite_setup(void) 1127 { 1128 struct crypto_testsuite_params *ts_params = &testsuite_params; 1129 uint8_t dev_id = ts_params->valid_devs[0]; 1130 struct rte_cryptodev_info dev_info; 1131 const enum rte_crypto_cipher_algorithm ciphers[] = { 1132 RTE_CRYPTO_CIPHER_KASUMI_F8 1133 }; 1134 const enum rte_crypto_auth_algorithm auths[] = { 1135 RTE_CRYPTO_AUTH_KASUMI_F9 1136 }; 1137 1138 rte_cryptodev_info_get(dev_id, &dev_info); 1139 1140 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1141 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1142 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1143 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1144 "testsuite not met\n"); 1145 return TEST_SKIPPED; 1146 } 1147 1148 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1149 && check_auth_capabilities_supported(auths, 1150 RTE_DIM(auths)) != 0) { 1151 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1152 "testsuite not met\n"); 1153 return TEST_SKIPPED; 1154 } 1155 1156 return 0; 1157 } 1158 1159 static int 1160 negative_aes_gcm_testsuite_setup(void) 1161 { 1162 struct crypto_testsuite_params *ts_params = &testsuite_params; 1163 uint8_t dev_id = ts_params->valid_devs[0]; 1164 struct rte_cryptodev_info dev_info; 1165 const enum rte_crypto_aead_algorithm aeads[] = { 1166 RTE_CRYPTO_AEAD_AES_GCM 1167 }; 1168 1169 rte_cryptodev_info_get(dev_id, &dev_info); 1170 1171 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1172 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1173 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1174 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1175 "AES GCM testsuite not met\n"); 1176 return TEST_SKIPPED; 1177 } 1178 1179 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1180 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1181 "AES GCM testsuite not met\n"); 1182 return TEST_SKIPPED; 1183 } 1184 1185 return 0; 1186 } 1187 1188 static int 1189 negative_aes_gmac_testsuite_setup(void) 1190 { 1191 struct crypto_testsuite_params *ts_params = &testsuite_params; 1192 uint8_t dev_id = ts_params->valid_devs[0]; 1193 struct rte_cryptodev_info dev_info; 1194 const enum rte_crypto_auth_algorithm auths[] = { 1195 RTE_CRYPTO_AUTH_AES_GMAC 1196 }; 1197 1198 rte_cryptodev_info_get(dev_id, &dev_info); 1199 1200 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1201 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1202 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1203 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1204 "AES GMAC testsuite not met\n"); 1205 return TEST_SKIPPED; 1206 } 1207 1208 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1209 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1210 "AES GMAC testsuite not met\n"); 1211 return TEST_SKIPPED; 1212 } 1213 1214 return 0; 1215 } 1216 1217 static int 1218 mixed_cipher_hash_testsuite_setup(void) 1219 { 1220 struct crypto_testsuite_params *ts_params = &testsuite_params; 1221 uint8_t dev_id = ts_params->valid_devs[0]; 1222 struct rte_cryptodev_info dev_info; 1223 uint64_t feat_flags; 1224 const enum rte_crypto_cipher_algorithm ciphers[] = { 1225 RTE_CRYPTO_CIPHER_NULL, 1226 RTE_CRYPTO_CIPHER_AES_CTR, 1227 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1228 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1229 }; 1230 const enum rte_crypto_auth_algorithm auths[] = { 1231 RTE_CRYPTO_AUTH_NULL, 1232 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1233 RTE_CRYPTO_AUTH_AES_CMAC, 1234 RTE_CRYPTO_AUTH_ZUC_EIA3 1235 }; 1236 1237 rte_cryptodev_info_get(dev_id, &dev_info); 1238 feat_flags = dev_info.feature_flags; 1239 1240 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1241 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1242 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1243 "Cipher Hash testsuite not met\n"); 1244 return TEST_SKIPPED; 1245 } 1246 1247 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1248 && check_auth_capabilities_supported(auths, 1249 RTE_DIM(auths)) != 0) { 1250 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1251 "Cipher Hash testsuite not met\n"); 1252 return TEST_SKIPPED; 1253 } 1254 1255 return 0; 1256 } 1257 1258 static int 1259 esn_testsuite_setup(void) 1260 { 1261 struct crypto_testsuite_params *ts_params = &testsuite_params; 1262 uint8_t dev_id = ts_params->valid_devs[0]; 1263 struct rte_cryptodev_info dev_info; 1264 const enum rte_crypto_cipher_algorithm ciphers[] = { 1265 RTE_CRYPTO_CIPHER_AES_CBC 1266 }; 1267 const enum rte_crypto_auth_algorithm auths[] = { 1268 RTE_CRYPTO_AUTH_SHA1_HMAC 1269 }; 1270 1271 rte_cryptodev_info_get(dev_id, &dev_info); 1272 1273 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1274 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1275 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1276 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1277 "testsuite not met\n"); 1278 return TEST_SKIPPED; 1279 } 1280 1281 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1282 && check_auth_capabilities_supported(auths, 1283 RTE_DIM(auths)) != 0) { 1284 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1285 "testsuite not met\n"); 1286 return TEST_SKIPPED; 1287 } 1288 1289 return 0; 1290 } 1291 1292 static int 1293 multi_session_testsuite_setup(void) 1294 { 1295 struct crypto_testsuite_params *ts_params = &testsuite_params; 1296 uint8_t dev_id = ts_params->valid_devs[0]; 1297 struct rte_cryptodev_info dev_info; 1298 const enum rte_crypto_cipher_algorithm ciphers[] = { 1299 RTE_CRYPTO_CIPHER_AES_CBC 1300 }; 1301 const enum rte_crypto_auth_algorithm auths[] = { 1302 RTE_CRYPTO_AUTH_SHA512_HMAC 1303 }; 1304 1305 rte_cryptodev_info_get(dev_id, &dev_info); 1306 1307 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1308 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1309 "Session testsuite not met\n"); 1310 return TEST_SKIPPED; 1311 } 1312 1313 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1314 && check_auth_capabilities_supported(auths, 1315 RTE_DIM(auths)) != 0) { 1316 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1317 "Session testsuite not met\n"); 1318 return TEST_SKIPPED; 1319 } 1320 1321 return 0; 1322 } 1323 1324 static int 1325 negative_hmac_sha1_testsuite_setup(void) 1326 { 1327 struct crypto_testsuite_params *ts_params = &testsuite_params; 1328 uint8_t dev_id = ts_params->valid_devs[0]; 1329 struct rte_cryptodev_info dev_info; 1330 const enum rte_crypto_cipher_algorithm ciphers[] = { 1331 RTE_CRYPTO_CIPHER_AES_CBC 1332 }; 1333 const enum rte_crypto_auth_algorithm auths[] = { 1334 RTE_CRYPTO_AUTH_SHA1_HMAC 1335 }; 1336 1337 rte_cryptodev_info_get(dev_id, &dev_info); 1338 1339 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1340 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1341 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1342 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1343 "HMAC SHA1 testsuite not met\n"); 1344 return TEST_SKIPPED; 1345 } 1346 1347 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1348 && check_auth_capabilities_supported(auths, 1349 RTE_DIM(auths)) != 0) { 1350 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1351 "HMAC SHA1 testsuite not met\n"); 1352 return TEST_SKIPPED; 1353 } 1354 1355 return 0; 1356 } 1357 1358 static int 1359 dev_configure_and_start(uint64_t ff_disable) 1360 { 1361 struct crypto_testsuite_params *ts_params = &testsuite_params; 1362 struct crypto_unittest_params *ut_params = &unittest_params; 1363 1364 uint16_t qp_id; 1365 1366 /* Clear unit test parameters before running test */ 1367 memset(ut_params, 0, sizeof(*ut_params)); 1368 1369 /* Reconfigure device to default parameters */ 1370 ts_params->conf.socket_id = SOCKET_ID_ANY; 1371 ts_params->conf.ff_disable = ff_disable; 1372 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1373 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1374 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 1375 1376 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1377 &ts_params->conf), 1378 "Failed to configure cryptodev %u", 1379 ts_params->valid_devs[0]); 1380 1381 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1382 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1383 ts_params->valid_devs[0], qp_id, 1384 &ts_params->qp_conf, 1385 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1386 "Failed to setup queue pair %u on cryptodev %u", 1387 qp_id, ts_params->valid_devs[0]); 1388 } 1389 1390 1391 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1392 1393 /* Start the device */ 1394 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1395 "Failed to start cryptodev %u", 1396 ts_params->valid_devs[0]); 1397 1398 return TEST_SUCCESS; 1399 } 1400 1401 int 1402 ut_setup(void) 1403 { 1404 /* Configure and start the device with security feature disabled */ 1405 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1406 } 1407 1408 static int 1409 ut_setup_security(void) 1410 { 1411 /* Configure and start the device with no features disabled */ 1412 return dev_configure_and_start(0); 1413 } 1414 1415 void 1416 ut_teardown(void) 1417 { 1418 struct crypto_testsuite_params *ts_params = &testsuite_params; 1419 struct crypto_unittest_params *ut_params = &unittest_params; 1420 1421 /* free crypto session structure */ 1422 #ifdef RTE_LIB_SECURITY 1423 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1424 if (ut_params->sec_session) { 1425 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1426 (ts_params->valid_devs[0]), 1427 ut_params->sec_session); 1428 ut_params->sec_session = NULL; 1429 } 1430 } else 1431 #endif 1432 { 1433 if (ut_params->sess) { 1434 rte_cryptodev_sym_session_clear( 1435 ts_params->valid_devs[0], 1436 ut_params->sess); 1437 rte_cryptodev_sym_session_free(ut_params->sess); 1438 ut_params->sess = NULL; 1439 } 1440 } 1441 1442 /* free crypto operation structure */ 1443 if (ut_params->op) 1444 rte_crypto_op_free(ut_params->op); 1445 1446 /* 1447 * free mbuf - both obuf and ibuf are usually the same, 1448 * so check if they point at the same address is necessary, 1449 * to avoid freeing the mbuf twice. 1450 */ 1451 if (ut_params->obuf) { 1452 rte_pktmbuf_free(ut_params->obuf); 1453 if (ut_params->ibuf == ut_params->obuf) 1454 ut_params->ibuf = 0; 1455 ut_params->obuf = 0; 1456 } 1457 if (ut_params->ibuf) { 1458 rte_pktmbuf_free(ut_params->ibuf); 1459 ut_params->ibuf = 0; 1460 } 1461 1462 if (ts_params->mbuf_pool != NULL) 1463 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1464 rte_mempool_avail_count(ts_params->mbuf_pool)); 1465 1466 /* Stop the device */ 1467 rte_cryptodev_stop(ts_params->valid_devs[0]); 1468 } 1469 1470 static int 1471 test_device_configure_invalid_dev_id(void) 1472 { 1473 struct crypto_testsuite_params *ts_params = &testsuite_params; 1474 uint16_t dev_id, num_devs = 0; 1475 1476 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1477 "Need at least %d devices for test", 1); 1478 1479 /* valid dev_id values */ 1480 dev_id = ts_params->valid_devs[0]; 1481 1482 /* Stop the device in case it's started so it can be configured */ 1483 rte_cryptodev_stop(dev_id); 1484 1485 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1486 "Failed test for rte_cryptodev_configure: " 1487 "invalid dev_num %u", dev_id); 1488 1489 /* invalid dev_id values */ 1490 dev_id = num_devs; 1491 1492 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1493 "Failed test for rte_cryptodev_configure: " 1494 "invalid dev_num %u", dev_id); 1495 1496 dev_id = 0xff; 1497 1498 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1499 "Failed test for rte_cryptodev_configure:" 1500 "invalid dev_num %u", dev_id); 1501 1502 return TEST_SUCCESS; 1503 } 1504 1505 static int 1506 test_device_configure_invalid_queue_pair_ids(void) 1507 { 1508 struct crypto_testsuite_params *ts_params = &testsuite_params; 1509 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1510 1511 /* Stop the device in case it's started so it can be configured */ 1512 rte_cryptodev_stop(ts_params->valid_devs[0]); 1513 1514 /* valid - max value queue pairs */ 1515 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1516 1517 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1518 &ts_params->conf), 1519 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1520 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1521 1522 /* valid - one queue pairs */ 1523 ts_params->conf.nb_queue_pairs = 1; 1524 1525 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1526 &ts_params->conf), 1527 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1528 ts_params->valid_devs[0], 1529 ts_params->conf.nb_queue_pairs); 1530 1531 1532 /* invalid - zero queue pairs */ 1533 ts_params->conf.nb_queue_pairs = 0; 1534 1535 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1536 &ts_params->conf), 1537 "Failed test for rte_cryptodev_configure, dev_id %u," 1538 " invalid qps: %u", 1539 ts_params->valid_devs[0], 1540 ts_params->conf.nb_queue_pairs); 1541 1542 1543 /* invalid - max value supported by field queue pairs */ 1544 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1545 1546 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1547 &ts_params->conf), 1548 "Failed test for rte_cryptodev_configure, dev_id %u," 1549 " invalid qps: %u", 1550 ts_params->valid_devs[0], 1551 ts_params->conf.nb_queue_pairs); 1552 1553 1554 /* invalid - max value + 1 queue pairs */ 1555 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1556 1557 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1558 &ts_params->conf), 1559 "Failed test for rte_cryptodev_configure, dev_id %u," 1560 " invalid qps: %u", 1561 ts_params->valid_devs[0], 1562 ts_params->conf.nb_queue_pairs); 1563 1564 /* revert to original testsuite value */ 1565 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1566 1567 return TEST_SUCCESS; 1568 } 1569 1570 static int 1571 test_queue_pair_descriptor_setup(void) 1572 { 1573 struct crypto_testsuite_params *ts_params = &testsuite_params; 1574 struct rte_cryptodev_qp_conf qp_conf = { 1575 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1576 }; 1577 uint16_t qp_id; 1578 1579 /* Stop the device in case it's started so it can be configured */ 1580 rte_cryptodev_stop(ts_params->valid_devs[0]); 1581 1582 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1583 &ts_params->conf), 1584 "Failed to configure cryptodev %u", 1585 ts_params->valid_devs[0]); 1586 1587 /* 1588 * Test various ring sizes on this device. memzones can't be 1589 * freed so are re-used if ring is released and re-created. 1590 */ 1591 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1592 qp_conf.mp_session = ts_params->session_mpool; 1593 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1594 1595 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1596 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1597 ts_params->valid_devs[0], qp_id, &qp_conf, 1598 rte_cryptodev_socket_id( 1599 ts_params->valid_devs[0])), 1600 "Failed test for " 1601 "rte_cryptodev_queue_pair_setup: num_inflights " 1602 "%u on qp %u on cryptodev %u", 1603 qp_conf.nb_descriptors, qp_id, 1604 ts_params->valid_devs[0]); 1605 } 1606 1607 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1608 1609 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1610 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1611 ts_params->valid_devs[0], qp_id, &qp_conf, 1612 rte_cryptodev_socket_id( 1613 ts_params->valid_devs[0])), 1614 "Failed test for" 1615 " rte_cryptodev_queue_pair_setup: num_inflights" 1616 " %u on qp %u on cryptodev %u", 1617 qp_conf.nb_descriptors, qp_id, 1618 ts_params->valid_devs[0]); 1619 } 1620 1621 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1622 1623 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1624 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1625 ts_params->valid_devs[0], qp_id, &qp_conf, 1626 rte_cryptodev_socket_id( 1627 ts_params->valid_devs[0])), 1628 "Failed test for " 1629 "rte_cryptodev_queue_pair_setup: num_inflights" 1630 " %u on qp %u on cryptodev %u", 1631 qp_conf.nb_descriptors, qp_id, 1632 ts_params->valid_devs[0]); 1633 } 1634 1635 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1636 1637 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1638 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1639 ts_params->valid_devs[0], qp_id, &qp_conf, 1640 rte_cryptodev_socket_id( 1641 ts_params->valid_devs[0])), 1642 "Failed test for" 1643 " rte_cryptodev_queue_pair_setup:" 1644 "num_inflights %u on qp %u on cryptodev %u", 1645 qp_conf.nb_descriptors, qp_id, 1646 ts_params->valid_devs[0]); 1647 } 1648 1649 /* test invalid queue pair id */ 1650 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1651 1652 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1653 1654 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1655 ts_params->valid_devs[0], 1656 qp_id, &qp_conf, 1657 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1658 "Failed test for rte_cryptodev_queue_pair_setup:" 1659 "invalid qp %u on cryptodev %u", 1660 qp_id, ts_params->valid_devs[0]); 1661 1662 qp_id = 0xffff; /*invalid*/ 1663 1664 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1665 ts_params->valid_devs[0], 1666 qp_id, &qp_conf, 1667 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1668 "Failed test for rte_cryptodev_queue_pair_setup:" 1669 "invalid qp %u on cryptodev %u", 1670 qp_id, ts_params->valid_devs[0]); 1671 1672 return TEST_SUCCESS; 1673 } 1674 1675 /* ***** Plaintext data for tests ***** */ 1676 1677 const char catch_22_quote_1[] = 1678 "There was only one catch and that was Catch-22, which " 1679 "specified that a concern for one's safety in the face of " 1680 "dangers that were real and immediate was the process of a " 1681 "rational mind. Orr was crazy and could be grounded. All he " 1682 "had to do was ask; and as soon as he did, he would no longer " 1683 "be crazy and would have to fly more missions. Orr would be " 1684 "crazy to fly more missions and sane if he didn't, but if he " 1685 "was sane he had to fly them. If he flew them he was crazy " 1686 "and didn't have to; but if he didn't want to he was sane and " 1687 "had to. Yossarian was moved very deeply by the absolute " 1688 "simplicity of this clause of Catch-22 and let out a " 1689 "respectful whistle. \"That's some catch, that Catch-22\", he " 1690 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1691 1692 const char catch_22_quote[] = 1693 "What a lousy earth! He wondered how many people were " 1694 "destitute that same night even in his own prosperous country, " 1695 "how many homes were shanties, how many husbands were drunk " 1696 "and wives socked, and how many children were bullied, abused, " 1697 "or abandoned. How many families hungered for food they could " 1698 "not afford to buy? How many hearts were broken? How many " 1699 "suicides would take place that same night, how many people " 1700 "would go insane? How many cockroaches and landlords would " 1701 "triumph? How many winners were losers, successes failures, " 1702 "and rich men poor men? How many wise guys were stupid? How " 1703 "many happy endings were unhappy endings? How many honest men " 1704 "were liars, brave men cowards, loyal men traitors, how many " 1705 "sainted men were corrupt, how many people in positions of " 1706 "trust had sold their souls to bodyguards, how many had never " 1707 "had souls? How many straight-and-narrow paths were crooked " 1708 "paths? How many best families were worst families and how " 1709 "many good people were bad people? When you added them all up " 1710 "and then subtracted, you might be left with only the children, " 1711 "and perhaps with Albert Einstein and an old violinist or " 1712 "sculptor somewhere."; 1713 1714 #define QUOTE_480_BYTES (480) 1715 #define QUOTE_512_BYTES (512) 1716 #define QUOTE_768_BYTES (768) 1717 #define QUOTE_1024_BYTES (1024) 1718 1719 1720 1721 /* ***** SHA1 Hash Tests ***** */ 1722 1723 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1724 1725 static uint8_t hmac_sha1_key[] = { 1726 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1727 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1728 0xDE, 0xF4, 0xDE, 0xAD }; 1729 1730 /* ***** SHA224 Hash Tests ***** */ 1731 1732 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1733 1734 1735 /* ***** AES-CBC Cipher Tests ***** */ 1736 1737 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1738 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1739 1740 static uint8_t aes_cbc_key[] = { 1741 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1742 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1743 1744 static uint8_t aes_cbc_iv[] = { 1745 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1746 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1747 1748 1749 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1750 1751 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1752 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1753 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1754 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1755 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1756 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1757 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1758 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1759 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1760 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1761 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1762 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1763 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1764 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1765 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1766 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1767 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1768 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1769 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1770 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1771 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1772 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1773 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1774 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1775 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1776 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1777 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1778 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1779 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1780 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1781 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1782 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1783 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1784 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1785 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1786 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1787 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1788 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1789 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1790 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1791 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1792 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1793 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1794 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1795 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1796 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1797 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1798 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1799 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1800 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1801 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1802 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1803 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1804 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1805 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1806 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1807 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1808 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1809 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1810 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1811 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1812 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1813 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1814 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1815 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1816 }; 1817 1818 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1819 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1820 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1821 0x18, 0x8c, 0x1d, 0x32 1822 }; 1823 1824 1825 /* Multisession Vector context Test */ 1826 /*Begin Session 0 */ 1827 static uint8_t ms_aes_cbc_key0[] = { 1828 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1829 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1830 }; 1831 1832 static uint8_t ms_aes_cbc_iv0[] = { 1833 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1834 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1835 }; 1836 1837 static const uint8_t ms_aes_cbc_cipher0[] = { 1838 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1839 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1840 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1841 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1842 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1843 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1844 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1845 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1846 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1847 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1848 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1849 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1850 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1851 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1852 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1853 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1854 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1855 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1856 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1857 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1858 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1859 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1860 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1861 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1862 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1863 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1864 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1865 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1866 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1867 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1868 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1869 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1870 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1871 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1872 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1873 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1874 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1875 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1876 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1877 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1878 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1879 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1880 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1881 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1882 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1883 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1884 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1885 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1886 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1887 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1888 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1889 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1890 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1891 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1892 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1893 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1894 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1895 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1896 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1897 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1898 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1899 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1900 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1901 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1902 }; 1903 1904 1905 static uint8_t ms_hmac_key0[] = { 1906 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1907 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1908 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1909 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1910 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1911 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1912 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1913 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1914 }; 1915 1916 static const uint8_t ms_hmac_digest0[] = { 1917 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1918 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1919 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1920 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1921 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1922 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1923 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1924 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1925 }; 1926 1927 /* End Session 0 */ 1928 /* Begin session 1 */ 1929 1930 static uint8_t ms_aes_cbc_key1[] = { 1931 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1932 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1933 }; 1934 1935 static uint8_t ms_aes_cbc_iv1[] = { 1936 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1937 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1938 }; 1939 1940 static const uint8_t ms_aes_cbc_cipher1[] = { 1941 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1942 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1943 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1944 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1945 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1946 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1947 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1948 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1949 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1950 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1951 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1952 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1953 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1954 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1955 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1956 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1957 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1958 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1959 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1960 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1961 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1962 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1963 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1964 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1965 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1966 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1967 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1968 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1969 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1970 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1971 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1972 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1973 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1974 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1975 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1976 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1977 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1978 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1979 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1980 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1981 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1982 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1983 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1984 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1985 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1986 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1987 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1988 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1989 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1990 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1991 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1992 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1993 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1994 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1995 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1996 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1997 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1998 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1999 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2000 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2001 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2002 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2003 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2004 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2005 2006 }; 2007 2008 static uint8_t ms_hmac_key1[] = { 2009 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2010 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2011 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2012 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2013 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2014 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2015 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2016 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2017 }; 2018 2019 static const uint8_t ms_hmac_digest1[] = { 2020 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2021 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2022 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2023 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2024 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2025 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2026 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2027 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2028 }; 2029 /* End Session 1 */ 2030 /* Begin Session 2 */ 2031 static uint8_t ms_aes_cbc_key2[] = { 2032 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2033 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2034 }; 2035 2036 static uint8_t ms_aes_cbc_iv2[] = { 2037 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2038 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2039 }; 2040 2041 static const uint8_t ms_aes_cbc_cipher2[] = { 2042 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2043 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2044 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2045 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2046 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2047 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2048 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2049 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2050 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2051 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2052 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2053 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2054 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2055 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2056 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2057 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2058 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2059 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2060 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2061 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2062 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2063 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2064 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2065 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2066 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2067 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2068 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2069 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2070 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2071 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2072 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2073 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2074 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2075 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2076 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2077 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2078 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2079 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2080 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2081 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2082 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2083 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2084 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2085 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2086 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2087 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2088 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2089 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2090 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2091 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2092 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2093 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2094 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2095 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2096 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2097 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2098 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2099 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2100 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2101 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2102 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2103 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2104 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2105 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2106 }; 2107 2108 static uint8_t ms_hmac_key2[] = { 2109 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2110 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2111 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2112 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2113 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2114 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2115 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2116 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2117 }; 2118 2119 static const uint8_t ms_hmac_digest2[] = { 2120 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2121 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2122 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2123 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2124 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2125 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2126 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2127 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2128 }; 2129 2130 /* End Session 2 */ 2131 2132 2133 static int 2134 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2135 { 2136 struct crypto_testsuite_params *ts_params = &testsuite_params; 2137 struct crypto_unittest_params *ut_params = &unittest_params; 2138 int status; 2139 2140 /* Verify the capabilities */ 2141 struct rte_cryptodev_sym_capability_idx cap_idx; 2142 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2143 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2144 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2145 &cap_idx) == NULL) 2146 return TEST_SKIPPED; 2147 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2148 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2149 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2150 &cap_idx) == NULL) 2151 return TEST_SKIPPED; 2152 2153 /* Generate test mbuf data and space for digest */ 2154 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2155 catch_22_quote, QUOTE_512_BYTES, 0); 2156 2157 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2158 DIGEST_BYTE_LENGTH_SHA1); 2159 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2160 2161 /* Setup Cipher Parameters */ 2162 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2163 ut_params->cipher_xform.next = &ut_params->auth_xform; 2164 2165 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2166 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2167 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2168 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2169 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2170 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2171 2172 /* Setup HMAC Parameters */ 2173 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2174 2175 ut_params->auth_xform.next = NULL; 2176 2177 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2178 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2179 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2180 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2181 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2182 2183 ut_params->sess = rte_cryptodev_sym_session_create( 2184 ts_params->session_mpool); 2185 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2186 2187 /* Create crypto session*/ 2188 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2189 ut_params->sess, &ut_params->cipher_xform, 2190 ts_params->session_priv_mpool); 2191 2192 if (status == -ENOTSUP) 2193 return TEST_SKIPPED; 2194 2195 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 2196 2197 /* Generate crypto op data structure */ 2198 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2199 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2200 TEST_ASSERT_NOT_NULL(ut_params->op, 2201 "Failed to allocate symmetric crypto operation struct"); 2202 2203 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2204 2205 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2206 2207 /* set crypto operation source mbuf */ 2208 sym_op->m_src = ut_params->ibuf; 2209 2210 /* Set crypto operation authentication parameters */ 2211 sym_op->auth.digest.data = ut_params->digest; 2212 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2213 ut_params->ibuf, QUOTE_512_BYTES); 2214 2215 sym_op->auth.data.offset = 0; 2216 sym_op->auth.data.length = QUOTE_512_BYTES; 2217 2218 /* Copy IV at the end of the crypto operation */ 2219 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2220 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2221 2222 /* Set crypto operation cipher parameters */ 2223 sym_op->cipher.data.offset = 0; 2224 sym_op->cipher.data.length = QUOTE_512_BYTES; 2225 2226 /* Process crypto operation */ 2227 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2228 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2229 ut_params->op); 2230 else 2231 TEST_ASSERT_NOT_NULL( 2232 process_crypto_request(ts_params->valid_devs[0], 2233 ut_params->op), 2234 "failed to process sym crypto op"); 2235 2236 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2237 "crypto op processing failed"); 2238 2239 /* Validate obuf */ 2240 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2241 uint8_t *); 2242 2243 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2244 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2245 QUOTE_512_BYTES, 2246 "ciphertext data not as expected"); 2247 2248 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2249 2250 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2251 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2252 gbl_driver_id == rte_cryptodev_driver_id_get( 2253 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2254 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2255 DIGEST_BYTE_LENGTH_SHA1, 2256 "Generated digest data not as expected"); 2257 2258 return TEST_SUCCESS; 2259 } 2260 2261 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2262 2263 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2264 2265 static uint8_t hmac_sha512_key[] = { 2266 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2267 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2268 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2269 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2270 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2271 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2272 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2273 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2274 2275 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2276 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2277 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2278 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2279 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2280 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2281 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2282 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2283 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2284 2285 2286 2287 static int 2288 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2289 struct crypto_unittest_params *ut_params, 2290 uint8_t *cipher_key, 2291 uint8_t *hmac_key); 2292 2293 static int 2294 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2295 struct crypto_unittest_params *ut_params, 2296 struct crypto_testsuite_params *ts_params, 2297 const uint8_t *cipher, 2298 const uint8_t *digest, 2299 const uint8_t *iv); 2300 2301 2302 static int 2303 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2304 struct crypto_unittest_params *ut_params, 2305 uint8_t *cipher_key, 2306 uint8_t *hmac_key) 2307 { 2308 2309 /* Setup Cipher Parameters */ 2310 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2311 ut_params->cipher_xform.next = NULL; 2312 2313 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2314 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2315 ut_params->cipher_xform.cipher.key.data = cipher_key; 2316 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2317 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2318 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2319 2320 /* Setup HMAC Parameters */ 2321 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2322 ut_params->auth_xform.next = &ut_params->cipher_xform; 2323 2324 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2325 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2326 ut_params->auth_xform.auth.key.data = hmac_key; 2327 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2328 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2329 2330 return TEST_SUCCESS; 2331 } 2332 2333 2334 static int 2335 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2336 struct crypto_unittest_params *ut_params, 2337 struct crypto_testsuite_params *ts_params, 2338 const uint8_t *cipher, 2339 const uint8_t *digest, 2340 const uint8_t *iv) 2341 { 2342 /* Generate test mbuf data and digest */ 2343 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2344 (const char *) 2345 cipher, 2346 QUOTE_512_BYTES, 0); 2347 2348 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2349 DIGEST_BYTE_LENGTH_SHA512); 2350 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2351 2352 rte_memcpy(ut_params->digest, 2353 digest, 2354 DIGEST_BYTE_LENGTH_SHA512); 2355 2356 /* Generate Crypto op data structure */ 2357 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2358 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2359 TEST_ASSERT_NOT_NULL(ut_params->op, 2360 "Failed to allocate symmetric crypto operation struct"); 2361 2362 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2363 2364 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2365 2366 /* set crypto operation source mbuf */ 2367 sym_op->m_src = ut_params->ibuf; 2368 2369 sym_op->auth.digest.data = ut_params->digest; 2370 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2371 ut_params->ibuf, QUOTE_512_BYTES); 2372 2373 sym_op->auth.data.offset = 0; 2374 sym_op->auth.data.length = QUOTE_512_BYTES; 2375 2376 /* Copy IV at the end of the crypto operation */ 2377 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2378 iv, CIPHER_IV_LENGTH_AES_CBC); 2379 2380 sym_op->cipher.data.offset = 0; 2381 sym_op->cipher.data.length = QUOTE_512_BYTES; 2382 2383 /* Process crypto operation */ 2384 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2385 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2386 ut_params->op); 2387 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2388 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2389 ut_params->op, 1, 1, 0, 0); 2390 else 2391 TEST_ASSERT_NOT_NULL( 2392 process_crypto_request(ts_params->valid_devs[0], 2393 ut_params->op), 2394 "failed to process sym crypto op"); 2395 2396 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2397 "crypto op processing failed"); 2398 2399 ut_params->obuf = ut_params->op->sym->m_src; 2400 2401 /* Validate obuf */ 2402 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2403 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2404 catch_22_quote, 2405 QUOTE_512_BYTES, 2406 "Plaintext data not as expected"); 2407 2408 /* Validate obuf */ 2409 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2410 "Digest verification failed"); 2411 2412 return TEST_SUCCESS; 2413 } 2414 2415 /* ***** SNOW 3G Tests ***** */ 2416 static int 2417 create_wireless_algo_hash_session(uint8_t dev_id, 2418 const uint8_t *key, const uint8_t key_len, 2419 const uint8_t iv_len, const uint8_t auth_len, 2420 enum rte_crypto_auth_operation op, 2421 enum rte_crypto_auth_algorithm algo) 2422 { 2423 uint8_t hash_key[key_len]; 2424 int status; 2425 2426 struct crypto_testsuite_params *ts_params = &testsuite_params; 2427 struct crypto_unittest_params *ut_params = &unittest_params; 2428 2429 memcpy(hash_key, key, key_len); 2430 2431 debug_hexdump(stdout, "key:", key, key_len); 2432 2433 /* Setup Authentication Parameters */ 2434 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2435 ut_params->auth_xform.next = NULL; 2436 2437 ut_params->auth_xform.auth.op = op; 2438 ut_params->auth_xform.auth.algo = algo; 2439 ut_params->auth_xform.auth.key.length = key_len; 2440 ut_params->auth_xform.auth.key.data = hash_key; 2441 ut_params->auth_xform.auth.digest_length = auth_len; 2442 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2443 ut_params->auth_xform.auth.iv.length = iv_len; 2444 ut_params->sess = rte_cryptodev_sym_session_create( 2445 ts_params->session_mpool); 2446 2447 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2448 &ut_params->auth_xform, 2449 ts_params->session_priv_mpool); 2450 if (status == -ENOTSUP) 2451 return TEST_SKIPPED; 2452 2453 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2454 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2455 return 0; 2456 } 2457 2458 static int 2459 create_wireless_algo_cipher_session(uint8_t dev_id, 2460 enum rte_crypto_cipher_operation op, 2461 enum rte_crypto_cipher_algorithm algo, 2462 const uint8_t *key, const uint8_t key_len, 2463 uint8_t iv_len) 2464 { 2465 uint8_t cipher_key[key_len]; 2466 int status; 2467 struct crypto_testsuite_params *ts_params = &testsuite_params; 2468 struct crypto_unittest_params *ut_params = &unittest_params; 2469 2470 memcpy(cipher_key, key, key_len); 2471 2472 /* Setup Cipher Parameters */ 2473 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2474 ut_params->cipher_xform.next = NULL; 2475 2476 ut_params->cipher_xform.cipher.algo = algo; 2477 ut_params->cipher_xform.cipher.op = op; 2478 ut_params->cipher_xform.cipher.key.data = cipher_key; 2479 ut_params->cipher_xform.cipher.key.length = key_len; 2480 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2481 ut_params->cipher_xform.cipher.iv.length = iv_len; 2482 2483 debug_hexdump(stdout, "key:", key, key_len); 2484 2485 /* Create Crypto session */ 2486 ut_params->sess = rte_cryptodev_sym_session_create( 2487 ts_params->session_mpool); 2488 2489 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2490 &ut_params->cipher_xform, 2491 ts_params->session_priv_mpool); 2492 if (status == -ENOTSUP) 2493 return TEST_SKIPPED; 2494 2495 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2496 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2497 return 0; 2498 } 2499 2500 static int 2501 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2502 unsigned int cipher_len, 2503 unsigned int cipher_offset) 2504 { 2505 struct crypto_testsuite_params *ts_params = &testsuite_params; 2506 struct crypto_unittest_params *ut_params = &unittest_params; 2507 2508 /* Generate Crypto op data structure */ 2509 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2510 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2511 TEST_ASSERT_NOT_NULL(ut_params->op, 2512 "Failed to allocate pktmbuf offload"); 2513 2514 /* Set crypto operation data parameters */ 2515 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2516 2517 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2518 2519 /* set crypto operation source mbuf */ 2520 sym_op->m_src = ut_params->ibuf; 2521 2522 /* iv */ 2523 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2524 iv, iv_len); 2525 sym_op->cipher.data.length = cipher_len; 2526 sym_op->cipher.data.offset = cipher_offset; 2527 return 0; 2528 } 2529 2530 static int 2531 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2532 unsigned int cipher_len, 2533 unsigned int cipher_offset) 2534 { 2535 struct crypto_testsuite_params *ts_params = &testsuite_params; 2536 struct crypto_unittest_params *ut_params = &unittest_params; 2537 2538 /* Generate Crypto op data structure */ 2539 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2540 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2541 TEST_ASSERT_NOT_NULL(ut_params->op, 2542 "Failed to allocate pktmbuf offload"); 2543 2544 /* Set crypto operation data parameters */ 2545 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2546 2547 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2548 2549 /* set crypto operation source mbuf */ 2550 sym_op->m_src = ut_params->ibuf; 2551 sym_op->m_dst = ut_params->obuf; 2552 2553 /* iv */ 2554 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2555 iv, iv_len); 2556 sym_op->cipher.data.length = cipher_len; 2557 sym_op->cipher.data.offset = cipher_offset; 2558 return 0; 2559 } 2560 2561 static int 2562 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2563 enum rte_crypto_cipher_operation cipher_op, 2564 enum rte_crypto_auth_operation auth_op, 2565 enum rte_crypto_auth_algorithm auth_algo, 2566 enum rte_crypto_cipher_algorithm cipher_algo, 2567 const uint8_t *key, uint8_t key_len, 2568 uint8_t auth_iv_len, uint8_t auth_len, 2569 uint8_t cipher_iv_len) 2570 2571 { 2572 uint8_t cipher_auth_key[key_len]; 2573 int status; 2574 2575 struct crypto_testsuite_params *ts_params = &testsuite_params; 2576 struct crypto_unittest_params *ut_params = &unittest_params; 2577 2578 memcpy(cipher_auth_key, key, key_len); 2579 2580 /* Setup Authentication Parameters */ 2581 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2582 ut_params->auth_xform.next = NULL; 2583 2584 ut_params->auth_xform.auth.op = auth_op; 2585 ut_params->auth_xform.auth.algo = auth_algo; 2586 ut_params->auth_xform.auth.key.length = key_len; 2587 /* Hash key = cipher key */ 2588 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2589 ut_params->auth_xform.auth.digest_length = auth_len; 2590 /* Auth IV will be after cipher IV */ 2591 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2592 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2593 2594 /* Setup Cipher Parameters */ 2595 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2596 ut_params->cipher_xform.next = &ut_params->auth_xform; 2597 2598 ut_params->cipher_xform.cipher.algo = cipher_algo; 2599 ut_params->cipher_xform.cipher.op = cipher_op; 2600 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2601 ut_params->cipher_xform.cipher.key.length = key_len; 2602 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2603 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2604 2605 debug_hexdump(stdout, "key:", key, key_len); 2606 2607 /* Create Crypto session*/ 2608 ut_params->sess = rte_cryptodev_sym_session_create( 2609 ts_params->session_mpool); 2610 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2611 2612 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2613 &ut_params->cipher_xform, 2614 ts_params->session_priv_mpool); 2615 if (status == -ENOTSUP) 2616 return TEST_SKIPPED; 2617 2618 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2619 return 0; 2620 } 2621 2622 static int 2623 create_wireless_cipher_auth_session(uint8_t dev_id, 2624 enum rte_crypto_cipher_operation cipher_op, 2625 enum rte_crypto_auth_operation auth_op, 2626 enum rte_crypto_auth_algorithm auth_algo, 2627 enum rte_crypto_cipher_algorithm cipher_algo, 2628 const struct wireless_test_data *tdata) 2629 { 2630 const uint8_t key_len = tdata->key.len; 2631 uint8_t cipher_auth_key[key_len]; 2632 int status; 2633 2634 struct crypto_testsuite_params *ts_params = &testsuite_params; 2635 struct crypto_unittest_params *ut_params = &unittest_params; 2636 const uint8_t *key = tdata->key.data; 2637 const uint8_t auth_len = tdata->digest.len; 2638 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2639 uint8_t auth_iv_len = tdata->auth_iv.len; 2640 2641 memcpy(cipher_auth_key, key, key_len); 2642 2643 /* Setup Authentication Parameters */ 2644 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2645 ut_params->auth_xform.next = NULL; 2646 2647 ut_params->auth_xform.auth.op = auth_op; 2648 ut_params->auth_xform.auth.algo = auth_algo; 2649 ut_params->auth_xform.auth.key.length = key_len; 2650 /* Hash key = cipher key */ 2651 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2652 ut_params->auth_xform.auth.digest_length = auth_len; 2653 /* Auth IV will be after cipher IV */ 2654 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2655 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2656 2657 /* Setup Cipher Parameters */ 2658 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2659 ut_params->cipher_xform.next = &ut_params->auth_xform; 2660 2661 ut_params->cipher_xform.cipher.algo = cipher_algo; 2662 ut_params->cipher_xform.cipher.op = cipher_op; 2663 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2664 ut_params->cipher_xform.cipher.key.length = key_len; 2665 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2666 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2667 2668 2669 debug_hexdump(stdout, "key:", key, key_len); 2670 2671 /* Create Crypto session*/ 2672 ut_params->sess = rte_cryptodev_sym_session_create( 2673 ts_params->session_mpool); 2674 2675 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2676 &ut_params->cipher_xform, 2677 ts_params->session_priv_mpool); 2678 if (status == -ENOTSUP) 2679 return TEST_SKIPPED; 2680 2681 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2682 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2683 return 0; 2684 } 2685 2686 static int 2687 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2688 const struct wireless_test_data *tdata) 2689 { 2690 return create_wireless_cipher_auth_session(dev_id, 2691 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2692 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2693 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2694 } 2695 2696 static int 2697 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2698 enum rte_crypto_cipher_operation cipher_op, 2699 enum rte_crypto_auth_operation auth_op, 2700 enum rte_crypto_auth_algorithm auth_algo, 2701 enum rte_crypto_cipher_algorithm cipher_algo, 2702 const uint8_t *key, const uint8_t key_len, 2703 uint8_t auth_iv_len, uint8_t auth_len, 2704 uint8_t cipher_iv_len) 2705 { 2706 uint8_t auth_cipher_key[key_len]; 2707 int status; 2708 struct crypto_testsuite_params *ts_params = &testsuite_params; 2709 struct crypto_unittest_params *ut_params = &unittest_params; 2710 2711 memcpy(auth_cipher_key, key, key_len); 2712 2713 /* Setup Authentication Parameters */ 2714 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2715 ut_params->auth_xform.auth.op = auth_op; 2716 ut_params->auth_xform.next = &ut_params->cipher_xform; 2717 ut_params->auth_xform.auth.algo = auth_algo; 2718 ut_params->auth_xform.auth.key.length = key_len; 2719 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2720 ut_params->auth_xform.auth.digest_length = auth_len; 2721 /* Auth IV will be after cipher IV */ 2722 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2723 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2724 2725 /* Setup Cipher Parameters */ 2726 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2727 ut_params->cipher_xform.next = NULL; 2728 ut_params->cipher_xform.cipher.algo = cipher_algo; 2729 ut_params->cipher_xform.cipher.op = cipher_op; 2730 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2731 ut_params->cipher_xform.cipher.key.length = key_len; 2732 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2733 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2734 2735 debug_hexdump(stdout, "key:", key, key_len); 2736 2737 /* Create Crypto session*/ 2738 ut_params->sess = rte_cryptodev_sym_session_create( 2739 ts_params->session_mpool); 2740 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2741 2742 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2743 ut_params->auth_xform.next = NULL; 2744 ut_params->cipher_xform.next = &ut_params->auth_xform; 2745 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2746 &ut_params->cipher_xform, 2747 ts_params->session_priv_mpool); 2748 2749 } else 2750 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2751 &ut_params->auth_xform, 2752 ts_params->session_priv_mpool); 2753 2754 if (status == -ENOTSUP) 2755 return TEST_SKIPPED; 2756 2757 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2758 2759 return 0; 2760 } 2761 2762 static int 2763 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2764 unsigned int auth_tag_len, 2765 const uint8_t *iv, unsigned int iv_len, 2766 unsigned int data_pad_len, 2767 enum rte_crypto_auth_operation op, 2768 unsigned int auth_len, unsigned int auth_offset) 2769 { 2770 struct crypto_testsuite_params *ts_params = &testsuite_params; 2771 2772 struct crypto_unittest_params *ut_params = &unittest_params; 2773 2774 /* Generate Crypto op data structure */ 2775 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2776 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2777 TEST_ASSERT_NOT_NULL(ut_params->op, 2778 "Failed to allocate pktmbuf offload"); 2779 2780 /* Set crypto operation data parameters */ 2781 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2782 2783 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2784 2785 /* set crypto operation source mbuf */ 2786 sym_op->m_src = ut_params->ibuf; 2787 2788 /* iv */ 2789 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2790 iv, iv_len); 2791 /* digest */ 2792 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2793 ut_params->ibuf, auth_tag_len); 2794 2795 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2796 "no room to append auth tag"); 2797 ut_params->digest = sym_op->auth.digest.data; 2798 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2799 ut_params->ibuf, data_pad_len); 2800 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2801 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2802 else 2803 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2804 2805 debug_hexdump(stdout, "digest:", 2806 sym_op->auth.digest.data, 2807 auth_tag_len); 2808 2809 sym_op->auth.data.length = auth_len; 2810 sym_op->auth.data.offset = auth_offset; 2811 2812 return 0; 2813 } 2814 2815 static int 2816 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2817 enum rte_crypto_auth_operation op) 2818 { 2819 struct crypto_testsuite_params *ts_params = &testsuite_params; 2820 struct crypto_unittest_params *ut_params = &unittest_params; 2821 2822 const uint8_t *auth_tag = tdata->digest.data; 2823 const unsigned int auth_tag_len = tdata->digest.len; 2824 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2825 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2826 2827 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2828 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2829 const uint8_t *auth_iv = tdata->auth_iv.data; 2830 const uint8_t auth_iv_len = tdata->auth_iv.len; 2831 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2832 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2833 2834 /* Generate Crypto op data structure */ 2835 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2836 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2837 TEST_ASSERT_NOT_NULL(ut_params->op, 2838 "Failed to allocate pktmbuf offload"); 2839 /* Set crypto operation data parameters */ 2840 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2841 2842 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2843 2844 /* set crypto operation source mbuf */ 2845 sym_op->m_src = ut_params->ibuf; 2846 2847 /* digest */ 2848 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2849 ut_params->ibuf, auth_tag_len); 2850 2851 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2852 "no room to append auth tag"); 2853 ut_params->digest = sym_op->auth.digest.data; 2854 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2855 ut_params->ibuf, data_pad_len); 2856 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2857 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2858 else 2859 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2860 2861 debug_hexdump(stdout, "digest:", 2862 sym_op->auth.digest.data, 2863 auth_tag_len); 2864 2865 /* Copy cipher and auth IVs at the end of the crypto operation */ 2866 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2867 IV_OFFSET); 2868 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2869 iv_ptr += cipher_iv_len; 2870 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2871 2872 sym_op->cipher.data.length = cipher_len; 2873 sym_op->cipher.data.offset = 0; 2874 sym_op->auth.data.length = auth_len; 2875 sym_op->auth.data.offset = 0; 2876 2877 return 0; 2878 } 2879 2880 static int 2881 create_zuc_cipher_hash_generate_operation( 2882 const struct wireless_test_data *tdata) 2883 { 2884 return create_wireless_cipher_hash_operation(tdata, 2885 RTE_CRYPTO_AUTH_OP_GENERATE); 2886 } 2887 2888 static int 2889 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2890 const unsigned auth_tag_len, 2891 const uint8_t *auth_iv, uint8_t auth_iv_len, 2892 unsigned data_pad_len, 2893 enum rte_crypto_auth_operation op, 2894 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2895 const unsigned cipher_len, const unsigned cipher_offset, 2896 const unsigned auth_len, const unsigned auth_offset) 2897 { 2898 struct crypto_testsuite_params *ts_params = &testsuite_params; 2899 struct crypto_unittest_params *ut_params = &unittest_params; 2900 2901 enum rte_crypto_cipher_algorithm cipher_algo = 2902 ut_params->cipher_xform.cipher.algo; 2903 enum rte_crypto_auth_algorithm auth_algo = 2904 ut_params->auth_xform.auth.algo; 2905 2906 /* Generate Crypto op data structure */ 2907 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2908 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2909 TEST_ASSERT_NOT_NULL(ut_params->op, 2910 "Failed to allocate pktmbuf offload"); 2911 /* Set crypto operation data parameters */ 2912 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2913 2914 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2915 2916 /* set crypto operation source mbuf */ 2917 sym_op->m_src = ut_params->ibuf; 2918 2919 /* digest */ 2920 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2921 ut_params->ibuf, auth_tag_len); 2922 2923 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2924 "no room to append auth tag"); 2925 ut_params->digest = sym_op->auth.digest.data; 2926 2927 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2928 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2929 ut_params->ibuf, data_pad_len); 2930 } else { 2931 struct rte_mbuf *m = ut_params->ibuf; 2932 unsigned int offset = data_pad_len; 2933 2934 while (offset > m->data_len && m->next != NULL) { 2935 offset -= m->data_len; 2936 m = m->next; 2937 } 2938 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2939 m, offset); 2940 } 2941 2942 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2943 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2944 else 2945 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2946 2947 debug_hexdump(stdout, "digest:", 2948 sym_op->auth.digest.data, 2949 auth_tag_len); 2950 2951 /* Copy cipher and auth IVs at the end of the crypto operation */ 2952 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2953 IV_OFFSET); 2954 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2955 iv_ptr += cipher_iv_len; 2956 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2957 2958 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2959 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2960 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2961 sym_op->cipher.data.length = cipher_len; 2962 sym_op->cipher.data.offset = cipher_offset; 2963 } else { 2964 sym_op->cipher.data.length = cipher_len >> 3; 2965 sym_op->cipher.data.offset = cipher_offset >> 3; 2966 } 2967 2968 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2969 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2970 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2971 sym_op->auth.data.length = auth_len; 2972 sym_op->auth.data.offset = auth_offset; 2973 } else { 2974 sym_op->auth.data.length = auth_len >> 3; 2975 sym_op->auth.data.offset = auth_offset >> 3; 2976 } 2977 2978 return 0; 2979 } 2980 2981 static int 2982 create_wireless_algo_auth_cipher_operation( 2983 const uint8_t *auth_tag, unsigned int auth_tag_len, 2984 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2985 const uint8_t *auth_iv, uint8_t auth_iv_len, 2986 unsigned int data_pad_len, 2987 unsigned int cipher_len, unsigned int cipher_offset, 2988 unsigned int auth_len, unsigned int auth_offset, 2989 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2990 { 2991 struct crypto_testsuite_params *ts_params = &testsuite_params; 2992 struct crypto_unittest_params *ut_params = &unittest_params; 2993 2994 enum rte_crypto_cipher_algorithm cipher_algo = 2995 ut_params->cipher_xform.cipher.algo; 2996 enum rte_crypto_auth_algorithm auth_algo = 2997 ut_params->auth_xform.auth.algo; 2998 2999 /* Generate Crypto op data structure */ 3000 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3001 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3002 TEST_ASSERT_NOT_NULL(ut_params->op, 3003 "Failed to allocate pktmbuf offload"); 3004 3005 /* Set crypto operation data parameters */ 3006 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3007 3008 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3009 3010 /* set crypto operation mbufs */ 3011 sym_op->m_src = ut_params->ibuf; 3012 if (op_mode == OUT_OF_PLACE) 3013 sym_op->m_dst = ut_params->obuf; 3014 3015 /* digest */ 3016 if (!do_sgl) { 3017 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3018 (op_mode == IN_PLACE ? 3019 ut_params->ibuf : ut_params->obuf), 3020 uint8_t *, data_pad_len); 3021 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3022 (op_mode == IN_PLACE ? 3023 ut_params->ibuf : ut_params->obuf), 3024 data_pad_len); 3025 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3026 } else { 3027 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3028 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3029 sym_op->m_src : sym_op->m_dst); 3030 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3031 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3032 sgl_buf = sgl_buf->next; 3033 } 3034 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3035 uint8_t *, remaining_off); 3036 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3037 remaining_off); 3038 memset(sym_op->auth.digest.data, 0, remaining_off); 3039 while (sgl_buf->next != NULL) { 3040 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3041 0, rte_pktmbuf_data_len(sgl_buf)); 3042 sgl_buf = sgl_buf->next; 3043 } 3044 } 3045 3046 /* Copy digest for the verification */ 3047 if (verify) 3048 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3049 3050 /* Copy cipher and auth IVs at the end of the crypto operation */ 3051 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3052 ut_params->op, uint8_t *, IV_OFFSET); 3053 3054 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3055 iv_ptr += cipher_iv_len; 3056 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3057 3058 /* Only copy over the offset data needed from src to dst in OOP, 3059 * if the auth and cipher offsets are not aligned 3060 */ 3061 if (op_mode == OUT_OF_PLACE) { 3062 if (cipher_offset > auth_offset) 3063 rte_memcpy( 3064 rte_pktmbuf_mtod_offset( 3065 sym_op->m_dst, 3066 uint8_t *, auth_offset >> 3), 3067 rte_pktmbuf_mtod_offset( 3068 sym_op->m_src, 3069 uint8_t *, auth_offset >> 3), 3070 ((cipher_offset >> 3) - (auth_offset >> 3))); 3071 } 3072 3073 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3074 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3075 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3076 sym_op->cipher.data.length = cipher_len; 3077 sym_op->cipher.data.offset = cipher_offset; 3078 } else { 3079 sym_op->cipher.data.length = cipher_len >> 3; 3080 sym_op->cipher.data.offset = cipher_offset >> 3; 3081 } 3082 3083 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3084 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3085 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3086 sym_op->auth.data.length = auth_len; 3087 sym_op->auth.data.offset = auth_offset; 3088 } else { 3089 sym_op->auth.data.length = auth_len >> 3; 3090 sym_op->auth.data.offset = auth_offset >> 3; 3091 } 3092 3093 return 0; 3094 } 3095 3096 static int 3097 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3098 { 3099 struct crypto_testsuite_params *ts_params = &testsuite_params; 3100 struct crypto_unittest_params *ut_params = &unittest_params; 3101 3102 int retval; 3103 unsigned plaintext_pad_len; 3104 unsigned plaintext_len; 3105 uint8_t *plaintext; 3106 struct rte_cryptodev_info dev_info; 3107 3108 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3109 uint64_t feat_flags = dev_info.feature_flags; 3110 3111 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3112 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3113 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3114 return TEST_SKIPPED; 3115 } 3116 3117 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3118 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3119 printf("Device doesn't support RAW data-path APIs.\n"); 3120 return TEST_SKIPPED; 3121 } 3122 3123 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3124 return TEST_SKIPPED; 3125 3126 /* Verify the capabilities */ 3127 struct rte_cryptodev_sym_capability_idx cap_idx; 3128 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3129 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3130 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3131 &cap_idx) == NULL) 3132 return TEST_SKIPPED; 3133 3134 /* Create SNOW 3G session */ 3135 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3136 tdata->key.data, tdata->key.len, 3137 tdata->auth_iv.len, tdata->digest.len, 3138 RTE_CRYPTO_AUTH_OP_GENERATE, 3139 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3140 if (retval < 0) 3141 return retval; 3142 3143 /* alloc mbuf and set payload */ 3144 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3145 3146 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3147 rte_pktmbuf_tailroom(ut_params->ibuf)); 3148 3149 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3150 /* Append data which is padded to a multiple of */ 3151 /* the algorithms block size */ 3152 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3153 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3154 plaintext_pad_len); 3155 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3156 3157 /* Create SNOW 3G operation */ 3158 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3159 tdata->auth_iv.data, tdata->auth_iv.len, 3160 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3161 tdata->validAuthLenInBits.len, 3162 0); 3163 if (retval < 0) 3164 return retval; 3165 3166 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3167 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3168 ut_params->op, 0, 1, 1, 0); 3169 else 3170 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3171 ut_params->op); 3172 ut_params->obuf = ut_params->op->sym->m_src; 3173 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3174 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3175 + plaintext_pad_len; 3176 3177 /* Validate obuf */ 3178 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3179 ut_params->digest, 3180 tdata->digest.data, 3181 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3182 "SNOW 3G Generated auth tag not as expected"); 3183 3184 return 0; 3185 } 3186 3187 static int 3188 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3189 { 3190 struct crypto_testsuite_params *ts_params = &testsuite_params; 3191 struct crypto_unittest_params *ut_params = &unittest_params; 3192 3193 int retval; 3194 unsigned plaintext_pad_len; 3195 unsigned plaintext_len; 3196 uint8_t *plaintext; 3197 struct rte_cryptodev_info dev_info; 3198 3199 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3200 uint64_t feat_flags = dev_info.feature_flags; 3201 3202 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3203 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3204 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3205 return TEST_SKIPPED; 3206 } 3207 3208 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3209 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3210 printf("Device doesn't support RAW data-path APIs.\n"); 3211 return TEST_SKIPPED; 3212 } 3213 3214 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3215 return TEST_SKIPPED; 3216 3217 /* Verify the capabilities */ 3218 struct rte_cryptodev_sym_capability_idx cap_idx; 3219 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3220 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3221 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3222 &cap_idx) == NULL) 3223 return TEST_SKIPPED; 3224 3225 /* Create SNOW 3G session */ 3226 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3227 tdata->key.data, tdata->key.len, 3228 tdata->auth_iv.len, tdata->digest.len, 3229 RTE_CRYPTO_AUTH_OP_VERIFY, 3230 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3231 if (retval < 0) 3232 return retval; 3233 /* alloc mbuf and set payload */ 3234 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3235 3236 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3237 rte_pktmbuf_tailroom(ut_params->ibuf)); 3238 3239 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3240 /* Append data which is padded to a multiple of */ 3241 /* the algorithms block size */ 3242 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3243 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3244 plaintext_pad_len); 3245 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3246 3247 /* Create SNOW 3G operation */ 3248 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3249 tdata->digest.len, 3250 tdata->auth_iv.data, tdata->auth_iv.len, 3251 plaintext_pad_len, 3252 RTE_CRYPTO_AUTH_OP_VERIFY, 3253 tdata->validAuthLenInBits.len, 3254 0); 3255 if (retval < 0) 3256 return retval; 3257 3258 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3259 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3260 ut_params->op, 0, 1, 1, 0); 3261 else 3262 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3263 ut_params->op); 3264 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3265 ut_params->obuf = ut_params->op->sym->m_src; 3266 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3267 + plaintext_pad_len; 3268 3269 /* Validate obuf */ 3270 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3271 return 0; 3272 else 3273 return -1; 3274 3275 return 0; 3276 } 3277 3278 static int 3279 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3280 { 3281 struct crypto_testsuite_params *ts_params = &testsuite_params; 3282 struct crypto_unittest_params *ut_params = &unittest_params; 3283 3284 int retval; 3285 unsigned plaintext_pad_len; 3286 unsigned plaintext_len; 3287 uint8_t *plaintext; 3288 struct rte_cryptodev_info dev_info; 3289 3290 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3291 uint64_t feat_flags = dev_info.feature_flags; 3292 3293 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3294 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3295 printf("Device doesn't support RAW data-path APIs.\n"); 3296 return TEST_SKIPPED; 3297 } 3298 3299 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3300 return TEST_SKIPPED; 3301 3302 /* Verify the capabilities */ 3303 struct rte_cryptodev_sym_capability_idx cap_idx; 3304 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3305 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3306 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3307 &cap_idx) == NULL) 3308 return TEST_SKIPPED; 3309 3310 /* Create KASUMI session */ 3311 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3312 tdata->key.data, tdata->key.len, 3313 0, tdata->digest.len, 3314 RTE_CRYPTO_AUTH_OP_GENERATE, 3315 RTE_CRYPTO_AUTH_KASUMI_F9); 3316 if (retval < 0) 3317 return retval; 3318 3319 /* alloc mbuf and set payload */ 3320 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3321 3322 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3323 rte_pktmbuf_tailroom(ut_params->ibuf)); 3324 3325 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3326 /* Append data which is padded to a multiple of */ 3327 /* the algorithms block size */ 3328 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3329 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3330 plaintext_pad_len); 3331 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3332 3333 /* Create KASUMI operation */ 3334 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3335 NULL, 0, 3336 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3337 tdata->plaintext.len, 3338 0); 3339 if (retval < 0) 3340 return retval; 3341 3342 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3343 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3344 ut_params->op); 3345 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3346 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3347 ut_params->op, 0, 1, 1, 0); 3348 else 3349 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3350 ut_params->op); 3351 3352 ut_params->obuf = ut_params->op->sym->m_src; 3353 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3354 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3355 + plaintext_pad_len; 3356 3357 /* Validate obuf */ 3358 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3359 ut_params->digest, 3360 tdata->digest.data, 3361 DIGEST_BYTE_LENGTH_KASUMI_F9, 3362 "KASUMI Generated auth tag not as expected"); 3363 3364 return 0; 3365 } 3366 3367 static int 3368 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3369 { 3370 struct crypto_testsuite_params *ts_params = &testsuite_params; 3371 struct crypto_unittest_params *ut_params = &unittest_params; 3372 3373 int retval; 3374 unsigned plaintext_pad_len; 3375 unsigned plaintext_len; 3376 uint8_t *plaintext; 3377 struct rte_cryptodev_info dev_info; 3378 3379 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3380 uint64_t feat_flags = dev_info.feature_flags; 3381 3382 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3383 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3384 printf("Device doesn't support RAW data-path APIs.\n"); 3385 return TEST_SKIPPED; 3386 } 3387 3388 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3389 return TEST_SKIPPED; 3390 3391 /* Verify the capabilities */ 3392 struct rte_cryptodev_sym_capability_idx cap_idx; 3393 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3394 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3395 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3396 &cap_idx) == NULL) 3397 return TEST_SKIPPED; 3398 3399 /* Create KASUMI session */ 3400 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3401 tdata->key.data, tdata->key.len, 3402 0, tdata->digest.len, 3403 RTE_CRYPTO_AUTH_OP_VERIFY, 3404 RTE_CRYPTO_AUTH_KASUMI_F9); 3405 if (retval < 0) 3406 return retval; 3407 /* alloc mbuf and set payload */ 3408 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3409 3410 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3411 rte_pktmbuf_tailroom(ut_params->ibuf)); 3412 3413 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3414 /* Append data which is padded to a multiple */ 3415 /* of the algorithms block size */ 3416 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3417 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3418 plaintext_pad_len); 3419 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3420 3421 /* Create KASUMI operation */ 3422 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3423 tdata->digest.len, 3424 NULL, 0, 3425 plaintext_pad_len, 3426 RTE_CRYPTO_AUTH_OP_VERIFY, 3427 tdata->plaintext.len, 3428 0); 3429 if (retval < 0) 3430 return retval; 3431 3432 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3433 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3434 ut_params->op, 0, 1, 1, 0); 3435 else 3436 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3437 ut_params->op); 3438 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3439 ut_params->obuf = ut_params->op->sym->m_src; 3440 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3441 + plaintext_pad_len; 3442 3443 /* Validate obuf */ 3444 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3445 return 0; 3446 else 3447 return -1; 3448 3449 return 0; 3450 } 3451 3452 static int 3453 test_snow3g_hash_generate_test_case_1(void) 3454 { 3455 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3456 } 3457 3458 static int 3459 test_snow3g_hash_generate_test_case_2(void) 3460 { 3461 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3462 } 3463 3464 static int 3465 test_snow3g_hash_generate_test_case_3(void) 3466 { 3467 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3468 } 3469 3470 static int 3471 test_snow3g_hash_generate_test_case_4(void) 3472 { 3473 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3474 } 3475 3476 static int 3477 test_snow3g_hash_generate_test_case_5(void) 3478 { 3479 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3480 } 3481 3482 static int 3483 test_snow3g_hash_generate_test_case_6(void) 3484 { 3485 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3486 } 3487 3488 static int 3489 test_snow3g_hash_verify_test_case_1(void) 3490 { 3491 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3492 3493 } 3494 3495 static int 3496 test_snow3g_hash_verify_test_case_2(void) 3497 { 3498 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3499 } 3500 3501 static int 3502 test_snow3g_hash_verify_test_case_3(void) 3503 { 3504 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3505 } 3506 3507 static int 3508 test_snow3g_hash_verify_test_case_4(void) 3509 { 3510 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3511 } 3512 3513 static int 3514 test_snow3g_hash_verify_test_case_5(void) 3515 { 3516 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3517 } 3518 3519 static int 3520 test_snow3g_hash_verify_test_case_6(void) 3521 { 3522 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3523 } 3524 3525 static int 3526 test_kasumi_hash_generate_test_case_1(void) 3527 { 3528 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3529 } 3530 3531 static int 3532 test_kasumi_hash_generate_test_case_2(void) 3533 { 3534 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3535 } 3536 3537 static int 3538 test_kasumi_hash_generate_test_case_3(void) 3539 { 3540 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3541 } 3542 3543 static int 3544 test_kasumi_hash_generate_test_case_4(void) 3545 { 3546 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3547 } 3548 3549 static int 3550 test_kasumi_hash_generate_test_case_5(void) 3551 { 3552 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3553 } 3554 3555 static int 3556 test_kasumi_hash_generate_test_case_6(void) 3557 { 3558 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3559 } 3560 3561 static int 3562 test_kasumi_hash_verify_test_case_1(void) 3563 { 3564 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3565 } 3566 3567 static int 3568 test_kasumi_hash_verify_test_case_2(void) 3569 { 3570 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3571 } 3572 3573 static int 3574 test_kasumi_hash_verify_test_case_3(void) 3575 { 3576 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3577 } 3578 3579 static int 3580 test_kasumi_hash_verify_test_case_4(void) 3581 { 3582 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3583 } 3584 3585 static int 3586 test_kasumi_hash_verify_test_case_5(void) 3587 { 3588 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3589 } 3590 3591 static int 3592 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3593 { 3594 struct crypto_testsuite_params *ts_params = &testsuite_params; 3595 struct crypto_unittest_params *ut_params = &unittest_params; 3596 3597 int retval; 3598 uint8_t *plaintext, *ciphertext; 3599 unsigned plaintext_pad_len; 3600 unsigned plaintext_len; 3601 struct rte_cryptodev_info dev_info; 3602 3603 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3604 uint64_t feat_flags = dev_info.feature_flags; 3605 3606 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3607 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3608 printf("Device doesn't support RAW data-path APIs.\n"); 3609 return TEST_SKIPPED; 3610 } 3611 3612 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3613 return TEST_SKIPPED; 3614 3615 /* Verify the capabilities */ 3616 struct rte_cryptodev_sym_capability_idx cap_idx; 3617 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3618 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3619 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3620 &cap_idx) == NULL) 3621 return TEST_SKIPPED; 3622 3623 /* Create KASUMI session */ 3624 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3625 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3626 RTE_CRYPTO_CIPHER_KASUMI_F8, 3627 tdata->key.data, tdata->key.len, 3628 tdata->cipher_iv.len); 3629 if (retval < 0) 3630 return retval; 3631 3632 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3633 3634 /* Clear mbuf payload */ 3635 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3636 rte_pktmbuf_tailroom(ut_params->ibuf)); 3637 3638 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3639 /* Append data which is padded to a multiple */ 3640 /* of the algorithms block size */ 3641 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3642 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3643 plaintext_pad_len); 3644 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3645 3646 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3647 3648 /* Create KASUMI operation */ 3649 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3650 tdata->cipher_iv.len, 3651 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3652 tdata->validCipherOffsetInBits.len); 3653 if (retval < 0) 3654 return retval; 3655 3656 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3657 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3658 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3659 else 3660 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3661 ut_params->op); 3662 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3663 3664 ut_params->obuf = ut_params->op->sym->m_dst; 3665 if (ut_params->obuf) 3666 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3667 else 3668 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3669 3670 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3671 3672 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3673 (tdata->validCipherOffsetInBits.len >> 3); 3674 /* Validate obuf */ 3675 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3676 ciphertext, 3677 reference_ciphertext, 3678 tdata->validCipherLenInBits.len, 3679 "KASUMI Ciphertext data not as expected"); 3680 return 0; 3681 } 3682 3683 static int 3684 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3685 { 3686 struct crypto_testsuite_params *ts_params = &testsuite_params; 3687 struct crypto_unittest_params *ut_params = &unittest_params; 3688 3689 int retval; 3690 3691 unsigned int plaintext_pad_len; 3692 unsigned int plaintext_len; 3693 3694 uint8_t buffer[10000]; 3695 const uint8_t *ciphertext; 3696 3697 struct rte_cryptodev_info dev_info; 3698 3699 /* Verify the capabilities */ 3700 struct rte_cryptodev_sym_capability_idx cap_idx; 3701 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3702 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3703 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3704 &cap_idx) == NULL) 3705 return TEST_SKIPPED; 3706 3707 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3708 3709 uint64_t feat_flags = dev_info.feature_flags; 3710 3711 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3712 printf("Device doesn't support in-place scatter-gather. " 3713 "Test Skipped.\n"); 3714 return TEST_SKIPPED; 3715 } 3716 3717 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3718 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3719 printf("Device doesn't support RAW data-path APIs.\n"); 3720 return TEST_SKIPPED; 3721 } 3722 3723 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3724 return TEST_SKIPPED; 3725 3726 /* Create KASUMI session */ 3727 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3728 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3729 RTE_CRYPTO_CIPHER_KASUMI_F8, 3730 tdata->key.data, tdata->key.len, 3731 tdata->cipher_iv.len); 3732 if (retval < 0) 3733 return retval; 3734 3735 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3736 3737 3738 /* Append data which is padded to a multiple */ 3739 /* of the algorithms block size */ 3740 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3741 3742 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3743 plaintext_pad_len, 10, 0); 3744 3745 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3746 3747 /* Create KASUMI operation */ 3748 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3749 tdata->cipher_iv.len, 3750 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3751 tdata->validCipherOffsetInBits.len); 3752 if (retval < 0) 3753 return retval; 3754 3755 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3756 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3757 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3758 else 3759 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3760 ut_params->op); 3761 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3762 3763 ut_params->obuf = ut_params->op->sym->m_dst; 3764 3765 if (ut_params->obuf) 3766 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3767 plaintext_len, buffer); 3768 else 3769 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3770 tdata->validCipherOffsetInBits.len >> 3, 3771 plaintext_len, buffer); 3772 3773 /* Validate obuf */ 3774 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3775 3776 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3777 (tdata->validCipherOffsetInBits.len >> 3); 3778 /* Validate obuf */ 3779 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3780 ciphertext, 3781 reference_ciphertext, 3782 tdata->validCipherLenInBits.len, 3783 "KASUMI Ciphertext data not as expected"); 3784 return 0; 3785 } 3786 3787 static int 3788 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3789 { 3790 struct crypto_testsuite_params *ts_params = &testsuite_params; 3791 struct crypto_unittest_params *ut_params = &unittest_params; 3792 3793 int retval; 3794 uint8_t *plaintext, *ciphertext; 3795 unsigned plaintext_pad_len; 3796 unsigned plaintext_len; 3797 3798 /* Verify the capabilities */ 3799 struct rte_cryptodev_sym_capability_idx cap_idx; 3800 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3801 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3802 /* Data-path service does not support OOP */ 3803 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3804 &cap_idx) == NULL) 3805 return TEST_SKIPPED; 3806 3807 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3808 return TEST_SKIPPED; 3809 3810 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3811 return TEST_SKIPPED; 3812 3813 /* Create KASUMI session */ 3814 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3815 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3816 RTE_CRYPTO_CIPHER_KASUMI_F8, 3817 tdata->key.data, tdata->key.len, 3818 tdata->cipher_iv.len); 3819 if (retval < 0) 3820 return retval; 3821 3822 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3823 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3824 3825 /* Clear mbuf payload */ 3826 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3827 rte_pktmbuf_tailroom(ut_params->ibuf)); 3828 3829 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3830 /* Append data which is padded to a multiple */ 3831 /* of the algorithms block size */ 3832 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3833 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3834 plaintext_pad_len); 3835 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3836 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3837 3838 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3839 3840 /* Create KASUMI operation */ 3841 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3842 tdata->cipher_iv.len, 3843 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3844 tdata->validCipherOffsetInBits.len); 3845 if (retval < 0) 3846 return retval; 3847 3848 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3849 ut_params->op); 3850 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3851 3852 ut_params->obuf = ut_params->op->sym->m_dst; 3853 if (ut_params->obuf) 3854 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3855 else 3856 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3857 3858 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3859 3860 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3861 (tdata->validCipherOffsetInBits.len >> 3); 3862 /* Validate obuf */ 3863 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3864 ciphertext, 3865 reference_ciphertext, 3866 tdata->validCipherLenInBits.len, 3867 "KASUMI Ciphertext data not as expected"); 3868 return 0; 3869 } 3870 3871 static int 3872 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3873 { 3874 struct crypto_testsuite_params *ts_params = &testsuite_params; 3875 struct crypto_unittest_params *ut_params = &unittest_params; 3876 3877 int retval; 3878 unsigned int plaintext_pad_len; 3879 unsigned int plaintext_len; 3880 3881 const uint8_t *ciphertext; 3882 uint8_t buffer[2048]; 3883 3884 struct rte_cryptodev_info dev_info; 3885 3886 /* Verify the capabilities */ 3887 struct rte_cryptodev_sym_capability_idx cap_idx; 3888 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3889 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3890 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3891 &cap_idx) == NULL) 3892 return TEST_SKIPPED; 3893 3894 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3895 return TEST_SKIPPED; 3896 3897 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3898 return TEST_SKIPPED; 3899 3900 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3901 3902 uint64_t feat_flags = dev_info.feature_flags; 3903 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3904 printf("Device doesn't support out-of-place scatter-gather " 3905 "in both input and output mbufs. " 3906 "Test Skipped.\n"); 3907 return TEST_SKIPPED; 3908 } 3909 3910 /* Create KASUMI session */ 3911 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3912 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3913 RTE_CRYPTO_CIPHER_KASUMI_F8, 3914 tdata->key.data, tdata->key.len, 3915 tdata->cipher_iv.len); 3916 if (retval < 0) 3917 return retval; 3918 3919 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3920 /* Append data which is padded to a multiple */ 3921 /* of the algorithms block size */ 3922 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3923 3924 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3925 plaintext_pad_len, 10, 0); 3926 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3927 plaintext_pad_len, 3, 0); 3928 3929 /* Append data which is padded to a multiple */ 3930 /* of the algorithms block size */ 3931 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3932 3933 /* Create KASUMI operation */ 3934 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3935 tdata->cipher_iv.len, 3936 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3937 tdata->validCipherOffsetInBits.len); 3938 if (retval < 0) 3939 return retval; 3940 3941 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3942 ut_params->op); 3943 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3944 3945 ut_params->obuf = ut_params->op->sym->m_dst; 3946 if (ut_params->obuf) 3947 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3948 plaintext_pad_len, buffer); 3949 else 3950 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3951 tdata->validCipherOffsetInBits.len >> 3, 3952 plaintext_pad_len, buffer); 3953 3954 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3955 (tdata->validCipherOffsetInBits.len >> 3); 3956 /* Validate obuf */ 3957 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3958 ciphertext, 3959 reference_ciphertext, 3960 tdata->validCipherLenInBits.len, 3961 "KASUMI Ciphertext data not as expected"); 3962 return 0; 3963 } 3964 3965 3966 static int 3967 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3968 { 3969 struct crypto_testsuite_params *ts_params = &testsuite_params; 3970 struct crypto_unittest_params *ut_params = &unittest_params; 3971 3972 int retval; 3973 uint8_t *ciphertext, *plaintext; 3974 unsigned ciphertext_pad_len; 3975 unsigned ciphertext_len; 3976 3977 /* Verify the capabilities */ 3978 struct rte_cryptodev_sym_capability_idx cap_idx; 3979 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3980 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3981 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3982 &cap_idx) == NULL) 3983 return TEST_SKIPPED; 3984 3985 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3986 return TEST_SKIPPED; 3987 3988 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3989 return TEST_SKIPPED; 3990 3991 /* Create KASUMI session */ 3992 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3993 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3994 RTE_CRYPTO_CIPHER_KASUMI_F8, 3995 tdata->key.data, tdata->key.len, 3996 tdata->cipher_iv.len); 3997 if (retval < 0) 3998 return retval; 3999 4000 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4001 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4002 4003 /* Clear mbuf payload */ 4004 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4005 rte_pktmbuf_tailroom(ut_params->ibuf)); 4006 4007 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4008 /* Append data which is padded to a multiple */ 4009 /* of the algorithms block size */ 4010 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4011 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4012 ciphertext_pad_len); 4013 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4014 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4015 4016 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4017 4018 /* Create KASUMI operation */ 4019 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4020 tdata->cipher_iv.len, 4021 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4022 tdata->validCipherOffsetInBits.len); 4023 if (retval < 0) 4024 return retval; 4025 4026 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4027 ut_params->op); 4028 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4029 4030 ut_params->obuf = ut_params->op->sym->m_dst; 4031 if (ut_params->obuf) 4032 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4033 else 4034 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4035 4036 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4037 4038 const uint8_t *reference_plaintext = tdata->plaintext.data + 4039 (tdata->validCipherOffsetInBits.len >> 3); 4040 /* Validate obuf */ 4041 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4042 plaintext, 4043 reference_plaintext, 4044 tdata->validCipherLenInBits.len, 4045 "KASUMI Plaintext data not as expected"); 4046 return 0; 4047 } 4048 4049 static int 4050 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4051 { 4052 struct crypto_testsuite_params *ts_params = &testsuite_params; 4053 struct crypto_unittest_params *ut_params = &unittest_params; 4054 4055 int retval; 4056 uint8_t *ciphertext, *plaintext; 4057 unsigned ciphertext_pad_len; 4058 unsigned ciphertext_len; 4059 struct rte_cryptodev_info dev_info; 4060 4061 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4062 uint64_t feat_flags = dev_info.feature_flags; 4063 4064 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4065 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4066 printf("Device doesn't support RAW data-path APIs.\n"); 4067 return TEST_SKIPPED; 4068 } 4069 4070 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4071 return TEST_SKIPPED; 4072 4073 /* Verify the capabilities */ 4074 struct rte_cryptodev_sym_capability_idx cap_idx; 4075 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4076 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4077 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4078 &cap_idx) == NULL) 4079 return TEST_SKIPPED; 4080 4081 /* Create KASUMI session */ 4082 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4083 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4084 RTE_CRYPTO_CIPHER_KASUMI_F8, 4085 tdata->key.data, tdata->key.len, 4086 tdata->cipher_iv.len); 4087 if (retval < 0) 4088 return retval; 4089 4090 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4091 4092 /* Clear mbuf payload */ 4093 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4094 rte_pktmbuf_tailroom(ut_params->ibuf)); 4095 4096 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4097 /* Append data which is padded to a multiple */ 4098 /* of the algorithms block size */ 4099 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4100 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4101 ciphertext_pad_len); 4102 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4103 4104 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4105 4106 /* Create KASUMI operation */ 4107 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4108 tdata->cipher_iv.len, 4109 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4110 tdata->validCipherOffsetInBits.len); 4111 if (retval < 0) 4112 return retval; 4113 4114 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4115 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4116 ut_params->op, 1, 0, 1, 0); 4117 else 4118 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4119 ut_params->op); 4120 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4121 4122 ut_params->obuf = ut_params->op->sym->m_dst; 4123 if (ut_params->obuf) 4124 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4125 else 4126 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4127 4128 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4129 4130 const uint8_t *reference_plaintext = tdata->plaintext.data + 4131 (tdata->validCipherOffsetInBits.len >> 3); 4132 /* Validate obuf */ 4133 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4134 plaintext, 4135 reference_plaintext, 4136 tdata->validCipherLenInBits.len, 4137 "KASUMI Plaintext data not as expected"); 4138 return 0; 4139 } 4140 4141 static int 4142 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4143 { 4144 struct crypto_testsuite_params *ts_params = &testsuite_params; 4145 struct crypto_unittest_params *ut_params = &unittest_params; 4146 4147 int retval; 4148 uint8_t *plaintext, *ciphertext; 4149 unsigned plaintext_pad_len; 4150 unsigned plaintext_len; 4151 struct rte_cryptodev_info dev_info; 4152 4153 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4154 uint64_t feat_flags = dev_info.feature_flags; 4155 4156 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4157 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4158 printf("Device doesn't support RAW data-path APIs.\n"); 4159 return TEST_SKIPPED; 4160 } 4161 4162 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4163 return TEST_SKIPPED; 4164 4165 /* Verify the capabilities */ 4166 struct rte_cryptodev_sym_capability_idx cap_idx; 4167 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4168 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4169 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4170 &cap_idx) == NULL) 4171 return TEST_SKIPPED; 4172 4173 /* Create SNOW 3G session */ 4174 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4175 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4176 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4177 tdata->key.data, tdata->key.len, 4178 tdata->cipher_iv.len); 4179 if (retval < 0) 4180 return retval; 4181 4182 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4183 4184 /* Clear mbuf payload */ 4185 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4186 rte_pktmbuf_tailroom(ut_params->ibuf)); 4187 4188 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4189 /* Append data which is padded to a multiple of */ 4190 /* the algorithms block size */ 4191 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4192 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4193 plaintext_pad_len); 4194 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4195 4196 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4197 4198 /* Create SNOW 3G operation */ 4199 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4200 tdata->cipher_iv.len, 4201 tdata->validCipherLenInBits.len, 4202 0); 4203 if (retval < 0) 4204 return retval; 4205 4206 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4207 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4208 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4209 else 4210 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4211 ut_params->op); 4212 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4213 4214 ut_params->obuf = ut_params->op->sym->m_dst; 4215 if (ut_params->obuf) 4216 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4217 else 4218 ciphertext = plaintext; 4219 4220 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4221 4222 /* Validate obuf */ 4223 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4224 ciphertext, 4225 tdata->ciphertext.data, 4226 tdata->validDataLenInBits.len, 4227 "SNOW 3G Ciphertext data not as expected"); 4228 return 0; 4229 } 4230 4231 4232 static int 4233 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4234 { 4235 struct crypto_testsuite_params *ts_params = &testsuite_params; 4236 struct crypto_unittest_params *ut_params = &unittest_params; 4237 uint8_t *plaintext, *ciphertext; 4238 4239 int retval; 4240 unsigned plaintext_pad_len; 4241 unsigned plaintext_len; 4242 struct rte_cryptodev_info dev_info; 4243 4244 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4245 uint64_t feat_flags = dev_info.feature_flags; 4246 4247 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4248 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4249 printf("Device does not support RAW data-path APIs.\n"); 4250 return -ENOTSUP; 4251 } 4252 4253 /* Verify the capabilities */ 4254 struct rte_cryptodev_sym_capability_idx cap_idx; 4255 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4256 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4257 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4258 &cap_idx) == NULL) 4259 return TEST_SKIPPED; 4260 4261 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4262 return TEST_SKIPPED; 4263 4264 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4265 return TEST_SKIPPED; 4266 4267 /* Create SNOW 3G session */ 4268 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4269 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4270 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4271 tdata->key.data, tdata->key.len, 4272 tdata->cipher_iv.len); 4273 if (retval < 0) 4274 return retval; 4275 4276 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4277 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4278 4279 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4280 "Failed to allocate input buffer in mempool"); 4281 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4282 "Failed to allocate output buffer in mempool"); 4283 4284 /* Clear mbuf payload */ 4285 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4286 rte_pktmbuf_tailroom(ut_params->ibuf)); 4287 4288 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4289 /* Append data which is padded to a multiple of */ 4290 /* the algorithms block size */ 4291 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4292 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4293 plaintext_pad_len); 4294 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4295 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4296 4297 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4298 4299 /* Create SNOW 3G operation */ 4300 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4301 tdata->cipher_iv.len, 4302 tdata->validCipherLenInBits.len, 4303 0); 4304 if (retval < 0) 4305 return retval; 4306 4307 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4308 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4309 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4310 else 4311 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4312 ut_params->op); 4313 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4314 4315 ut_params->obuf = ut_params->op->sym->m_dst; 4316 if (ut_params->obuf) 4317 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4318 else 4319 ciphertext = plaintext; 4320 4321 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4322 4323 /* Validate obuf */ 4324 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4325 ciphertext, 4326 tdata->ciphertext.data, 4327 tdata->validDataLenInBits.len, 4328 "SNOW 3G Ciphertext data not as expected"); 4329 return 0; 4330 } 4331 4332 static int 4333 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4334 { 4335 struct crypto_testsuite_params *ts_params = &testsuite_params; 4336 struct crypto_unittest_params *ut_params = &unittest_params; 4337 4338 int retval; 4339 unsigned int plaintext_pad_len; 4340 unsigned int plaintext_len; 4341 uint8_t buffer[10000]; 4342 const uint8_t *ciphertext; 4343 4344 struct rte_cryptodev_info dev_info; 4345 4346 /* Verify the capabilities */ 4347 struct rte_cryptodev_sym_capability_idx cap_idx; 4348 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4349 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4350 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4351 &cap_idx) == NULL) 4352 return TEST_SKIPPED; 4353 4354 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4355 return TEST_SKIPPED; 4356 4357 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4358 return TEST_SKIPPED; 4359 4360 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4361 4362 uint64_t feat_flags = dev_info.feature_flags; 4363 4364 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4365 printf("Device doesn't support out-of-place scatter-gather " 4366 "in both input and output mbufs. " 4367 "Test Skipped.\n"); 4368 return TEST_SKIPPED; 4369 } 4370 4371 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4372 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4373 printf("Device does not support RAW data-path APIs.\n"); 4374 return -ENOTSUP; 4375 } 4376 4377 /* Create SNOW 3G session */ 4378 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4379 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4380 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4381 tdata->key.data, tdata->key.len, 4382 tdata->cipher_iv.len); 4383 if (retval < 0) 4384 return retval; 4385 4386 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4387 /* Append data which is padded to a multiple of */ 4388 /* the algorithms block size */ 4389 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4390 4391 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4392 plaintext_pad_len, 10, 0); 4393 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4394 plaintext_pad_len, 3, 0); 4395 4396 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4397 "Failed to allocate input buffer in mempool"); 4398 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4399 "Failed to allocate output buffer in mempool"); 4400 4401 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4402 4403 /* Create SNOW 3G operation */ 4404 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4405 tdata->cipher_iv.len, 4406 tdata->validCipherLenInBits.len, 4407 0); 4408 if (retval < 0) 4409 return retval; 4410 4411 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4412 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4413 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4414 else 4415 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4416 ut_params->op); 4417 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4418 4419 ut_params->obuf = ut_params->op->sym->m_dst; 4420 if (ut_params->obuf) 4421 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4422 plaintext_len, buffer); 4423 else 4424 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4425 plaintext_len, buffer); 4426 4427 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4428 4429 /* Validate obuf */ 4430 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4431 ciphertext, 4432 tdata->ciphertext.data, 4433 tdata->validDataLenInBits.len, 4434 "SNOW 3G Ciphertext data not as expected"); 4435 4436 return 0; 4437 } 4438 4439 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4440 static void 4441 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4442 { 4443 uint8_t curr_byte, prev_byte; 4444 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4445 uint8_t lower_byte_mask = (1 << offset) - 1; 4446 unsigned i; 4447 4448 prev_byte = buffer[0]; 4449 buffer[0] >>= offset; 4450 4451 for (i = 1; i < length_in_bytes; i++) { 4452 curr_byte = buffer[i]; 4453 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4454 (curr_byte >> offset); 4455 prev_byte = curr_byte; 4456 } 4457 } 4458 4459 static int 4460 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4461 { 4462 struct crypto_testsuite_params *ts_params = &testsuite_params; 4463 struct crypto_unittest_params *ut_params = &unittest_params; 4464 uint8_t *plaintext, *ciphertext; 4465 int retval; 4466 uint32_t plaintext_len; 4467 uint32_t plaintext_pad_len; 4468 uint8_t extra_offset = 4; 4469 uint8_t *expected_ciphertext_shifted; 4470 struct rte_cryptodev_info dev_info; 4471 4472 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4473 uint64_t feat_flags = dev_info.feature_flags; 4474 4475 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4476 ((tdata->validDataLenInBits.len % 8) != 0)) { 4477 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4478 return TEST_SKIPPED; 4479 } 4480 4481 /* Verify the capabilities */ 4482 struct rte_cryptodev_sym_capability_idx cap_idx; 4483 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4484 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4485 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4486 &cap_idx) == NULL) 4487 return TEST_SKIPPED; 4488 4489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4490 return TEST_SKIPPED; 4491 4492 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4493 return TEST_SKIPPED; 4494 4495 /* Create SNOW 3G session */ 4496 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4497 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4498 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4499 tdata->key.data, tdata->key.len, 4500 tdata->cipher_iv.len); 4501 if (retval < 0) 4502 return retval; 4503 4504 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4505 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4506 4507 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4508 "Failed to allocate input buffer in mempool"); 4509 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4510 "Failed to allocate output buffer in mempool"); 4511 4512 /* Clear mbuf payload */ 4513 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4514 rte_pktmbuf_tailroom(ut_params->ibuf)); 4515 4516 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4517 /* 4518 * Append data which is padded to a 4519 * multiple of the algorithms block size 4520 */ 4521 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4522 4523 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4524 plaintext_pad_len); 4525 4526 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4527 4528 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4529 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4530 4531 #ifdef RTE_APP_TEST_DEBUG 4532 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4533 #endif 4534 /* Create SNOW 3G operation */ 4535 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4536 tdata->cipher_iv.len, 4537 tdata->validCipherLenInBits.len, 4538 extra_offset); 4539 if (retval < 0) 4540 return retval; 4541 4542 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4543 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4544 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4545 else 4546 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4547 ut_params->op); 4548 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4549 4550 ut_params->obuf = ut_params->op->sym->m_dst; 4551 if (ut_params->obuf) 4552 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4553 else 4554 ciphertext = plaintext; 4555 4556 #ifdef RTE_APP_TEST_DEBUG 4557 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4558 #endif 4559 4560 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4561 4562 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4563 "failed to reserve memory for ciphertext shifted\n"); 4564 4565 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4566 ceil_byte_length(tdata->ciphertext.len)); 4567 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4568 extra_offset); 4569 /* Validate obuf */ 4570 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4571 ciphertext, 4572 expected_ciphertext_shifted, 4573 tdata->validDataLenInBits.len, 4574 extra_offset, 4575 "SNOW 3G Ciphertext data not as expected"); 4576 return 0; 4577 } 4578 4579 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4580 { 4581 struct crypto_testsuite_params *ts_params = &testsuite_params; 4582 struct crypto_unittest_params *ut_params = &unittest_params; 4583 4584 int retval; 4585 4586 uint8_t *plaintext, *ciphertext; 4587 unsigned ciphertext_pad_len; 4588 unsigned ciphertext_len; 4589 struct rte_cryptodev_info dev_info; 4590 4591 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4592 uint64_t feat_flags = dev_info.feature_flags; 4593 4594 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4595 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4596 printf("Device doesn't support RAW data-path APIs.\n"); 4597 return TEST_SKIPPED; 4598 } 4599 4600 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4601 return TEST_SKIPPED; 4602 4603 /* Verify the capabilities */ 4604 struct rte_cryptodev_sym_capability_idx cap_idx; 4605 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4606 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4607 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4608 &cap_idx) == NULL) 4609 return TEST_SKIPPED; 4610 4611 /* Create SNOW 3G session */ 4612 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4613 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4614 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4615 tdata->key.data, tdata->key.len, 4616 tdata->cipher_iv.len); 4617 if (retval < 0) 4618 return retval; 4619 4620 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4621 4622 /* Clear mbuf payload */ 4623 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4624 rte_pktmbuf_tailroom(ut_params->ibuf)); 4625 4626 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4627 /* Append data which is padded to a multiple of */ 4628 /* the algorithms block size */ 4629 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4630 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4631 ciphertext_pad_len); 4632 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4633 4634 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4635 4636 /* Create SNOW 3G operation */ 4637 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4638 tdata->cipher_iv.len, 4639 tdata->validCipherLenInBits.len, 4640 tdata->cipher.offset_bits); 4641 if (retval < 0) 4642 return retval; 4643 4644 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4645 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4646 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4647 else 4648 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4649 ut_params->op); 4650 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4651 ut_params->obuf = ut_params->op->sym->m_dst; 4652 if (ut_params->obuf) 4653 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4654 else 4655 plaintext = ciphertext; 4656 4657 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4658 4659 /* Validate obuf */ 4660 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4661 tdata->plaintext.data, 4662 tdata->validDataLenInBits.len, 4663 "SNOW 3G Plaintext data not as expected"); 4664 return 0; 4665 } 4666 4667 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4668 { 4669 struct crypto_testsuite_params *ts_params = &testsuite_params; 4670 struct crypto_unittest_params *ut_params = &unittest_params; 4671 4672 int retval; 4673 4674 uint8_t *plaintext, *ciphertext; 4675 unsigned ciphertext_pad_len; 4676 unsigned ciphertext_len; 4677 struct rte_cryptodev_info dev_info; 4678 4679 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4680 uint64_t feat_flags = dev_info.feature_flags; 4681 4682 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4683 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4684 printf("Device does not support RAW data-path APIs.\n"); 4685 return -ENOTSUP; 4686 } 4687 /* Verify the capabilities */ 4688 struct rte_cryptodev_sym_capability_idx cap_idx; 4689 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4690 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4691 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4692 &cap_idx) == NULL) 4693 return TEST_SKIPPED; 4694 4695 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4696 return TEST_SKIPPED; 4697 4698 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4699 return TEST_SKIPPED; 4700 4701 /* Create SNOW 3G session */ 4702 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4703 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4704 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4705 tdata->key.data, tdata->key.len, 4706 tdata->cipher_iv.len); 4707 if (retval < 0) 4708 return retval; 4709 4710 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4711 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4712 4713 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4714 "Failed to allocate input buffer"); 4715 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4716 "Failed to allocate output buffer"); 4717 4718 /* Clear mbuf payload */ 4719 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4720 rte_pktmbuf_tailroom(ut_params->ibuf)); 4721 4722 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4723 rte_pktmbuf_tailroom(ut_params->obuf)); 4724 4725 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4726 /* Append data which is padded to a multiple of */ 4727 /* the algorithms block size */ 4728 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4729 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4730 ciphertext_pad_len); 4731 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4732 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4733 4734 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4735 4736 /* Create SNOW 3G operation */ 4737 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4738 tdata->cipher_iv.len, 4739 tdata->validCipherLenInBits.len, 4740 0); 4741 if (retval < 0) 4742 return retval; 4743 4744 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4745 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4746 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4747 else 4748 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4749 ut_params->op); 4750 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4751 ut_params->obuf = ut_params->op->sym->m_dst; 4752 if (ut_params->obuf) 4753 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4754 else 4755 plaintext = ciphertext; 4756 4757 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4758 4759 /* Validate obuf */ 4760 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4761 tdata->plaintext.data, 4762 tdata->validDataLenInBits.len, 4763 "SNOW 3G Plaintext data not as expected"); 4764 return 0; 4765 } 4766 4767 static int 4768 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4769 { 4770 struct crypto_testsuite_params *ts_params = &testsuite_params; 4771 struct crypto_unittest_params *ut_params = &unittest_params; 4772 4773 int retval; 4774 4775 uint8_t *plaintext, *ciphertext; 4776 unsigned int plaintext_pad_len; 4777 unsigned int plaintext_len; 4778 4779 struct rte_cryptodev_info dev_info; 4780 struct rte_cryptodev_sym_capability_idx cap_idx; 4781 4782 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4783 uint64_t feat_flags = dev_info.feature_flags; 4784 4785 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4786 ((tdata->validAuthLenInBits.len % 8 != 0) || 4787 (tdata->validDataLenInBits.len % 8 != 0))) { 4788 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4789 return TEST_SKIPPED; 4790 } 4791 4792 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4793 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4794 printf("Device doesn't support RAW data-path APIs.\n"); 4795 return TEST_SKIPPED; 4796 } 4797 4798 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4799 return TEST_SKIPPED; 4800 4801 /* Check if device supports ZUC EEA3 */ 4802 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4803 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4804 4805 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4806 &cap_idx) == NULL) 4807 return TEST_SKIPPED; 4808 4809 /* Check if device supports ZUC EIA3 */ 4810 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4811 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4812 4813 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4814 &cap_idx) == NULL) 4815 return TEST_SKIPPED; 4816 4817 /* Create ZUC session */ 4818 retval = create_zuc_cipher_auth_encrypt_generate_session( 4819 ts_params->valid_devs[0], 4820 tdata); 4821 if (retval != 0) 4822 return retval; 4823 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4824 4825 /* clear mbuf payload */ 4826 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4827 rte_pktmbuf_tailroom(ut_params->ibuf)); 4828 4829 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4830 /* Append data which is padded to a multiple of */ 4831 /* the algorithms block size */ 4832 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4833 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4834 plaintext_pad_len); 4835 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4836 4837 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4838 4839 /* Create ZUC operation */ 4840 retval = create_zuc_cipher_hash_generate_operation(tdata); 4841 if (retval < 0) 4842 return retval; 4843 4844 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4845 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4846 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4847 else 4848 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4849 ut_params->op); 4850 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4851 ut_params->obuf = ut_params->op->sym->m_src; 4852 if (ut_params->obuf) 4853 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4854 else 4855 ciphertext = plaintext; 4856 4857 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4858 /* Validate obuf */ 4859 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4860 ciphertext, 4861 tdata->ciphertext.data, 4862 tdata->validDataLenInBits.len, 4863 "ZUC Ciphertext data not as expected"); 4864 4865 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4866 + plaintext_pad_len; 4867 4868 /* Validate obuf */ 4869 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4870 ut_params->digest, 4871 tdata->digest.data, 4872 4, 4873 "ZUC Generated auth tag not as expected"); 4874 return 0; 4875 } 4876 4877 static int 4878 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4879 { 4880 struct crypto_testsuite_params *ts_params = &testsuite_params; 4881 struct crypto_unittest_params *ut_params = &unittest_params; 4882 4883 int retval; 4884 4885 uint8_t *plaintext, *ciphertext; 4886 unsigned plaintext_pad_len; 4887 unsigned plaintext_len; 4888 struct rte_cryptodev_info dev_info; 4889 4890 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4891 uint64_t feat_flags = dev_info.feature_flags; 4892 4893 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4894 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4895 printf("Device doesn't support RAW data-path APIs.\n"); 4896 return TEST_SKIPPED; 4897 } 4898 4899 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4900 return TEST_SKIPPED; 4901 4902 /* Verify the capabilities */ 4903 struct rte_cryptodev_sym_capability_idx cap_idx; 4904 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4905 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4906 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4907 &cap_idx) == NULL) 4908 return TEST_SKIPPED; 4909 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4910 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4911 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4912 &cap_idx) == NULL) 4913 return TEST_SKIPPED; 4914 4915 /* Create SNOW 3G session */ 4916 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4917 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4918 RTE_CRYPTO_AUTH_OP_GENERATE, 4919 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4920 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4921 tdata->key.data, tdata->key.len, 4922 tdata->auth_iv.len, tdata->digest.len, 4923 tdata->cipher_iv.len); 4924 if (retval != 0) 4925 return retval; 4926 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4927 4928 /* clear mbuf payload */ 4929 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4930 rte_pktmbuf_tailroom(ut_params->ibuf)); 4931 4932 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4933 /* Append data which is padded to a multiple of */ 4934 /* the algorithms block size */ 4935 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4936 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4937 plaintext_pad_len); 4938 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4939 4940 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4941 4942 /* Create SNOW 3G operation */ 4943 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4944 tdata->digest.len, tdata->auth_iv.data, 4945 tdata->auth_iv.len, 4946 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4947 tdata->cipher_iv.data, tdata->cipher_iv.len, 4948 tdata->validCipherLenInBits.len, 4949 0, 4950 tdata->validAuthLenInBits.len, 4951 0 4952 ); 4953 if (retval < 0) 4954 return retval; 4955 4956 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4957 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4958 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4959 else 4960 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4961 ut_params->op); 4962 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4963 ut_params->obuf = ut_params->op->sym->m_src; 4964 if (ut_params->obuf) 4965 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4966 else 4967 ciphertext = plaintext; 4968 4969 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4970 /* Validate obuf */ 4971 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4972 ciphertext, 4973 tdata->ciphertext.data, 4974 tdata->validDataLenInBits.len, 4975 "SNOW 3G Ciphertext data not as expected"); 4976 4977 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4978 + plaintext_pad_len; 4979 4980 /* Validate obuf */ 4981 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4982 ut_params->digest, 4983 tdata->digest.data, 4984 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4985 "SNOW 3G Generated auth tag not as expected"); 4986 return 0; 4987 } 4988 4989 static int 4990 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4991 uint8_t op_mode, uint8_t verify) 4992 { 4993 struct crypto_testsuite_params *ts_params = &testsuite_params; 4994 struct crypto_unittest_params *ut_params = &unittest_params; 4995 4996 int retval; 4997 4998 uint8_t *plaintext = NULL, *ciphertext = NULL; 4999 unsigned int plaintext_pad_len; 5000 unsigned int plaintext_len; 5001 unsigned int ciphertext_pad_len; 5002 unsigned int ciphertext_len; 5003 5004 struct rte_cryptodev_info dev_info; 5005 5006 /* Verify the capabilities */ 5007 struct rte_cryptodev_sym_capability_idx cap_idx; 5008 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5009 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5010 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5011 &cap_idx) == NULL) 5012 return TEST_SKIPPED; 5013 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5014 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5015 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5016 &cap_idx) == NULL) 5017 return TEST_SKIPPED; 5018 5019 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5020 return TEST_SKIPPED; 5021 5022 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5023 5024 uint64_t feat_flags = dev_info.feature_flags; 5025 5026 if (op_mode == OUT_OF_PLACE) { 5027 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5028 printf("Device doesn't support digest encrypted.\n"); 5029 return TEST_SKIPPED; 5030 } 5031 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5032 return TEST_SKIPPED; 5033 } 5034 5035 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5036 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5037 printf("Device doesn't support RAW data-path APIs.\n"); 5038 return TEST_SKIPPED; 5039 } 5040 5041 /* Create SNOW 3G session */ 5042 retval = create_wireless_algo_auth_cipher_session( 5043 ts_params->valid_devs[0], 5044 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5045 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5046 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5047 : RTE_CRYPTO_AUTH_OP_GENERATE), 5048 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5049 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5050 tdata->key.data, tdata->key.len, 5051 tdata->auth_iv.len, tdata->digest.len, 5052 tdata->cipher_iv.len); 5053 if (retval != 0) 5054 return retval; 5055 5056 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5057 if (op_mode == OUT_OF_PLACE) 5058 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5059 5060 /* clear mbuf payload */ 5061 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5062 rte_pktmbuf_tailroom(ut_params->ibuf)); 5063 if (op_mode == OUT_OF_PLACE) 5064 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5065 rte_pktmbuf_tailroom(ut_params->obuf)); 5066 5067 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5068 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5069 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5070 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5071 5072 if (verify) { 5073 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5074 ciphertext_pad_len); 5075 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5076 if (op_mode == OUT_OF_PLACE) 5077 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5078 debug_hexdump(stdout, "ciphertext:", ciphertext, 5079 ciphertext_len); 5080 } else { 5081 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5082 plaintext_pad_len); 5083 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5084 if (op_mode == OUT_OF_PLACE) 5085 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5086 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5087 } 5088 5089 /* Create SNOW 3G operation */ 5090 retval = create_wireless_algo_auth_cipher_operation( 5091 tdata->digest.data, tdata->digest.len, 5092 tdata->cipher_iv.data, tdata->cipher_iv.len, 5093 tdata->auth_iv.data, tdata->auth_iv.len, 5094 (tdata->digest.offset_bytes == 0 ? 5095 (verify ? ciphertext_pad_len : plaintext_pad_len) 5096 : tdata->digest.offset_bytes), 5097 tdata->validCipherLenInBits.len, 5098 tdata->cipher.offset_bits, 5099 tdata->validAuthLenInBits.len, 5100 tdata->auth.offset_bits, 5101 op_mode, 0, verify); 5102 5103 if (retval < 0) 5104 return retval; 5105 5106 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5107 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5108 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5109 else 5110 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5111 ut_params->op); 5112 5113 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5114 5115 ut_params->obuf = (op_mode == IN_PLACE ? 5116 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5117 5118 if (verify) { 5119 if (ut_params->obuf) 5120 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5121 uint8_t *); 5122 else 5123 plaintext = ciphertext + 5124 (tdata->cipher.offset_bits >> 3); 5125 5126 debug_hexdump(stdout, "plaintext:", plaintext, 5127 (tdata->plaintext.len >> 3) - tdata->digest.len); 5128 debug_hexdump(stdout, "plaintext expected:", 5129 tdata->plaintext.data, 5130 (tdata->plaintext.len >> 3) - tdata->digest.len); 5131 } else { 5132 if (ut_params->obuf) 5133 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5134 uint8_t *); 5135 else 5136 ciphertext = plaintext; 5137 5138 debug_hexdump(stdout, "ciphertext:", ciphertext, 5139 ciphertext_len); 5140 debug_hexdump(stdout, "ciphertext expected:", 5141 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5142 5143 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5144 + (tdata->digest.offset_bytes == 0 ? 5145 plaintext_pad_len : tdata->digest.offset_bytes); 5146 5147 debug_hexdump(stdout, "digest:", ut_params->digest, 5148 tdata->digest.len); 5149 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5150 tdata->digest.len); 5151 } 5152 5153 /* Validate obuf */ 5154 if (verify) { 5155 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5156 plaintext, 5157 tdata->plaintext.data, 5158 (tdata->plaintext.len - tdata->cipher.offset_bits - 5159 (tdata->digest.len << 3)), 5160 tdata->cipher.offset_bits, 5161 "SNOW 3G Plaintext data not as expected"); 5162 } else { 5163 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5164 ciphertext, 5165 tdata->ciphertext.data, 5166 (tdata->validDataLenInBits.len - 5167 tdata->cipher.offset_bits), 5168 tdata->cipher.offset_bits, 5169 "SNOW 3G Ciphertext data not as expected"); 5170 5171 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5172 ut_params->digest, 5173 tdata->digest.data, 5174 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5175 "SNOW 3G Generated auth tag not as expected"); 5176 } 5177 return 0; 5178 } 5179 5180 static int 5181 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5182 uint8_t op_mode, uint8_t verify) 5183 { 5184 struct crypto_testsuite_params *ts_params = &testsuite_params; 5185 struct crypto_unittest_params *ut_params = &unittest_params; 5186 5187 int retval; 5188 5189 const uint8_t *plaintext = NULL; 5190 const uint8_t *ciphertext = NULL; 5191 const uint8_t *digest = NULL; 5192 unsigned int plaintext_pad_len; 5193 unsigned int plaintext_len; 5194 unsigned int ciphertext_pad_len; 5195 unsigned int ciphertext_len; 5196 uint8_t buffer[10000]; 5197 uint8_t digest_buffer[10000]; 5198 5199 struct rte_cryptodev_info dev_info; 5200 5201 /* Verify the capabilities */ 5202 struct rte_cryptodev_sym_capability_idx cap_idx; 5203 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5204 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5205 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5206 &cap_idx) == NULL) 5207 return TEST_SKIPPED; 5208 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5209 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5210 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5211 &cap_idx) == NULL) 5212 return TEST_SKIPPED; 5213 5214 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5215 return TEST_SKIPPED; 5216 5217 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5218 5219 uint64_t feat_flags = dev_info.feature_flags; 5220 5221 if (op_mode == IN_PLACE) { 5222 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5223 printf("Device doesn't support in-place scatter-gather " 5224 "in both input and output mbufs.\n"); 5225 return TEST_SKIPPED; 5226 } 5227 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5228 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5229 printf("Device doesn't support RAW data-path APIs.\n"); 5230 return TEST_SKIPPED; 5231 } 5232 } else { 5233 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5234 return TEST_SKIPPED; 5235 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5236 printf("Device doesn't support out-of-place scatter-gather " 5237 "in both input and output mbufs.\n"); 5238 return TEST_SKIPPED; 5239 } 5240 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5241 printf("Device doesn't support digest encrypted.\n"); 5242 return TEST_SKIPPED; 5243 } 5244 } 5245 5246 /* Create SNOW 3G session */ 5247 retval = create_wireless_algo_auth_cipher_session( 5248 ts_params->valid_devs[0], 5249 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5250 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5251 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5252 : RTE_CRYPTO_AUTH_OP_GENERATE), 5253 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5254 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5255 tdata->key.data, tdata->key.len, 5256 tdata->auth_iv.len, tdata->digest.len, 5257 tdata->cipher_iv.len); 5258 5259 if (retval != 0) 5260 return retval; 5261 5262 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5263 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5264 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5265 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5266 5267 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5268 plaintext_pad_len, 15, 0); 5269 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5270 "Failed to allocate input buffer in mempool"); 5271 5272 if (op_mode == OUT_OF_PLACE) { 5273 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5274 plaintext_pad_len, 15, 0); 5275 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5276 "Failed to allocate output buffer in mempool"); 5277 } 5278 5279 if (verify) { 5280 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5281 tdata->ciphertext.data); 5282 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5283 ciphertext_len, buffer); 5284 debug_hexdump(stdout, "ciphertext:", ciphertext, 5285 ciphertext_len); 5286 } else { 5287 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5288 tdata->plaintext.data); 5289 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5290 plaintext_len, buffer); 5291 debug_hexdump(stdout, "plaintext:", plaintext, 5292 plaintext_len); 5293 } 5294 memset(buffer, 0, sizeof(buffer)); 5295 5296 /* Create SNOW 3G operation */ 5297 retval = create_wireless_algo_auth_cipher_operation( 5298 tdata->digest.data, tdata->digest.len, 5299 tdata->cipher_iv.data, tdata->cipher_iv.len, 5300 tdata->auth_iv.data, tdata->auth_iv.len, 5301 (tdata->digest.offset_bytes == 0 ? 5302 (verify ? ciphertext_pad_len : plaintext_pad_len) 5303 : tdata->digest.offset_bytes), 5304 tdata->validCipherLenInBits.len, 5305 tdata->cipher.offset_bits, 5306 tdata->validAuthLenInBits.len, 5307 tdata->auth.offset_bits, 5308 op_mode, 1, verify); 5309 5310 if (retval < 0) 5311 return retval; 5312 5313 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5314 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5315 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5316 else 5317 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5318 ut_params->op); 5319 5320 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5321 5322 ut_params->obuf = (op_mode == IN_PLACE ? 5323 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5324 5325 if (verify) { 5326 if (ut_params->obuf) 5327 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5328 plaintext_len, buffer); 5329 else 5330 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5331 plaintext_len, buffer); 5332 5333 debug_hexdump(stdout, "plaintext:", plaintext, 5334 (tdata->plaintext.len >> 3) - tdata->digest.len); 5335 debug_hexdump(stdout, "plaintext expected:", 5336 tdata->plaintext.data, 5337 (tdata->plaintext.len >> 3) - tdata->digest.len); 5338 } else { 5339 if (ut_params->obuf) 5340 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5341 ciphertext_len, buffer); 5342 else 5343 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5344 ciphertext_len, buffer); 5345 5346 debug_hexdump(stdout, "ciphertext:", ciphertext, 5347 ciphertext_len); 5348 debug_hexdump(stdout, "ciphertext expected:", 5349 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5350 5351 if (ut_params->obuf) 5352 digest = rte_pktmbuf_read(ut_params->obuf, 5353 (tdata->digest.offset_bytes == 0 ? 5354 plaintext_pad_len : tdata->digest.offset_bytes), 5355 tdata->digest.len, digest_buffer); 5356 else 5357 digest = rte_pktmbuf_read(ut_params->ibuf, 5358 (tdata->digest.offset_bytes == 0 ? 5359 plaintext_pad_len : tdata->digest.offset_bytes), 5360 tdata->digest.len, digest_buffer); 5361 5362 debug_hexdump(stdout, "digest:", digest, 5363 tdata->digest.len); 5364 debug_hexdump(stdout, "digest expected:", 5365 tdata->digest.data, tdata->digest.len); 5366 } 5367 5368 /* Validate obuf */ 5369 if (verify) { 5370 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5371 plaintext, 5372 tdata->plaintext.data, 5373 (tdata->plaintext.len - tdata->cipher.offset_bits - 5374 (tdata->digest.len << 3)), 5375 tdata->cipher.offset_bits, 5376 "SNOW 3G Plaintext data not as expected"); 5377 } else { 5378 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5379 ciphertext, 5380 tdata->ciphertext.data, 5381 (tdata->validDataLenInBits.len - 5382 tdata->cipher.offset_bits), 5383 tdata->cipher.offset_bits, 5384 "SNOW 3G Ciphertext data not as expected"); 5385 5386 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5387 digest, 5388 tdata->digest.data, 5389 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5390 "SNOW 3G Generated auth tag not as expected"); 5391 } 5392 return 0; 5393 } 5394 5395 static int 5396 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5397 uint8_t op_mode, uint8_t verify) 5398 { 5399 struct crypto_testsuite_params *ts_params = &testsuite_params; 5400 struct crypto_unittest_params *ut_params = &unittest_params; 5401 5402 int retval; 5403 5404 uint8_t *plaintext = NULL, *ciphertext = NULL; 5405 unsigned int plaintext_pad_len; 5406 unsigned int plaintext_len; 5407 unsigned int ciphertext_pad_len; 5408 unsigned int ciphertext_len; 5409 5410 struct rte_cryptodev_info dev_info; 5411 5412 /* Verify the capabilities */ 5413 struct rte_cryptodev_sym_capability_idx cap_idx; 5414 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5415 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5416 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5417 &cap_idx) == NULL) 5418 return TEST_SKIPPED; 5419 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5420 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5421 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5422 &cap_idx) == NULL) 5423 return TEST_SKIPPED; 5424 5425 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5426 5427 uint64_t feat_flags = dev_info.feature_flags; 5428 5429 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5430 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5431 printf("Device doesn't support RAW data-path APIs.\n"); 5432 return TEST_SKIPPED; 5433 } 5434 5435 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5436 return TEST_SKIPPED; 5437 5438 if (op_mode == OUT_OF_PLACE) { 5439 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5440 return TEST_SKIPPED; 5441 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5442 printf("Device doesn't support digest encrypted.\n"); 5443 return TEST_SKIPPED; 5444 } 5445 } 5446 5447 /* Create KASUMI session */ 5448 retval = create_wireless_algo_auth_cipher_session( 5449 ts_params->valid_devs[0], 5450 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5451 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5452 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5453 : RTE_CRYPTO_AUTH_OP_GENERATE), 5454 RTE_CRYPTO_AUTH_KASUMI_F9, 5455 RTE_CRYPTO_CIPHER_KASUMI_F8, 5456 tdata->key.data, tdata->key.len, 5457 0, tdata->digest.len, 5458 tdata->cipher_iv.len); 5459 5460 if (retval != 0) 5461 return retval; 5462 5463 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5464 if (op_mode == OUT_OF_PLACE) 5465 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5466 5467 /* clear mbuf payload */ 5468 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5469 rte_pktmbuf_tailroom(ut_params->ibuf)); 5470 if (op_mode == OUT_OF_PLACE) 5471 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5472 rte_pktmbuf_tailroom(ut_params->obuf)); 5473 5474 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5475 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5476 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5477 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5478 5479 if (verify) { 5480 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5481 ciphertext_pad_len); 5482 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5483 if (op_mode == OUT_OF_PLACE) 5484 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5485 debug_hexdump(stdout, "ciphertext:", ciphertext, 5486 ciphertext_len); 5487 } else { 5488 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5489 plaintext_pad_len); 5490 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5491 if (op_mode == OUT_OF_PLACE) 5492 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5493 debug_hexdump(stdout, "plaintext:", plaintext, 5494 plaintext_len); 5495 } 5496 5497 /* Create KASUMI operation */ 5498 retval = create_wireless_algo_auth_cipher_operation( 5499 tdata->digest.data, tdata->digest.len, 5500 tdata->cipher_iv.data, tdata->cipher_iv.len, 5501 NULL, 0, 5502 (tdata->digest.offset_bytes == 0 ? 5503 (verify ? ciphertext_pad_len : plaintext_pad_len) 5504 : tdata->digest.offset_bytes), 5505 tdata->validCipherLenInBits.len, 5506 tdata->validCipherOffsetInBits.len, 5507 tdata->validAuthLenInBits.len, 5508 0, 5509 op_mode, 0, verify); 5510 5511 if (retval < 0) 5512 return retval; 5513 5514 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5515 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5516 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5517 else 5518 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5519 ut_params->op); 5520 5521 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5522 5523 ut_params->obuf = (op_mode == IN_PLACE ? 5524 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5525 5526 5527 if (verify) { 5528 if (ut_params->obuf) 5529 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5530 uint8_t *); 5531 else 5532 plaintext = ciphertext; 5533 5534 debug_hexdump(stdout, "plaintext:", plaintext, 5535 (tdata->plaintext.len >> 3) - tdata->digest.len); 5536 debug_hexdump(stdout, "plaintext expected:", 5537 tdata->plaintext.data, 5538 (tdata->plaintext.len >> 3) - tdata->digest.len); 5539 } else { 5540 if (ut_params->obuf) 5541 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5542 uint8_t *); 5543 else 5544 ciphertext = plaintext; 5545 5546 debug_hexdump(stdout, "ciphertext:", ciphertext, 5547 ciphertext_len); 5548 debug_hexdump(stdout, "ciphertext expected:", 5549 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5550 5551 ut_params->digest = rte_pktmbuf_mtod( 5552 ut_params->obuf, uint8_t *) + 5553 (tdata->digest.offset_bytes == 0 ? 5554 plaintext_pad_len : tdata->digest.offset_bytes); 5555 5556 debug_hexdump(stdout, "digest:", ut_params->digest, 5557 tdata->digest.len); 5558 debug_hexdump(stdout, "digest expected:", 5559 tdata->digest.data, tdata->digest.len); 5560 } 5561 5562 /* Validate obuf */ 5563 if (verify) { 5564 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5565 plaintext, 5566 tdata->plaintext.data, 5567 tdata->plaintext.len >> 3, 5568 "KASUMI Plaintext data not as expected"); 5569 } else { 5570 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5571 ciphertext, 5572 tdata->ciphertext.data, 5573 tdata->ciphertext.len >> 3, 5574 "KASUMI Ciphertext data not as expected"); 5575 5576 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5577 ut_params->digest, 5578 tdata->digest.data, 5579 DIGEST_BYTE_LENGTH_KASUMI_F9, 5580 "KASUMI Generated auth tag not as expected"); 5581 } 5582 return 0; 5583 } 5584 5585 static int 5586 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5587 uint8_t op_mode, uint8_t verify) 5588 { 5589 struct crypto_testsuite_params *ts_params = &testsuite_params; 5590 struct crypto_unittest_params *ut_params = &unittest_params; 5591 5592 int retval; 5593 5594 const uint8_t *plaintext = NULL; 5595 const uint8_t *ciphertext = NULL; 5596 const uint8_t *digest = NULL; 5597 unsigned int plaintext_pad_len; 5598 unsigned int plaintext_len; 5599 unsigned int ciphertext_pad_len; 5600 unsigned int ciphertext_len; 5601 uint8_t buffer[10000]; 5602 uint8_t digest_buffer[10000]; 5603 5604 struct rte_cryptodev_info dev_info; 5605 5606 /* Verify the capabilities */ 5607 struct rte_cryptodev_sym_capability_idx cap_idx; 5608 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5609 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5610 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5611 &cap_idx) == NULL) 5612 return TEST_SKIPPED; 5613 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5614 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5615 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5616 &cap_idx) == NULL) 5617 return TEST_SKIPPED; 5618 5619 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5620 return TEST_SKIPPED; 5621 5622 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5623 5624 uint64_t feat_flags = dev_info.feature_flags; 5625 5626 if (op_mode == IN_PLACE) { 5627 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5628 printf("Device doesn't support in-place scatter-gather " 5629 "in both input and output mbufs.\n"); 5630 return TEST_SKIPPED; 5631 } 5632 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5633 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5634 printf("Device doesn't support RAW data-path APIs.\n"); 5635 return TEST_SKIPPED; 5636 } 5637 } else { 5638 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5639 return TEST_SKIPPED; 5640 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5641 printf("Device doesn't support out-of-place scatter-gather " 5642 "in both input and output mbufs.\n"); 5643 return TEST_SKIPPED; 5644 } 5645 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5646 printf("Device doesn't support digest encrypted.\n"); 5647 return TEST_SKIPPED; 5648 } 5649 } 5650 5651 /* Create KASUMI session */ 5652 retval = create_wireless_algo_auth_cipher_session( 5653 ts_params->valid_devs[0], 5654 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5655 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5656 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5657 : RTE_CRYPTO_AUTH_OP_GENERATE), 5658 RTE_CRYPTO_AUTH_KASUMI_F9, 5659 RTE_CRYPTO_CIPHER_KASUMI_F8, 5660 tdata->key.data, tdata->key.len, 5661 0, tdata->digest.len, 5662 tdata->cipher_iv.len); 5663 5664 if (retval != 0) 5665 return retval; 5666 5667 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5668 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5669 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5670 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5671 5672 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5673 plaintext_pad_len, 15, 0); 5674 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5675 "Failed to allocate input buffer in mempool"); 5676 5677 if (op_mode == OUT_OF_PLACE) { 5678 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5679 plaintext_pad_len, 15, 0); 5680 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5681 "Failed to allocate output buffer in mempool"); 5682 } 5683 5684 if (verify) { 5685 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5686 tdata->ciphertext.data); 5687 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5688 ciphertext_len, buffer); 5689 debug_hexdump(stdout, "ciphertext:", ciphertext, 5690 ciphertext_len); 5691 } else { 5692 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5693 tdata->plaintext.data); 5694 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5695 plaintext_len, buffer); 5696 debug_hexdump(stdout, "plaintext:", plaintext, 5697 plaintext_len); 5698 } 5699 memset(buffer, 0, sizeof(buffer)); 5700 5701 /* Create KASUMI operation */ 5702 retval = create_wireless_algo_auth_cipher_operation( 5703 tdata->digest.data, tdata->digest.len, 5704 tdata->cipher_iv.data, tdata->cipher_iv.len, 5705 NULL, 0, 5706 (tdata->digest.offset_bytes == 0 ? 5707 (verify ? ciphertext_pad_len : plaintext_pad_len) 5708 : tdata->digest.offset_bytes), 5709 tdata->validCipherLenInBits.len, 5710 tdata->validCipherOffsetInBits.len, 5711 tdata->validAuthLenInBits.len, 5712 0, 5713 op_mode, 1, verify); 5714 5715 if (retval < 0) 5716 return retval; 5717 5718 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5719 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5720 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5721 else 5722 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5723 ut_params->op); 5724 5725 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5726 5727 ut_params->obuf = (op_mode == IN_PLACE ? 5728 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5729 5730 if (verify) { 5731 if (ut_params->obuf) 5732 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5733 plaintext_len, buffer); 5734 else 5735 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5736 plaintext_len, buffer); 5737 5738 debug_hexdump(stdout, "plaintext:", plaintext, 5739 (tdata->plaintext.len >> 3) - tdata->digest.len); 5740 debug_hexdump(stdout, "plaintext expected:", 5741 tdata->plaintext.data, 5742 (tdata->plaintext.len >> 3) - tdata->digest.len); 5743 } else { 5744 if (ut_params->obuf) 5745 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5746 ciphertext_len, buffer); 5747 else 5748 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5749 ciphertext_len, buffer); 5750 5751 debug_hexdump(stdout, "ciphertext:", ciphertext, 5752 ciphertext_len); 5753 debug_hexdump(stdout, "ciphertext expected:", 5754 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5755 5756 if (ut_params->obuf) 5757 digest = rte_pktmbuf_read(ut_params->obuf, 5758 (tdata->digest.offset_bytes == 0 ? 5759 plaintext_pad_len : tdata->digest.offset_bytes), 5760 tdata->digest.len, digest_buffer); 5761 else 5762 digest = rte_pktmbuf_read(ut_params->ibuf, 5763 (tdata->digest.offset_bytes == 0 ? 5764 plaintext_pad_len : tdata->digest.offset_bytes), 5765 tdata->digest.len, digest_buffer); 5766 5767 debug_hexdump(stdout, "digest:", digest, 5768 tdata->digest.len); 5769 debug_hexdump(stdout, "digest expected:", 5770 tdata->digest.data, tdata->digest.len); 5771 } 5772 5773 /* Validate obuf */ 5774 if (verify) { 5775 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5776 plaintext, 5777 tdata->plaintext.data, 5778 tdata->plaintext.len >> 3, 5779 "KASUMI Plaintext data not as expected"); 5780 } else { 5781 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5782 ciphertext, 5783 tdata->ciphertext.data, 5784 tdata->validDataLenInBits.len, 5785 "KASUMI Ciphertext data not as expected"); 5786 5787 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5788 digest, 5789 tdata->digest.data, 5790 DIGEST_BYTE_LENGTH_KASUMI_F9, 5791 "KASUMI Generated auth tag not as expected"); 5792 } 5793 return 0; 5794 } 5795 5796 static int 5797 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5798 { 5799 struct crypto_testsuite_params *ts_params = &testsuite_params; 5800 struct crypto_unittest_params *ut_params = &unittest_params; 5801 5802 int retval; 5803 5804 uint8_t *plaintext, *ciphertext; 5805 unsigned plaintext_pad_len; 5806 unsigned plaintext_len; 5807 struct rte_cryptodev_info dev_info; 5808 5809 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5810 uint64_t feat_flags = dev_info.feature_flags; 5811 5812 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5813 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5814 printf("Device doesn't support RAW data-path APIs.\n"); 5815 return TEST_SKIPPED; 5816 } 5817 5818 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5819 return TEST_SKIPPED; 5820 5821 /* Verify the capabilities */ 5822 struct rte_cryptodev_sym_capability_idx cap_idx; 5823 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5824 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5825 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5826 &cap_idx) == NULL) 5827 return TEST_SKIPPED; 5828 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5829 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5830 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5831 &cap_idx) == NULL) 5832 return TEST_SKIPPED; 5833 5834 /* Create KASUMI session */ 5835 retval = create_wireless_algo_cipher_auth_session( 5836 ts_params->valid_devs[0], 5837 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5838 RTE_CRYPTO_AUTH_OP_GENERATE, 5839 RTE_CRYPTO_AUTH_KASUMI_F9, 5840 RTE_CRYPTO_CIPHER_KASUMI_F8, 5841 tdata->key.data, tdata->key.len, 5842 0, tdata->digest.len, 5843 tdata->cipher_iv.len); 5844 if (retval != 0) 5845 return retval; 5846 5847 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5848 5849 /* clear mbuf payload */ 5850 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5851 rte_pktmbuf_tailroom(ut_params->ibuf)); 5852 5853 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5854 /* Append data which is padded to a multiple of */ 5855 /* the algorithms block size */ 5856 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5857 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5858 plaintext_pad_len); 5859 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5860 5861 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5862 5863 /* Create KASUMI operation */ 5864 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5865 tdata->digest.len, NULL, 0, 5866 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5867 tdata->cipher_iv.data, tdata->cipher_iv.len, 5868 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5869 tdata->validCipherOffsetInBits.len, 5870 tdata->validAuthLenInBits.len, 5871 0 5872 ); 5873 if (retval < 0) 5874 return retval; 5875 5876 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5877 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5878 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5879 else 5880 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5881 ut_params->op); 5882 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5883 5884 if (ut_params->op->sym->m_dst) 5885 ut_params->obuf = ut_params->op->sym->m_dst; 5886 else 5887 ut_params->obuf = ut_params->op->sym->m_src; 5888 5889 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5890 tdata->validCipherOffsetInBits.len >> 3); 5891 5892 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5893 + plaintext_pad_len; 5894 5895 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5896 (tdata->validCipherOffsetInBits.len >> 3); 5897 /* Validate obuf */ 5898 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5899 ciphertext, 5900 reference_ciphertext, 5901 tdata->validCipherLenInBits.len, 5902 "KASUMI Ciphertext data not as expected"); 5903 5904 /* Validate obuf */ 5905 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5906 ut_params->digest, 5907 tdata->digest.data, 5908 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5909 "KASUMI Generated auth tag not as expected"); 5910 return 0; 5911 } 5912 5913 static int 5914 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5915 const enum rte_crypto_cipher_algorithm cipher_algo, 5916 const uint16_t key_size, const uint16_t iv_size) 5917 { 5918 struct rte_cryptodev_sym_capability_idx cap_idx; 5919 const struct rte_cryptodev_symmetric_capability *cap; 5920 5921 /* Check if device supports the algorithm */ 5922 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5923 cap_idx.algo.cipher = cipher_algo; 5924 5925 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5926 &cap_idx); 5927 5928 if (cap == NULL) 5929 return -1; 5930 5931 /* Check if device supports key size and IV size */ 5932 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5933 iv_size) < 0) { 5934 return -1; 5935 } 5936 5937 return 0; 5938 } 5939 5940 static int 5941 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5942 const enum rte_crypto_auth_algorithm auth_algo, 5943 const uint16_t key_size, const uint16_t iv_size, 5944 const uint16_t tag_size) 5945 { 5946 struct rte_cryptodev_sym_capability_idx cap_idx; 5947 const struct rte_cryptodev_symmetric_capability *cap; 5948 5949 /* Check if device supports the algorithm */ 5950 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5951 cap_idx.algo.auth = auth_algo; 5952 5953 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5954 &cap_idx); 5955 5956 if (cap == NULL) 5957 return -1; 5958 5959 /* Check if device supports key size and IV size */ 5960 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5961 tag_size, iv_size) < 0) { 5962 return -1; 5963 } 5964 5965 return 0; 5966 } 5967 5968 static int 5969 test_zuc_encryption(const struct wireless_test_data *tdata) 5970 { 5971 struct crypto_testsuite_params *ts_params = &testsuite_params; 5972 struct crypto_unittest_params *ut_params = &unittest_params; 5973 5974 int retval; 5975 uint8_t *plaintext, *ciphertext; 5976 unsigned plaintext_pad_len; 5977 unsigned plaintext_len; 5978 struct rte_cryptodev_info dev_info; 5979 5980 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5981 uint64_t feat_flags = dev_info.feature_flags; 5982 5983 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5984 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5985 printf("Device doesn't support RAW data-path APIs.\n"); 5986 return TEST_SKIPPED; 5987 } 5988 5989 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5990 return TEST_SKIPPED; 5991 5992 /* Check if device supports ZUC EEA3 */ 5993 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5994 tdata->key.len, tdata->cipher_iv.len) < 0) 5995 return TEST_SKIPPED; 5996 5997 /* Create ZUC session */ 5998 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5999 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6000 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6001 tdata->key.data, tdata->key.len, 6002 tdata->cipher_iv.len); 6003 if (retval != 0) 6004 return retval; 6005 6006 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6007 6008 /* Clear mbuf payload */ 6009 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6010 rte_pktmbuf_tailroom(ut_params->ibuf)); 6011 6012 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6013 /* Append data which is padded to a multiple */ 6014 /* of the algorithms block size */ 6015 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6016 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6017 plaintext_pad_len); 6018 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6019 6020 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6021 6022 /* Create ZUC operation */ 6023 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6024 tdata->cipher_iv.len, 6025 tdata->plaintext.len, 6026 0); 6027 if (retval < 0) 6028 return retval; 6029 6030 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6031 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6032 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6033 else 6034 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6035 ut_params->op); 6036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6037 6038 ut_params->obuf = ut_params->op->sym->m_dst; 6039 if (ut_params->obuf) 6040 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6041 else 6042 ciphertext = plaintext; 6043 6044 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6045 6046 /* Validate obuf */ 6047 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6048 ciphertext, 6049 tdata->ciphertext.data, 6050 tdata->validCipherLenInBits.len, 6051 "ZUC Ciphertext data not as expected"); 6052 return 0; 6053 } 6054 6055 static int 6056 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6057 { 6058 struct crypto_testsuite_params *ts_params = &testsuite_params; 6059 struct crypto_unittest_params *ut_params = &unittest_params; 6060 6061 int retval; 6062 6063 unsigned int plaintext_pad_len; 6064 unsigned int plaintext_len; 6065 const uint8_t *ciphertext; 6066 uint8_t ciphertext_buffer[2048]; 6067 struct rte_cryptodev_info dev_info; 6068 6069 /* Check if device supports ZUC EEA3 */ 6070 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6071 tdata->key.len, tdata->cipher_iv.len) < 0) 6072 return TEST_SKIPPED; 6073 6074 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6075 return TEST_SKIPPED; 6076 6077 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6078 6079 uint64_t feat_flags = dev_info.feature_flags; 6080 6081 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6082 printf("Device doesn't support in-place scatter-gather. " 6083 "Test Skipped.\n"); 6084 return TEST_SKIPPED; 6085 } 6086 6087 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6088 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6089 printf("Device doesn't support RAW data-path APIs.\n"); 6090 return TEST_SKIPPED; 6091 } 6092 6093 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6094 6095 /* Append data which is padded to a multiple */ 6096 /* of the algorithms block size */ 6097 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6098 6099 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6100 plaintext_pad_len, 10, 0); 6101 6102 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6103 tdata->plaintext.data); 6104 6105 /* Create ZUC session */ 6106 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6107 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6108 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6109 tdata->key.data, tdata->key.len, 6110 tdata->cipher_iv.len); 6111 if (retval < 0) 6112 return retval; 6113 6114 /* Clear mbuf payload */ 6115 6116 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6117 6118 /* Create ZUC operation */ 6119 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6120 tdata->cipher_iv.len, tdata->plaintext.len, 6121 0); 6122 if (retval < 0) 6123 return retval; 6124 6125 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6126 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6127 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6128 else 6129 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6130 ut_params->op); 6131 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6132 6133 ut_params->obuf = ut_params->op->sym->m_dst; 6134 if (ut_params->obuf) 6135 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6136 0, plaintext_len, ciphertext_buffer); 6137 else 6138 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6139 0, plaintext_len, ciphertext_buffer); 6140 6141 /* Validate obuf */ 6142 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6143 6144 /* Validate obuf */ 6145 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6146 ciphertext, 6147 tdata->ciphertext.data, 6148 tdata->validCipherLenInBits.len, 6149 "ZUC Ciphertext data not as expected"); 6150 6151 return 0; 6152 } 6153 6154 static int 6155 test_zuc_authentication(const struct wireless_test_data *tdata) 6156 { 6157 struct crypto_testsuite_params *ts_params = &testsuite_params; 6158 struct crypto_unittest_params *ut_params = &unittest_params; 6159 6160 int retval; 6161 unsigned plaintext_pad_len; 6162 unsigned plaintext_len; 6163 uint8_t *plaintext; 6164 6165 struct rte_cryptodev_info dev_info; 6166 6167 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6168 uint64_t feat_flags = dev_info.feature_flags; 6169 6170 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6171 (tdata->validAuthLenInBits.len % 8 != 0)) { 6172 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6173 return TEST_SKIPPED; 6174 } 6175 6176 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6177 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6178 printf("Device doesn't support RAW data-path APIs.\n"); 6179 return TEST_SKIPPED; 6180 } 6181 6182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6183 return TEST_SKIPPED; 6184 6185 /* Check if device supports ZUC EIA3 */ 6186 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6187 tdata->key.len, tdata->auth_iv.len, 6188 tdata->digest.len) < 0) 6189 return TEST_SKIPPED; 6190 6191 /* Create ZUC session */ 6192 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6193 tdata->key.data, tdata->key.len, 6194 tdata->auth_iv.len, tdata->digest.len, 6195 RTE_CRYPTO_AUTH_OP_GENERATE, 6196 RTE_CRYPTO_AUTH_ZUC_EIA3); 6197 if (retval != 0) 6198 return retval; 6199 6200 /* alloc mbuf and set payload */ 6201 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6202 6203 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6204 rte_pktmbuf_tailroom(ut_params->ibuf)); 6205 6206 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6207 /* Append data which is padded to a multiple of */ 6208 /* the algorithms block size */ 6209 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6210 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6211 plaintext_pad_len); 6212 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6213 6214 /* Create ZUC operation */ 6215 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6216 tdata->auth_iv.data, tdata->auth_iv.len, 6217 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6218 tdata->validAuthLenInBits.len, 6219 0); 6220 if (retval < 0) 6221 return retval; 6222 6223 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6224 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6225 ut_params->op, 0, 1, 1, 0); 6226 else 6227 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6228 ut_params->op); 6229 ut_params->obuf = ut_params->op->sym->m_src; 6230 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6231 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6232 + plaintext_pad_len; 6233 6234 /* Validate obuf */ 6235 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6236 ut_params->digest, 6237 tdata->digest.data, 6238 tdata->digest.len, 6239 "ZUC Generated auth tag not as expected"); 6240 6241 return 0; 6242 } 6243 6244 static int 6245 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6246 uint8_t op_mode, uint8_t verify) 6247 { 6248 struct crypto_testsuite_params *ts_params = &testsuite_params; 6249 struct crypto_unittest_params *ut_params = &unittest_params; 6250 6251 int retval; 6252 6253 uint8_t *plaintext = NULL, *ciphertext = NULL; 6254 unsigned int plaintext_pad_len; 6255 unsigned int plaintext_len; 6256 unsigned int ciphertext_pad_len; 6257 unsigned int ciphertext_len; 6258 6259 struct rte_cryptodev_info dev_info; 6260 6261 /* Check if device supports ZUC EEA3 */ 6262 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6263 tdata->key.len, tdata->cipher_iv.len) < 0) 6264 return TEST_SKIPPED; 6265 6266 /* Check if device supports ZUC EIA3 */ 6267 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6268 tdata->key.len, tdata->auth_iv.len, 6269 tdata->digest.len) < 0) 6270 return TEST_SKIPPED; 6271 6272 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6273 6274 uint64_t feat_flags = dev_info.feature_flags; 6275 6276 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6277 printf("Device doesn't support digest encrypted.\n"); 6278 return TEST_SKIPPED; 6279 } 6280 if (op_mode == IN_PLACE) { 6281 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6282 printf("Device doesn't support in-place scatter-gather " 6283 "in both input and output mbufs.\n"); 6284 return TEST_SKIPPED; 6285 } 6286 6287 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6288 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6289 printf("Device doesn't support RAW data-path APIs.\n"); 6290 return TEST_SKIPPED; 6291 } 6292 } else { 6293 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6294 return TEST_SKIPPED; 6295 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6296 printf("Device doesn't support out-of-place scatter-gather " 6297 "in both input and output mbufs.\n"); 6298 return TEST_SKIPPED; 6299 } 6300 } 6301 6302 /* Create ZUC session */ 6303 retval = create_wireless_algo_auth_cipher_session( 6304 ts_params->valid_devs[0], 6305 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6306 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6307 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6308 : RTE_CRYPTO_AUTH_OP_GENERATE), 6309 RTE_CRYPTO_AUTH_ZUC_EIA3, 6310 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6311 tdata->key.data, tdata->key.len, 6312 tdata->auth_iv.len, tdata->digest.len, 6313 tdata->cipher_iv.len); 6314 6315 if (retval != 0) 6316 return retval; 6317 6318 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6319 if (op_mode == OUT_OF_PLACE) 6320 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6321 6322 /* clear mbuf payload */ 6323 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6324 rte_pktmbuf_tailroom(ut_params->ibuf)); 6325 if (op_mode == OUT_OF_PLACE) 6326 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6327 rte_pktmbuf_tailroom(ut_params->obuf)); 6328 6329 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6330 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6331 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6332 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6333 6334 if (verify) { 6335 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6336 ciphertext_pad_len); 6337 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6338 debug_hexdump(stdout, "ciphertext:", ciphertext, 6339 ciphertext_len); 6340 } else { 6341 /* make sure enough space to cover partial digest verify case */ 6342 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6343 ciphertext_pad_len); 6344 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6345 debug_hexdump(stdout, "plaintext:", plaintext, 6346 plaintext_len); 6347 } 6348 6349 if (op_mode == OUT_OF_PLACE) 6350 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6351 6352 /* Create ZUC operation */ 6353 retval = create_wireless_algo_auth_cipher_operation( 6354 tdata->digest.data, tdata->digest.len, 6355 tdata->cipher_iv.data, tdata->cipher_iv.len, 6356 tdata->auth_iv.data, tdata->auth_iv.len, 6357 (tdata->digest.offset_bytes == 0 ? 6358 (verify ? ciphertext_pad_len : plaintext_pad_len) 6359 : tdata->digest.offset_bytes), 6360 tdata->validCipherLenInBits.len, 6361 tdata->validCipherOffsetInBits.len, 6362 tdata->validAuthLenInBits.len, 6363 0, 6364 op_mode, 0, verify); 6365 6366 if (retval < 0) 6367 return retval; 6368 6369 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6370 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6371 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6372 else 6373 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6374 ut_params->op); 6375 6376 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6377 6378 ut_params->obuf = (op_mode == IN_PLACE ? 6379 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6380 6381 6382 if (verify) { 6383 if (ut_params->obuf) 6384 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6385 uint8_t *); 6386 else 6387 plaintext = ciphertext; 6388 6389 debug_hexdump(stdout, "plaintext:", plaintext, 6390 (tdata->plaintext.len >> 3) - tdata->digest.len); 6391 debug_hexdump(stdout, "plaintext expected:", 6392 tdata->plaintext.data, 6393 (tdata->plaintext.len >> 3) - tdata->digest.len); 6394 } else { 6395 if (ut_params->obuf) 6396 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6397 uint8_t *); 6398 else 6399 ciphertext = plaintext; 6400 6401 debug_hexdump(stdout, "ciphertext:", ciphertext, 6402 ciphertext_len); 6403 debug_hexdump(stdout, "ciphertext expected:", 6404 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6405 6406 ut_params->digest = rte_pktmbuf_mtod( 6407 ut_params->obuf, uint8_t *) + 6408 (tdata->digest.offset_bytes == 0 ? 6409 plaintext_pad_len : tdata->digest.offset_bytes); 6410 6411 debug_hexdump(stdout, "digest:", ut_params->digest, 6412 tdata->digest.len); 6413 debug_hexdump(stdout, "digest expected:", 6414 tdata->digest.data, tdata->digest.len); 6415 } 6416 6417 /* Validate obuf */ 6418 if (verify) { 6419 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6420 plaintext, 6421 tdata->plaintext.data, 6422 tdata->plaintext.len >> 3, 6423 "ZUC Plaintext data not as expected"); 6424 } else { 6425 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6426 ciphertext, 6427 tdata->ciphertext.data, 6428 tdata->ciphertext.len >> 3, 6429 "ZUC Ciphertext data not as expected"); 6430 6431 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6432 ut_params->digest, 6433 tdata->digest.data, 6434 DIGEST_BYTE_LENGTH_KASUMI_F9, 6435 "ZUC Generated auth tag not as expected"); 6436 } 6437 return 0; 6438 } 6439 6440 static int 6441 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6442 uint8_t op_mode, uint8_t verify) 6443 { 6444 struct crypto_testsuite_params *ts_params = &testsuite_params; 6445 struct crypto_unittest_params *ut_params = &unittest_params; 6446 6447 int retval; 6448 6449 const uint8_t *plaintext = NULL; 6450 const uint8_t *ciphertext = NULL; 6451 const uint8_t *digest = NULL; 6452 unsigned int plaintext_pad_len; 6453 unsigned int plaintext_len; 6454 unsigned int ciphertext_pad_len; 6455 unsigned int ciphertext_len; 6456 uint8_t buffer[10000]; 6457 uint8_t digest_buffer[10000]; 6458 6459 struct rte_cryptodev_info dev_info; 6460 6461 /* Check if device supports ZUC EEA3 */ 6462 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6463 tdata->key.len, tdata->cipher_iv.len) < 0) 6464 return TEST_SKIPPED; 6465 6466 /* Check if device supports ZUC EIA3 */ 6467 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6468 tdata->key.len, tdata->auth_iv.len, 6469 tdata->digest.len) < 0) 6470 return TEST_SKIPPED; 6471 6472 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6473 6474 uint64_t feat_flags = dev_info.feature_flags; 6475 6476 if (op_mode == IN_PLACE) { 6477 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6478 printf("Device doesn't support in-place scatter-gather " 6479 "in both input and output mbufs.\n"); 6480 return TEST_SKIPPED; 6481 } 6482 6483 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6484 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6485 printf("Device doesn't support RAW data-path APIs.\n"); 6486 return TEST_SKIPPED; 6487 } 6488 } else { 6489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6490 return TEST_SKIPPED; 6491 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6492 printf("Device doesn't support out-of-place scatter-gather " 6493 "in both input and output mbufs.\n"); 6494 return TEST_SKIPPED; 6495 } 6496 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6497 printf("Device doesn't support digest encrypted.\n"); 6498 return TEST_SKIPPED; 6499 } 6500 } 6501 6502 /* Create ZUC session */ 6503 retval = create_wireless_algo_auth_cipher_session( 6504 ts_params->valid_devs[0], 6505 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6506 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6507 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6508 : RTE_CRYPTO_AUTH_OP_GENERATE), 6509 RTE_CRYPTO_AUTH_ZUC_EIA3, 6510 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6511 tdata->key.data, tdata->key.len, 6512 tdata->auth_iv.len, tdata->digest.len, 6513 tdata->cipher_iv.len); 6514 6515 if (retval != 0) 6516 return retval; 6517 6518 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6519 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6520 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6521 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6522 6523 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6524 plaintext_pad_len, 15, 0); 6525 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6526 "Failed to allocate input buffer in mempool"); 6527 6528 if (op_mode == OUT_OF_PLACE) { 6529 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6530 plaintext_pad_len, 15, 0); 6531 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6532 "Failed to allocate output buffer in mempool"); 6533 } 6534 6535 if (verify) { 6536 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6537 tdata->ciphertext.data); 6538 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6539 ciphertext_len, buffer); 6540 debug_hexdump(stdout, "ciphertext:", ciphertext, 6541 ciphertext_len); 6542 } else { 6543 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6544 tdata->plaintext.data); 6545 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6546 plaintext_len, buffer); 6547 debug_hexdump(stdout, "plaintext:", plaintext, 6548 plaintext_len); 6549 } 6550 memset(buffer, 0, sizeof(buffer)); 6551 6552 /* Create ZUC operation */ 6553 retval = create_wireless_algo_auth_cipher_operation( 6554 tdata->digest.data, tdata->digest.len, 6555 tdata->cipher_iv.data, tdata->cipher_iv.len, 6556 NULL, 0, 6557 (tdata->digest.offset_bytes == 0 ? 6558 (verify ? ciphertext_pad_len : plaintext_pad_len) 6559 : tdata->digest.offset_bytes), 6560 tdata->validCipherLenInBits.len, 6561 tdata->validCipherOffsetInBits.len, 6562 tdata->validAuthLenInBits.len, 6563 0, 6564 op_mode, 1, verify); 6565 6566 if (retval < 0) 6567 return retval; 6568 6569 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6570 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6571 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6572 else 6573 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6574 ut_params->op); 6575 6576 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6577 6578 ut_params->obuf = (op_mode == IN_PLACE ? 6579 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6580 6581 if (verify) { 6582 if (ut_params->obuf) 6583 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6584 plaintext_len, buffer); 6585 else 6586 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6587 plaintext_len, buffer); 6588 6589 debug_hexdump(stdout, "plaintext:", plaintext, 6590 (tdata->plaintext.len >> 3) - tdata->digest.len); 6591 debug_hexdump(stdout, "plaintext expected:", 6592 tdata->plaintext.data, 6593 (tdata->plaintext.len >> 3) - tdata->digest.len); 6594 } else { 6595 if (ut_params->obuf) 6596 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6597 ciphertext_len, buffer); 6598 else 6599 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6600 ciphertext_len, buffer); 6601 6602 debug_hexdump(stdout, "ciphertext:", ciphertext, 6603 ciphertext_len); 6604 debug_hexdump(stdout, "ciphertext expected:", 6605 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6606 6607 if (ut_params->obuf) 6608 digest = rte_pktmbuf_read(ut_params->obuf, 6609 (tdata->digest.offset_bytes == 0 ? 6610 plaintext_pad_len : tdata->digest.offset_bytes), 6611 tdata->digest.len, digest_buffer); 6612 else 6613 digest = rte_pktmbuf_read(ut_params->ibuf, 6614 (tdata->digest.offset_bytes == 0 ? 6615 plaintext_pad_len : tdata->digest.offset_bytes), 6616 tdata->digest.len, digest_buffer); 6617 6618 debug_hexdump(stdout, "digest:", digest, 6619 tdata->digest.len); 6620 debug_hexdump(stdout, "digest expected:", 6621 tdata->digest.data, tdata->digest.len); 6622 } 6623 6624 /* Validate obuf */ 6625 if (verify) { 6626 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6627 plaintext, 6628 tdata->plaintext.data, 6629 tdata->plaintext.len >> 3, 6630 "ZUC Plaintext data not as expected"); 6631 } else { 6632 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6633 ciphertext, 6634 tdata->ciphertext.data, 6635 tdata->validDataLenInBits.len, 6636 "ZUC Ciphertext data not as expected"); 6637 6638 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6639 digest, 6640 tdata->digest.data, 6641 DIGEST_BYTE_LENGTH_KASUMI_F9, 6642 "ZUC Generated auth tag not as expected"); 6643 } 6644 return 0; 6645 } 6646 6647 static int 6648 test_kasumi_encryption_test_case_1(void) 6649 { 6650 return test_kasumi_encryption(&kasumi_test_case_1); 6651 } 6652 6653 static int 6654 test_kasumi_encryption_test_case_1_sgl(void) 6655 { 6656 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6657 } 6658 6659 static int 6660 test_kasumi_encryption_test_case_1_oop(void) 6661 { 6662 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6663 } 6664 6665 static int 6666 test_kasumi_encryption_test_case_1_oop_sgl(void) 6667 { 6668 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6669 } 6670 6671 static int 6672 test_kasumi_encryption_test_case_2(void) 6673 { 6674 return test_kasumi_encryption(&kasumi_test_case_2); 6675 } 6676 6677 static int 6678 test_kasumi_encryption_test_case_3(void) 6679 { 6680 return test_kasumi_encryption(&kasumi_test_case_3); 6681 } 6682 6683 static int 6684 test_kasumi_encryption_test_case_4(void) 6685 { 6686 return test_kasumi_encryption(&kasumi_test_case_4); 6687 } 6688 6689 static int 6690 test_kasumi_encryption_test_case_5(void) 6691 { 6692 return test_kasumi_encryption(&kasumi_test_case_5); 6693 } 6694 6695 static int 6696 test_kasumi_decryption_test_case_1(void) 6697 { 6698 return test_kasumi_decryption(&kasumi_test_case_1); 6699 } 6700 6701 static int 6702 test_kasumi_decryption_test_case_1_oop(void) 6703 { 6704 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6705 } 6706 6707 static int 6708 test_kasumi_decryption_test_case_2(void) 6709 { 6710 return test_kasumi_decryption(&kasumi_test_case_2); 6711 } 6712 6713 static int 6714 test_kasumi_decryption_test_case_3(void) 6715 { 6716 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6717 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6718 return TEST_SKIPPED; 6719 return test_kasumi_decryption(&kasumi_test_case_3); 6720 } 6721 6722 static int 6723 test_kasumi_decryption_test_case_4(void) 6724 { 6725 return test_kasumi_decryption(&kasumi_test_case_4); 6726 } 6727 6728 static int 6729 test_kasumi_decryption_test_case_5(void) 6730 { 6731 return test_kasumi_decryption(&kasumi_test_case_5); 6732 } 6733 static int 6734 test_snow3g_encryption_test_case_1(void) 6735 { 6736 return test_snow3g_encryption(&snow3g_test_case_1); 6737 } 6738 6739 static int 6740 test_snow3g_encryption_test_case_1_oop(void) 6741 { 6742 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6743 } 6744 6745 static int 6746 test_snow3g_encryption_test_case_1_oop_sgl(void) 6747 { 6748 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6749 } 6750 6751 6752 static int 6753 test_snow3g_encryption_test_case_1_offset_oop(void) 6754 { 6755 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6756 } 6757 6758 static int 6759 test_snow3g_encryption_test_case_2(void) 6760 { 6761 return test_snow3g_encryption(&snow3g_test_case_2); 6762 } 6763 6764 static int 6765 test_snow3g_encryption_test_case_3(void) 6766 { 6767 return test_snow3g_encryption(&snow3g_test_case_3); 6768 } 6769 6770 static int 6771 test_snow3g_encryption_test_case_4(void) 6772 { 6773 return test_snow3g_encryption(&snow3g_test_case_4); 6774 } 6775 6776 static int 6777 test_snow3g_encryption_test_case_5(void) 6778 { 6779 return test_snow3g_encryption(&snow3g_test_case_5); 6780 } 6781 6782 static int 6783 test_snow3g_decryption_test_case_1(void) 6784 { 6785 return test_snow3g_decryption(&snow3g_test_case_1); 6786 } 6787 6788 static int 6789 test_snow3g_decryption_test_case_1_oop(void) 6790 { 6791 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6792 } 6793 6794 static int 6795 test_snow3g_decryption_test_case_2(void) 6796 { 6797 return test_snow3g_decryption(&snow3g_test_case_2); 6798 } 6799 6800 static int 6801 test_snow3g_decryption_test_case_3(void) 6802 { 6803 return test_snow3g_decryption(&snow3g_test_case_3); 6804 } 6805 6806 static int 6807 test_snow3g_decryption_test_case_4(void) 6808 { 6809 return test_snow3g_decryption(&snow3g_test_case_4); 6810 } 6811 6812 static int 6813 test_snow3g_decryption_test_case_5(void) 6814 { 6815 return test_snow3g_decryption(&snow3g_test_case_5); 6816 } 6817 6818 /* 6819 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6820 * Pattern digest from snow3g_test_data must be allocated as 6821 * 4 last bytes in plaintext. 6822 */ 6823 static void 6824 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6825 struct snow3g_hash_test_data *output) 6826 { 6827 if ((pattern != NULL) && (output != NULL)) { 6828 output->key.len = pattern->key.len; 6829 6830 memcpy(output->key.data, 6831 pattern->key.data, pattern->key.len); 6832 6833 output->auth_iv.len = pattern->auth_iv.len; 6834 6835 memcpy(output->auth_iv.data, 6836 pattern->auth_iv.data, pattern->auth_iv.len); 6837 6838 output->plaintext.len = pattern->plaintext.len; 6839 6840 memcpy(output->plaintext.data, 6841 pattern->plaintext.data, pattern->plaintext.len >> 3); 6842 6843 output->digest.len = pattern->digest.len; 6844 6845 memcpy(output->digest.data, 6846 &pattern->plaintext.data[pattern->digest.offset_bytes], 6847 pattern->digest.len); 6848 6849 output->validAuthLenInBits.len = 6850 pattern->validAuthLenInBits.len; 6851 } 6852 } 6853 6854 /* 6855 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6856 */ 6857 static int 6858 test_snow3g_decryption_with_digest_test_case_1(void) 6859 { 6860 struct snow3g_hash_test_data snow3g_hash_data; 6861 struct rte_cryptodev_info dev_info; 6862 struct crypto_testsuite_params *ts_params = &testsuite_params; 6863 6864 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6865 uint64_t feat_flags = dev_info.feature_flags; 6866 6867 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6868 printf("Device doesn't support encrypted digest operations.\n"); 6869 return TEST_SKIPPED; 6870 } 6871 6872 /* 6873 * Function prepare data for hash veryfication test case. 6874 * Digest is allocated in 4 last bytes in plaintext, pattern. 6875 */ 6876 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6877 6878 return test_snow3g_decryption(&snow3g_test_case_7) & 6879 test_snow3g_authentication_verify(&snow3g_hash_data); 6880 } 6881 6882 static int 6883 test_snow3g_cipher_auth_test_case_1(void) 6884 { 6885 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6886 } 6887 6888 static int 6889 test_snow3g_auth_cipher_test_case_1(void) 6890 { 6891 return test_snow3g_auth_cipher( 6892 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6893 } 6894 6895 static int 6896 test_snow3g_auth_cipher_test_case_2(void) 6897 { 6898 return test_snow3g_auth_cipher( 6899 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6900 } 6901 6902 static int 6903 test_snow3g_auth_cipher_test_case_2_oop(void) 6904 { 6905 return test_snow3g_auth_cipher( 6906 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6907 } 6908 6909 static int 6910 test_snow3g_auth_cipher_part_digest_enc(void) 6911 { 6912 return test_snow3g_auth_cipher( 6913 &snow3g_auth_cipher_partial_digest_encryption, 6914 IN_PLACE, 0); 6915 } 6916 6917 static int 6918 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6919 { 6920 return test_snow3g_auth_cipher( 6921 &snow3g_auth_cipher_partial_digest_encryption, 6922 OUT_OF_PLACE, 0); 6923 } 6924 6925 static int 6926 test_snow3g_auth_cipher_test_case_3_sgl(void) 6927 { 6928 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6929 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6930 return TEST_SKIPPED; 6931 return test_snow3g_auth_cipher_sgl( 6932 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6933 } 6934 6935 static int 6936 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6937 { 6938 return test_snow3g_auth_cipher_sgl( 6939 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6940 } 6941 6942 static int 6943 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6944 { 6945 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6946 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6947 return TEST_SKIPPED; 6948 return test_snow3g_auth_cipher_sgl( 6949 &snow3g_auth_cipher_partial_digest_encryption, 6950 IN_PLACE, 0); 6951 } 6952 6953 static int 6954 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6955 { 6956 return test_snow3g_auth_cipher_sgl( 6957 &snow3g_auth_cipher_partial_digest_encryption, 6958 OUT_OF_PLACE, 0); 6959 } 6960 6961 static int 6962 test_snow3g_auth_cipher_verify_test_case_1(void) 6963 { 6964 return test_snow3g_auth_cipher( 6965 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6966 } 6967 6968 static int 6969 test_snow3g_auth_cipher_verify_test_case_2(void) 6970 { 6971 return test_snow3g_auth_cipher( 6972 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6973 } 6974 6975 static int 6976 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6977 { 6978 return test_snow3g_auth_cipher( 6979 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6980 } 6981 6982 static int 6983 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6984 { 6985 return test_snow3g_auth_cipher( 6986 &snow3g_auth_cipher_partial_digest_encryption, 6987 IN_PLACE, 1); 6988 } 6989 6990 static int 6991 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6992 { 6993 return test_snow3g_auth_cipher( 6994 &snow3g_auth_cipher_partial_digest_encryption, 6995 OUT_OF_PLACE, 1); 6996 } 6997 6998 static int 6999 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7000 { 7001 return test_snow3g_auth_cipher_sgl( 7002 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7003 } 7004 7005 static int 7006 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7007 { 7008 return test_snow3g_auth_cipher_sgl( 7009 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7010 } 7011 7012 static int 7013 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7014 { 7015 return test_snow3g_auth_cipher_sgl( 7016 &snow3g_auth_cipher_partial_digest_encryption, 7017 IN_PLACE, 1); 7018 } 7019 7020 static int 7021 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7022 { 7023 return test_snow3g_auth_cipher_sgl( 7024 &snow3g_auth_cipher_partial_digest_encryption, 7025 OUT_OF_PLACE, 1); 7026 } 7027 7028 static int 7029 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7030 { 7031 return test_snow3g_auth_cipher( 7032 &snow3g_test_case_7, IN_PLACE, 0); 7033 } 7034 7035 static int 7036 test_kasumi_auth_cipher_test_case_1(void) 7037 { 7038 return test_kasumi_auth_cipher( 7039 &kasumi_test_case_3, IN_PLACE, 0); 7040 } 7041 7042 static int 7043 test_kasumi_auth_cipher_test_case_2(void) 7044 { 7045 return test_kasumi_auth_cipher( 7046 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7047 } 7048 7049 static int 7050 test_kasumi_auth_cipher_test_case_2_oop(void) 7051 { 7052 return test_kasumi_auth_cipher( 7053 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7054 } 7055 7056 static int 7057 test_kasumi_auth_cipher_test_case_2_sgl(void) 7058 { 7059 return test_kasumi_auth_cipher_sgl( 7060 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7061 } 7062 7063 static int 7064 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7065 { 7066 return test_kasumi_auth_cipher_sgl( 7067 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7068 } 7069 7070 static int 7071 test_kasumi_auth_cipher_verify_test_case_1(void) 7072 { 7073 return test_kasumi_auth_cipher( 7074 &kasumi_test_case_3, IN_PLACE, 1); 7075 } 7076 7077 static int 7078 test_kasumi_auth_cipher_verify_test_case_2(void) 7079 { 7080 return test_kasumi_auth_cipher( 7081 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7082 } 7083 7084 static int 7085 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7086 { 7087 return test_kasumi_auth_cipher( 7088 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7089 } 7090 7091 static int 7092 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7093 { 7094 return test_kasumi_auth_cipher_sgl( 7095 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7096 } 7097 7098 static int 7099 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7100 { 7101 return test_kasumi_auth_cipher_sgl( 7102 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7103 } 7104 7105 static int 7106 test_kasumi_cipher_auth_test_case_1(void) 7107 { 7108 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7109 } 7110 7111 static int 7112 test_zuc_encryption_test_case_1(void) 7113 { 7114 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7115 } 7116 7117 static int 7118 test_zuc_encryption_test_case_2(void) 7119 { 7120 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7121 } 7122 7123 static int 7124 test_zuc_encryption_test_case_3(void) 7125 { 7126 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7127 } 7128 7129 static int 7130 test_zuc_encryption_test_case_4(void) 7131 { 7132 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7133 } 7134 7135 static int 7136 test_zuc_encryption_test_case_5(void) 7137 { 7138 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7139 } 7140 7141 static int 7142 test_zuc_encryption_test_case_6_sgl(void) 7143 { 7144 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7145 } 7146 7147 static int 7148 test_zuc_hash_generate_test_case_1(void) 7149 { 7150 return test_zuc_authentication(&zuc_test_case_auth_1b); 7151 } 7152 7153 static int 7154 test_zuc_hash_generate_test_case_2(void) 7155 { 7156 return test_zuc_authentication(&zuc_test_case_auth_90b); 7157 } 7158 7159 static int 7160 test_zuc_hash_generate_test_case_3(void) 7161 { 7162 return test_zuc_authentication(&zuc_test_case_auth_577b); 7163 } 7164 7165 static int 7166 test_zuc_hash_generate_test_case_4(void) 7167 { 7168 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7169 } 7170 7171 static int 7172 test_zuc_hash_generate_test_case_5(void) 7173 { 7174 return test_zuc_authentication(&zuc_test_auth_5670b); 7175 } 7176 7177 static int 7178 test_zuc_hash_generate_test_case_6(void) 7179 { 7180 return test_zuc_authentication(&zuc_test_case_auth_128b); 7181 } 7182 7183 static int 7184 test_zuc_hash_generate_test_case_7(void) 7185 { 7186 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7187 } 7188 7189 static int 7190 test_zuc_hash_generate_test_case_8(void) 7191 { 7192 return test_zuc_authentication(&zuc_test_case_auth_584b); 7193 } 7194 7195 static int 7196 test_zuc_hash_generate_test_case_9(void) 7197 { 7198 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b); 7199 } 7200 7201 static int 7202 test_zuc_hash_generate_test_case_10(void) 7203 { 7204 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b); 7205 } 7206 7207 static int 7208 test_zuc_hash_generate_test_case_11(void) 7209 { 7210 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b); 7211 } 7212 7213 static int 7214 test_zuc_cipher_auth_test_case_1(void) 7215 { 7216 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7217 } 7218 7219 static int 7220 test_zuc_cipher_auth_test_case_2(void) 7221 { 7222 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7223 } 7224 7225 static int 7226 test_zuc_auth_cipher_test_case_1(void) 7227 { 7228 return test_zuc_auth_cipher( 7229 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7230 } 7231 7232 static int 7233 test_zuc_auth_cipher_test_case_1_oop(void) 7234 { 7235 return test_zuc_auth_cipher( 7236 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7237 } 7238 7239 static int 7240 test_zuc_auth_cipher_test_case_1_sgl(void) 7241 { 7242 return test_zuc_auth_cipher_sgl( 7243 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7244 } 7245 7246 static int 7247 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7248 { 7249 return test_zuc_auth_cipher_sgl( 7250 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7251 } 7252 7253 static int 7254 test_zuc_auth_cipher_verify_test_case_1(void) 7255 { 7256 return test_zuc_auth_cipher( 7257 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7258 } 7259 7260 static int 7261 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7262 { 7263 return test_zuc_auth_cipher( 7264 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7265 } 7266 7267 static int 7268 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7269 { 7270 return test_zuc_auth_cipher_sgl( 7271 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7272 } 7273 7274 static int 7275 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7276 { 7277 return test_zuc_auth_cipher_sgl( 7278 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7279 } 7280 7281 static int 7282 test_zuc256_encryption_test_case_1(void) 7283 { 7284 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7285 } 7286 7287 static int 7288 test_zuc256_encryption_test_case_2(void) 7289 { 7290 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7291 } 7292 7293 static int 7294 test_zuc256_authentication_test_case_1(void) 7295 { 7296 return test_zuc_authentication(&zuc256_test_case_auth_1); 7297 } 7298 7299 static int 7300 test_zuc256_authentication_test_case_2(void) 7301 { 7302 return test_zuc_authentication(&zuc256_test_case_auth_2); 7303 } 7304 7305 static int 7306 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7307 { 7308 uint8_t dev_id = testsuite_params.valid_devs[0]; 7309 7310 struct rte_cryptodev_sym_capability_idx cap_idx; 7311 7312 /* Check if device supports particular cipher algorithm */ 7313 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7314 cap_idx.algo.cipher = tdata->cipher_algo; 7315 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7316 return TEST_SKIPPED; 7317 7318 /* Check if device supports particular hash algorithm */ 7319 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7320 cap_idx.algo.auth = tdata->auth_algo; 7321 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7322 return TEST_SKIPPED; 7323 7324 return 0; 7325 } 7326 7327 static int 7328 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7329 uint8_t op_mode, uint8_t verify) 7330 { 7331 struct crypto_testsuite_params *ts_params = &testsuite_params; 7332 struct crypto_unittest_params *ut_params = &unittest_params; 7333 7334 int retval; 7335 7336 uint8_t *plaintext = NULL, *ciphertext = NULL; 7337 unsigned int plaintext_pad_len; 7338 unsigned int plaintext_len; 7339 unsigned int ciphertext_pad_len; 7340 unsigned int ciphertext_len; 7341 7342 struct rte_cryptodev_info dev_info; 7343 struct rte_crypto_op *op; 7344 7345 /* Check if device supports particular algorithms separately */ 7346 if (test_mixed_check_if_unsupported(tdata)) 7347 return TEST_SKIPPED; 7348 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7349 return TEST_SKIPPED; 7350 7351 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7352 7353 uint64_t feat_flags = dev_info.feature_flags; 7354 7355 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7356 printf("Device doesn't support digest encrypted.\n"); 7357 return TEST_SKIPPED; 7358 } 7359 7360 /* Create the session */ 7361 if (verify) 7362 retval = create_wireless_algo_cipher_auth_session( 7363 ts_params->valid_devs[0], 7364 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7365 RTE_CRYPTO_AUTH_OP_VERIFY, 7366 tdata->auth_algo, 7367 tdata->cipher_algo, 7368 tdata->auth_key.data, tdata->auth_key.len, 7369 tdata->auth_iv.len, tdata->digest_enc.len, 7370 tdata->cipher_iv.len); 7371 else 7372 retval = create_wireless_algo_auth_cipher_session( 7373 ts_params->valid_devs[0], 7374 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7375 RTE_CRYPTO_AUTH_OP_GENERATE, 7376 tdata->auth_algo, 7377 tdata->cipher_algo, 7378 tdata->auth_key.data, tdata->auth_key.len, 7379 tdata->auth_iv.len, tdata->digest_enc.len, 7380 tdata->cipher_iv.len); 7381 if (retval != 0) 7382 return retval; 7383 7384 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7385 if (op_mode == OUT_OF_PLACE) 7386 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7387 7388 /* clear mbuf payload */ 7389 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7390 rte_pktmbuf_tailroom(ut_params->ibuf)); 7391 if (op_mode == OUT_OF_PLACE) { 7392 7393 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7394 rte_pktmbuf_tailroom(ut_params->obuf)); 7395 } 7396 7397 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7398 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7399 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7400 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7401 7402 if (verify) { 7403 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7404 ciphertext_pad_len); 7405 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7406 debug_hexdump(stdout, "ciphertext:", ciphertext, 7407 ciphertext_len); 7408 } else { 7409 /* make sure enough space to cover partial digest verify case */ 7410 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7411 ciphertext_pad_len); 7412 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7413 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7414 } 7415 7416 if (op_mode == OUT_OF_PLACE) 7417 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7418 7419 /* Create the operation */ 7420 retval = create_wireless_algo_auth_cipher_operation( 7421 tdata->digest_enc.data, tdata->digest_enc.len, 7422 tdata->cipher_iv.data, tdata->cipher_iv.len, 7423 tdata->auth_iv.data, tdata->auth_iv.len, 7424 (tdata->digest_enc.offset == 0 ? 7425 plaintext_pad_len 7426 : tdata->digest_enc.offset), 7427 tdata->validCipherLen.len_bits, 7428 tdata->cipher.offset_bits, 7429 tdata->validAuthLen.len_bits, 7430 tdata->auth.offset_bits, 7431 op_mode, 0, verify); 7432 7433 if (retval < 0) 7434 return retval; 7435 7436 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7437 7438 /* Check if the op failed because the device doesn't */ 7439 /* support this particular combination of algorithms */ 7440 if (op == NULL && ut_params->op->status == 7441 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7442 printf("Device doesn't support this mixed combination. " 7443 "Test Skipped.\n"); 7444 return TEST_SKIPPED; 7445 } 7446 ut_params->op = op; 7447 7448 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7449 7450 ut_params->obuf = (op_mode == IN_PLACE ? 7451 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7452 7453 if (verify) { 7454 if (ut_params->obuf) 7455 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7456 uint8_t *); 7457 else 7458 plaintext = ciphertext + 7459 (tdata->cipher.offset_bits >> 3); 7460 7461 debug_hexdump(stdout, "plaintext:", plaintext, 7462 tdata->plaintext.len_bits >> 3); 7463 debug_hexdump(stdout, "plaintext expected:", 7464 tdata->plaintext.data, 7465 tdata->plaintext.len_bits >> 3); 7466 } else { 7467 if (ut_params->obuf) 7468 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7469 uint8_t *); 7470 else 7471 ciphertext = plaintext; 7472 7473 debug_hexdump(stdout, "ciphertext:", ciphertext, 7474 ciphertext_len); 7475 debug_hexdump(stdout, "ciphertext expected:", 7476 tdata->ciphertext.data, 7477 tdata->ciphertext.len_bits >> 3); 7478 7479 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7480 + (tdata->digest_enc.offset == 0 ? 7481 plaintext_pad_len : tdata->digest_enc.offset); 7482 7483 debug_hexdump(stdout, "digest:", ut_params->digest, 7484 tdata->digest_enc.len); 7485 debug_hexdump(stdout, "digest expected:", 7486 tdata->digest_enc.data, 7487 tdata->digest_enc.len); 7488 } 7489 7490 if (!verify) { 7491 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7492 ut_params->digest, 7493 tdata->digest_enc.data, 7494 tdata->digest_enc.len, 7495 "Generated auth tag not as expected"); 7496 } 7497 7498 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7499 if (verify) { 7500 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7501 plaintext, 7502 tdata->plaintext.data, 7503 tdata->plaintext.len_bits >> 3, 7504 "Plaintext data not as expected"); 7505 } else { 7506 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7507 ciphertext, 7508 tdata->ciphertext.data, 7509 tdata->validDataLen.len_bits, 7510 "Ciphertext data not as expected"); 7511 } 7512 } 7513 7514 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7515 "crypto op processing failed"); 7516 7517 return 0; 7518 } 7519 7520 static int 7521 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7522 uint8_t op_mode, uint8_t verify) 7523 { 7524 struct crypto_testsuite_params *ts_params = &testsuite_params; 7525 struct crypto_unittest_params *ut_params = &unittest_params; 7526 7527 int retval; 7528 7529 const uint8_t *plaintext = NULL; 7530 const uint8_t *ciphertext = NULL; 7531 const uint8_t *digest = NULL; 7532 unsigned int plaintext_pad_len; 7533 unsigned int plaintext_len; 7534 unsigned int ciphertext_pad_len; 7535 unsigned int ciphertext_len; 7536 uint8_t buffer[10000]; 7537 uint8_t digest_buffer[10000]; 7538 7539 struct rte_cryptodev_info dev_info; 7540 struct rte_crypto_op *op; 7541 7542 /* Check if device supports particular algorithms */ 7543 if (test_mixed_check_if_unsupported(tdata)) 7544 return TEST_SKIPPED; 7545 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7546 return TEST_SKIPPED; 7547 7548 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7549 7550 uint64_t feat_flags = dev_info.feature_flags; 7551 7552 if (op_mode == IN_PLACE) { 7553 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7554 printf("Device doesn't support in-place scatter-gather " 7555 "in both input and output mbufs.\n"); 7556 return TEST_SKIPPED; 7557 } 7558 } else { 7559 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7560 printf("Device doesn't support out-of-place scatter-gather " 7561 "in both input and output mbufs.\n"); 7562 return TEST_SKIPPED; 7563 } 7564 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7565 printf("Device doesn't support digest encrypted.\n"); 7566 return TEST_SKIPPED; 7567 } 7568 } 7569 7570 /* Create the session */ 7571 if (verify) 7572 retval = create_wireless_algo_cipher_auth_session( 7573 ts_params->valid_devs[0], 7574 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7575 RTE_CRYPTO_AUTH_OP_VERIFY, 7576 tdata->auth_algo, 7577 tdata->cipher_algo, 7578 tdata->auth_key.data, tdata->auth_key.len, 7579 tdata->auth_iv.len, tdata->digest_enc.len, 7580 tdata->cipher_iv.len); 7581 else 7582 retval = create_wireless_algo_auth_cipher_session( 7583 ts_params->valid_devs[0], 7584 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7585 RTE_CRYPTO_AUTH_OP_GENERATE, 7586 tdata->auth_algo, 7587 tdata->cipher_algo, 7588 tdata->auth_key.data, tdata->auth_key.len, 7589 tdata->auth_iv.len, tdata->digest_enc.len, 7590 tdata->cipher_iv.len); 7591 if (retval != 0) 7592 return retval; 7593 7594 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7595 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7596 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7597 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7598 7599 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7600 ciphertext_pad_len, 15, 0); 7601 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7602 "Failed to allocate input buffer in mempool"); 7603 7604 if (op_mode == OUT_OF_PLACE) { 7605 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7606 plaintext_pad_len, 15, 0); 7607 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7608 "Failed to allocate output buffer in mempool"); 7609 } 7610 7611 if (verify) { 7612 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7613 tdata->ciphertext.data); 7614 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7615 ciphertext_len, buffer); 7616 debug_hexdump(stdout, "ciphertext:", ciphertext, 7617 ciphertext_len); 7618 } else { 7619 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7620 tdata->plaintext.data); 7621 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7622 plaintext_len, buffer); 7623 debug_hexdump(stdout, "plaintext:", plaintext, 7624 plaintext_len); 7625 } 7626 memset(buffer, 0, sizeof(buffer)); 7627 7628 /* Create the operation */ 7629 retval = create_wireless_algo_auth_cipher_operation( 7630 tdata->digest_enc.data, tdata->digest_enc.len, 7631 tdata->cipher_iv.data, tdata->cipher_iv.len, 7632 tdata->auth_iv.data, tdata->auth_iv.len, 7633 (tdata->digest_enc.offset == 0 ? 7634 plaintext_pad_len 7635 : tdata->digest_enc.offset), 7636 tdata->validCipherLen.len_bits, 7637 tdata->cipher.offset_bits, 7638 tdata->validAuthLen.len_bits, 7639 tdata->auth.offset_bits, 7640 op_mode, 1, verify); 7641 7642 if (retval < 0) 7643 return retval; 7644 7645 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7646 7647 /* Check if the op failed because the device doesn't */ 7648 /* support this particular combination of algorithms */ 7649 if (op == NULL && ut_params->op->status == 7650 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7651 printf("Device doesn't support this mixed combination. " 7652 "Test Skipped.\n"); 7653 return TEST_SKIPPED; 7654 } 7655 ut_params->op = op; 7656 7657 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7658 7659 ut_params->obuf = (op_mode == IN_PLACE ? 7660 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7661 7662 if (verify) { 7663 if (ut_params->obuf) 7664 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7665 plaintext_len, buffer); 7666 else 7667 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7668 plaintext_len, buffer); 7669 7670 debug_hexdump(stdout, "plaintext:", plaintext, 7671 (tdata->plaintext.len_bits >> 3) - 7672 tdata->digest_enc.len); 7673 debug_hexdump(stdout, "plaintext expected:", 7674 tdata->plaintext.data, 7675 (tdata->plaintext.len_bits >> 3) - 7676 tdata->digest_enc.len); 7677 } else { 7678 if (ut_params->obuf) 7679 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7680 ciphertext_len, buffer); 7681 else 7682 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7683 ciphertext_len, buffer); 7684 7685 debug_hexdump(stdout, "ciphertext:", ciphertext, 7686 ciphertext_len); 7687 debug_hexdump(stdout, "ciphertext expected:", 7688 tdata->ciphertext.data, 7689 tdata->ciphertext.len_bits >> 3); 7690 7691 if (ut_params->obuf) 7692 digest = rte_pktmbuf_read(ut_params->obuf, 7693 (tdata->digest_enc.offset == 0 ? 7694 plaintext_pad_len : 7695 tdata->digest_enc.offset), 7696 tdata->digest_enc.len, digest_buffer); 7697 else 7698 digest = rte_pktmbuf_read(ut_params->ibuf, 7699 (tdata->digest_enc.offset == 0 ? 7700 plaintext_pad_len : 7701 tdata->digest_enc.offset), 7702 tdata->digest_enc.len, digest_buffer); 7703 7704 debug_hexdump(stdout, "digest:", digest, 7705 tdata->digest_enc.len); 7706 debug_hexdump(stdout, "digest expected:", 7707 tdata->digest_enc.data, tdata->digest_enc.len); 7708 } 7709 7710 if (!verify) { 7711 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7712 digest, 7713 tdata->digest_enc.data, 7714 tdata->digest_enc.len, 7715 "Generated auth tag not as expected"); 7716 } 7717 7718 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7719 if (verify) { 7720 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7721 plaintext, 7722 tdata->plaintext.data, 7723 tdata->plaintext.len_bits >> 3, 7724 "Plaintext data not as expected"); 7725 } else { 7726 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7727 ciphertext, 7728 tdata->ciphertext.data, 7729 tdata->validDataLen.len_bits, 7730 "Ciphertext data not as expected"); 7731 } 7732 } 7733 7734 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7735 "crypto op processing failed"); 7736 7737 return 0; 7738 } 7739 7740 /** AUTH AES CMAC + CIPHER AES CTR */ 7741 7742 static int 7743 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7744 { 7745 return test_mixed_auth_cipher( 7746 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7747 } 7748 7749 static int 7750 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7751 { 7752 return test_mixed_auth_cipher( 7753 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7754 } 7755 7756 static int 7757 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7758 { 7759 return test_mixed_auth_cipher_sgl( 7760 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7761 } 7762 7763 static int 7764 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7765 { 7766 return test_mixed_auth_cipher_sgl( 7767 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7768 } 7769 7770 static int 7771 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7772 { 7773 return test_mixed_auth_cipher( 7774 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7775 } 7776 7777 static int 7778 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7779 { 7780 return test_mixed_auth_cipher( 7781 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7782 } 7783 7784 static int 7785 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7786 { 7787 return test_mixed_auth_cipher_sgl( 7788 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7789 } 7790 7791 static int 7792 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7793 { 7794 return test_mixed_auth_cipher_sgl( 7795 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7796 } 7797 7798 /** MIXED AUTH + CIPHER */ 7799 7800 static int 7801 test_auth_zuc_cipher_snow_test_case_1(void) 7802 { 7803 return test_mixed_auth_cipher( 7804 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7805 } 7806 7807 static int 7808 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7809 { 7810 return test_mixed_auth_cipher( 7811 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7812 } 7813 7814 static int 7815 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7816 { 7817 return test_mixed_auth_cipher( 7818 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7819 } 7820 7821 static int 7822 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7823 { 7824 return test_mixed_auth_cipher( 7825 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7826 } 7827 7828 static int 7829 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7830 { 7831 return test_mixed_auth_cipher( 7832 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7833 } 7834 7835 static int 7836 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7837 { 7838 return test_mixed_auth_cipher( 7839 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7840 } 7841 7842 static int 7843 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7844 { 7845 return test_mixed_auth_cipher( 7846 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7847 } 7848 7849 static int 7850 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7851 { 7852 return test_mixed_auth_cipher( 7853 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7854 } 7855 7856 static int 7857 test_auth_snow_cipher_zuc_test_case_1(void) 7858 { 7859 return test_mixed_auth_cipher( 7860 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7861 } 7862 7863 static int 7864 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7865 { 7866 return test_mixed_auth_cipher( 7867 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7868 } 7869 7870 static int 7871 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7872 { 7873 return test_mixed_auth_cipher( 7874 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7875 } 7876 7877 static int 7878 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7879 { 7880 return test_mixed_auth_cipher( 7881 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7882 } 7883 7884 static int 7885 test_auth_null_cipher_snow_test_case_1(void) 7886 { 7887 return test_mixed_auth_cipher( 7888 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7889 } 7890 7891 static int 7892 test_verify_auth_null_cipher_snow_test_case_1(void) 7893 { 7894 return test_mixed_auth_cipher( 7895 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7896 } 7897 7898 static int 7899 test_auth_null_cipher_zuc_test_case_1(void) 7900 { 7901 return test_mixed_auth_cipher( 7902 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7903 } 7904 7905 static int 7906 test_verify_auth_null_cipher_zuc_test_case_1(void) 7907 { 7908 return test_mixed_auth_cipher( 7909 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7910 } 7911 7912 static int 7913 test_auth_snow_cipher_null_test_case_1(void) 7914 { 7915 return test_mixed_auth_cipher( 7916 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7917 } 7918 7919 static int 7920 test_verify_auth_snow_cipher_null_test_case_1(void) 7921 { 7922 return test_mixed_auth_cipher( 7923 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7924 } 7925 7926 static int 7927 test_auth_zuc_cipher_null_test_case_1(void) 7928 { 7929 return test_mixed_auth_cipher( 7930 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7931 } 7932 7933 static int 7934 test_verify_auth_zuc_cipher_null_test_case_1(void) 7935 { 7936 return test_mixed_auth_cipher( 7937 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7938 } 7939 7940 static int 7941 test_auth_null_cipher_aes_ctr_test_case_1(void) 7942 { 7943 return test_mixed_auth_cipher( 7944 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7945 } 7946 7947 static int 7948 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7949 { 7950 return test_mixed_auth_cipher( 7951 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7952 } 7953 7954 static int 7955 test_auth_aes_cmac_cipher_null_test_case_1(void) 7956 { 7957 return test_mixed_auth_cipher( 7958 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7959 } 7960 7961 static int 7962 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7963 { 7964 return test_mixed_auth_cipher( 7965 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7966 } 7967 7968 /* ***** AEAD algorithm Tests ***** */ 7969 7970 static int 7971 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7972 enum rte_crypto_aead_operation op, 7973 const uint8_t *key, const uint8_t key_len, 7974 const uint16_t aad_len, const uint8_t auth_len, 7975 uint8_t iv_len) 7976 { 7977 uint8_t aead_key[key_len]; 7978 int status; 7979 7980 struct crypto_testsuite_params *ts_params = &testsuite_params; 7981 struct crypto_unittest_params *ut_params = &unittest_params; 7982 7983 memcpy(aead_key, key, key_len); 7984 7985 /* Setup AEAD Parameters */ 7986 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7987 ut_params->aead_xform.next = NULL; 7988 ut_params->aead_xform.aead.algo = algo; 7989 ut_params->aead_xform.aead.op = op; 7990 ut_params->aead_xform.aead.key.data = aead_key; 7991 ut_params->aead_xform.aead.key.length = key_len; 7992 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7993 ut_params->aead_xform.aead.iv.length = iv_len; 7994 ut_params->aead_xform.aead.digest_length = auth_len; 7995 ut_params->aead_xform.aead.aad_length = aad_len; 7996 7997 debug_hexdump(stdout, "key:", key, key_len); 7998 7999 /* Create Crypto session*/ 8000 ut_params->sess = rte_cryptodev_sym_session_create( 8001 ts_params->session_mpool); 8002 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8003 8004 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 8005 &ut_params->aead_xform, 8006 ts_params->session_priv_mpool); 8007 8008 return status; 8009 } 8010 8011 static int 8012 create_aead_xform(struct rte_crypto_op *op, 8013 enum rte_crypto_aead_algorithm algo, 8014 enum rte_crypto_aead_operation aead_op, 8015 uint8_t *key, const uint8_t key_len, 8016 const uint8_t aad_len, const uint8_t auth_len, 8017 uint8_t iv_len) 8018 { 8019 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8020 "failed to allocate space for crypto transform"); 8021 8022 struct rte_crypto_sym_op *sym_op = op->sym; 8023 8024 /* Setup AEAD Parameters */ 8025 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8026 sym_op->xform->next = NULL; 8027 sym_op->xform->aead.algo = algo; 8028 sym_op->xform->aead.op = aead_op; 8029 sym_op->xform->aead.key.data = key; 8030 sym_op->xform->aead.key.length = key_len; 8031 sym_op->xform->aead.iv.offset = IV_OFFSET; 8032 sym_op->xform->aead.iv.length = iv_len; 8033 sym_op->xform->aead.digest_length = auth_len; 8034 sym_op->xform->aead.aad_length = aad_len; 8035 8036 debug_hexdump(stdout, "key:", key, key_len); 8037 8038 return 0; 8039 } 8040 8041 static int 8042 create_aead_operation(enum rte_crypto_aead_operation op, 8043 const struct aead_test_data *tdata) 8044 { 8045 struct crypto_testsuite_params *ts_params = &testsuite_params; 8046 struct crypto_unittest_params *ut_params = &unittest_params; 8047 8048 uint8_t *plaintext, *ciphertext; 8049 unsigned int aad_pad_len, plaintext_pad_len; 8050 8051 /* Generate Crypto op data structure */ 8052 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8053 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8054 TEST_ASSERT_NOT_NULL(ut_params->op, 8055 "Failed to allocate symmetric crypto operation struct"); 8056 8057 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8058 8059 /* Append aad data */ 8060 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8061 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8062 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8063 aad_pad_len); 8064 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8065 "no room to append aad"); 8066 8067 sym_op->aead.aad.phys_addr = 8068 rte_pktmbuf_iova(ut_params->ibuf); 8069 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8070 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8071 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8072 tdata->aad.len); 8073 8074 /* Append IV at the end of the crypto operation*/ 8075 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8076 uint8_t *, IV_OFFSET); 8077 8078 /* Copy IV 1 byte after the IV pointer, according to the API */ 8079 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8080 debug_hexdump(stdout, "iv:", iv_ptr, 8081 tdata->iv.len); 8082 } else { 8083 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8084 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8085 aad_pad_len); 8086 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8087 "no room to append aad"); 8088 8089 sym_op->aead.aad.phys_addr = 8090 rte_pktmbuf_iova(ut_params->ibuf); 8091 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8092 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8093 tdata->aad.len); 8094 8095 /* Append IV at the end of the crypto operation*/ 8096 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8097 uint8_t *, IV_OFFSET); 8098 8099 if (tdata->iv.len == 0) { 8100 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8101 debug_hexdump(stdout, "iv:", iv_ptr, 8102 AES_GCM_J0_LENGTH); 8103 } else { 8104 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8105 debug_hexdump(stdout, "iv:", iv_ptr, 8106 tdata->iv.len); 8107 } 8108 } 8109 8110 /* Append plaintext/ciphertext */ 8111 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8112 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8113 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8114 plaintext_pad_len); 8115 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8116 8117 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8118 debug_hexdump(stdout, "plaintext:", plaintext, 8119 tdata->plaintext.len); 8120 8121 if (ut_params->obuf) { 8122 ciphertext = (uint8_t *)rte_pktmbuf_append( 8123 ut_params->obuf, 8124 plaintext_pad_len + aad_pad_len); 8125 TEST_ASSERT_NOT_NULL(ciphertext, 8126 "no room to append ciphertext"); 8127 8128 memset(ciphertext + aad_pad_len, 0, 8129 tdata->ciphertext.len); 8130 } 8131 } else { 8132 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8133 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8134 plaintext_pad_len); 8135 TEST_ASSERT_NOT_NULL(ciphertext, 8136 "no room to append ciphertext"); 8137 8138 memcpy(ciphertext, tdata->ciphertext.data, 8139 tdata->ciphertext.len); 8140 debug_hexdump(stdout, "ciphertext:", ciphertext, 8141 tdata->ciphertext.len); 8142 8143 if (ut_params->obuf) { 8144 plaintext = (uint8_t *)rte_pktmbuf_append( 8145 ut_params->obuf, 8146 plaintext_pad_len + aad_pad_len); 8147 TEST_ASSERT_NOT_NULL(plaintext, 8148 "no room to append plaintext"); 8149 8150 memset(plaintext + aad_pad_len, 0, 8151 tdata->plaintext.len); 8152 } 8153 } 8154 8155 /* Append digest data */ 8156 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8157 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8158 ut_params->obuf ? ut_params->obuf : 8159 ut_params->ibuf, 8160 tdata->auth_tag.len); 8161 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8162 "no room to append digest"); 8163 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8164 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8165 ut_params->obuf ? ut_params->obuf : 8166 ut_params->ibuf, 8167 plaintext_pad_len + 8168 aad_pad_len); 8169 } else { 8170 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8171 ut_params->ibuf, tdata->auth_tag.len); 8172 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8173 "no room to append digest"); 8174 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8175 ut_params->ibuf, 8176 plaintext_pad_len + aad_pad_len); 8177 8178 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8179 tdata->auth_tag.len); 8180 debug_hexdump(stdout, "digest:", 8181 sym_op->aead.digest.data, 8182 tdata->auth_tag.len); 8183 } 8184 8185 sym_op->aead.data.length = tdata->plaintext.len; 8186 sym_op->aead.data.offset = aad_pad_len; 8187 8188 return 0; 8189 } 8190 8191 static int 8192 test_authenticated_encryption(const struct aead_test_data *tdata) 8193 { 8194 struct crypto_testsuite_params *ts_params = &testsuite_params; 8195 struct crypto_unittest_params *ut_params = &unittest_params; 8196 8197 int retval; 8198 uint8_t *ciphertext, *auth_tag; 8199 uint16_t plaintext_pad_len; 8200 uint32_t i; 8201 struct rte_cryptodev_info dev_info; 8202 8203 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8204 uint64_t feat_flags = dev_info.feature_flags; 8205 8206 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8207 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8208 printf("Device doesn't support RAW data-path APIs.\n"); 8209 return TEST_SKIPPED; 8210 } 8211 8212 /* Verify the capabilities */ 8213 struct rte_cryptodev_sym_capability_idx cap_idx; 8214 const struct rte_cryptodev_symmetric_capability *capability; 8215 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8216 cap_idx.algo.aead = tdata->algo; 8217 capability = rte_cryptodev_sym_capability_get( 8218 ts_params->valid_devs[0], &cap_idx); 8219 if (capability == NULL) 8220 return TEST_SKIPPED; 8221 if (rte_cryptodev_sym_capability_check_aead( 8222 capability, tdata->key.len, tdata->auth_tag.len, 8223 tdata->aad.len, tdata->iv.len)) 8224 return TEST_SKIPPED; 8225 8226 /* Create AEAD session */ 8227 retval = create_aead_session(ts_params->valid_devs[0], 8228 tdata->algo, 8229 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8230 tdata->key.data, tdata->key.len, 8231 tdata->aad.len, tdata->auth_tag.len, 8232 tdata->iv.len); 8233 if (retval < 0) 8234 return retval; 8235 8236 if (tdata->aad.len > MBUF_SIZE) { 8237 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8238 /* Populate full size of add data */ 8239 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8240 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8241 } else 8242 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8243 8244 /* clear mbuf payload */ 8245 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8246 rte_pktmbuf_tailroom(ut_params->ibuf)); 8247 8248 /* Create AEAD operation */ 8249 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8250 if (retval < 0) 8251 return retval; 8252 8253 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8254 8255 ut_params->op->sym->m_src = ut_params->ibuf; 8256 8257 /* Process crypto operation */ 8258 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8259 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8260 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8261 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8262 ut_params->op, 0, 0, 0, 0); 8263 else 8264 TEST_ASSERT_NOT_NULL( 8265 process_crypto_request(ts_params->valid_devs[0], 8266 ut_params->op), "failed to process sym crypto op"); 8267 8268 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8269 "crypto op processing failed"); 8270 8271 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8272 8273 if (ut_params->op->sym->m_dst) { 8274 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8275 uint8_t *); 8276 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8277 uint8_t *, plaintext_pad_len); 8278 } else { 8279 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8280 uint8_t *, 8281 ut_params->op->sym->cipher.data.offset); 8282 auth_tag = ciphertext + plaintext_pad_len; 8283 } 8284 8285 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8286 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8287 8288 /* Validate obuf */ 8289 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8290 ciphertext, 8291 tdata->ciphertext.data, 8292 tdata->ciphertext.len, 8293 "Ciphertext data not as expected"); 8294 8295 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8296 auth_tag, 8297 tdata->auth_tag.data, 8298 tdata->auth_tag.len, 8299 "Generated auth tag not as expected"); 8300 8301 return 0; 8302 8303 } 8304 8305 #ifdef RTE_LIB_SECURITY 8306 static int 8307 security_proto_supported(enum rte_security_session_action_type action, 8308 enum rte_security_session_protocol proto) 8309 { 8310 struct crypto_testsuite_params *ts_params = &testsuite_params; 8311 8312 const struct rte_security_capability *capabilities; 8313 const struct rte_security_capability *capability; 8314 uint16_t i = 0; 8315 8316 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8317 rte_cryptodev_get_sec_ctx( 8318 ts_params->valid_devs[0]); 8319 8320 8321 capabilities = rte_security_capabilities_get(ctx); 8322 8323 if (capabilities == NULL) 8324 return -ENOTSUP; 8325 8326 while ((capability = &capabilities[i++])->action != 8327 RTE_SECURITY_ACTION_TYPE_NONE) { 8328 if (capability->action == action && 8329 capability->protocol == proto) 8330 return 0; 8331 } 8332 8333 return -ENOTSUP; 8334 } 8335 8336 /* Basic algorithm run function for async inplace mode. 8337 * Creates a session from input parameters and runs one operation 8338 * on input_vec. Checks the output of the crypto operation against 8339 * output_vec. 8340 */ 8341 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8342 enum rte_crypto_auth_operation opa, 8343 const uint8_t *input_vec, unsigned int input_vec_len, 8344 const uint8_t *output_vec, 8345 unsigned int output_vec_len, 8346 enum rte_crypto_cipher_algorithm cipher_alg, 8347 const uint8_t *cipher_key, uint32_t cipher_key_len, 8348 enum rte_crypto_auth_algorithm auth_alg, 8349 const uint8_t *auth_key, uint32_t auth_key_len, 8350 uint8_t bearer, enum rte_security_pdcp_domain domain, 8351 uint8_t packet_direction, uint8_t sn_size, 8352 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8353 { 8354 struct crypto_testsuite_params *ts_params = &testsuite_params; 8355 struct crypto_unittest_params *ut_params = &unittest_params; 8356 uint8_t *plaintext; 8357 int ret = TEST_SUCCESS; 8358 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8359 rte_cryptodev_get_sec_ctx( 8360 ts_params->valid_devs[0]); 8361 8362 /* Verify the capabilities */ 8363 struct rte_security_capability_idx sec_cap_idx; 8364 8365 sec_cap_idx.action = ut_params->type; 8366 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8367 sec_cap_idx.pdcp.domain = domain; 8368 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8369 return TEST_SKIPPED; 8370 8371 /* Generate test mbuf data */ 8372 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8373 8374 /* clear mbuf payload */ 8375 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8376 rte_pktmbuf_tailroom(ut_params->ibuf)); 8377 8378 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8379 input_vec_len); 8380 memcpy(plaintext, input_vec, input_vec_len); 8381 8382 /* Out of place support */ 8383 if (oop) { 8384 /* 8385 * For out-op-place we need to alloc another mbuf 8386 */ 8387 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8388 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8389 } 8390 8391 /* Setup Cipher Parameters */ 8392 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8393 ut_params->cipher_xform.cipher.algo = cipher_alg; 8394 ut_params->cipher_xform.cipher.op = opc; 8395 ut_params->cipher_xform.cipher.key.data = cipher_key; 8396 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8397 ut_params->cipher_xform.cipher.iv.length = 8398 packet_direction ? 4 : 0; 8399 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8400 8401 /* Setup HMAC Parameters if ICV header is required */ 8402 if (auth_alg != 0) { 8403 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8404 ut_params->auth_xform.next = NULL; 8405 ut_params->auth_xform.auth.algo = auth_alg; 8406 ut_params->auth_xform.auth.op = opa; 8407 ut_params->auth_xform.auth.key.data = auth_key; 8408 ut_params->auth_xform.auth.key.length = auth_key_len; 8409 8410 ut_params->cipher_xform.next = &ut_params->auth_xform; 8411 } else { 8412 ut_params->cipher_xform.next = NULL; 8413 } 8414 8415 struct rte_security_session_conf sess_conf = { 8416 .action_type = ut_params->type, 8417 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8418 {.pdcp = { 8419 .bearer = bearer, 8420 .domain = domain, 8421 .pkt_dir = packet_direction, 8422 .sn_size = sn_size, 8423 .hfn = packet_direction ? 0 : hfn, 8424 /** 8425 * hfn can be set as pdcp_test_hfn[i] 8426 * if hfn_ovrd is not set. Here, PDCP 8427 * packet direction is just used to 8428 * run half of the cases with session 8429 * HFN and other half with per packet 8430 * HFN. 8431 */ 8432 .hfn_threshold = hfn_threshold, 8433 .hfn_ovrd = packet_direction ? 1 : 0, 8434 .sdap_enabled = sdap, 8435 } }, 8436 .crypto_xform = &ut_params->cipher_xform 8437 }; 8438 8439 /* Create security session */ 8440 ut_params->sec_session = rte_security_session_create(ctx, 8441 &sess_conf, ts_params->session_mpool, 8442 ts_params->session_priv_mpool); 8443 8444 if (!ut_params->sec_session) { 8445 printf("TestCase %s()-%d line %d failed %s: ", 8446 __func__, i, __LINE__, "Failed to allocate session"); 8447 ret = TEST_FAILED; 8448 goto on_err; 8449 } 8450 8451 /* Generate crypto op data structure */ 8452 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8453 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8454 if (!ut_params->op) { 8455 printf("TestCase %s()-%d line %d failed %s: ", 8456 __func__, i, __LINE__, 8457 "Failed to allocate symmetric crypto operation struct"); 8458 ret = TEST_FAILED; 8459 goto on_err; 8460 } 8461 8462 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8463 uint32_t *, IV_OFFSET); 8464 *per_pkt_hfn = packet_direction ? hfn : 0; 8465 8466 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8467 8468 /* set crypto operation source mbuf */ 8469 ut_params->op->sym->m_src = ut_params->ibuf; 8470 if (oop) 8471 ut_params->op->sym->m_dst = ut_params->obuf; 8472 8473 /* Process crypto operation */ 8474 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8475 == NULL) { 8476 printf("TestCase %s()-%d line %d failed %s: ", 8477 __func__, i, __LINE__, 8478 "failed to process sym crypto op"); 8479 ret = TEST_FAILED; 8480 goto on_err; 8481 } 8482 8483 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8484 printf("TestCase %s()-%d line %d failed %s: ", 8485 __func__, i, __LINE__, "crypto op processing failed"); 8486 ret = TEST_FAILED; 8487 goto on_err; 8488 } 8489 8490 /* Validate obuf */ 8491 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8492 uint8_t *); 8493 if (oop) { 8494 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8495 uint8_t *); 8496 } 8497 8498 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8499 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8500 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8501 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8502 ret = TEST_FAILED; 8503 goto on_err; 8504 } 8505 8506 on_err: 8507 rte_crypto_op_free(ut_params->op); 8508 ut_params->op = NULL; 8509 8510 if (ut_params->sec_session) 8511 rte_security_session_destroy(ctx, ut_params->sec_session); 8512 ut_params->sec_session = NULL; 8513 8514 rte_pktmbuf_free(ut_params->ibuf); 8515 ut_params->ibuf = NULL; 8516 if (oop) { 8517 rte_pktmbuf_free(ut_params->obuf); 8518 ut_params->obuf = NULL; 8519 } 8520 8521 return ret; 8522 } 8523 8524 static int 8525 test_pdcp_proto_SGL(int i, int oop, 8526 enum rte_crypto_cipher_operation opc, 8527 enum rte_crypto_auth_operation opa, 8528 uint8_t *input_vec, 8529 unsigned int input_vec_len, 8530 uint8_t *output_vec, 8531 unsigned int output_vec_len, 8532 uint32_t fragsz, 8533 uint32_t fragsz_oop) 8534 { 8535 struct crypto_testsuite_params *ts_params = &testsuite_params; 8536 struct crypto_unittest_params *ut_params = &unittest_params; 8537 uint8_t *plaintext; 8538 struct rte_mbuf *buf, *buf_oop = NULL; 8539 int ret = TEST_SUCCESS; 8540 int to_trn = 0; 8541 int to_trn_tbl[16]; 8542 int segs = 1; 8543 unsigned int trn_data = 0; 8544 struct rte_cryptodev_info dev_info; 8545 uint64_t feat_flags; 8546 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8547 rte_cryptodev_get_sec_ctx( 8548 ts_params->valid_devs[0]); 8549 struct rte_mbuf *temp_mbuf; 8550 8551 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8552 feat_flags = dev_info.feature_flags; 8553 8554 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8555 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8556 printf("Device does not support RAW data-path APIs.\n"); 8557 return -ENOTSUP; 8558 } 8559 /* Verify the capabilities */ 8560 struct rte_security_capability_idx sec_cap_idx; 8561 8562 sec_cap_idx.action = ut_params->type; 8563 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8564 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8565 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8566 return TEST_SKIPPED; 8567 8568 if (fragsz > input_vec_len) 8569 fragsz = input_vec_len; 8570 8571 uint16_t plaintext_len = fragsz; 8572 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8573 8574 if (fragsz_oop > output_vec_len) 8575 frag_size_oop = output_vec_len; 8576 8577 int ecx = 0; 8578 if (input_vec_len % fragsz != 0) { 8579 if (input_vec_len / fragsz + 1 > 16) 8580 return 1; 8581 } else if (input_vec_len / fragsz > 16) 8582 return 1; 8583 8584 /* Out of place support */ 8585 if (oop) { 8586 /* 8587 * For out-op-place we need to alloc another mbuf 8588 */ 8589 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8590 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8591 buf_oop = ut_params->obuf; 8592 } 8593 8594 /* Generate test mbuf data */ 8595 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8596 8597 /* clear mbuf payload */ 8598 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8599 rte_pktmbuf_tailroom(ut_params->ibuf)); 8600 8601 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8602 plaintext_len); 8603 memcpy(plaintext, input_vec, plaintext_len); 8604 trn_data += plaintext_len; 8605 8606 buf = ut_params->ibuf; 8607 8608 /* 8609 * Loop until no more fragments 8610 */ 8611 8612 while (trn_data < input_vec_len) { 8613 ++segs; 8614 to_trn = (input_vec_len - trn_data < fragsz) ? 8615 (input_vec_len - trn_data) : fragsz; 8616 8617 to_trn_tbl[ecx++] = to_trn; 8618 8619 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8620 buf = buf->next; 8621 8622 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8623 rte_pktmbuf_tailroom(buf)); 8624 8625 /* OOP */ 8626 if (oop && !fragsz_oop) { 8627 buf_oop->next = 8628 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8629 buf_oop = buf_oop->next; 8630 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8631 0, rte_pktmbuf_tailroom(buf_oop)); 8632 rte_pktmbuf_append(buf_oop, to_trn); 8633 } 8634 8635 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8636 to_trn); 8637 8638 memcpy(plaintext, input_vec + trn_data, to_trn); 8639 trn_data += to_trn; 8640 } 8641 8642 ut_params->ibuf->nb_segs = segs; 8643 8644 segs = 1; 8645 if (fragsz_oop && oop) { 8646 to_trn = 0; 8647 ecx = 0; 8648 8649 trn_data = frag_size_oop; 8650 while (trn_data < output_vec_len) { 8651 ++segs; 8652 to_trn = 8653 (output_vec_len - trn_data < 8654 frag_size_oop) ? 8655 (output_vec_len - trn_data) : 8656 frag_size_oop; 8657 8658 to_trn_tbl[ecx++] = to_trn; 8659 8660 buf_oop->next = 8661 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8662 buf_oop = buf_oop->next; 8663 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8664 0, rte_pktmbuf_tailroom(buf_oop)); 8665 rte_pktmbuf_append(buf_oop, to_trn); 8666 8667 trn_data += to_trn; 8668 } 8669 ut_params->obuf->nb_segs = segs; 8670 } 8671 8672 /* Setup Cipher Parameters */ 8673 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8674 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8675 ut_params->cipher_xform.cipher.op = opc; 8676 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8677 ut_params->cipher_xform.cipher.key.length = 8678 pdcp_test_params[i].cipher_key_len; 8679 ut_params->cipher_xform.cipher.iv.length = 0; 8680 8681 /* Setup HMAC Parameters if ICV header is required */ 8682 if (pdcp_test_params[i].auth_alg != 0) { 8683 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8684 ut_params->auth_xform.next = NULL; 8685 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8686 ut_params->auth_xform.auth.op = opa; 8687 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8688 ut_params->auth_xform.auth.key.length = 8689 pdcp_test_params[i].auth_key_len; 8690 8691 ut_params->cipher_xform.next = &ut_params->auth_xform; 8692 } else { 8693 ut_params->cipher_xform.next = NULL; 8694 } 8695 8696 struct rte_security_session_conf sess_conf = { 8697 .action_type = ut_params->type, 8698 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8699 {.pdcp = { 8700 .bearer = pdcp_test_bearer[i], 8701 .domain = pdcp_test_params[i].domain, 8702 .pkt_dir = pdcp_test_packet_direction[i], 8703 .sn_size = pdcp_test_data_sn_size[i], 8704 .hfn = pdcp_test_hfn[i], 8705 .hfn_threshold = pdcp_test_hfn_threshold[i], 8706 .hfn_ovrd = 0, 8707 } }, 8708 .crypto_xform = &ut_params->cipher_xform 8709 }; 8710 8711 /* Create security session */ 8712 ut_params->sec_session = rte_security_session_create(ctx, 8713 &sess_conf, ts_params->session_mpool, 8714 ts_params->session_priv_mpool); 8715 8716 if (!ut_params->sec_session) { 8717 printf("TestCase %s()-%d line %d failed %s: ", 8718 __func__, i, __LINE__, "Failed to allocate session"); 8719 ret = TEST_FAILED; 8720 goto on_err; 8721 } 8722 8723 /* Generate crypto op data structure */ 8724 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8725 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8726 if (!ut_params->op) { 8727 printf("TestCase %s()-%d line %d failed %s: ", 8728 __func__, i, __LINE__, 8729 "Failed to allocate symmetric crypto operation struct"); 8730 ret = TEST_FAILED; 8731 goto on_err; 8732 } 8733 8734 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8735 8736 /* set crypto operation source mbuf */ 8737 ut_params->op->sym->m_src = ut_params->ibuf; 8738 if (oop) 8739 ut_params->op->sym->m_dst = ut_params->obuf; 8740 8741 /* Process crypto operation */ 8742 temp_mbuf = ut_params->op->sym->m_src; 8743 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8744 /* filling lengths */ 8745 while (temp_mbuf) { 8746 ut_params->op->sym->cipher.data.length 8747 += temp_mbuf->pkt_len; 8748 ut_params->op->sym->auth.data.length 8749 += temp_mbuf->pkt_len; 8750 temp_mbuf = temp_mbuf->next; 8751 } 8752 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8753 ut_params->op, 1, 1, 0, 0); 8754 } else { 8755 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 8756 ut_params->op); 8757 } 8758 if (ut_params->op == NULL) { 8759 printf("TestCase %s()-%d line %d failed %s: ", 8760 __func__, i, __LINE__, 8761 "failed to process sym crypto op"); 8762 ret = TEST_FAILED; 8763 goto on_err; 8764 } 8765 8766 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8767 printf("TestCase %s()-%d line %d failed %s: ", 8768 __func__, i, __LINE__, "crypto op processing failed"); 8769 ret = TEST_FAILED; 8770 goto on_err; 8771 } 8772 8773 /* Validate obuf */ 8774 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8775 uint8_t *); 8776 if (oop) { 8777 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8778 uint8_t *); 8779 } 8780 if (fragsz_oop) 8781 fragsz = frag_size_oop; 8782 if (memcmp(ciphertext, output_vec, fragsz)) { 8783 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8784 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8785 rte_hexdump(stdout, "reference", output_vec, fragsz); 8786 ret = TEST_FAILED; 8787 goto on_err; 8788 } 8789 8790 buf = ut_params->op->sym->m_src->next; 8791 if (oop) 8792 buf = ut_params->op->sym->m_dst->next; 8793 8794 unsigned int off = fragsz; 8795 8796 ecx = 0; 8797 while (buf) { 8798 ciphertext = rte_pktmbuf_mtod(buf, 8799 uint8_t *); 8800 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8801 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8802 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8803 rte_hexdump(stdout, "reference", output_vec + off, 8804 to_trn_tbl[ecx]); 8805 ret = TEST_FAILED; 8806 goto on_err; 8807 } 8808 off += to_trn_tbl[ecx++]; 8809 buf = buf->next; 8810 } 8811 on_err: 8812 rte_crypto_op_free(ut_params->op); 8813 ut_params->op = NULL; 8814 8815 if (ut_params->sec_session) 8816 rte_security_session_destroy(ctx, ut_params->sec_session); 8817 ut_params->sec_session = NULL; 8818 8819 rte_pktmbuf_free(ut_params->ibuf); 8820 ut_params->ibuf = NULL; 8821 if (oop) { 8822 rte_pktmbuf_free(ut_params->obuf); 8823 ut_params->obuf = NULL; 8824 } 8825 8826 return ret; 8827 } 8828 8829 int 8830 test_pdcp_proto_cplane_encap(int i) 8831 { 8832 return test_pdcp_proto( 8833 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8834 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8835 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8836 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8837 pdcp_test_params[i].cipher_key_len, 8838 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8839 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8840 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8841 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8842 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8843 } 8844 8845 int 8846 test_pdcp_proto_uplane_encap(int i) 8847 { 8848 return test_pdcp_proto( 8849 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8850 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8851 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8852 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8853 pdcp_test_params[i].cipher_key_len, 8854 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8855 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8856 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8857 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8858 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8859 } 8860 8861 int 8862 test_pdcp_proto_uplane_encap_with_int(int i) 8863 { 8864 return test_pdcp_proto( 8865 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8866 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8867 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8868 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8869 pdcp_test_params[i].cipher_key_len, 8870 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8871 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8872 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8873 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8874 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8875 } 8876 8877 int 8878 test_pdcp_proto_cplane_decap(int i) 8879 { 8880 return test_pdcp_proto( 8881 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8882 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8883 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8884 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8885 pdcp_test_params[i].cipher_key_len, 8886 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8887 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8888 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8889 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8890 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8891 } 8892 8893 int 8894 test_pdcp_proto_uplane_decap(int i) 8895 { 8896 return test_pdcp_proto( 8897 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8898 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8899 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8900 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8901 pdcp_test_params[i].cipher_key_len, 8902 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8903 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8904 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8905 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8906 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8907 } 8908 8909 int 8910 test_pdcp_proto_uplane_decap_with_int(int i) 8911 { 8912 return test_pdcp_proto( 8913 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8914 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8915 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8916 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8917 pdcp_test_params[i].cipher_key_len, 8918 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8919 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8920 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8921 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8922 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8923 } 8924 8925 static int 8926 test_PDCP_PROTO_SGL_in_place_32B(void) 8927 { 8928 /* i can be used for running any PDCP case 8929 * In this case it is uplane 12-bit AES-SNOW DL encap 8930 */ 8931 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8932 return test_pdcp_proto_SGL(i, IN_PLACE, 8933 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8934 RTE_CRYPTO_AUTH_OP_GENERATE, 8935 pdcp_test_data_in[i], 8936 pdcp_test_data_in_len[i], 8937 pdcp_test_data_out[i], 8938 pdcp_test_data_in_len[i]+4, 8939 32, 0); 8940 } 8941 static int 8942 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8943 { 8944 /* i can be used for running any PDCP case 8945 * In this case it is uplane 18-bit NULL-NULL DL encap 8946 */ 8947 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8948 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8949 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8950 RTE_CRYPTO_AUTH_OP_GENERATE, 8951 pdcp_test_data_in[i], 8952 pdcp_test_data_in_len[i], 8953 pdcp_test_data_out[i], 8954 pdcp_test_data_in_len[i]+4, 8955 32, 128); 8956 } 8957 static int 8958 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8959 { 8960 /* i can be used for running any PDCP case 8961 * In this case it is uplane 18-bit AES DL encap 8962 */ 8963 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8964 + DOWNLINK; 8965 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8966 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8967 RTE_CRYPTO_AUTH_OP_GENERATE, 8968 pdcp_test_data_in[i], 8969 pdcp_test_data_in_len[i], 8970 pdcp_test_data_out[i], 8971 pdcp_test_data_in_len[i], 8972 32, 40); 8973 } 8974 static int 8975 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8976 { 8977 /* i can be used for running any PDCP case 8978 * In this case it is cplane 12-bit AES-ZUC DL encap 8979 */ 8980 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8981 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8982 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8983 RTE_CRYPTO_AUTH_OP_GENERATE, 8984 pdcp_test_data_in[i], 8985 pdcp_test_data_in_len[i], 8986 pdcp_test_data_out[i], 8987 pdcp_test_data_in_len[i]+4, 8988 128, 32); 8989 } 8990 8991 static int 8992 test_PDCP_SDAP_PROTO_encap_all(void) 8993 { 8994 int i = 0, size = 0; 8995 int err, all_err = TEST_SUCCESS; 8996 const struct pdcp_sdap_test *cur_test; 8997 8998 size = RTE_DIM(list_pdcp_sdap_tests); 8999 9000 for (i = 0; i < size; i++) { 9001 cur_test = &list_pdcp_sdap_tests[i]; 9002 err = test_pdcp_proto( 9003 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9004 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9005 cur_test->in_len, cur_test->data_out, 9006 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9007 cur_test->param.cipher_alg, cur_test->cipher_key, 9008 cur_test->param.cipher_key_len, 9009 cur_test->param.auth_alg, 9010 cur_test->auth_key, cur_test->param.auth_key_len, 9011 cur_test->bearer, cur_test->param.domain, 9012 cur_test->packet_direction, cur_test->sn_size, 9013 cur_test->hfn, 9014 cur_test->hfn_threshold, SDAP_ENABLED); 9015 if (err) { 9016 printf("\t%d) %s: Encapsulation failed\n", 9017 cur_test->test_idx, 9018 cur_test->param.name); 9019 err = TEST_FAILED; 9020 } else { 9021 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9022 cur_test->param.name); 9023 err = TEST_SUCCESS; 9024 } 9025 all_err += err; 9026 } 9027 9028 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9029 9030 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9031 } 9032 9033 static int 9034 test_PDCP_PROTO_short_mac(void) 9035 { 9036 int i = 0, size = 0; 9037 int err, all_err = TEST_SUCCESS; 9038 const struct pdcp_short_mac_test *cur_test; 9039 9040 size = RTE_DIM(list_pdcp_smac_tests); 9041 9042 for (i = 0; i < size; i++) { 9043 cur_test = &list_pdcp_smac_tests[i]; 9044 err = test_pdcp_proto( 9045 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9046 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9047 cur_test->in_len, cur_test->data_out, 9048 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9049 RTE_CRYPTO_CIPHER_NULL, NULL, 9050 0, cur_test->param.auth_alg, 9051 cur_test->auth_key, cur_test->param.auth_key_len, 9052 0, cur_test->param.domain, 0, 0, 9053 0, 0, 0); 9054 if (err) { 9055 printf("\t%d) %s: Short MAC test failed\n", 9056 cur_test->test_idx, 9057 cur_test->param.name); 9058 err = TEST_FAILED; 9059 } else { 9060 printf("\t%d) %s: Short MAC test PASS\n", 9061 cur_test->test_idx, 9062 cur_test->param.name); 9063 rte_hexdump(stdout, "MAC I", 9064 cur_test->data_out + cur_test->in_len + 2, 9065 2); 9066 err = TEST_SUCCESS; 9067 } 9068 all_err += err; 9069 } 9070 9071 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9072 9073 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9074 9075 } 9076 9077 static int 9078 test_PDCP_SDAP_PROTO_decap_all(void) 9079 { 9080 int i = 0, size = 0; 9081 int err, all_err = TEST_SUCCESS; 9082 const struct pdcp_sdap_test *cur_test; 9083 9084 size = RTE_DIM(list_pdcp_sdap_tests); 9085 9086 for (i = 0; i < size; i++) { 9087 cur_test = &list_pdcp_sdap_tests[i]; 9088 err = test_pdcp_proto( 9089 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9090 RTE_CRYPTO_AUTH_OP_VERIFY, 9091 cur_test->data_out, 9092 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9093 cur_test->data_in, cur_test->in_len, 9094 cur_test->param.cipher_alg, 9095 cur_test->cipher_key, cur_test->param.cipher_key_len, 9096 cur_test->param.auth_alg, cur_test->auth_key, 9097 cur_test->param.auth_key_len, cur_test->bearer, 9098 cur_test->param.domain, cur_test->packet_direction, 9099 cur_test->sn_size, cur_test->hfn, 9100 cur_test->hfn_threshold, SDAP_ENABLED); 9101 if (err) { 9102 printf("\t%d) %s: Decapsulation failed\n", 9103 cur_test->test_idx, 9104 cur_test->param.name); 9105 err = TEST_FAILED; 9106 } else { 9107 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9108 cur_test->param.name); 9109 err = TEST_SUCCESS; 9110 } 9111 all_err += err; 9112 } 9113 9114 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9115 9116 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9117 } 9118 9119 static int 9120 test_ipsec_proto_process(const struct ipsec_test_data td[], 9121 struct ipsec_test_data res_d[], 9122 int nb_td, 9123 bool silent, 9124 const struct ipsec_test_flags *flags) 9125 { 9126 struct crypto_testsuite_params *ts_params = &testsuite_params; 9127 struct crypto_unittest_params *ut_params = &unittest_params; 9128 struct rte_security_capability_idx sec_cap_idx; 9129 const struct rte_security_capability *sec_cap; 9130 struct rte_security_ipsec_xform ipsec_xform; 9131 uint8_t dev_id = ts_params->valid_devs[0]; 9132 enum rte_security_ipsec_sa_direction dir; 9133 struct ipsec_test_data *res_d_tmp = NULL; 9134 uint32_t src = RTE_IPV4(192, 168, 1, 0); 9135 uint32_t dst = RTE_IPV4(192, 168, 1, 1); 9136 int salt_len, i, ret = TEST_SUCCESS; 9137 struct rte_security_ctx *ctx; 9138 uint8_t *input_text; 9139 uint32_t verify; 9140 9141 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9142 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9143 9144 /* Use first test data to create session */ 9145 9146 /* Copy IPsec xform */ 9147 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9148 9149 dir = ipsec_xform.direction; 9150 verify = flags->tunnel_hdr_verify; 9151 9152 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9153 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9154 src += 1; 9155 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9156 dst += 1; 9157 } 9158 9159 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src)); 9160 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst)); 9161 9162 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9163 9164 sec_cap_idx.action = ut_params->type; 9165 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9166 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9167 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9168 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9169 9170 if (flags->udp_encap) 9171 ipsec_xform.options.udp_encap = 1; 9172 9173 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9174 if (sec_cap == NULL) 9175 return TEST_SKIPPED; 9176 9177 /* Copy cipher session parameters */ 9178 if (td[0].aead) { 9179 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9180 sizeof(ut_params->aead_xform)); 9181 ut_params->aead_xform.aead.key.data = td[0].key.data; 9182 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9183 9184 /* Verify crypto capabilities */ 9185 if (test_ipsec_crypto_caps_aead_verify( 9186 sec_cap, 9187 &ut_params->aead_xform) != 0) { 9188 if (!silent) 9189 RTE_LOG(INFO, USER1, 9190 "Crypto capabilities not supported\n"); 9191 return TEST_SKIPPED; 9192 } 9193 } else { 9194 /* Only AEAD supported now */ 9195 return TEST_SKIPPED; 9196 } 9197 9198 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9199 return TEST_SKIPPED; 9200 9201 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9202 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9203 9204 struct rte_security_session_conf sess_conf = { 9205 .action_type = ut_params->type, 9206 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9207 .ipsec = ipsec_xform, 9208 .crypto_xform = &ut_params->aead_xform, 9209 }; 9210 9211 /* Create security session */ 9212 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9213 ts_params->session_mpool, 9214 ts_params->session_priv_mpool); 9215 9216 if (ut_params->sec_session == NULL) 9217 return TEST_SKIPPED; 9218 9219 for (i = 0; i < nb_td; i++) { 9220 /* Setup source mbuf payload */ 9221 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9222 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9223 rte_pktmbuf_tailroom(ut_params->ibuf)); 9224 9225 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9226 td[i].input_text.len); 9227 9228 memcpy(input_text, td[i].input_text.data, 9229 td[i].input_text.len); 9230 9231 /* Generate crypto op data structure */ 9232 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9233 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9234 if (!ut_params->op) { 9235 printf("TestCase %s line %d: %s\n", 9236 __func__, __LINE__, 9237 "failed to allocate crypto op"); 9238 ret = TEST_FAILED; 9239 goto crypto_op_free; 9240 } 9241 9242 /* Attach session to operation */ 9243 rte_security_attach_session(ut_params->op, 9244 ut_params->sec_session); 9245 9246 /* Set crypto operation mbufs */ 9247 ut_params->op->sym->m_src = ut_params->ibuf; 9248 ut_params->op->sym->m_dst = NULL; 9249 9250 /* Copy IV in crypto operation when IV generation is disabled */ 9251 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9252 ipsec_xform.options.iv_gen_disable == 1) { 9253 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9254 uint8_t *, 9255 IV_OFFSET); 9256 int len; 9257 9258 if (td[i].aead) 9259 len = td[i].xform.aead.aead.iv.length; 9260 else 9261 len = td[i].xform.chain.cipher.cipher.iv.length; 9262 9263 memcpy(iv, td[i].iv.data, len); 9264 } 9265 9266 /* Process crypto operation */ 9267 process_crypto_request(dev_id, ut_params->op); 9268 9269 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1); 9270 if (ret != TEST_SUCCESS) 9271 goto crypto_op_free; 9272 9273 if (res_d != NULL) 9274 res_d_tmp = &res_d[i]; 9275 9276 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9277 res_d_tmp, silent, flags); 9278 if (ret != TEST_SUCCESS) 9279 goto crypto_op_free; 9280 9281 rte_crypto_op_free(ut_params->op); 9282 ut_params->op = NULL; 9283 9284 rte_pktmbuf_free(ut_params->ibuf); 9285 ut_params->ibuf = NULL; 9286 } 9287 9288 crypto_op_free: 9289 rte_crypto_op_free(ut_params->op); 9290 ut_params->op = NULL; 9291 9292 rte_pktmbuf_free(ut_params->ibuf); 9293 ut_params->ibuf = NULL; 9294 9295 if (ut_params->sec_session) 9296 rte_security_session_destroy(ctx, ut_params->sec_session); 9297 ut_params->sec_session = NULL; 9298 9299 return ret; 9300 } 9301 9302 static int 9303 test_ipsec_proto_known_vec(const void *test_data) 9304 { 9305 struct ipsec_test_data td_outb; 9306 struct ipsec_test_flags flags; 9307 9308 memset(&flags, 0, sizeof(flags)); 9309 9310 memcpy(&td_outb, test_data, sizeof(td_outb)); 9311 9312 /* Disable IV gen to be able to test with known vectors */ 9313 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9314 9315 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9316 } 9317 9318 static int 9319 test_ipsec_proto_known_vec_inb(const void *td_outb) 9320 { 9321 struct ipsec_test_flags flags; 9322 struct ipsec_test_data td_inb; 9323 9324 memset(&flags, 0, sizeof(flags)); 9325 9326 test_ipsec_td_in_from_out(td_outb, &td_inb); 9327 9328 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9329 } 9330 9331 static int 9332 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9333 { 9334 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9335 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9336 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9337 int ret; 9338 9339 if (flags->iv_gen || 9340 flags->sa_expiry_pkts_soft || 9341 flags->sa_expiry_pkts_hard) 9342 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9343 9344 for (i = 0; i < RTE_DIM(aead_list); i++) { 9345 test_ipsec_td_prepare(&aead_list[i], 9346 NULL, 9347 flags, 9348 td_outb, 9349 nb_pkts); 9350 9351 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9352 flags); 9353 if (ret == TEST_SKIPPED) 9354 continue; 9355 9356 if (ret == TEST_FAILED) 9357 return TEST_FAILED; 9358 9359 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9360 9361 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9362 flags); 9363 if (ret == TEST_SKIPPED) 9364 continue; 9365 9366 if (ret == TEST_FAILED) 9367 return TEST_FAILED; 9368 9369 if (flags->display_alg) 9370 test_ipsec_display_alg(&aead_list[i], NULL); 9371 9372 pass_cnt++; 9373 } 9374 9375 if (pass_cnt > 0) 9376 return TEST_SUCCESS; 9377 else 9378 return TEST_SKIPPED; 9379 } 9380 9381 static int 9382 test_ipsec_proto_display_list(const void *data __rte_unused) 9383 { 9384 struct ipsec_test_flags flags; 9385 9386 memset(&flags, 0, sizeof(flags)); 9387 9388 flags.display_alg = true; 9389 9390 return test_ipsec_proto_all(&flags); 9391 } 9392 9393 static int 9394 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9395 { 9396 struct ipsec_test_flags flags; 9397 9398 memset(&flags, 0, sizeof(flags)); 9399 9400 flags.iv_gen = true; 9401 9402 return test_ipsec_proto_all(&flags); 9403 } 9404 9405 static int 9406 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9407 { 9408 struct ipsec_test_flags flags; 9409 9410 memset(&flags, 0, sizeof(flags)); 9411 9412 flags.sa_expiry_pkts_soft = true; 9413 9414 return test_ipsec_proto_all(&flags); 9415 } 9416 9417 static int 9418 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9419 { 9420 struct ipsec_test_flags flags; 9421 9422 memset(&flags, 0, sizeof(flags)); 9423 9424 flags.sa_expiry_pkts_hard = true; 9425 9426 return test_ipsec_proto_all(&flags); 9427 } 9428 9429 static int 9430 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9431 { 9432 struct ipsec_test_flags flags; 9433 9434 memset(&flags, 0, sizeof(flags)); 9435 9436 flags.icv_corrupt = true; 9437 9438 return test_ipsec_proto_all(&flags); 9439 } 9440 9441 static int 9442 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9443 { 9444 struct ipsec_test_flags flags; 9445 9446 memset(&flags, 0, sizeof(flags)); 9447 9448 flags.udp_encap = true; 9449 9450 return test_ipsec_proto_all(&flags); 9451 } 9452 9453 static int 9454 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9455 { 9456 struct ipsec_test_flags flags; 9457 9458 memset(&flags, 0, sizeof(flags)); 9459 9460 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9461 9462 return test_ipsec_proto_all(&flags); 9463 } 9464 9465 static int 9466 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9467 { 9468 struct ipsec_test_flags flags; 9469 9470 memset(&flags, 0, sizeof(flags)); 9471 9472 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9473 9474 return test_ipsec_proto_all(&flags); 9475 } 9476 9477 static int 9478 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9479 { 9480 struct ipsec_test_flags flags; 9481 9482 memset(&flags, 0, sizeof(flags)); 9483 9484 flags.udp_encap = true; 9485 flags.udp_ports_verify = true; 9486 9487 return test_ipsec_proto_all(&flags); 9488 } 9489 9490 static int 9491 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9492 { 9493 struct ipsec_test_flags flags; 9494 9495 memset(&flags, 0, sizeof(flags)); 9496 9497 flags.ip_csum = true; 9498 9499 return test_ipsec_proto_all(&flags); 9500 } 9501 9502 static int 9503 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9504 { 9505 struct ipsec_test_flags flags; 9506 9507 memset(&flags, 0, sizeof(flags)); 9508 9509 flags.l4_csum = true; 9510 9511 return test_ipsec_proto_all(&flags); 9512 } 9513 9514 static int 9515 test_PDCP_PROTO_all(void) 9516 { 9517 struct crypto_testsuite_params *ts_params = &testsuite_params; 9518 struct crypto_unittest_params *ut_params = &unittest_params; 9519 struct rte_cryptodev_info dev_info; 9520 int status; 9521 9522 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9523 uint64_t feat_flags = dev_info.feature_flags; 9524 9525 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 9526 return TEST_SKIPPED; 9527 9528 /* Set action type */ 9529 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9530 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9531 gbl_action_type; 9532 9533 if (security_proto_supported(ut_params->type, 9534 RTE_SECURITY_PROTOCOL_PDCP) < 0) 9535 return TEST_SKIPPED; 9536 9537 status = test_PDCP_PROTO_cplane_encap_all(); 9538 status += test_PDCP_PROTO_cplane_decap_all(); 9539 status += test_PDCP_PROTO_uplane_encap_all(); 9540 status += test_PDCP_PROTO_uplane_decap_all(); 9541 status += test_PDCP_PROTO_SGL_in_place_32B(); 9542 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 9543 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 9544 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 9545 status += test_PDCP_SDAP_PROTO_encap_all(); 9546 status += test_PDCP_SDAP_PROTO_decap_all(); 9547 status += test_PDCP_PROTO_short_mac(); 9548 9549 if (status) 9550 return TEST_FAILED; 9551 else 9552 return TEST_SUCCESS; 9553 } 9554 9555 static int 9556 test_docsis_proto_uplink(const void *data) 9557 { 9558 const struct docsis_test_data *d_td = data; 9559 struct crypto_testsuite_params *ts_params = &testsuite_params; 9560 struct crypto_unittest_params *ut_params = &unittest_params; 9561 uint8_t *plaintext = NULL; 9562 uint8_t *ciphertext = NULL; 9563 uint8_t *iv_ptr; 9564 int32_t cipher_len, crc_len; 9565 uint32_t crc_data_len; 9566 int ret = TEST_SUCCESS; 9567 9568 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9569 rte_cryptodev_get_sec_ctx( 9570 ts_params->valid_devs[0]); 9571 9572 /* Verify the capabilities */ 9573 struct rte_security_capability_idx sec_cap_idx; 9574 const struct rte_security_capability *sec_cap; 9575 const struct rte_cryptodev_capabilities *crypto_cap; 9576 const struct rte_cryptodev_symmetric_capability *sym_cap; 9577 int j = 0; 9578 9579 /* Set action type */ 9580 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9581 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9582 gbl_action_type; 9583 9584 if (security_proto_supported(ut_params->type, 9585 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9586 return TEST_SKIPPED; 9587 9588 sec_cap_idx.action = ut_params->type; 9589 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9590 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 9591 9592 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9593 if (sec_cap == NULL) 9594 return TEST_SKIPPED; 9595 9596 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9597 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9598 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9599 crypto_cap->sym.xform_type == 9600 RTE_CRYPTO_SYM_XFORM_CIPHER && 9601 crypto_cap->sym.cipher.algo == 9602 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9603 sym_cap = &crypto_cap->sym; 9604 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9605 d_td->key.len, 9606 d_td->iv.len) == 0) 9607 break; 9608 } 9609 } 9610 9611 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9612 return TEST_SKIPPED; 9613 9614 /* Setup source mbuf payload */ 9615 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9616 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9617 rte_pktmbuf_tailroom(ut_params->ibuf)); 9618 9619 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9620 d_td->ciphertext.len); 9621 9622 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 9623 9624 /* Setup cipher session parameters */ 9625 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9626 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9627 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 9628 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9629 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9630 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9631 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9632 ut_params->cipher_xform.next = NULL; 9633 9634 /* Setup DOCSIS session parameters */ 9635 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 9636 9637 struct rte_security_session_conf sess_conf = { 9638 .action_type = ut_params->type, 9639 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9640 .docsis = ut_params->docsis_xform, 9641 .crypto_xform = &ut_params->cipher_xform, 9642 }; 9643 9644 /* Create security session */ 9645 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9646 ts_params->session_mpool, 9647 ts_params->session_priv_mpool); 9648 9649 if (!ut_params->sec_session) { 9650 printf("Test function %s line %u: failed to allocate session\n", 9651 __func__, __LINE__); 9652 ret = TEST_FAILED; 9653 goto on_err; 9654 } 9655 9656 /* Generate crypto op data structure */ 9657 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9658 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9659 if (!ut_params->op) { 9660 printf("Test function %s line %u: failed to allocate symmetric " 9661 "crypto operation\n", __func__, __LINE__); 9662 ret = TEST_FAILED; 9663 goto on_err; 9664 } 9665 9666 /* Setup CRC operation parameters */ 9667 crc_len = d_td->ciphertext.no_crc == false ? 9668 (d_td->ciphertext.len - 9669 d_td->ciphertext.crc_offset - 9670 RTE_ETHER_CRC_LEN) : 9671 0; 9672 crc_len = crc_len > 0 ? crc_len : 0; 9673 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 9674 ut_params->op->sym->auth.data.length = crc_len; 9675 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 9676 9677 /* Setup cipher operation parameters */ 9678 cipher_len = d_td->ciphertext.no_cipher == false ? 9679 (d_td->ciphertext.len - 9680 d_td->ciphertext.cipher_offset) : 9681 0; 9682 cipher_len = cipher_len > 0 ? cipher_len : 0; 9683 ut_params->op->sym->cipher.data.length = cipher_len; 9684 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 9685 9686 /* Setup cipher IV */ 9687 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9688 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9689 9690 /* Attach session to operation */ 9691 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9692 9693 /* Set crypto operation mbufs */ 9694 ut_params->op->sym->m_src = ut_params->ibuf; 9695 ut_params->op->sym->m_dst = NULL; 9696 9697 /* Process crypto operation */ 9698 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9699 NULL) { 9700 printf("Test function %s line %u: failed to process security " 9701 "crypto op\n", __func__, __LINE__); 9702 ret = TEST_FAILED; 9703 goto on_err; 9704 } 9705 9706 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9707 printf("Test function %s line %u: failed to process crypto op\n", 9708 __func__, __LINE__); 9709 ret = TEST_FAILED; 9710 goto on_err; 9711 } 9712 9713 /* Validate plaintext */ 9714 plaintext = ciphertext; 9715 9716 if (memcmp(plaintext, d_td->plaintext.data, 9717 d_td->plaintext.len - crc_data_len)) { 9718 printf("Test function %s line %u: plaintext not as expected\n", 9719 __func__, __LINE__); 9720 rte_hexdump(stdout, "expected", d_td->plaintext.data, 9721 d_td->plaintext.len); 9722 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 9723 ret = TEST_FAILED; 9724 goto on_err; 9725 } 9726 9727 on_err: 9728 rte_crypto_op_free(ut_params->op); 9729 ut_params->op = NULL; 9730 9731 if (ut_params->sec_session) 9732 rte_security_session_destroy(ctx, ut_params->sec_session); 9733 ut_params->sec_session = NULL; 9734 9735 rte_pktmbuf_free(ut_params->ibuf); 9736 ut_params->ibuf = NULL; 9737 9738 return ret; 9739 } 9740 9741 static int 9742 test_docsis_proto_downlink(const void *data) 9743 { 9744 const struct docsis_test_data *d_td = data; 9745 struct crypto_testsuite_params *ts_params = &testsuite_params; 9746 struct crypto_unittest_params *ut_params = &unittest_params; 9747 uint8_t *plaintext = NULL; 9748 uint8_t *ciphertext = NULL; 9749 uint8_t *iv_ptr; 9750 int32_t cipher_len, crc_len; 9751 int ret = TEST_SUCCESS; 9752 9753 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9754 rte_cryptodev_get_sec_ctx( 9755 ts_params->valid_devs[0]); 9756 9757 /* Verify the capabilities */ 9758 struct rte_security_capability_idx sec_cap_idx; 9759 const struct rte_security_capability *sec_cap; 9760 const struct rte_cryptodev_capabilities *crypto_cap; 9761 const struct rte_cryptodev_symmetric_capability *sym_cap; 9762 int j = 0; 9763 9764 /* Set action type */ 9765 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9766 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9767 gbl_action_type; 9768 9769 if (security_proto_supported(ut_params->type, 9770 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9771 return TEST_SKIPPED; 9772 9773 sec_cap_idx.action = ut_params->type; 9774 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9775 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9776 9777 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9778 if (sec_cap == NULL) 9779 return TEST_SKIPPED; 9780 9781 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9782 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9783 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9784 crypto_cap->sym.xform_type == 9785 RTE_CRYPTO_SYM_XFORM_CIPHER && 9786 crypto_cap->sym.cipher.algo == 9787 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9788 sym_cap = &crypto_cap->sym; 9789 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9790 d_td->key.len, 9791 d_td->iv.len) == 0) 9792 break; 9793 } 9794 } 9795 9796 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9797 return TEST_SKIPPED; 9798 9799 /* Setup source mbuf payload */ 9800 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9801 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9802 rte_pktmbuf_tailroom(ut_params->ibuf)); 9803 9804 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9805 d_td->plaintext.len); 9806 9807 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 9808 9809 /* Setup cipher session parameters */ 9810 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9811 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9812 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9813 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9814 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9815 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9816 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9817 ut_params->cipher_xform.next = NULL; 9818 9819 /* Setup DOCSIS session parameters */ 9820 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9821 9822 struct rte_security_session_conf sess_conf = { 9823 .action_type = ut_params->type, 9824 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9825 .docsis = ut_params->docsis_xform, 9826 .crypto_xform = &ut_params->cipher_xform, 9827 }; 9828 9829 /* Create security session */ 9830 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9831 ts_params->session_mpool, 9832 ts_params->session_priv_mpool); 9833 9834 if (!ut_params->sec_session) { 9835 printf("Test function %s line %u: failed to allocate session\n", 9836 __func__, __LINE__); 9837 ret = TEST_FAILED; 9838 goto on_err; 9839 } 9840 9841 /* Generate crypto op data structure */ 9842 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9843 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9844 if (!ut_params->op) { 9845 printf("Test function %s line %u: failed to allocate symmetric " 9846 "crypto operation\n", __func__, __LINE__); 9847 ret = TEST_FAILED; 9848 goto on_err; 9849 } 9850 9851 /* Setup CRC operation parameters */ 9852 crc_len = d_td->plaintext.no_crc == false ? 9853 (d_td->plaintext.len - 9854 d_td->plaintext.crc_offset - 9855 RTE_ETHER_CRC_LEN) : 9856 0; 9857 crc_len = crc_len > 0 ? crc_len : 0; 9858 ut_params->op->sym->auth.data.length = crc_len; 9859 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 9860 9861 /* Setup cipher operation parameters */ 9862 cipher_len = d_td->plaintext.no_cipher == false ? 9863 (d_td->plaintext.len - 9864 d_td->plaintext.cipher_offset) : 9865 0; 9866 cipher_len = cipher_len > 0 ? cipher_len : 0; 9867 ut_params->op->sym->cipher.data.length = cipher_len; 9868 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 9869 9870 /* Setup cipher IV */ 9871 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9872 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9873 9874 /* Attach session to operation */ 9875 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9876 9877 /* Set crypto operation mbufs */ 9878 ut_params->op->sym->m_src = ut_params->ibuf; 9879 ut_params->op->sym->m_dst = NULL; 9880 9881 /* Process crypto operation */ 9882 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9883 NULL) { 9884 printf("Test function %s line %u: failed to process crypto op\n", 9885 __func__, __LINE__); 9886 ret = TEST_FAILED; 9887 goto on_err; 9888 } 9889 9890 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9891 printf("Test function %s line %u: crypto op processing failed\n", 9892 __func__, __LINE__); 9893 ret = TEST_FAILED; 9894 goto on_err; 9895 } 9896 9897 /* Validate ciphertext */ 9898 ciphertext = plaintext; 9899 9900 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 9901 printf("Test function %s line %u: plaintext not as expected\n", 9902 __func__, __LINE__); 9903 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 9904 d_td->ciphertext.len); 9905 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 9906 ret = TEST_FAILED; 9907 goto on_err; 9908 } 9909 9910 on_err: 9911 rte_crypto_op_free(ut_params->op); 9912 ut_params->op = NULL; 9913 9914 if (ut_params->sec_session) 9915 rte_security_session_destroy(ctx, ut_params->sec_session); 9916 ut_params->sec_session = NULL; 9917 9918 rte_pktmbuf_free(ut_params->ibuf); 9919 ut_params->ibuf = NULL; 9920 9921 return ret; 9922 } 9923 #endif 9924 9925 static int 9926 test_AES_GCM_authenticated_encryption_test_case_1(void) 9927 { 9928 return test_authenticated_encryption(&gcm_test_case_1); 9929 } 9930 9931 static int 9932 test_AES_GCM_authenticated_encryption_test_case_2(void) 9933 { 9934 return test_authenticated_encryption(&gcm_test_case_2); 9935 } 9936 9937 static int 9938 test_AES_GCM_authenticated_encryption_test_case_3(void) 9939 { 9940 return test_authenticated_encryption(&gcm_test_case_3); 9941 } 9942 9943 static int 9944 test_AES_GCM_authenticated_encryption_test_case_4(void) 9945 { 9946 return test_authenticated_encryption(&gcm_test_case_4); 9947 } 9948 9949 static int 9950 test_AES_GCM_authenticated_encryption_test_case_5(void) 9951 { 9952 return test_authenticated_encryption(&gcm_test_case_5); 9953 } 9954 9955 static int 9956 test_AES_GCM_authenticated_encryption_test_case_6(void) 9957 { 9958 return test_authenticated_encryption(&gcm_test_case_6); 9959 } 9960 9961 static int 9962 test_AES_GCM_authenticated_encryption_test_case_7(void) 9963 { 9964 return test_authenticated_encryption(&gcm_test_case_7); 9965 } 9966 9967 static int 9968 test_AES_GCM_authenticated_encryption_test_case_8(void) 9969 { 9970 return test_authenticated_encryption(&gcm_test_case_8); 9971 } 9972 9973 static int 9974 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 9975 { 9976 return test_authenticated_encryption(&gcm_J0_test_case_1); 9977 } 9978 9979 static int 9980 test_AES_GCM_auth_encryption_test_case_192_1(void) 9981 { 9982 return test_authenticated_encryption(&gcm_test_case_192_1); 9983 } 9984 9985 static int 9986 test_AES_GCM_auth_encryption_test_case_192_2(void) 9987 { 9988 return test_authenticated_encryption(&gcm_test_case_192_2); 9989 } 9990 9991 static int 9992 test_AES_GCM_auth_encryption_test_case_192_3(void) 9993 { 9994 return test_authenticated_encryption(&gcm_test_case_192_3); 9995 } 9996 9997 static int 9998 test_AES_GCM_auth_encryption_test_case_192_4(void) 9999 { 10000 return test_authenticated_encryption(&gcm_test_case_192_4); 10001 } 10002 10003 static int 10004 test_AES_GCM_auth_encryption_test_case_192_5(void) 10005 { 10006 return test_authenticated_encryption(&gcm_test_case_192_5); 10007 } 10008 10009 static int 10010 test_AES_GCM_auth_encryption_test_case_192_6(void) 10011 { 10012 return test_authenticated_encryption(&gcm_test_case_192_6); 10013 } 10014 10015 static int 10016 test_AES_GCM_auth_encryption_test_case_192_7(void) 10017 { 10018 return test_authenticated_encryption(&gcm_test_case_192_7); 10019 } 10020 10021 static int 10022 test_AES_GCM_auth_encryption_test_case_256_1(void) 10023 { 10024 return test_authenticated_encryption(&gcm_test_case_256_1); 10025 } 10026 10027 static int 10028 test_AES_GCM_auth_encryption_test_case_256_2(void) 10029 { 10030 return test_authenticated_encryption(&gcm_test_case_256_2); 10031 } 10032 10033 static int 10034 test_AES_GCM_auth_encryption_test_case_256_3(void) 10035 { 10036 return test_authenticated_encryption(&gcm_test_case_256_3); 10037 } 10038 10039 static int 10040 test_AES_GCM_auth_encryption_test_case_256_4(void) 10041 { 10042 return test_authenticated_encryption(&gcm_test_case_256_4); 10043 } 10044 10045 static int 10046 test_AES_GCM_auth_encryption_test_case_256_5(void) 10047 { 10048 return test_authenticated_encryption(&gcm_test_case_256_5); 10049 } 10050 10051 static int 10052 test_AES_GCM_auth_encryption_test_case_256_6(void) 10053 { 10054 return test_authenticated_encryption(&gcm_test_case_256_6); 10055 } 10056 10057 static int 10058 test_AES_GCM_auth_encryption_test_case_256_7(void) 10059 { 10060 return test_authenticated_encryption(&gcm_test_case_256_7); 10061 } 10062 10063 static int 10064 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10065 { 10066 return test_authenticated_encryption(&gcm_test_case_aad_1); 10067 } 10068 10069 static int 10070 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10071 { 10072 return test_authenticated_encryption(&gcm_test_case_aad_2); 10073 } 10074 10075 static int 10076 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10077 { 10078 struct aead_test_data tdata; 10079 int res; 10080 10081 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10082 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10083 tdata.iv.data[0] += 1; 10084 res = test_authenticated_encryption(&tdata); 10085 if (res == TEST_SKIPPED) 10086 return res; 10087 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10088 return TEST_SUCCESS; 10089 } 10090 10091 static int 10092 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10093 { 10094 struct aead_test_data tdata; 10095 int res; 10096 10097 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10098 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10099 tdata.plaintext.data[0] += 1; 10100 res = test_authenticated_encryption(&tdata); 10101 if (res == TEST_SKIPPED) 10102 return res; 10103 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10104 return TEST_SUCCESS; 10105 } 10106 10107 static int 10108 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10109 { 10110 struct aead_test_data tdata; 10111 int res; 10112 10113 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10114 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10115 tdata.ciphertext.data[0] += 1; 10116 res = test_authenticated_encryption(&tdata); 10117 if (res == TEST_SKIPPED) 10118 return res; 10119 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10120 return TEST_SUCCESS; 10121 } 10122 10123 static int 10124 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10125 { 10126 struct aead_test_data tdata; 10127 int res; 10128 10129 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10130 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10131 tdata.aad.len += 1; 10132 res = test_authenticated_encryption(&tdata); 10133 if (res == TEST_SKIPPED) 10134 return res; 10135 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10136 return TEST_SUCCESS; 10137 } 10138 10139 static int 10140 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10141 { 10142 struct aead_test_data tdata; 10143 uint8_t aad[gcm_test_case_7.aad.len]; 10144 int res; 10145 10146 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10147 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10148 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10149 aad[0] += 1; 10150 tdata.aad.data = aad; 10151 res = test_authenticated_encryption(&tdata); 10152 if (res == TEST_SKIPPED) 10153 return res; 10154 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10155 return TEST_SUCCESS; 10156 } 10157 10158 static int 10159 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10160 { 10161 struct aead_test_data tdata; 10162 int res; 10163 10164 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10165 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10166 tdata.auth_tag.data[0] += 1; 10167 res = test_authenticated_encryption(&tdata); 10168 if (res == TEST_SKIPPED) 10169 return res; 10170 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10171 return TEST_SUCCESS; 10172 } 10173 10174 static int 10175 test_authenticated_decryption(const struct aead_test_data *tdata) 10176 { 10177 struct crypto_testsuite_params *ts_params = &testsuite_params; 10178 struct crypto_unittest_params *ut_params = &unittest_params; 10179 10180 int retval; 10181 uint8_t *plaintext; 10182 uint32_t i; 10183 struct rte_cryptodev_info dev_info; 10184 10185 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10186 uint64_t feat_flags = dev_info.feature_flags; 10187 10188 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10189 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10190 printf("Device doesn't support RAW data-path APIs.\n"); 10191 return TEST_SKIPPED; 10192 } 10193 10194 /* Verify the capabilities */ 10195 struct rte_cryptodev_sym_capability_idx cap_idx; 10196 const struct rte_cryptodev_symmetric_capability *capability; 10197 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10198 cap_idx.algo.aead = tdata->algo; 10199 capability = rte_cryptodev_sym_capability_get( 10200 ts_params->valid_devs[0], &cap_idx); 10201 if (capability == NULL) 10202 return TEST_SKIPPED; 10203 if (rte_cryptodev_sym_capability_check_aead( 10204 capability, tdata->key.len, tdata->auth_tag.len, 10205 tdata->aad.len, tdata->iv.len)) 10206 return TEST_SKIPPED; 10207 10208 /* Create AEAD session */ 10209 retval = create_aead_session(ts_params->valid_devs[0], 10210 tdata->algo, 10211 RTE_CRYPTO_AEAD_OP_DECRYPT, 10212 tdata->key.data, tdata->key.len, 10213 tdata->aad.len, tdata->auth_tag.len, 10214 tdata->iv.len); 10215 if (retval < 0) 10216 return retval; 10217 10218 /* alloc mbuf and set payload */ 10219 if (tdata->aad.len > MBUF_SIZE) { 10220 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10221 /* Populate full size of add data */ 10222 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10223 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10224 } else 10225 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10226 10227 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10228 rte_pktmbuf_tailroom(ut_params->ibuf)); 10229 10230 /* Create AEAD operation */ 10231 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10232 if (retval < 0) 10233 return retval; 10234 10235 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10236 10237 ut_params->op->sym->m_src = ut_params->ibuf; 10238 10239 /* Process crypto operation */ 10240 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10241 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10242 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10243 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10244 ut_params->op, 0, 0, 0, 0); 10245 else 10246 TEST_ASSERT_NOT_NULL( 10247 process_crypto_request(ts_params->valid_devs[0], 10248 ut_params->op), "failed to process sym crypto op"); 10249 10250 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10251 "crypto op processing failed"); 10252 10253 if (ut_params->op->sym->m_dst) 10254 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10255 uint8_t *); 10256 else 10257 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10258 uint8_t *, 10259 ut_params->op->sym->cipher.data.offset); 10260 10261 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10262 10263 /* Validate obuf */ 10264 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10265 plaintext, 10266 tdata->plaintext.data, 10267 tdata->plaintext.len, 10268 "Plaintext data not as expected"); 10269 10270 TEST_ASSERT_EQUAL(ut_params->op->status, 10271 RTE_CRYPTO_OP_STATUS_SUCCESS, 10272 "Authentication failed"); 10273 10274 return 0; 10275 } 10276 10277 static int 10278 test_AES_GCM_authenticated_decryption_test_case_1(void) 10279 { 10280 return test_authenticated_decryption(&gcm_test_case_1); 10281 } 10282 10283 static int 10284 test_AES_GCM_authenticated_decryption_test_case_2(void) 10285 { 10286 return test_authenticated_decryption(&gcm_test_case_2); 10287 } 10288 10289 static int 10290 test_AES_GCM_authenticated_decryption_test_case_3(void) 10291 { 10292 return test_authenticated_decryption(&gcm_test_case_3); 10293 } 10294 10295 static int 10296 test_AES_GCM_authenticated_decryption_test_case_4(void) 10297 { 10298 return test_authenticated_decryption(&gcm_test_case_4); 10299 } 10300 10301 static int 10302 test_AES_GCM_authenticated_decryption_test_case_5(void) 10303 { 10304 return test_authenticated_decryption(&gcm_test_case_5); 10305 } 10306 10307 static int 10308 test_AES_GCM_authenticated_decryption_test_case_6(void) 10309 { 10310 return test_authenticated_decryption(&gcm_test_case_6); 10311 } 10312 10313 static int 10314 test_AES_GCM_authenticated_decryption_test_case_7(void) 10315 { 10316 return test_authenticated_decryption(&gcm_test_case_7); 10317 } 10318 10319 static int 10320 test_AES_GCM_authenticated_decryption_test_case_8(void) 10321 { 10322 return test_authenticated_decryption(&gcm_test_case_8); 10323 } 10324 10325 static int 10326 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 10327 { 10328 return test_authenticated_decryption(&gcm_J0_test_case_1); 10329 } 10330 10331 static int 10332 test_AES_GCM_auth_decryption_test_case_192_1(void) 10333 { 10334 return test_authenticated_decryption(&gcm_test_case_192_1); 10335 } 10336 10337 static int 10338 test_AES_GCM_auth_decryption_test_case_192_2(void) 10339 { 10340 return test_authenticated_decryption(&gcm_test_case_192_2); 10341 } 10342 10343 static int 10344 test_AES_GCM_auth_decryption_test_case_192_3(void) 10345 { 10346 return test_authenticated_decryption(&gcm_test_case_192_3); 10347 } 10348 10349 static int 10350 test_AES_GCM_auth_decryption_test_case_192_4(void) 10351 { 10352 return test_authenticated_decryption(&gcm_test_case_192_4); 10353 } 10354 10355 static int 10356 test_AES_GCM_auth_decryption_test_case_192_5(void) 10357 { 10358 return test_authenticated_decryption(&gcm_test_case_192_5); 10359 } 10360 10361 static int 10362 test_AES_GCM_auth_decryption_test_case_192_6(void) 10363 { 10364 return test_authenticated_decryption(&gcm_test_case_192_6); 10365 } 10366 10367 static int 10368 test_AES_GCM_auth_decryption_test_case_192_7(void) 10369 { 10370 return test_authenticated_decryption(&gcm_test_case_192_7); 10371 } 10372 10373 static int 10374 test_AES_GCM_auth_decryption_test_case_256_1(void) 10375 { 10376 return test_authenticated_decryption(&gcm_test_case_256_1); 10377 } 10378 10379 static int 10380 test_AES_GCM_auth_decryption_test_case_256_2(void) 10381 { 10382 return test_authenticated_decryption(&gcm_test_case_256_2); 10383 } 10384 10385 static int 10386 test_AES_GCM_auth_decryption_test_case_256_3(void) 10387 { 10388 return test_authenticated_decryption(&gcm_test_case_256_3); 10389 } 10390 10391 static int 10392 test_AES_GCM_auth_decryption_test_case_256_4(void) 10393 { 10394 return test_authenticated_decryption(&gcm_test_case_256_4); 10395 } 10396 10397 static int 10398 test_AES_GCM_auth_decryption_test_case_256_5(void) 10399 { 10400 return test_authenticated_decryption(&gcm_test_case_256_5); 10401 } 10402 10403 static int 10404 test_AES_GCM_auth_decryption_test_case_256_6(void) 10405 { 10406 return test_authenticated_decryption(&gcm_test_case_256_6); 10407 } 10408 10409 static int 10410 test_AES_GCM_auth_decryption_test_case_256_7(void) 10411 { 10412 return test_authenticated_decryption(&gcm_test_case_256_7); 10413 } 10414 10415 static int 10416 test_AES_GCM_auth_decryption_test_case_aad_1(void) 10417 { 10418 return test_authenticated_decryption(&gcm_test_case_aad_1); 10419 } 10420 10421 static int 10422 test_AES_GCM_auth_decryption_test_case_aad_2(void) 10423 { 10424 return test_authenticated_decryption(&gcm_test_case_aad_2); 10425 } 10426 10427 static int 10428 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 10429 { 10430 struct aead_test_data tdata; 10431 int res; 10432 10433 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10434 tdata.iv.data[0] += 1; 10435 res = test_authenticated_decryption(&tdata); 10436 if (res == TEST_SKIPPED) 10437 return res; 10438 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10439 return TEST_SUCCESS; 10440 } 10441 10442 static int 10443 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 10444 { 10445 struct aead_test_data tdata; 10446 int res; 10447 10448 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10449 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10450 tdata.plaintext.data[0] += 1; 10451 res = test_authenticated_decryption(&tdata); 10452 if (res == TEST_SKIPPED) 10453 return res; 10454 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10455 return TEST_SUCCESS; 10456 } 10457 10458 static int 10459 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 10460 { 10461 struct aead_test_data tdata; 10462 int res; 10463 10464 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10465 tdata.ciphertext.data[0] += 1; 10466 res = test_authenticated_decryption(&tdata); 10467 if (res == TEST_SKIPPED) 10468 return res; 10469 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10470 return TEST_SUCCESS; 10471 } 10472 10473 static int 10474 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 10475 { 10476 struct aead_test_data tdata; 10477 int res; 10478 10479 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10480 tdata.aad.len += 1; 10481 res = test_authenticated_decryption(&tdata); 10482 if (res == TEST_SKIPPED) 10483 return res; 10484 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10485 return TEST_SUCCESS; 10486 } 10487 10488 static int 10489 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 10490 { 10491 struct aead_test_data tdata; 10492 uint8_t aad[gcm_test_case_7.aad.len]; 10493 int res; 10494 10495 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10496 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10497 aad[0] += 1; 10498 tdata.aad.data = aad; 10499 res = test_authenticated_decryption(&tdata); 10500 if (res == TEST_SKIPPED) 10501 return res; 10502 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10503 return TEST_SUCCESS; 10504 } 10505 10506 static int 10507 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 10508 { 10509 struct aead_test_data tdata; 10510 int res; 10511 10512 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10513 tdata.auth_tag.data[0] += 1; 10514 res = test_authenticated_decryption(&tdata); 10515 if (res == TEST_SKIPPED) 10516 return res; 10517 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 10518 return TEST_SUCCESS; 10519 } 10520 10521 static int 10522 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 10523 { 10524 struct crypto_testsuite_params *ts_params = &testsuite_params; 10525 struct crypto_unittest_params *ut_params = &unittest_params; 10526 10527 int retval; 10528 uint8_t *ciphertext, *auth_tag; 10529 uint16_t plaintext_pad_len; 10530 struct rte_cryptodev_info dev_info; 10531 10532 /* Verify the capabilities */ 10533 struct rte_cryptodev_sym_capability_idx cap_idx; 10534 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10535 cap_idx.algo.aead = tdata->algo; 10536 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10537 &cap_idx) == NULL) 10538 return TEST_SKIPPED; 10539 10540 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10541 uint64_t feat_flags = dev_info.feature_flags; 10542 10543 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10544 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 10545 return TEST_SKIPPED; 10546 10547 /* not supported with CPU crypto */ 10548 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10549 return TEST_SKIPPED; 10550 10551 /* Create AEAD session */ 10552 retval = create_aead_session(ts_params->valid_devs[0], 10553 tdata->algo, 10554 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10555 tdata->key.data, tdata->key.len, 10556 tdata->aad.len, tdata->auth_tag.len, 10557 tdata->iv.len); 10558 if (retval < 0) 10559 return retval; 10560 10561 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10562 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10563 10564 /* clear mbuf payload */ 10565 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10566 rte_pktmbuf_tailroom(ut_params->ibuf)); 10567 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10568 rte_pktmbuf_tailroom(ut_params->obuf)); 10569 10570 /* Create AEAD operation */ 10571 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10572 if (retval < 0) 10573 return retval; 10574 10575 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10576 10577 ut_params->op->sym->m_src = ut_params->ibuf; 10578 ut_params->op->sym->m_dst = ut_params->obuf; 10579 10580 /* Process crypto operation */ 10581 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10582 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10583 ut_params->op, 0, 0, 0, 0); 10584 else 10585 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10586 ut_params->op), "failed to process sym crypto op"); 10587 10588 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10589 "crypto op processing failed"); 10590 10591 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10592 10593 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10594 ut_params->op->sym->cipher.data.offset); 10595 auth_tag = ciphertext + plaintext_pad_len; 10596 10597 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10598 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10599 10600 /* Validate obuf */ 10601 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10602 ciphertext, 10603 tdata->ciphertext.data, 10604 tdata->ciphertext.len, 10605 "Ciphertext data not as expected"); 10606 10607 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10608 auth_tag, 10609 tdata->auth_tag.data, 10610 tdata->auth_tag.len, 10611 "Generated auth tag not as expected"); 10612 10613 return 0; 10614 10615 } 10616 10617 static int 10618 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 10619 { 10620 return test_authenticated_encryption_oop(&gcm_test_case_5); 10621 } 10622 10623 static int 10624 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 10625 { 10626 struct crypto_testsuite_params *ts_params = &testsuite_params; 10627 struct crypto_unittest_params *ut_params = &unittest_params; 10628 10629 int retval; 10630 uint8_t *plaintext; 10631 struct rte_cryptodev_info dev_info; 10632 10633 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10634 uint64_t feat_flags = dev_info.feature_flags; 10635 10636 /* Verify the capabilities */ 10637 struct rte_cryptodev_sym_capability_idx cap_idx; 10638 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10639 cap_idx.algo.aead = tdata->algo; 10640 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10641 &cap_idx) == NULL) 10642 return TEST_SKIPPED; 10643 10644 /* not supported with CPU crypto and raw data-path APIs*/ 10645 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 10646 global_api_test_type == CRYPTODEV_RAW_API_TEST) 10647 return TEST_SKIPPED; 10648 10649 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10650 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10651 printf("Device does not support RAW data-path APIs.\n"); 10652 return TEST_SKIPPED; 10653 } 10654 10655 /* Create AEAD session */ 10656 retval = create_aead_session(ts_params->valid_devs[0], 10657 tdata->algo, 10658 RTE_CRYPTO_AEAD_OP_DECRYPT, 10659 tdata->key.data, tdata->key.len, 10660 tdata->aad.len, tdata->auth_tag.len, 10661 tdata->iv.len); 10662 if (retval < 0) 10663 return retval; 10664 10665 /* alloc mbuf and set payload */ 10666 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10667 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10668 10669 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10670 rte_pktmbuf_tailroom(ut_params->ibuf)); 10671 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10672 rte_pktmbuf_tailroom(ut_params->obuf)); 10673 10674 /* Create AEAD operation */ 10675 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10676 if (retval < 0) 10677 return retval; 10678 10679 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10680 10681 ut_params->op->sym->m_src = ut_params->ibuf; 10682 ut_params->op->sym->m_dst = ut_params->obuf; 10683 10684 /* Process crypto operation */ 10685 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10686 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10687 ut_params->op, 0, 0, 0, 0); 10688 else 10689 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10690 ut_params->op), "failed to process sym crypto op"); 10691 10692 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10693 "crypto op processing failed"); 10694 10695 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10696 ut_params->op->sym->cipher.data.offset); 10697 10698 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10699 10700 /* Validate obuf */ 10701 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10702 plaintext, 10703 tdata->plaintext.data, 10704 tdata->plaintext.len, 10705 "Plaintext data not as expected"); 10706 10707 TEST_ASSERT_EQUAL(ut_params->op->status, 10708 RTE_CRYPTO_OP_STATUS_SUCCESS, 10709 "Authentication failed"); 10710 return 0; 10711 } 10712 10713 static int 10714 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 10715 { 10716 return test_authenticated_decryption_oop(&gcm_test_case_5); 10717 } 10718 10719 static int 10720 test_authenticated_encryption_sessionless( 10721 const struct aead_test_data *tdata) 10722 { 10723 struct crypto_testsuite_params *ts_params = &testsuite_params; 10724 struct crypto_unittest_params *ut_params = &unittest_params; 10725 10726 int retval; 10727 uint8_t *ciphertext, *auth_tag; 10728 uint16_t plaintext_pad_len; 10729 uint8_t key[tdata->key.len + 1]; 10730 struct rte_cryptodev_info dev_info; 10731 10732 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10733 uint64_t feat_flags = dev_info.feature_flags; 10734 10735 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10736 printf("Device doesn't support Sessionless ops.\n"); 10737 return TEST_SKIPPED; 10738 } 10739 10740 /* not supported with CPU crypto */ 10741 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10742 return TEST_SKIPPED; 10743 10744 /* Verify the capabilities */ 10745 struct rte_cryptodev_sym_capability_idx cap_idx; 10746 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10747 cap_idx.algo.aead = tdata->algo; 10748 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10749 &cap_idx) == NULL) 10750 return TEST_SKIPPED; 10751 10752 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10753 10754 /* clear mbuf payload */ 10755 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10756 rte_pktmbuf_tailroom(ut_params->ibuf)); 10757 10758 /* Create AEAD operation */ 10759 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10760 if (retval < 0) 10761 return retval; 10762 10763 /* Create GCM xform */ 10764 memcpy(key, tdata->key.data, tdata->key.len); 10765 retval = create_aead_xform(ut_params->op, 10766 tdata->algo, 10767 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10768 key, tdata->key.len, 10769 tdata->aad.len, tdata->auth_tag.len, 10770 tdata->iv.len); 10771 if (retval < 0) 10772 return retval; 10773 10774 ut_params->op->sym->m_src = ut_params->ibuf; 10775 10776 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10777 RTE_CRYPTO_OP_SESSIONLESS, 10778 "crypto op session type not sessionless"); 10779 10780 /* Process crypto operation */ 10781 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10782 ut_params->op), "failed to process sym crypto op"); 10783 10784 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10785 10786 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10787 "crypto op status not success"); 10788 10789 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10790 10791 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10792 ut_params->op->sym->cipher.data.offset); 10793 auth_tag = ciphertext + plaintext_pad_len; 10794 10795 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10796 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10797 10798 /* Validate obuf */ 10799 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10800 ciphertext, 10801 tdata->ciphertext.data, 10802 tdata->ciphertext.len, 10803 "Ciphertext data not as expected"); 10804 10805 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10806 auth_tag, 10807 tdata->auth_tag.data, 10808 tdata->auth_tag.len, 10809 "Generated auth tag not as expected"); 10810 10811 return 0; 10812 10813 } 10814 10815 static int 10816 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 10817 { 10818 return test_authenticated_encryption_sessionless( 10819 &gcm_test_case_5); 10820 } 10821 10822 static int 10823 test_authenticated_decryption_sessionless( 10824 const struct aead_test_data *tdata) 10825 { 10826 struct crypto_testsuite_params *ts_params = &testsuite_params; 10827 struct crypto_unittest_params *ut_params = &unittest_params; 10828 10829 int retval; 10830 uint8_t *plaintext; 10831 uint8_t key[tdata->key.len + 1]; 10832 struct rte_cryptodev_info dev_info; 10833 10834 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10835 uint64_t feat_flags = dev_info.feature_flags; 10836 10837 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10838 printf("Device doesn't support Sessionless ops.\n"); 10839 return TEST_SKIPPED; 10840 } 10841 10842 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10843 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10844 printf("Device doesn't support RAW data-path APIs.\n"); 10845 return TEST_SKIPPED; 10846 } 10847 10848 /* not supported with CPU crypto */ 10849 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10850 return TEST_SKIPPED; 10851 10852 /* Verify the capabilities */ 10853 struct rte_cryptodev_sym_capability_idx cap_idx; 10854 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10855 cap_idx.algo.aead = tdata->algo; 10856 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10857 &cap_idx) == NULL) 10858 return TEST_SKIPPED; 10859 10860 /* alloc mbuf and set payload */ 10861 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10862 10863 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10864 rte_pktmbuf_tailroom(ut_params->ibuf)); 10865 10866 /* Create AEAD operation */ 10867 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10868 if (retval < 0) 10869 return retval; 10870 10871 /* Create AEAD xform */ 10872 memcpy(key, tdata->key.data, tdata->key.len); 10873 retval = create_aead_xform(ut_params->op, 10874 tdata->algo, 10875 RTE_CRYPTO_AEAD_OP_DECRYPT, 10876 key, tdata->key.len, 10877 tdata->aad.len, tdata->auth_tag.len, 10878 tdata->iv.len); 10879 if (retval < 0) 10880 return retval; 10881 10882 ut_params->op->sym->m_src = ut_params->ibuf; 10883 10884 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10885 RTE_CRYPTO_OP_SESSIONLESS, 10886 "crypto op session type not sessionless"); 10887 10888 /* Process crypto operation */ 10889 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10890 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10891 ut_params->op, 0, 0, 0, 0); 10892 else 10893 TEST_ASSERT_NOT_NULL(process_crypto_request( 10894 ts_params->valid_devs[0], ut_params->op), 10895 "failed to process sym crypto op"); 10896 10897 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10898 10899 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10900 "crypto op status not success"); 10901 10902 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10903 ut_params->op->sym->cipher.data.offset); 10904 10905 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10906 10907 /* Validate obuf */ 10908 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10909 plaintext, 10910 tdata->plaintext.data, 10911 tdata->plaintext.len, 10912 "Plaintext data not as expected"); 10913 10914 TEST_ASSERT_EQUAL(ut_params->op->status, 10915 RTE_CRYPTO_OP_STATUS_SUCCESS, 10916 "Authentication failed"); 10917 return 0; 10918 } 10919 10920 static int 10921 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 10922 { 10923 return test_authenticated_decryption_sessionless( 10924 &gcm_test_case_5); 10925 } 10926 10927 static int 10928 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 10929 { 10930 return test_authenticated_encryption(&ccm_test_case_128_1); 10931 } 10932 10933 static int 10934 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 10935 { 10936 return test_authenticated_encryption(&ccm_test_case_128_2); 10937 } 10938 10939 static int 10940 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 10941 { 10942 return test_authenticated_encryption(&ccm_test_case_128_3); 10943 } 10944 10945 static int 10946 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 10947 { 10948 return test_authenticated_decryption(&ccm_test_case_128_1); 10949 } 10950 10951 static int 10952 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 10953 { 10954 return test_authenticated_decryption(&ccm_test_case_128_2); 10955 } 10956 10957 static int 10958 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 10959 { 10960 return test_authenticated_decryption(&ccm_test_case_128_3); 10961 } 10962 10963 static int 10964 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 10965 { 10966 return test_authenticated_encryption(&ccm_test_case_192_1); 10967 } 10968 10969 static int 10970 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 10971 { 10972 return test_authenticated_encryption(&ccm_test_case_192_2); 10973 } 10974 10975 static int 10976 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 10977 { 10978 return test_authenticated_encryption(&ccm_test_case_192_3); 10979 } 10980 10981 static int 10982 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 10983 { 10984 return test_authenticated_decryption(&ccm_test_case_192_1); 10985 } 10986 10987 static int 10988 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 10989 { 10990 return test_authenticated_decryption(&ccm_test_case_192_2); 10991 } 10992 10993 static int 10994 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 10995 { 10996 return test_authenticated_decryption(&ccm_test_case_192_3); 10997 } 10998 10999 static int 11000 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11001 { 11002 return test_authenticated_encryption(&ccm_test_case_256_1); 11003 } 11004 11005 static int 11006 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11007 { 11008 return test_authenticated_encryption(&ccm_test_case_256_2); 11009 } 11010 11011 static int 11012 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11013 { 11014 return test_authenticated_encryption(&ccm_test_case_256_3); 11015 } 11016 11017 static int 11018 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11019 { 11020 return test_authenticated_decryption(&ccm_test_case_256_1); 11021 } 11022 11023 static int 11024 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11025 { 11026 return test_authenticated_decryption(&ccm_test_case_256_2); 11027 } 11028 11029 static int 11030 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11031 { 11032 return test_authenticated_decryption(&ccm_test_case_256_3); 11033 } 11034 11035 static int 11036 test_stats(void) 11037 { 11038 struct crypto_testsuite_params *ts_params = &testsuite_params; 11039 struct rte_cryptodev_stats stats; 11040 11041 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11042 return TEST_SKIPPED; 11043 11044 /* Verify the capabilities */ 11045 struct rte_cryptodev_sym_capability_idx cap_idx; 11046 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11047 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11048 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11049 &cap_idx) == NULL) 11050 return TEST_SKIPPED; 11051 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11052 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11053 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11054 &cap_idx) == NULL) 11055 return TEST_SKIPPED; 11056 11057 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11058 == -ENOTSUP) 11059 return TEST_SKIPPED; 11060 11061 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11062 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11063 &stats) == -ENODEV), 11064 "rte_cryptodev_stats_get invalid dev failed"); 11065 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11066 "rte_cryptodev_stats_get invalid Param failed"); 11067 11068 /* Test expected values */ 11069 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11070 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11071 &stats), 11072 "rte_cryptodev_stats_get failed"); 11073 TEST_ASSERT((stats.enqueued_count == 1), 11074 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11075 TEST_ASSERT((stats.dequeued_count == 1), 11076 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11077 TEST_ASSERT((stats.enqueue_err_count == 0), 11078 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11079 TEST_ASSERT((stats.dequeue_err_count == 0), 11080 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11081 11082 /* invalid device but should ignore and not reset device stats*/ 11083 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11084 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11085 &stats), 11086 "rte_cryptodev_stats_get failed"); 11087 TEST_ASSERT((stats.enqueued_count == 1), 11088 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11089 11090 /* check that a valid reset clears stats */ 11091 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11092 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11093 &stats), 11094 "rte_cryptodev_stats_get failed"); 11095 TEST_ASSERT((stats.enqueued_count == 0), 11096 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11097 TEST_ASSERT((stats.dequeued_count == 0), 11098 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11099 11100 return TEST_SUCCESS; 11101 } 11102 11103 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11104 struct crypto_unittest_params *ut_params, 11105 enum rte_crypto_auth_operation op, 11106 const struct HMAC_MD5_vector *test_case) 11107 { 11108 uint8_t key[64]; 11109 int status; 11110 11111 memcpy(key, test_case->key.data, test_case->key.len); 11112 11113 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11114 ut_params->auth_xform.next = NULL; 11115 ut_params->auth_xform.auth.op = op; 11116 11117 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11118 11119 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11120 ut_params->auth_xform.auth.key.length = test_case->key.len; 11121 ut_params->auth_xform.auth.key.data = key; 11122 11123 ut_params->sess = rte_cryptodev_sym_session_create( 11124 ts_params->session_mpool); 11125 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11126 if (ut_params->sess == NULL) 11127 return TEST_FAILED; 11128 11129 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11130 ut_params->sess, &ut_params->auth_xform, 11131 ts_params->session_priv_mpool); 11132 if (status == -ENOTSUP) 11133 return TEST_SKIPPED; 11134 11135 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11136 11137 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11138 rte_pktmbuf_tailroom(ut_params->ibuf)); 11139 11140 return 0; 11141 } 11142 11143 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11144 const struct HMAC_MD5_vector *test_case, 11145 uint8_t **plaintext) 11146 { 11147 uint16_t plaintext_pad_len; 11148 11149 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11150 11151 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11152 16); 11153 11154 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11155 plaintext_pad_len); 11156 memcpy(*plaintext, test_case->plaintext.data, 11157 test_case->plaintext.len); 11158 11159 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11160 ut_params->ibuf, MD5_DIGEST_LEN); 11161 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11162 "no room to append digest"); 11163 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11164 ut_params->ibuf, plaintext_pad_len); 11165 11166 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11167 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11168 test_case->auth_tag.len); 11169 } 11170 11171 sym_op->auth.data.offset = 0; 11172 sym_op->auth.data.length = test_case->plaintext.len; 11173 11174 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11175 ut_params->op->sym->m_src = ut_params->ibuf; 11176 11177 return 0; 11178 } 11179 11180 static int 11181 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11182 { 11183 uint16_t plaintext_pad_len; 11184 uint8_t *plaintext, *auth_tag; 11185 11186 struct crypto_testsuite_params *ts_params = &testsuite_params; 11187 struct crypto_unittest_params *ut_params = &unittest_params; 11188 struct rte_cryptodev_info dev_info; 11189 11190 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11191 uint64_t feat_flags = dev_info.feature_flags; 11192 11193 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11194 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11195 printf("Device doesn't support RAW data-path APIs.\n"); 11196 return TEST_SKIPPED; 11197 } 11198 11199 /* Verify the capabilities */ 11200 struct rte_cryptodev_sym_capability_idx cap_idx; 11201 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11202 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11203 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11204 &cap_idx) == NULL) 11205 return TEST_SKIPPED; 11206 11207 if (MD5_HMAC_create_session(ts_params, ut_params, 11208 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11209 return TEST_FAILED; 11210 11211 /* Generate Crypto op data structure */ 11212 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11213 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11214 TEST_ASSERT_NOT_NULL(ut_params->op, 11215 "Failed to allocate symmetric crypto operation struct"); 11216 11217 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11218 16); 11219 11220 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11221 return TEST_FAILED; 11222 11223 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11224 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11225 ut_params->op); 11226 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11227 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11228 ut_params->op, 0, 1, 0, 0); 11229 else 11230 TEST_ASSERT_NOT_NULL( 11231 process_crypto_request(ts_params->valid_devs[0], 11232 ut_params->op), 11233 "failed to process sym crypto op"); 11234 11235 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11236 "crypto op processing failed"); 11237 11238 if (ut_params->op->sym->m_dst) { 11239 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11240 uint8_t *, plaintext_pad_len); 11241 } else { 11242 auth_tag = plaintext + plaintext_pad_len; 11243 } 11244 11245 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11246 auth_tag, 11247 test_case->auth_tag.data, 11248 test_case->auth_tag.len, 11249 "HMAC_MD5 generated tag not as expected"); 11250 11251 return TEST_SUCCESS; 11252 } 11253 11254 static int 11255 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11256 { 11257 uint8_t *plaintext; 11258 11259 struct crypto_testsuite_params *ts_params = &testsuite_params; 11260 struct crypto_unittest_params *ut_params = &unittest_params; 11261 struct rte_cryptodev_info dev_info; 11262 11263 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11264 uint64_t feat_flags = dev_info.feature_flags; 11265 11266 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11267 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11268 printf("Device doesn't support RAW data-path APIs.\n"); 11269 return TEST_SKIPPED; 11270 } 11271 11272 /* Verify the capabilities */ 11273 struct rte_cryptodev_sym_capability_idx cap_idx; 11274 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11275 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11276 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11277 &cap_idx) == NULL) 11278 return TEST_SKIPPED; 11279 11280 if (MD5_HMAC_create_session(ts_params, ut_params, 11281 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11282 return TEST_FAILED; 11283 } 11284 11285 /* Generate Crypto op data structure */ 11286 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11287 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11288 TEST_ASSERT_NOT_NULL(ut_params->op, 11289 "Failed to allocate symmetric crypto operation struct"); 11290 11291 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11292 return TEST_FAILED; 11293 11294 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11295 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11296 ut_params->op); 11297 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11298 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11299 ut_params->op, 0, 1, 0, 0); 11300 else 11301 TEST_ASSERT_NOT_NULL( 11302 process_crypto_request(ts_params->valid_devs[0], 11303 ut_params->op), 11304 "failed to process sym crypto op"); 11305 11306 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11307 "HMAC_MD5 crypto op processing failed"); 11308 11309 return TEST_SUCCESS; 11310 } 11311 11312 static int 11313 test_MD5_HMAC_generate_case_1(void) 11314 { 11315 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 11316 } 11317 11318 static int 11319 test_MD5_HMAC_verify_case_1(void) 11320 { 11321 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 11322 } 11323 11324 static int 11325 test_MD5_HMAC_generate_case_2(void) 11326 { 11327 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 11328 } 11329 11330 static int 11331 test_MD5_HMAC_verify_case_2(void) 11332 { 11333 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 11334 } 11335 11336 static int 11337 test_multi_session(void) 11338 { 11339 struct crypto_testsuite_params *ts_params = &testsuite_params; 11340 struct crypto_unittest_params *ut_params = &unittest_params; 11341 11342 struct rte_cryptodev_info dev_info; 11343 struct rte_cryptodev_sym_session **sessions; 11344 11345 uint16_t i; 11346 int status; 11347 11348 /* Verify the capabilities */ 11349 struct rte_cryptodev_sym_capability_idx cap_idx; 11350 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11351 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11352 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11353 &cap_idx) == NULL) 11354 return TEST_SKIPPED; 11355 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11356 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11357 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11358 &cap_idx) == NULL) 11359 return TEST_SKIPPED; 11360 11361 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 11362 aes_cbc_key, hmac_sha512_key); 11363 11364 11365 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11366 11367 sessions = rte_malloc(NULL, 11368 sizeof(struct rte_cryptodev_sym_session *) * 11369 (MAX_NB_SESSIONS + 1), 0); 11370 11371 /* Create multiple crypto sessions*/ 11372 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11373 11374 sessions[i] = rte_cryptodev_sym_session_create( 11375 ts_params->session_mpool); 11376 TEST_ASSERT_NOT_NULL(sessions[i], 11377 "Session creation failed at session number %u", 11378 i); 11379 11380 status = rte_cryptodev_sym_session_init( 11381 ts_params->valid_devs[0], 11382 sessions[i], &ut_params->auth_xform, 11383 ts_params->session_priv_mpool); 11384 if (status == -ENOTSUP) 11385 return TEST_SKIPPED; 11386 11387 /* Attempt to send a request on each session */ 11388 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 11389 sessions[i], 11390 ut_params, 11391 ts_params, 11392 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 11393 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 11394 aes_cbc_iv), 11395 "Failed to perform decrypt on request number %u.", i); 11396 /* free crypto operation structure */ 11397 if (ut_params->op) 11398 rte_crypto_op_free(ut_params->op); 11399 11400 /* 11401 * free mbuf - both obuf and ibuf are usually the same, 11402 * so check if they point at the same address is necessary, 11403 * to avoid freeing the mbuf twice. 11404 */ 11405 if (ut_params->obuf) { 11406 rte_pktmbuf_free(ut_params->obuf); 11407 if (ut_params->ibuf == ut_params->obuf) 11408 ut_params->ibuf = 0; 11409 ut_params->obuf = 0; 11410 } 11411 if (ut_params->ibuf) { 11412 rte_pktmbuf_free(ut_params->ibuf); 11413 ut_params->ibuf = 0; 11414 } 11415 } 11416 11417 sessions[i] = NULL; 11418 /* Next session create should fail */ 11419 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11420 sessions[i], &ut_params->auth_xform, 11421 ts_params->session_priv_mpool); 11422 TEST_ASSERT_NULL(sessions[i], 11423 "Session creation succeeded unexpectedly!"); 11424 11425 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11426 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11427 sessions[i]); 11428 rte_cryptodev_sym_session_free(sessions[i]); 11429 } 11430 11431 rte_free(sessions); 11432 11433 return TEST_SUCCESS; 11434 } 11435 11436 struct multi_session_params { 11437 struct crypto_unittest_params ut_params; 11438 uint8_t *cipher_key; 11439 uint8_t *hmac_key; 11440 const uint8_t *cipher; 11441 const uint8_t *digest; 11442 uint8_t *iv; 11443 }; 11444 11445 #define MB_SESSION_NUMBER 3 11446 11447 static int 11448 test_multi_session_random_usage(void) 11449 { 11450 struct crypto_testsuite_params *ts_params = &testsuite_params; 11451 struct rte_cryptodev_info dev_info; 11452 struct rte_cryptodev_sym_session **sessions; 11453 uint32_t i, j; 11454 struct multi_session_params ut_paramz[] = { 11455 11456 { 11457 .cipher_key = ms_aes_cbc_key0, 11458 .hmac_key = ms_hmac_key0, 11459 .cipher = ms_aes_cbc_cipher0, 11460 .digest = ms_hmac_digest0, 11461 .iv = ms_aes_cbc_iv0 11462 }, 11463 { 11464 .cipher_key = ms_aes_cbc_key1, 11465 .hmac_key = ms_hmac_key1, 11466 .cipher = ms_aes_cbc_cipher1, 11467 .digest = ms_hmac_digest1, 11468 .iv = ms_aes_cbc_iv1 11469 }, 11470 { 11471 .cipher_key = ms_aes_cbc_key2, 11472 .hmac_key = ms_hmac_key2, 11473 .cipher = ms_aes_cbc_cipher2, 11474 .digest = ms_hmac_digest2, 11475 .iv = ms_aes_cbc_iv2 11476 }, 11477 11478 }; 11479 int status; 11480 11481 /* Verify the capabilities */ 11482 struct rte_cryptodev_sym_capability_idx cap_idx; 11483 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11484 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11485 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11486 &cap_idx) == NULL) 11487 return TEST_SKIPPED; 11488 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11489 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11490 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11491 &cap_idx) == NULL) 11492 return TEST_SKIPPED; 11493 11494 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11495 11496 sessions = rte_malloc(NULL, 11497 (sizeof(struct rte_cryptodev_sym_session *) 11498 * MAX_NB_SESSIONS) + 1, 0); 11499 11500 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11501 sessions[i] = rte_cryptodev_sym_session_create( 11502 ts_params->session_mpool); 11503 TEST_ASSERT_NOT_NULL(sessions[i], 11504 "Session creation failed at session number %u", 11505 i); 11506 11507 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 11508 sizeof(struct crypto_unittest_params)); 11509 11510 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 11511 &ut_paramz[i].ut_params, 11512 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 11513 11514 /* Create multiple crypto sessions*/ 11515 status = rte_cryptodev_sym_session_init( 11516 ts_params->valid_devs[0], 11517 sessions[i], 11518 &ut_paramz[i].ut_params.auth_xform, 11519 ts_params->session_priv_mpool); 11520 11521 if (status == -ENOTSUP) 11522 return TEST_SKIPPED; 11523 11524 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11525 } 11526 11527 srand(time(NULL)); 11528 for (i = 0; i < 40000; i++) { 11529 11530 j = rand() % MB_SESSION_NUMBER; 11531 11532 TEST_ASSERT_SUCCESS( 11533 test_AES_CBC_HMAC_SHA512_decrypt_perform( 11534 sessions[j], 11535 &ut_paramz[j].ut_params, 11536 ts_params, ut_paramz[j].cipher, 11537 ut_paramz[j].digest, 11538 ut_paramz[j].iv), 11539 "Failed to perform decrypt on request number %u.", i); 11540 11541 if (ut_paramz[j].ut_params.op) 11542 rte_crypto_op_free(ut_paramz[j].ut_params.op); 11543 11544 /* 11545 * free mbuf - both obuf and ibuf are usually the same, 11546 * so check if they point at the same address is necessary, 11547 * to avoid freeing the mbuf twice. 11548 */ 11549 if (ut_paramz[j].ut_params.obuf) { 11550 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 11551 if (ut_paramz[j].ut_params.ibuf 11552 == ut_paramz[j].ut_params.obuf) 11553 ut_paramz[j].ut_params.ibuf = 0; 11554 ut_paramz[j].ut_params.obuf = 0; 11555 } 11556 if (ut_paramz[j].ut_params.ibuf) { 11557 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 11558 ut_paramz[j].ut_params.ibuf = 0; 11559 } 11560 } 11561 11562 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11563 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11564 sessions[i]); 11565 rte_cryptodev_sym_session_free(sessions[i]); 11566 } 11567 11568 rte_free(sessions); 11569 11570 return TEST_SUCCESS; 11571 } 11572 11573 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 11574 0xab, 0xab, 0xab, 0xab, 11575 0xab, 0xab, 0xab, 0xab, 11576 0xab, 0xab, 0xab, 0xab}; 11577 11578 static int 11579 test_null_invalid_operation(void) 11580 { 11581 struct crypto_testsuite_params *ts_params = &testsuite_params; 11582 struct crypto_unittest_params *ut_params = &unittest_params; 11583 int ret; 11584 11585 /* This test is for NULL PMD only */ 11586 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11587 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11588 return TEST_SKIPPED; 11589 11590 /* Setup Cipher Parameters */ 11591 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11592 ut_params->cipher_xform.next = NULL; 11593 11594 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 11595 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11596 11597 ut_params->sess = rte_cryptodev_sym_session_create( 11598 ts_params->session_mpool); 11599 11600 /* Create Crypto session*/ 11601 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11602 ut_params->sess, &ut_params->cipher_xform, 11603 ts_params->session_priv_mpool); 11604 TEST_ASSERT(ret < 0, 11605 "Session creation succeeded unexpectedly"); 11606 11607 11608 /* Setup HMAC Parameters */ 11609 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11610 ut_params->auth_xform.next = NULL; 11611 11612 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 11613 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11614 11615 ut_params->sess = rte_cryptodev_sym_session_create( 11616 ts_params->session_mpool); 11617 11618 /* Create Crypto session*/ 11619 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11620 ut_params->sess, &ut_params->auth_xform, 11621 ts_params->session_priv_mpool); 11622 TEST_ASSERT(ret < 0, 11623 "Session creation succeeded unexpectedly"); 11624 11625 return TEST_SUCCESS; 11626 } 11627 11628 11629 #define NULL_BURST_LENGTH (32) 11630 11631 static int 11632 test_null_burst_operation(void) 11633 { 11634 struct crypto_testsuite_params *ts_params = &testsuite_params; 11635 struct crypto_unittest_params *ut_params = &unittest_params; 11636 int status; 11637 11638 unsigned i, burst_len = NULL_BURST_LENGTH; 11639 11640 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 11641 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 11642 11643 /* This test is for NULL PMD only */ 11644 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11645 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11646 return TEST_SKIPPED; 11647 11648 /* Setup Cipher Parameters */ 11649 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11650 ut_params->cipher_xform.next = &ut_params->auth_xform; 11651 11652 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 11653 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11654 11655 /* Setup HMAC Parameters */ 11656 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11657 ut_params->auth_xform.next = NULL; 11658 11659 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 11660 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11661 11662 ut_params->sess = rte_cryptodev_sym_session_create( 11663 ts_params->session_mpool); 11664 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11665 11666 /* Create Crypto session*/ 11667 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11668 ut_params->sess, &ut_params->cipher_xform, 11669 ts_params->session_priv_mpool); 11670 11671 if (status == -ENOTSUP) 11672 return TEST_SKIPPED; 11673 11674 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11675 11676 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 11677 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 11678 burst_len, "failed to generate burst of crypto ops"); 11679 11680 /* Generate an operation for each mbuf in burst */ 11681 for (i = 0; i < burst_len; i++) { 11682 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11683 11684 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 11685 11686 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 11687 sizeof(unsigned)); 11688 *data = i; 11689 11690 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 11691 11692 burst[i]->sym->m_src = m; 11693 } 11694 11695 /* Process crypto operation */ 11696 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 11697 0, burst, burst_len), 11698 burst_len, 11699 "Error enqueuing burst"); 11700 11701 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 11702 0, burst_dequeued, burst_len), 11703 burst_len, 11704 "Error dequeuing burst"); 11705 11706 11707 for (i = 0; i < burst_len; i++) { 11708 TEST_ASSERT_EQUAL( 11709 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 11710 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 11711 uint32_t *), 11712 "data not as expected"); 11713 11714 rte_pktmbuf_free(burst[i]->sym->m_src); 11715 rte_crypto_op_free(burst[i]); 11716 } 11717 11718 return TEST_SUCCESS; 11719 } 11720 11721 static uint16_t 11722 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11723 uint16_t nb_ops, void *user_param) 11724 { 11725 RTE_SET_USED(dev_id); 11726 RTE_SET_USED(qp_id); 11727 RTE_SET_USED(ops); 11728 RTE_SET_USED(user_param); 11729 11730 printf("crypto enqueue callback called\n"); 11731 return nb_ops; 11732 } 11733 11734 static uint16_t 11735 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11736 uint16_t nb_ops, void *user_param) 11737 { 11738 RTE_SET_USED(dev_id); 11739 RTE_SET_USED(qp_id); 11740 RTE_SET_USED(ops); 11741 RTE_SET_USED(user_param); 11742 11743 printf("crypto dequeue callback called\n"); 11744 return nb_ops; 11745 } 11746 11747 /* 11748 * Thread using enqueue/dequeue callback with RCU. 11749 */ 11750 static int 11751 test_enqdeq_callback_thread(void *arg) 11752 { 11753 RTE_SET_USED(arg); 11754 /* DP thread calls rte_cryptodev_enqueue_burst()/ 11755 * rte_cryptodev_dequeue_burst() and invokes callback. 11756 */ 11757 test_null_burst_operation(); 11758 return 0; 11759 } 11760 11761 static int 11762 test_enq_callback_setup(void) 11763 { 11764 struct crypto_testsuite_params *ts_params = &testsuite_params; 11765 struct rte_cryptodev_info dev_info; 11766 struct rte_cryptodev_qp_conf qp_conf = { 11767 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11768 }; 11769 11770 struct rte_cryptodev_cb *cb; 11771 uint16_t qp_id = 0; 11772 11773 /* Stop the device in case it's started so it can be configured */ 11774 rte_cryptodev_stop(ts_params->valid_devs[0]); 11775 11776 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11777 11778 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11779 &ts_params->conf), 11780 "Failed to configure cryptodev %u", 11781 ts_params->valid_devs[0]); 11782 11783 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11784 qp_conf.mp_session = ts_params->session_mpool; 11785 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11786 11787 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11788 ts_params->valid_devs[0], qp_id, &qp_conf, 11789 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11790 "Failed test for " 11791 "rte_cryptodev_queue_pair_setup: num_inflights " 11792 "%u on qp %u on cryptodev %u", 11793 qp_conf.nb_descriptors, qp_id, 11794 ts_params->valid_devs[0]); 11795 11796 /* Test with invalid crypto device */ 11797 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 11798 qp_id, test_enq_callback, NULL); 11799 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11800 "cryptodev %u did not fail", 11801 qp_id, RTE_CRYPTO_MAX_DEVS); 11802 11803 /* Test with invalid queue pair */ 11804 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11805 dev_info.max_nb_queue_pairs + 1, 11806 test_enq_callback, NULL); 11807 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11808 "cryptodev %u did not fail", 11809 dev_info.max_nb_queue_pairs + 1, 11810 ts_params->valid_devs[0]); 11811 11812 /* Test with NULL callback */ 11813 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11814 qp_id, NULL, NULL); 11815 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11816 "cryptodev %u did not fail", 11817 qp_id, ts_params->valid_devs[0]); 11818 11819 /* Test with valid configuration */ 11820 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11821 qp_id, test_enq_callback, NULL); 11822 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11823 "qp %u on cryptodev %u", 11824 qp_id, ts_params->valid_devs[0]); 11825 11826 rte_cryptodev_start(ts_params->valid_devs[0]); 11827 11828 /* Launch a thread */ 11829 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11830 rte_get_next_lcore(-1, 1, 0)); 11831 11832 /* Wait until reader exited. */ 11833 rte_eal_mp_wait_lcore(); 11834 11835 /* Test with invalid crypto device */ 11836 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11837 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11838 "Expected call to fail as crypto device is invalid"); 11839 11840 /* Test with invalid queue pair */ 11841 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11842 ts_params->valid_devs[0], 11843 dev_info.max_nb_queue_pairs + 1, cb), 11844 "Expected call to fail as queue pair is invalid"); 11845 11846 /* Test with NULL callback */ 11847 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11848 ts_params->valid_devs[0], qp_id, NULL), 11849 "Expected call to fail as callback is NULL"); 11850 11851 /* Test with valid configuration */ 11852 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 11853 ts_params->valid_devs[0], qp_id, cb), 11854 "Failed test to remove callback on " 11855 "qp %u on cryptodev %u", 11856 qp_id, ts_params->valid_devs[0]); 11857 11858 return TEST_SUCCESS; 11859 } 11860 11861 static int 11862 test_deq_callback_setup(void) 11863 { 11864 struct crypto_testsuite_params *ts_params = &testsuite_params; 11865 struct rte_cryptodev_info dev_info; 11866 struct rte_cryptodev_qp_conf qp_conf = { 11867 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11868 }; 11869 11870 struct rte_cryptodev_cb *cb; 11871 uint16_t qp_id = 0; 11872 11873 /* Stop the device in case it's started so it can be configured */ 11874 rte_cryptodev_stop(ts_params->valid_devs[0]); 11875 11876 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11877 11878 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11879 &ts_params->conf), 11880 "Failed to configure cryptodev %u", 11881 ts_params->valid_devs[0]); 11882 11883 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11884 qp_conf.mp_session = ts_params->session_mpool; 11885 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11886 11887 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11888 ts_params->valid_devs[0], qp_id, &qp_conf, 11889 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11890 "Failed test for " 11891 "rte_cryptodev_queue_pair_setup: num_inflights " 11892 "%u on qp %u on cryptodev %u", 11893 qp_conf.nb_descriptors, qp_id, 11894 ts_params->valid_devs[0]); 11895 11896 /* Test with invalid crypto device */ 11897 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 11898 qp_id, test_deq_callback, NULL); 11899 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11900 "cryptodev %u did not fail", 11901 qp_id, RTE_CRYPTO_MAX_DEVS); 11902 11903 /* Test with invalid queue pair */ 11904 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11905 dev_info.max_nb_queue_pairs + 1, 11906 test_deq_callback, NULL); 11907 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11908 "cryptodev %u did not fail", 11909 dev_info.max_nb_queue_pairs + 1, 11910 ts_params->valid_devs[0]); 11911 11912 /* Test with NULL callback */ 11913 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11914 qp_id, NULL, NULL); 11915 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11916 "cryptodev %u did not fail", 11917 qp_id, ts_params->valid_devs[0]); 11918 11919 /* Test with valid configuration */ 11920 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11921 qp_id, test_deq_callback, NULL); 11922 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11923 "qp %u on cryptodev %u", 11924 qp_id, ts_params->valid_devs[0]); 11925 11926 rte_cryptodev_start(ts_params->valid_devs[0]); 11927 11928 /* Launch a thread */ 11929 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11930 rte_get_next_lcore(-1, 1, 0)); 11931 11932 /* Wait until reader exited. */ 11933 rte_eal_mp_wait_lcore(); 11934 11935 /* Test with invalid crypto device */ 11936 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11937 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11938 "Expected call to fail as crypto device is invalid"); 11939 11940 /* Test with invalid queue pair */ 11941 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11942 ts_params->valid_devs[0], 11943 dev_info.max_nb_queue_pairs + 1, cb), 11944 "Expected call to fail as queue pair is invalid"); 11945 11946 /* Test with NULL callback */ 11947 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11948 ts_params->valid_devs[0], qp_id, NULL), 11949 "Expected call to fail as callback is NULL"); 11950 11951 /* Test with valid configuration */ 11952 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 11953 ts_params->valid_devs[0], qp_id, cb), 11954 "Failed test to remove callback on " 11955 "qp %u on cryptodev %u", 11956 qp_id, ts_params->valid_devs[0]); 11957 11958 return TEST_SUCCESS; 11959 } 11960 11961 static void 11962 generate_gmac_large_plaintext(uint8_t *data) 11963 { 11964 uint16_t i; 11965 11966 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 11967 memcpy(&data[i], &data[0], 32); 11968 } 11969 11970 static int 11971 create_gmac_operation(enum rte_crypto_auth_operation op, 11972 const struct gmac_test_data *tdata) 11973 { 11974 struct crypto_testsuite_params *ts_params = &testsuite_params; 11975 struct crypto_unittest_params *ut_params = &unittest_params; 11976 struct rte_crypto_sym_op *sym_op; 11977 11978 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11979 11980 /* Generate Crypto op data structure */ 11981 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11982 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11983 TEST_ASSERT_NOT_NULL(ut_params->op, 11984 "Failed to allocate symmetric crypto operation struct"); 11985 11986 sym_op = ut_params->op->sym; 11987 11988 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11989 ut_params->ibuf, tdata->gmac_tag.len); 11990 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11991 "no room to append digest"); 11992 11993 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11994 ut_params->ibuf, plaintext_pad_len); 11995 11996 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11997 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11998 tdata->gmac_tag.len); 11999 debug_hexdump(stdout, "digest:", 12000 sym_op->auth.digest.data, 12001 tdata->gmac_tag.len); 12002 } 12003 12004 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12005 uint8_t *, IV_OFFSET); 12006 12007 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12008 12009 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12010 12011 sym_op->cipher.data.length = 0; 12012 sym_op->cipher.data.offset = 0; 12013 12014 sym_op->auth.data.offset = 0; 12015 sym_op->auth.data.length = tdata->plaintext.len; 12016 12017 return 0; 12018 } 12019 12020 static int 12021 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12022 const struct gmac_test_data *tdata, 12023 void *digest_mem, uint64_t digest_phys) 12024 { 12025 struct crypto_testsuite_params *ts_params = &testsuite_params; 12026 struct crypto_unittest_params *ut_params = &unittest_params; 12027 struct rte_crypto_sym_op *sym_op; 12028 12029 /* Generate Crypto op data structure */ 12030 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12031 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12032 TEST_ASSERT_NOT_NULL(ut_params->op, 12033 "Failed to allocate symmetric crypto operation struct"); 12034 12035 sym_op = ut_params->op->sym; 12036 12037 sym_op->auth.digest.data = digest_mem; 12038 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12039 "no room to append digest"); 12040 12041 sym_op->auth.digest.phys_addr = digest_phys; 12042 12043 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12044 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12045 tdata->gmac_tag.len); 12046 debug_hexdump(stdout, "digest:", 12047 sym_op->auth.digest.data, 12048 tdata->gmac_tag.len); 12049 } 12050 12051 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12052 uint8_t *, IV_OFFSET); 12053 12054 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12055 12056 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12057 12058 sym_op->cipher.data.length = 0; 12059 sym_op->cipher.data.offset = 0; 12060 12061 sym_op->auth.data.offset = 0; 12062 sym_op->auth.data.length = tdata->plaintext.len; 12063 12064 return 0; 12065 } 12066 12067 static int create_gmac_session(uint8_t dev_id, 12068 const struct gmac_test_data *tdata, 12069 enum rte_crypto_auth_operation auth_op) 12070 { 12071 uint8_t auth_key[tdata->key.len]; 12072 int status; 12073 12074 struct crypto_testsuite_params *ts_params = &testsuite_params; 12075 struct crypto_unittest_params *ut_params = &unittest_params; 12076 12077 memcpy(auth_key, tdata->key.data, tdata->key.len); 12078 12079 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12080 ut_params->auth_xform.next = NULL; 12081 12082 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12083 ut_params->auth_xform.auth.op = auth_op; 12084 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12085 ut_params->auth_xform.auth.key.length = tdata->key.len; 12086 ut_params->auth_xform.auth.key.data = auth_key; 12087 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12088 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12089 12090 12091 ut_params->sess = rte_cryptodev_sym_session_create( 12092 ts_params->session_mpool); 12093 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12094 12095 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12096 &ut_params->auth_xform, 12097 ts_params->session_priv_mpool); 12098 12099 return status; 12100 } 12101 12102 static int 12103 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12104 { 12105 struct crypto_testsuite_params *ts_params = &testsuite_params; 12106 struct crypto_unittest_params *ut_params = &unittest_params; 12107 struct rte_cryptodev_info dev_info; 12108 12109 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12110 uint64_t feat_flags = dev_info.feature_flags; 12111 12112 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12113 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12114 printf("Device doesn't support RAW data-path APIs.\n"); 12115 return TEST_SKIPPED; 12116 } 12117 12118 int retval; 12119 12120 uint8_t *auth_tag, *plaintext; 12121 uint16_t plaintext_pad_len; 12122 12123 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12124 "No GMAC length in the source data"); 12125 12126 /* Verify the capabilities */ 12127 struct rte_cryptodev_sym_capability_idx cap_idx; 12128 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12129 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12130 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12131 &cap_idx) == NULL) 12132 return TEST_SKIPPED; 12133 12134 retval = create_gmac_session(ts_params->valid_devs[0], 12135 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12136 12137 if (retval == -ENOTSUP) 12138 return TEST_SKIPPED; 12139 if (retval < 0) 12140 return retval; 12141 12142 if (tdata->plaintext.len > MBUF_SIZE) 12143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12144 else 12145 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12146 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12147 "Failed to allocate input buffer in mempool"); 12148 12149 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12150 rte_pktmbuf_tailroom(ut_params->ibuf)); 12151 12152 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12153 /* 12154 * Runtime generate the large plain text instead of use hard code 12155 * plain text vector. It is done to avoid create huge source file 12156 * with the test vector. 12157 */ 12158 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12159 generate_gmac_large_plaintext(tdata->plaintext.data); 12160 12161 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12162 plaintext_pad_len); 12163 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12164 12165 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12166 debug_hexdump(stdout, "plaintext:", plaintext, 12167 tdata->plaintext.len); 12168 12169 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12170 tdata); 12171 12172 if (retval < 0) 12173 return retval; 12174 12175 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12176 12177 ut_params->op->sym->m_src = ut_params->ibuf; 12178 12179 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12180 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12181 ut_params->op); 12182 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12183 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12184 ut_params->op, 0, 1, 0, 0); 12185 else 12186 TEST_ASSERT_NOT_NULL( 12187 process_crypto_request(ts_params->valid_devs[0], 12188 ut_params->op), "failed to process sym crypto op"); 12189 12190 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12191 "crypto op processing failed"); 12192 12193 if (ut_params->op->sym->m_dst) { 12194 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12195 uint8_t *, plaintext_pad_len); 12196 } else { 12197 auth_tag = plaintext + plaintext_pad_len; 12198 } 12199 12200 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12201 12202 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12203 auth_tag, 12204 tdata->gmac_tag.data, 12205 tdata->gmac_tag.len, 12206 "GMAC Generated auth tag not as expected"); 12207 12208 return 0; 12209 } 12210 12211 static int 12212 test_AES_GMAC_authentication_test_case_1(void) 12213 { 12214 return test_AES_GMAC_authentication(&gmac_test_case_1); 12215 } 12216 12217 static int 12218 test_AES_GMAC_authentication_test_case_2(void) 12219 { 12220 return test_AES_GMAC_authentication(&gmac_test_case_2); 12221 } 12222 12223 static int 12224 test_AES_GMAC_authentication_test_case_3(void) 12225 { 12226 return test_AES_GMAC_authentication(&gmac_test_case_3); 12227 } 12228 12229 static int 12230 test_AES_GMAC_authentication_test_case_4(void) 12231 { 12232 return test_AES_GMAC_authentication(&gmac_test_case_4); 12233 } 12234 12235 static int 12236 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12237 { 12238 struct crypto_testsuite_params *ts_params = &testsuite_params; 12239 struct crypto_unittest_params *ut_params = &unittest_params; 12240 int retval; 12241 uint32_t plaintext_pad_len; 12242 uint8_t *plaintext; 12243 struct rte_cryptodev_info dev_info; 12244 12245 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12246 uint64_t feat_flags = dev_info.feature_flags; 12247 12248 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12249 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12250 printf("Device doesn't support RAW data-path APIs.\n"); 12251 return TEST_SKIPPED; 12252 } 12253 12254 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12255 "No GMAC length in the source data"); 12256 12257 /* Verify the capabilities */ 12258 struct rte_cryptodev_sym_capability_idx cap_idx; 12259 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12260 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12261 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12262 &cap_idx) == NULL) 12263 return TEST_SKIPPED; 12264 12265 retval = create_gmac_session(ts_params->valid_devs[0], 12266 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12267 12268 if (retval == -ENOTSUP) 12269 return TEST_SKIPPED; 12270 if (retval < 0) 12271 return retval; 12272 12273 if (tdata->plaintext.len > MBUF_SIZE) 12274 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12275 else 12276 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12277 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12278 "Failed to allocate input buffer in mempool"); 12279 12280 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12281 rte_pktmbuf_tailroom(ut_params->ibuf)); 12282 12283 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12284 12285 /* 12286 * Runtime generate the large plain text instead of use hard code 12287 * plain text vector. It is done to avoid create huge source file 12288 * with the test vector. 12289 */ 12290 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12291 generate_gmac_large_plaintext(tdata->plaintext.data); 12292 12293 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12294 plaintext_pad_len); 12295 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12296 12297 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12298 debug_hexdump(stdout, "plaintext:", plaintext, 12299 tdata->plaintext.len); 12300 12301 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 12302 tdata); 12303 12304 if (retval < 0) 12305 return retval; 12306 12307 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12308 12309 ut_params->op->sym->m_src = ut_params->ibuf; 12310 12311 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12312 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12313 ut_params->op); 12314 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12315 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12316 ut_params->op, 0, 1, 0, 0); 12317 else 12318 TEST_ASSERT_NOT_NULL( 12319 process_crypto_request(ts_params->valid_devs[0], 12320 ut_params->op), "failed to process sym crypto op"); 12321 12322 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12323 "crypto op processing failed"); 12324 12325 return 0; 12326 12327 } 12328 12329 static int 12330 test_AES_GMAC_authentication_verify_test_case_1(void) 12331 { 12332 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 12333 } 12334 12335 static int 12336 test_AES_GMAC_authentication_verify_test_case_2(void) 12337 { 12338 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 12339 } 12340 12341 static int 12342 test_AES_GMAC_authentication_verify_test_case_3(void) 12343 { 12344 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 12345 } 12346 12347 static int 12348 test_AES_GMAC_authentication_verify_test_case_4(void) 12349 { 12350 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 12351 } 12352 12353 static int 12354 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 12355 uint32_t fragsz) 12356 { 12357 struct crypto_testsuite_params *ts_params = &testsuite_params; 12358 struct crypto_unittest_params *ut_params = &unittest_params; 12359 struct rte_cryptodev_info dev_info; 12360 uint64_t feature_flags; 12361 unsigned int trn_data = 0; 12362 void *digest_mem = NULL; 12363 uint32_t segs = 1; 12364 unsigned int to_trn = 0; 12365 struct rte_mbuf *buf = NULL; 12366 uint8_t *auth_tag, *plaintext; 12367 int retval; 12368 12369 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12370 "No GMAC length in the source data"); 12371 12372 /* Verify the capabilities */ 12373 struct rte_cryptodev_sym_capability_idx cap_idx; 12374 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12375 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12376 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12377 &cap_idx) == NULL) 12378 return TEST_SKIPPED; 12379 12380 /* Check for any input SGL support */ 12381 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12382 feature_flags = dev_info.feature_flags; 12383 12384 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 12385 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 12386 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 12387 return TEST_SKIPPED; 12388 12389 if (fragsz > tdata->plaintext.len) 12390 fragsz = tdata->plaintext.len; 12391 12392 uint16_t plaintext_len = fragsz; 12393 12394 retval = create_gmac_session(ts_params->valid_devs[0], 12395 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12396 12397 if (retval == -ENOTSUP) 12398 return TEST_SKIPPED; 12399 if (retval < 0) 12400 return retval; 12401 12402 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12403 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12404 "Failed to allocate input buffer in mempool"); 12405 12406 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12407 rte_pktmbuf_tailroom(ut_params->ibuf)); 12408 12409 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12410 plaintext_len); 12411 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12412 12413 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12414 12415 trn_data += plaintext_len; 12416 12417 buf = ut_params->ibuf; 12418 12419 /* 12420 * Loop until no more fragments 12421 */ 12422 12423 while (trn_data < tdata->plaintext.len) { 12424 ++segs; 12425 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12426 (tdata->plaintext.len - trn_data) : fragsz; 12427 12428 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12429 buf = buf->next; 12430 12431 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12432 rte_pktmbuf_tailroom(buf)); 12433 12434 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12435 to_trn); 12436 12437 memcpy(plaintext, tdata->plaintext.data + trn_data, 12438 to_trn); 12439 trn_data += to_trn; 12440 if (trn_data == tdata->plaintext.len) 12441 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12442 tdata->gmac_tag.len); 12443 } 12444 ut_params->ibuf->nb_segs = segs; 12445 12446 /* 12447 * Place digest at the end of the last buffer 12448 */ 12449 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12450 12451 if (!digest_mem) { 12452 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12453 + tdata->gmac_tag.len); 12454 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12455 tdata->plaintext.len); 12456 } 12457 12458 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 12459 tdata, digest_mem, digest_phys); 12460 12461 if (retval < 0) 12462 return retval; 12463 12464 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12465 12466 ut_params->op->sym->m_src = ut_params->ibuf; 12467 12468 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12469 return TEST_SKIPPED; 12470 12471 TEST_ASSERT_NOT_NULL( 12472 process_crypto_request(ts_params->valid_devs[0], 12473 ut_params->op), "failed to process sym crypto op"); 12474 12475 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12476 "crypto op processing failed"); 12477 12478 auth_tag = digest_mem; 12479 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12480 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12481 auth_tag, 12482 tdata->gmac_tag.data, 12483 tdata->gmac_tag.len, 12484 "GMAC Generated auth tag not as expected"); 12485 12486 return 0; 12487 } 12488 12489 /* Segment size not multiple of block size (16B) */ 12490 static int 12491 test_AES_GMAC_authentication_SGL_40B(void) 12492 { 12493 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 12494 } 12495 12496 static int 12497 test_AES_GMAC_authentication_SGL_80B(void) 12498 { 12499 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 12500 } 12501 12502 static int 12503 test_AES_GMAC_authentication_SGL_2048B(void) 12504 { 12505 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 12506 } 12507 12508 /* Segment size not multiple of block size (16B) */ 12509 static int 12510 test_AES_GMAC_authentication_SGL_2047B(void) 12511 { 12512 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 12513 } 12514 12515 struct test_crypto_vector { 12516 enum rte_crypto_cipher_algorithm crypto_algo; 12517 unsigned int cipher_offset; 12518 unsigned int cipher_len; 12519 12520 struct { 12521 uint8_t data[64]; 12522 unsigned int len; 12523 } cipher_key; 12524 12525 struct { 12526 uint8_t data[64]; 12527 unsigned int len; 12528 } iv; 12529 12530 struct { 12531 const uint8_t *data; 12532 unsigned int len; 12533 } plaintext; 12534 12535 struct { 12536 const uint8_t *data; 12537 unsigned int len; 12538 } ciphertext; 12539 12540 enum rte_crypto_auth_algorithm auth_algo; 12541 unsigned int auth_offset; 12542 12543 struct { 12544 uint8_t data[128]; 12545 unsigned int len; 12546 } auth_key; 12547 12548 struct { 12549 const uint8_t *data; 12550 unsigned int len; 12551 } aad; 12552 12553 struct { 12554 uint8_t data[128]; 12555 unsigned int len; 12556 } digest; 12557 }; 12558 12559 static const struct test_crypto_vector 12560 hmac_sha1_test_crypto_vector = { 12561 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12562 .plaintext = { 12563 .data = plaintext_hash, 12564 .len = 512 12565 }, 12566 .auth_key = { 12567 .data = { 12568 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12569 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12570 0xDE, 0xF4, 0xDE, 0xAD 12571 }, 12572 .len = 20 12573 }, 12574 .digest = { 12575 .data = { 12576 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 12577 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 12578 0x3F, 0x91, 0x64, 0x59 12579 }, 12580 .len = 20 12581 } 12582 }; 12583 12584 static const struct test_crypto_vector 12585 aes128_gmac_test_vector = { 12586 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 12587 .plaintext = { 12588 .data = plaintext_hash, 12589 .len = 512 12590 }, 12591 .iv = { 12592 .data = { 12593 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12594 0x08, 0x09, 0x0A, 0x0B 12595 }, 12596 .len = 12 12597 }, 12598 .auth_key = { 12599 .data = { 12600 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12601 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 12602 }, 12603 .len = 16 12604 }, 12605 .digest = { 12606 .data = { 12607 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 12608 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 12609 }, 12610 .len = 16 12611 } 12612 }; 12613 12614 static const struct test_crypto_vector 12615 aes128cbc_hmac_sha1_test_vector = { 12616 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12617 .cipher_offset = 0, 12618 .cipher_len = 512, 12619 .cipher_key = { 12620 .data = { 12621 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12622 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12623 }, 12624 .len = 16 12625 }, 12626 .iv = { 12627 .data = { 12628 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12629 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12630 }, 12631 .len = 16 12632 }, 12633 .plaintext = { 12634 .data = plaintext_hash, 12635 .len = 512 12636 }, 12637 .ciphertext = { 12638 .data = ciphertext512_aes128cbc, 12639 .len = 512 12640 }, 12641 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12642 .auth_offset = 0, 12643 .auth_key = { 12644 .data = { 12645 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12646 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12647 0xDE, 0xF4, 0xDE, 0xAD 12648 }, 12649 .len = 20 12650 }, 12651 .digest = { 12652 .data = { 12653 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 12654 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12655 0x18, 0x8C, 0x1D, 0x32 12656 }, 12657 .len = 20 12658 } 12659 }; 12660 12661 static const struct test_crypto_vector 12662 aes128cbc_hmac_sha1_aad_test_vector = { 12663 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12664 .cipher_offset = 8, 12665 .cipher_len = 496, 12666 .cipher_key = { 12667 .data = { 12668 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12669 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12670 }, 12671 .len = 16 12672 }, 12673 .iv = { 12674 .data = { 12675 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12676 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12677 }, 12678 .len = 16 12679 }, 12680 .plaintext = { 12681 .data = plaintext_hash, 12682 .len = 512 12683 }, 12684 .ciphertext = { 12685 .data = ciphertext512_aes128cbc_aad, 12686 .len = 512 12687 }, 12688 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12689 .auth_offset = 0, 12690 .auth_key = { 12691 .data = { 12692 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12693 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12694 0xDE, 0xF4, 0xDE, 0xAD 12695 }, 12696 .len = 20 12697 }, 12698 .digest = { 12699 .data = { 12700 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 12701 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 12702 0x62, 0x0F, 0xFB, 0x10 12703 }, 12704 .len = 20 12705 } 12706 }; 12707 12708 static void 12709 data_corruption(uint8_t *data) 12710 { 12711 data[0] += 1; 12712 } 12713 12714 static void 12715 tag_corruption(uint8_t *data, unsigned int tag_offset) 12716 { 12717 data[tag_offset] += 1; 12718 } 12719 12720 static int 12721 create_auth_session(struct crypto_unittest_params *ut_params, 12722 uint8_t dev_id, 12723 const struct test_crypto_vector *reference, 12724 enum rte_crypto_auth_operation auth_op) 12725 { 12726 struct crypto_testsuite_params *ts_params = &testsuite_params; 12727 uint8_t auth_key[reference->auth_key.len + 1]; 12728 int status; 12729 12730 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12731 12732 /* Setup Authentication Parameters */ 12733 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12734 ut_params->auth_xform.auth.op = auth_op; 12735 ut_params->auth_xform.next = NULL; 12736 ut_params->auth_xform.auth.algo = reference->auth_algo; 12737 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12738 ut_params->auth_xform.auth.key.data = auth_key; 12739 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12740 12741 /* Create Crypto session*/ 12742 ut_params->sess = rte_cryptodev_sym_session_create( 12743 ts_params->session_mpool); 12744 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12745 12746 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12747 &ut_params->auth_xform, 12748 ts_params->session_priv_mpool); 12749 12750 return status; 12751 } 12752 12753 static int 12754 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 12755 uint8_t dev_id, 12756 const struct test_crypto_vector *reference, 12757 enum rte_crypto_auth_operation auth_op, 12758 enum rte_crypto_cipher_operation cipher_op) 12759 { 12760 struct crypto_testsuite_params *ts_params = &testsuite_params; 12761 uint8_t cipher_key[reference->cipher_key.len + 1]; 12762 uint8_t auth_key[reference->auth_key.len + 1]; 12763 int status; 12764 12765 memcpy(cipher_key, reference->cipher_key.data, 12766 reference->cipher_key.len); 12767 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12768 12769 /* Setup Authentication Parameters */ 12770 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12771 ut_params->auth_xform.auth.op = auth_op; 12772 ut_params->auth_xform.auth.algo = reference->auth_algo; 12773 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12774 ut_params->auth_xform.auth.key.data = auth_key; 12775 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12776 12777 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 12778 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12779 ut_params->auth_xform.auth.iv.length = reference->iv.len; 12780 } else { 12781 ut_params->auth_xform.next = &ut_params->cipher_xform; 12782 12783 /* Setup Cipher Parameters */ 12784 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12785 ut_params->cipher_xform.next = NULL; 12786 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12787 ut_params->cipher_xform.cipher.op = cipher_op; 12788 ut_params->cipher_xform.cipher.key.data = cipher_key; 12789 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12790 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12791 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12792 } 12793 12794 /* Create Crypto session*/ 12795 ut_params->sess = rte_cryptodev_sym_session_create( 12796 ts_params->session_mpool); 12797 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12798 12799 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12800 &ut_params->auth_xform, 12801 ts_params->session_priv_mpool); 12802 12803 return status; 12804 } 12805 12806 static int 12807 create_auth_operation(struct crypto_testsuite_params *ts_params, 12808 struct crypto_unittest_params *ut_params, 12809 const struct test_crypto_vector *reference, 12810 unsigned int auth_generate) 12811 { 12812 /* Generate Crypto op data structure */ 12813 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12814 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12815 TEST_ASSERT_NOT_NULL(ut_params->op, 12816 "Failed to allocate pktmbuf offload"); 12817 12818 /* Set crypto operation data parameters */ 12819 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12820 12821 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12822 12823 /* set crypto operation source mbuf */ 12824 sym_op->m_src = ut_params->ibuf; 12825 12826 /* digest */ 12827 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12828 ut_params->ibuf, reference->digest.len); 12829 12830 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12831 "no room to append auth tag"); 12832 12833 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12834 ut_params->ibuf, reference->plaintext.len); 12835 12836 if (auth_generate) 12837 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12838 else 12839 memcpy(sym_op->auth.digest.data, 12840 reference->digest.data, 12841 reference->digest.len); 12842 12843 debug_hexdump(stdout, "digest:", 12844 sym_op->auth.digest.data, 12845 reference->digest.len); 12846 12847 sym_op->auth.data.length = reference->plaintext.len; 12848 sym_op->auth.data.offset = 0; 12849 12850 return 0; 12851 } 12852 12853 static int 12854 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 12855 struct crypto_unittest_params *ut_params, 12856 const struct test_crypto_vector *reference, 12857 unsigned int auth_generate) 12858 { 12859 /* Generate Crypto op data structure */ 12860 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12861 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12862 TEST_ASSERT_NOT_NULL(ut_params->op, 12863 "Failed to allocate pktmbuf offload"); 12864 12865 /* Set crypto operation data parameters */ 12866 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12867 12868 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12869 12870 /* set crypto operation source mbuf */ 12871 sym_op->m_src = ut_params->ibuf; 12872 12873 /* digest */ 12874 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12875 ut_params->ibuf, reference->digest.len); 12876 12877 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12878 "no room to append auth tag"); 12879 12880 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12881 ut_params->ibuf, reference->ciphertext.len); 12882 12883 if (auth_generate) 12884 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12885 else 12886 memcpy(sym_op->auth.digest.data, 12887 reference->digest.data, 12888 reference->digest.len); 12889 12890 debug_hexdump(stdout, "digest:", 12891 sym_op->auth.digest.data, 12892 reference->digest.len); 12893 12894 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12895 reference->iv.data, reference->iv.len); 12896 12897 sym_op->cipher.data.length = 0; 12898 sym_op->cipher.data.offset = 0; 12899 12900 sym_op->auth.data.length = reference->plaintext.len; 12901 sym_op->auth.data.offset = 0; 12902 12903 return 0; 12904 } 12905 12906 static int 12907 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 12908 struct crypto_unittest_params *ut_params, 12909 const struct test_crypto_vector *reference, 12910 unsigned int auth_generate) 12911 { 12912 /* Generate Crypto op data structure */ 12913 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12914 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12915 TEST_ASSERT_NOT_NULL(ut_params->op, 12916 "Failed to allocate pktmbuf offload"); 12917 12918 /* Set crypto operation data parameters */ 12919 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12920 12921 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12922 12923 /* set crypto operation source mbuf */ 12924 sym_op->m_src = ut_params->ibuf; 12925 12926 /* digest */ 12927 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12928 ut_params->ibuf, reference->digest.len); 12929 12930 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12931 "no room to append auth tag"); 12932 12933 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12934 ut_params->ibuf, reference->ciphertext.len); 12935 12936 if (auth_generate) 12937 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12938 else 12939 memcpy(sym_op->auth.digest.data, 12940 reference->digest.data, 12941 reference->digest.len); 12942 12943 debug_hexdump(stdout, "digest:", 12944 sym_op->auth.digest.data, 12945 reference->digest.len); 12946 12947 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12948 reference->iv.data, reference->iv.len); 12949 12950 sym_op->cipher.data.length = reference->cipher_len; 12951 sym_op->cipher.data.offset = reference->cipher_offset; 12952 12953 sym_op->auth.data.length = reference->plaintext.len; 12954 sym_op->auth.data.offset = reference->auth_offset; 12955 12956 return 0; 12957 } 12958 12959 static int 12960 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 12961 struct crypto_unittest_params *ut_params, 12962 const struct test_crypto_vector *reference) 12963 { 12964 return create_auth_operation(ts_params, ut_params, reference, 0); 12965 } 12966 12967 static int 12968 create_auth_verify_GMAC_operation( 12969 struct crypto_testsuite_params *ts_params, 12970 struct crypto_unittest_params *ut_params, 12971 const struct test_crypto_vector *reference) 12972 { 12973 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 12974 } 12975 12976 static int 12977 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 12978 struct crypto_unittest_params *ut_params, 12979 const struct test_crypto_vector *reference) 12980 { 12981 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 12982 } 12983 12984 static int 12985 test_authentication_verify_fail_when_data_corruption( 12986 struct crypto_testsuite_params *ts_params, 12987 struct crypto_unittest_params *ut_params, 12988 const struct test_crypto_vector *reference, 12989 unsigned int data_corrupted) 12990 { 12991 int retval; 12992 12993 uint8_t *plaintext; 12994 struct rte_cryptodev_info dev_info; 12995 12996 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12997 uint64_t feat_flags = dev_info.feature_flags; 12998 12999 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13000 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13001 printf("Device doesn't support RAW data-path APIs.\n"); 13002 return TEST_SKIPPED; 13003 } 13004 13005 /* Verify the capabilities */ 13006 struct rte_cryptodev_sym_capability_idx cap_idx; 13007 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13008 cap_idx.algo.auth = reference->auth_algo; 13009 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13010 &cap_idx) == NULL) 13011 return TEST_SKIPPED; 13012 13013 13014 /* Create session */ 13015 retval = create_auth_session(ut_params, 13016 ts_params->valid_devs[0], 13017 reference, 13018 RTE_CRYPTO_AUTH_OP_VERIFY); 13019 13020 if (retval == -ENOTSUP) 13021 return TEST_SKIPPED; 13022 if (retval < 0) 13023 return retval; 13024 13025 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13026 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13027 "Failed to allocate input buffer in mempool"); 13028 13029 /* clear mbuf payload */ 13030 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13031 rte_pktmbuf_tailroom(ut_params->ibuf)); 13032 13033 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13034 reference->plaintext.len); 13035 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13036 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13037 13038 debug_hexdump(stdout, "plaintext:", plaintext, 13039 reference->plaintext.len); 13040 13041 /* Create operation */ 13042 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13043 13044 if (retval < 0) 13045 return retval; 13046 13047 if (data_corrupted) 13048 data_corruption(plaintext); 13049 else 13050 tag_corruption(plaintext, reference->plaintext.len); 13051 13052 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13053 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13054 ut_params->op); 13055 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13056 RTE_CRYPTO_OP_STATUS_SUCCESS, 13057 "authentication not failed"); 13058 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13059 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13060 ut_params->op, 0, 1, 0, 0); 13061 else { 13062 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13063 ut_params->op); 13064 } 13065 if (ut_params->op == NULL) 13066 return 0; 13067 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13068 return 0; 13069 13070 return -1; 13071 } 13072 13073 static int 13074 test_authentication_verify_GMAC_fail_when_corruption( 13075 struct crypto_testsuite_params *ts_params, 13076 struct crypto_unittest_params *ut_params, 13077 const struct test_crypto_vector *reference, 13078 unsigned int data_corrupted) 13079 { 13080 int retval; 13081 uint8_t *plaintext; 13082 struct rte_cryptodev_info dev_info; 13083 13084 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13085 uint64_t feat_flags = dev_info.feature_flags; 13086 13087 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13088 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13089 printf("Device doesn't support RAW data-path APIs.\n"); 13090 return TEST_SKIPPED; 13091 } 13092 13093 /* Verify the capabilities */ 13094 struct rte_cryptodev_sym_capability_idx cap_idx; 13095 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13096 cap_idx.algo.auth = reference->auth_algo; 13097 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13098 &cap_idx) == NULL) 13099 return TEST_SKIPPED; 13100 13101 /* Create session */ 13102 retval = create_auth_cipher_session(ut_params, 13103 ts_params->valid_devs[0], 13104 reference, 13105 RTE_CRYPTO_AUTH_OP_VERIFY, 13106 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13107 if (retval < 0) 13108 return retval; 13109 13110 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13111 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13112 "Failed to allocate input buffer in mempool"); 13113 13114 /* clear mbuf payload */ 13115 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13116 rte_pktmbuf_tailroom(ut_params->ibuf)); 13117 13118 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13119 reference->plaintext.len); 13120 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13121 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13122 13123 debug_hexdump(stdout, "plaintext:", plaintext, 13124 reference->plaintext.len); 13125 13126 /* Create operation */ 13127 retval = create_auth_verify_GMAC_operation(ts_params, 13128 ut_params, 13129 reference); 13130 13131 if (retval < 0) 13132 return retval; 13133 13134 if (data_corrupted) 13135 data_corruption(plaintext); 13136 else 13137 tag_corruption(plaintext, reference->aad.len); 13138 13139 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13140 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13141 ut_params->op); 13142 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13143 RTE_CRYPTO_OP_STATUS_SUCCESS, 13144 "authentication not failed"); 13145 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13146 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13147 ut_params->op, 0, 1, 0, 0); 13148 else { 13149 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13150 ut_params->op); 13151 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13152 } 13153 13154 return 0; 13155 } 13156 13157 static int 13158 test_authenticated_decryption_fail_when_corruption( 13159 struct crypto_testsuite_params *ts_params, 13160 struct crypto_unittest_params *ut_params, 13161 const struct test_crypto_vector *reference, 13162 unsigned int data_corrupted) 13163 { 13164 int retval; 13165 13166 uint8_t *ciphertext; 13167 struct rte_cryptodev_info dev_info; 13168 13169 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13170 uint64_t feat_flags = dev_info.feature_flags; 13171 13172 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13173 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13174 printf("Device doesn't support RAW data-path APIs.\n"); 13175 return TEST_SKIPPED; 13176 } 13177 13178 /* Verify the capabilities */ 13179 struct rte_cryptodev_sym_capability_idx cap_idx; 13180 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13181 cap_idx.algo.auth = reference->auth_algo; 13182 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13183 &cap_idx) == NULL) 13184 return TEST_SKIPPED; 13185 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13186 cap_idx.algo.cipher = reference->crypto_algo; 13187 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13188 &cap_idx) == NULL) 13189 return TEST_SKIPPED; 13190 13191 /* Create session */ 13192 retval = create_auth_cipher_session(ut_params, 13193 ts_params->valid_devs[0], 13194 reference, 13195 RTE_CRYPTO_AUTH_OP_VERIFY, 13196 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13197 13198 if (retval == -ENOTSUP) 13199 return TEST_SKIPPED; 13200 if (retval < 0) 13201 return retval; 13202 13203 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13204 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13205 "Failed to allocate input buffer in mempool"); 13206 13207 /* clear mbuf payload */ 13208 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13209 rte_pktmbuf_tailroom(ut_params->ibuf)); 13210 13211 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13212 reference->ciphertext.len); 13213 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13214 memcpy(ciphertext, reference->ciphertext.data, 13215 reference->ciphertext.len); 13216 13217 /* Create operation */ 13218 retval = create_cipher_auth_verify_operation(ts_params, 13219 ut_params, 13220 reference); 13221 13222 if (retval < 0) 13223 return retval; 13224 13225 if (data_corrupted) 13226 data_corruption(ciphertext); 13227 else 13228 tag_corruption(ciphertext, reference->ciphertext.len); 13229 13230 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13231 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13232 ut_params->op); 13233 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13234 RTE_CRYPTO_OP_STATUS_SUCCESS, 13235 "authentication not failed"); 13236 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13237 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13238 ut_params->op, 1, 1, 0, 0); 13239 else { 13240 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13241 ut_params->op); 13242 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13243 } 13244 13245 return 0; 13246 } 13247 13248 static int 13249 test_authenticated_encrypt_with_esn( 13250 struct crypto_testsuite_params *ts_params, 13251 struct crypto_unittest_params *ut_params, 13252 const struct test_crypto_vector *reference) 13253 { 13254 int retval; 13255 13256 uint8_t *authciphertext, *plaintext, *auth_tag; 13257 uint16_t plaintext_pad_len; 13258 uint8_t cipher_key[reference->cipher_key.len + 1]; 13259 uint8_t auth_key[reference->auth_key.len + 1]; 13260 struct rte_cryptodev_info dev_info; 13261 int status; 13262 13263 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13264 uint64_t feat_flags = dev_info.feature_flags; 13265 13266 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13267 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13268 printf("Device doesn't support RAW data-path APIs.\n"); 13269 return TEST_SKIPPED; 13270 } 13271 13272 /* Verify the capabilities */ 13273 struct rte_cryptodev_sym_capability_idx cap_idx; 13274 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13275 cap_idx.algo.auth = reference->auth_algo; 13276 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13277 &cap_idx) == NULL) 13278 return TEST_SKIPPED; 13279 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13280 cap_idx.algo.cipher = reference->crypto_algo; 13281 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13282 &cap_idx) == NULL) 13283 return TEST_SKIPPED; 13284 13285 /* Create session */ 13286 memcpy(cipher_key, reference->cipher_key.data, 13287 reference->cipher_key.len); 13288 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13289 13290 /* Setup Cipher Parameters */ 13291 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13292 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13293 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13294 ut_params->cipher_xform.cipher.key.data = cipher_key; 13295 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13296 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13297 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13298 13299 ut_params->cipher_xform.next = &ut_params->auth_xform; 13300 13301 /* Setup Authentication Parameters */ 13302 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13303 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13304 ut_params->auth_xform.auth.algo = reference->auth_algo; 13305 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13306 ut_params->auth_xform.auth.key.data = auth_key; 13307 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13308 ut_params->auth_xform.next = NULL; 13309 13310 /* Create Crypto session*/ 13311 ut_params->sess = rte_cryptodev_sym_session_create( 13312 ts_params->session_mpool); 13313 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13314 13315 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13316 ut_params->sess, 13317 &ut_params->cipher_xform, 13318 ts_params->session_priv_mpool); 13319 13320 if (status == -ENOTSUP) 13321 return TEST_SKIPPED; 13322 13323 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 13324 13325 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13326 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13327 "Failed to allocate input buffer in mempool"); 13328 13329 /* clear mbuf payload */ 13330 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13331 rte_pktmbuf_tailroom(ut_params->ibuf)); 13332 13333 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13334 reference->plaintext.len); 13335 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13336 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13337 13338 /* Create operation */ 13339 retval = create_cipher_auth_operation(ts_params, 13340 ut_params, 13341 reference, 0); 13342 13343 if (retval < 0) 13344 return retval; 13345 13346 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13347 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13348 ut_params->op); 13349 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13350 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13351 ut_params->op, 1, 1, 0, 0); 13352 else 13353 ut_params->op = process_crypto_request( 13354 ts_params->valid_devs[0], ut_params->op); 13355 13356 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 13357 13358 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13359 "crypto op processing failed"); 13360 13361 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 13362 13363 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13364 ut_params->op->sym->auth.data.offset); 13365 auth_tag = authciphertext + plaintext_pad_len; 13366 debug_hexdump(stdout, "ciphertext:", authciphertext, 13367 reference->ciphertext.len); 13368 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 13369 13370 /* Validate obuf */ 13371 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13372 authciphertext, 13373 reference->ciphertext.data, 13374 reference->ciphertext.len, 13375 "Ciphertext data not as expected"); 13376 13377 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13378 auth_tag, 13379 reference->digest.data, 13380 reference->digest.len, 13381 "Generated digest not as expected"); 13382 13383 return TEST_SUCCESS; 13384 13385 } 13386 13387 static int 13388 test_authenticated_decrypt_with_esn( 13389 struct crypto_testsuite_params *ts_params, 13390 struct crypto_unittest_params *ut_params, 13391 const struct test_crypto_vector *reference) 13392 { 13393 int retval; 13394 13395 uint8_t *ciphertext; 13396 uint8_t cipher_key[reference->cipher_key.len + 1]; 13397 uint8_t auth_key[reference->auth_key.len + 1]; 13398 struct rte_cryptodev_info dev_info; 13399 13400 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13401 uint64_t feat_flags = dev_info.feature_flags; 13402 13403 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13404 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13405 printf("Device doesn't support RAW data-path APIs.\n"); 13406 return TEST_SKIPPED; 13407 } 13408 13409 /* Verify the capabilities */ 13410 struct rte_cryptodev_sym_capability_idx cap_idx; 13411 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13412 cap_idx.algo.auth = reference->auth_algo; 13413 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13414 &cap_idx) == NULL) 13415 return TEST_SKIPPED; 13416 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13417 cap_idx.algo.cipher = reference->crypto_algo; 13418 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13419 &cap_idx) == NULL) 13420 return TEST_SKIPPED; 13421 13422 /* Create session */ 13423 memcpy(cipher_key, reference->cipher_key.data, 13424 reference->cipher_key.len); 13425 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13426 13427 /* Setup Authentication Parameters */ 13428 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13429 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 13430 ut_params->auth_xform.auth.algo = reference->auth_algo; 13431 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13432 ut_params->auth_xform.auth.key.data = auth_key; 13433 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13434 ut_params->auth_xform.next = &ut_params->cipher_xform; 13435 13436 /* Setup Cipher Parameters */ 13437 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13438 ut_params->cipher_xform.next = NULL; 13439 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13440 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 13441 ut_params->cipher_xform.cipher.key.data = cipher_key; 13442 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13443 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13444 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13445 13446 /* Create Crypto session*/ 13447 ut_params->sess = rte_cryptodev_sym_session_create( 13448 ts_params->session_mpool); 13449 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13450 13451 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13452 ut_params->sess, 13453 &ut_params->auth_xform, 13454 ts_params->session_priv_mpool); 13455 13456 if (retval == -ENOTSUP) 13457 return TEST_SKIPPED; 13458 13459 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 13460 13461 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13462 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13463 "Failed to allocate input buffer in mempool"); 13464 13465 /* clear mbuf payload */ 13466 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13467 rte_pktmbuf_tailroom(ut_params->ibuf)); 13468 13469 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13470 reference->ciphertext.len); 13471 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13472 memcpy(ciphertext, reference->ciphertext.data, 13473 reference->ciphertext.len); 13474 13475 /* Create operation */ 13476 retval = create_cipher_auth_verify_operation(ts_params, 13477 ut_params, 13478 reference); 13479 13480 if (retval < 0) 13481 return retval; 13482 13483 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13484 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13485 ut_params->op); 13486 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13487 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13488 ut_params->op, 1, 1, 0, 0); 13489 else 13490 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13491 ut_params->op); 13492 13493 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13494 TEST_ASSERT_EQUAL(ut_params->op->status, 13495 RTE_CRYPTO_OP_STATUS_SUCCESS, 13496 "crypto op processing passed"); 13497 13498 ut_params->obuf = ut_params->op->sym->m_src; 13499 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 13500 13501 return 0; 13502 } 13503 13504 static int 13505 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 13506 const struct aead_test_data *tdata, 13507 void *digest_mem, uint64_t digest_phys) 13508 { 13509 struct crypto_testsuite_params *ts_params = &testsuite_params; 13510 struct crypto_unittest_params *ut_params = &unittest_params; 13511 13512 const unsigned int auth_tag_len = tdata->auth_tag.len; 13513 const unsigned int iv_len = tdata->iv.len; 13514 unsigned int aad_len = tdata->aad.len; 13515 unsigned int aad_len_pad = 0; 13516 13517 /* Generate Crypto op data structure */ 13518 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13519 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13520 TEST_ASSERT_NOT_NULL(ut_params->op, 13521 "Failed to allocate symmetric crypto operation struct"); 13522 13523 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13524 13525 sym_op->aead.digest.data = digest_mem; 13526 13527 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 13528 "no room to append digest"); 13529 13530 sym_op->aead.digest.phys_addr = digest_phys; 13531 13532 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 13533 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 13534 auth_tag_len); 13535 debug_hexdump(stdout, "digest:", 13536 sym_op->aead.digest.data, 13537 auth_tag_len); 13538 } 13539 13540 /* Append aad data */ 13541 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 13542 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13543 uint8_t *, IV_OFFSET); 13544 13545 /* Copy IV 1 byte after the IV pointer, according to the API */ 13546 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 13547 13548 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 13549 13550 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13551 ut_params->ibuf, aad_len); 13552 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13553 "no room to prepend aad"); 13554 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13555 ut_params->ibuf); 13556 13557 memset(sym_op->aead.aad.data, 0, aad_len); 13558 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 13559 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13560 13561 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13562 debug_hexdump(stdout, "aad:", 13563 sym_op->aead.aad.data, aad_len); 13564 } else { 13565 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13566 uint8_t *, IV_OFFSET); 13567 13568 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 13569 13570 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 13571 13572 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13573 ut_params->ibuf, aad_len_pad); 13574 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13575 "no room to prepend aad"); 13576 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13577 ut_params->ibuf); 13578 13579 memset(sym_op->aead.aad.data, 0, aad_len); 13580 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13581 13582 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13583 debug_hexdump(stdout, "aad:", 13584 sym_op->aead.aad.data, aad_len); 13585 } 13586 13587 sym_op->aead.data.length = tdata->plaintext.len; 13588 sym_op->aead.data.offset = aad_len_pad; 13589 13590 return 0; 13591 } 13592 13593 #define SGL_MAX_NO 16 13594 13595 static int 13596 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 13597 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 13598 { 13599 struct crypto_testsuite_params *ts_params = &testsuite_params; 13600 struct crypto_unittest_params *ut_params = &unittest_params; 13601 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 13602 int retval; 13603 int to_trn = 0; 13604 int to_trn_tbl[SGL_MAX_NO]; 13605 int segs = 1; 13606 unsigned int trn_data = 0; 13607 uint8_t *plaintext, *ciphertext, *auth_tag; 13608 struct rte_cryptodev_info dev_info; 13609 13610 /* Verify the capabilities */ 13611 struct rte_cryptodev_sym_capability_idx cap_idx; 13612 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13613 cap_idx.algo.aead = tdata->algo; 13614 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13615 &cap_idx) == NULL) 13616 return TEST_SKIPPED; 13617 13618 /* OOP not supported with CPU crypto */ 13619 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13620 return TEST_SKIPPED; 13621 13622 /* Detailed check for the particular SGL support flag */ 13623 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13624 if (!oop) { 13625 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13626 if (sgl_in && (!(dev_info.feature_flags & 13627 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 13628 return TEST_SKIPPED; 13629 13630 uint64_t feat_flags = dev_info.feature_flags; 13631 13632 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13633 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13634 printf("Device doesn't support RAW data-path APIs.\n"); 13635 return TEST_SKIPPED; 13636 } 13637 } else { 13638 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13639 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 13640 tdata->plaintext.len; 13641 /* Raw data path API does not support OOP */ 13642 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13643 return TEST_SKIPPED; 13644 if (sgl_in && !sgl_out) { 13645 if (!(dev_info.feature_flags & 13646 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 13647 return TEST_SKIPPED; 13648 } else if (!sgl_in && sgl_out) { 13649 if (!(dev_info.feature_flags & 13650 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 13651 return TEST_SKIPPED; 13652 } else if (sgl_in && sgl_out) { 13653 if (!(dev_info.feature_flags & 13654 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 13655 return TEST_SKIPPED; 13656 } 13657 } 13658 13659 if (fragsz > tdata->plaintext.len) 13660 fragsz = tdata->plaintext.len; 13661 13662 uint16_t plaintext_len = fragsz; 13663 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 13664 13665 if (fragsz_oop > tdata->plaintext.len) 13666 frag_size_oop = tdata->plaintext.len; 13667 13668 int ecx = 0; 13669 void *digest_mem = NULL; 13670 13671 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 13672 13673 if (tdata->plaintext.len % fragsz != 0) { 13674 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 13675 return 1; 13676 } else { 13677 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 13678 return 1; 13679 } 13680 13681 /* 13682 * For out-op-place we need to alloc another mbuf 13683 */ 13684 if (oop) { 13685 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13686 rte_pktmbuf_append(ut_params->obuf, 13687 frag_size_oop + prepend_len); 13688 buf_oop = ut_params->obuf; 13689 } 13690 13691 /* Create AEAD session */ 13692 retval = create_aead_session(ts_params->valid_devs[0], 13693 tdata->algo, 13694 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13695 tdata->key.data, tdata->key.len, 13696 tdata->aad.len, tdata->auth_tag.len, 13697 tdata->iv.len); 13698 if (retval < 0) 13699 return retval; 13700 13701 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13702 13703 /* clear mbuf payload */ 13704 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13705 rte_pktmbuf_tailroom(ut_params->ibuf)); 13706 13707 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13708 plaintext_len); 13709 13710 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13711 13712 trn_data += plaintext_len; 13713 13714 buf = ut_params->ibuf; 13715 13716 /* 13717 * Loop until no more fragments 13718 */ 13719 13720 while (trn_data < tdata->plaintext.len) { 13721 ++segs; 13722 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13723 (tdata->plaintext.len - trn_data) : fragsz; 13724 13725 to_trn_tbl[ecx++] = to_trn; 13726 13727 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13728 buf = buf->next; 13729 13730 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13731 rte_pktmbuf_tailroom(buf)); 13732 13733 /* OOP */ 13734 if (oop && !fragsz_oop) { 13735 buf_last_oop = buf_oop->next = 13736 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13737 buf_oop = buf_oop->next; 13738 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13739 0, rte_pktmbuf_tailroom(buf_oop)); 13740 rte_pktmbuf_append(buf_oop, to_trn); 13741 } 13742 13743 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13744 to_trn); 13745 13746 memcpy(plaintext, tdata->plaintext.data + trn_data, 13747 to_trn); 13748 trn_data += to_trn; 13749 if (trn_data == tdata->plaintext.len) { 13750 if (oop) { 13751 if (!fragsz_oop) 13752 digest_mem = rte_pktmbuf_append(buf_oop, 13753 tdata->auth_tag.len); 13754 } else 13755 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13756 tdata->auth_tag.len); 13757 } 13758 } 13759 13760 uint64_t digest_phys = 0; 13761 13762 ut_params->ibuf->nb_segs = segs; 13763 13764 segs = 1; 13765 if (fragsz_oop && oop) { 13766 to_trn = 0; 13767 ecx = 0; 13768 13769 if (frag_size_oop == tdata->plaintext.len) { 13770 digest_mem = rte_pktmbuf_append(ut_params->obuf, 13771 tdata->auth_tag.len); 13772 13773 digest_phys = rte_pktmbuf_iova_offset( 13774 ut_params->obuf, 13775 tdata->plaintext.len + prepend_len); 13776 } 13777 13778 trn_data = frag_size_oop; 13779 while (trn_data < tdata->plaintext.len) { 13780 ++segs; 13781 to_trn = 13782 (tdata->plaintext.len - trn_data < 13783 frag_size_oop) ? 13784 (tdata->plaintext.len - trn_data) : 13785 frag_size_oop; 13786 13787 to_trn_tbl[ecx++] = to_trn; 13788 13789 buf_last_oop = buf_oop->next = 13790 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13791 buf_oop = buf_oop->next; 13792 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13793 0, rte_pktmbuf_tailroom(buf_oop)); 13794 rte_pktmbuf_append(buf_oop, to_trn); 13795 13796 trn_data += to_trn; 13797 13798 if (trn_data == tdata->plaintext.len) { 13799 digest_mem = rte_pktmbuf_append(buf_oop, 13800 tdata->auth_tag.len); 13801 } 13802 } 13803 13804 ut_params->obuf->nb_segs = segs; 13805 } 13806 13807 /* 13808 * Place digest at the end of the last buffer 13809 */ 13810 if (!digest_phys) 13811 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13812 if (oop && buf_last_oop) 13813 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 13814 13815 if (!digest_mem && !oop) { 13816 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13817 + tdata->auth_tag.len); 13818 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13819 tdata->plaintext.len); 13820 } 13821 13822 /* Create AEAD operation */ 13823 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 13824 tdata, digest_mem, digest_phys); 13825 13826 if (retval < 0) 13827 return retval; 13828 13829 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13830 13831 ut_params->op->sym->m_src = ut_params->ibuf; 13832 if (oop) 13833 ut_params->op->sym->m_dst = ut_params->obuf; 13834 13835 /* Process crypto operation */ 13836 if (oop == IN_PLACE && 13837 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13838 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 13839 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13840 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13841 ut_params->op, 0, 0, 0, 0); 13842 else 13843 TEST_ASSERT_NOT_NULL( 13844 process_crypto_request(ts_params->valid_devs[0], 13845 ut_params->op), "failed to process sym crypto op"); 13846 13847 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13848 "crypto op processing failed"); 13849 13850 13851 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 13852 uint8_t *, prepend_len); 13853 if (oop) { 13854 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13855 uint8_t *, prepend_len); 13856 } 13857 13858 if (fragsz_oop) 13859 fragsz = fragsz_oop; 13860 13861 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13862 ciphertext, 13863 tdata->ciphertext.data, 13864 fragsz, 13865 "Ciphertext data not as expected"); 13866 13867 buf = ut_params->op->sym->m_src->next; 13868 if (oop) 13869 buf = ut_params->op->sym->m_dst->next; 13870 13871 unsigned int off = fragsz; 13872 13873 ecx = 0; 13874 while (buf) { 13875 ciphertext = rte_pktmbuf_mtod(buf, 13876 uint8_t *); 13877 13878 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13879 ciphertext, 13880 tdata->ciphertext.data + off, 13881 to_trn_tbl[ecx], 13882 "Ciphertext data not as expected"); 13883 13884 off += to_trn_tbl[ecx++]; 13885 buf = buf->next; 13886 } 13887 13888 auth_tag = digest_mem; 13889 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13890 auth_tag, 13891 tdata->auth_tag.data, 13892 tdata->auth_tag.len, 13893 "Generated auth tag not as expected"); 13894 13895 return 0; 13896 } 13897 13898 static int 13899 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 13900 { 13901 return test_authenticated_encryption_SGL( 13902 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 13903 } 13904 13905 static int 13906 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 13907 { 13908 return test_authenticated_encryption_SGL( 13909 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 13910 } 13911 13912 static int 13913 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 13914 { 13915 return test_authenticated_encryption_SGL( 13916 &gcm_test_case_8, OUT_OF_PLACE, 400, 13917 gcm_test_case_8.plaintext.len); 13918 } 13919 13920 static int 13921 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 13922 { 13923 /* This test is not for OPENSSL PMD */ 13924 if (gbl_driver_id == rte_cryptodev_driver_id_get( 13925 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 13926 return TEST_SKIPPED; 13927 13928 return test_authenticated_encryption_SGL( 13929 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 13930 } 13931 13932 static int 13933 test_authentication_verify_fail_when_data_corrupted( 13934 struct crypto_testsuite_params *ts_params, 13935 struct crypto_unittest_params *ut_params, 13936 const struct test_crypto_vector *reference) 13937 { 13938 return test_authentication_verify_fail_when_data_corruption( 13939 ts_params, ut_params, reference, 1); 13940 } 13941 13942 static int 13943 test_authentication_verify_fail_when_tag_corrupted( 13944 struct crypto_testsuite_params *ts_params, 13945 struct crypto_unittest_params *ut_params, 13946 const struct test_crypto_vector *reference) 13947 { 13948 return test_authentication_verify_fail_when_data_corruption( 13949 ts_params, ut_params, reference, 0); 13950 } 13951 13952 static int 13953 test_authentication_verify_GMAC_fail_when_data_corrupted( 13954 struct crypto_testsuite_params *ts_params, 13955 struct crypto_unittest_params *ut_params, 13956 const struct test_crypto_vector *reference) 13957 { 13958 return test_authentication_verify_GMAC_fail_when_corruption( 13959 ts_params, ut_params, reference, 1); 13960 } 13961 13962 static int 13963 test_authentication_verify_GMAC_fail_when_tag_corrupted( 13964 struct crypto_testsuite_params *ts_params, 13965 struct crypto_unittest_params *ut_params, 13966 const struct test_crypto_vector *reference) 13967 { 13968 return test_authentication_verify_GMAC_fail_when_corruption( 13969 ts_params, ut_params, reference, 0); 13970 } 13971 13972 static int 13973 test_authenticated_decryption_fail_when_data_corrupted( 13974 struct crypto_testsuite_params *ts_params, 13975 struct crypto_unittest_params *ut_params, 13976 const struct test_crypto_vector *reference) 13977 { 13978 return test_authenticated_decryption_fail_when_corruption( 13979 ts_params, ut_params, reference, 1); 13980 } 13981 13982 static int 13983 test_authenticated_decryption_fail_when_tag_corrupted( 13984 struct crypto_testsuite_params *ts_params, 13985 struct crypto_unittest_params *ut_params, 13986 const struct test_crypto_vector *reference) 13987 { 13988 return test_authenticated_decryption_fail_when_corruption( 13989 ts_params, ut_params, reference, 0); 13990 } 13991 13992 static int 13993 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 13994 { 13995 return test_authentication_verify_fail_when_data_corrupted( 13996 &testsuite_params, &unittest_params, 13997 &hmac_sha1_test_crypto_vector); 13998 } 13999 14000 static int 14001 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14002 { 14003 return test_authentication_verify_fail_when_tag_corrupted( 14004 &testsuite_params, &unittest_params, 14005 &hmac_sha1_test_crypto_vector); 14006 } 14007 14008 static int 14009 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14010 { 14011 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14012 &testsuite_params, &unittest_params, 14013 &aes128_gmac_test_vector); 14014 } 14015 14016 static int 14017 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14018 { 14019 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14020 &testsuite_params, &unittest_params, 14021 &aes128_gmac_test_vector); 14022 } 14023 14024 static int 14025 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14026 { 14027 return test_authenticated_decryption_fail_when_data_corrupted( 14028 &testsuite_params, 14029 &unittest_params, 14030 &aes128cbc_hmac_sha1_test_vector); 14031 } 14032 14033 static int 14034 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14035 { 14036 return test_authenticated_decryption_fail_when_tag_corrupted( 14037 &testsuite_params, 14038 &unittest_params, 14039 &aes128cbc_hmac_sha1_test_vector); 14040 } 14041 14042 static int 14043 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14044 { 14045 return test_authenticated_encrypt_with_esn( 14046 &testsuite_params, 14047 &unittest_params, 14048 &aes128cbc_hmac_sha1_aad_test_vector); 14049 } 14050 14051 static int 14052 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14053 { 14054 return test_authenticated_decrypt_with_esn( 14055 &testsuite_params, 14056 &unittest_params, 14057 &aes128cbc_hmac_sha1_aad_test_vector); 14058 } 14059 14060 static int 14061 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14062 { 14063 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14064 } 14065 14066 static int 14067 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14068 { 14069 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14070 } 14071 14072 static int 14073 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14074 { 14075 return test_authenticated_encryption_SGL( 14076 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14077 chacha20_poly1305_case_2.plaintext.len); 14078 } 14079 14080 #ifdef RTE_CRYPTO_SCHEDULER 14081 14082 /* global AESNI worker IDs for the scheduler test */ 14083 uint8_t aesni_ids[2]; 14084 14085 static int 14086 scheduler_testsuite_setup(void) 14087 { 14088 uint32_t i = 0; 14089 int32_t nb_devs, ret; 14090 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14091 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14092 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14093 uint16_t worker_core_count = 0; 14094 uint16_t socket_id = 0; 14095 14096 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14097 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14098 14099 /* Identify the Worker Cores 14100 * Use 2 worker cores for the device args 14101 */ 14102 RTE_LCORE_FOREACH_WORKER(i) { 14103 if (worker_core_count > 1) 14104 break; 14105 snprintf(vdev_args, sizeof(vdev_args), 14106 "%s%d", temp_str, i); 14107 strcpy(temp_str, vdev_args); 14108 strlcat(temp_str, ";", sizeof(temp_str)); 14109 worker_core_count++; 14110 socket_id = rte_lcore_to_socket_id(i); 14111 } 14112 if (worker_core_count != 2) { 14113 RTE_LOG(ERR, USER1, 14114 "Cryptodev scheduler test require at least " 14115 "two worker cores to run. " 14116 "Please use the correct coremask.\n"); 14117 return TEST_FAILED; 14118 } 14119 strcpy(temp_str, vdev_args); 14120 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14121 temp_str, socket_id); 14122 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14123 nb_devs = rte_cryptodev_device_count_by_driver( 14124 rte_cryptodev_driver_id_get( 14125 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14126 if (nb_devs < 1) { 14127 ret = rte_vdev_init( 14128 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14129 vdev_args); 14130 TEST_ASSERT(ret == 0, 14131 "Failed to create instance %u of pmd : %s", 14132 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14133 } 14134 } 14135 return testsuite_setup(); 14136 } 14137 14138 static int 14139 test_scheduler_attach_worker_op(void) 14140 { 14141 struct crypto_testsuite_params *ts_params = &testsuite_params; 14142 uint8_t sched_id = ts_params->valid_devs[0]; 14143 uint32_t i, nb_devs_attached = 0; 14144 int ret; 14145 char vdev_name[32]; 14146 unsigned int count = rte_cryptodev_count(); 14147 14148 /* create 2 AESNI_MB vdevs on top of existing devices */ 14149 for (i = count; i < count + 2; i++) { 14150 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14151 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14152 i); 14153 ret = rte_vdev_init(vdev_name, NULL); 14154 14155 TEST_ASSERT(ret == 0, 14156 "Failed to create instance %u of" 14157 " pmd : %s", 14158 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14159 14160 if (ret < 0) { 14161 RTE_LOG(ERR, USER1, 14162 "Failed to create 2 AESNI MB PMDs.\n"); 14163 return TEST_SKIPPED; 14164 } 14165 } 14166 14167 /* attach 2 AESNI_MB cdevs */ 14168 for (i = count; i < count + 2; i++) { 14169 struct rte_cryptodev_info info; 14170 unsigned int session_size; 14171 14172 rte_cryptodev_info_get(i, &info); 14173 if (info.driver_id != rte_cryptodev_driver_id_get( 14174 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14175 continue; 14176 14177 session_size = rte_cryptodev_sym_get_private_session_size(i); 14178 /* 14179 * Create the session mempool again, since now there are new devices 14180 * to use the mempool. 14181 */ 14182 if (ts_params->session_mpool) { 14183 rte_mempool_free(ts_params->session_mpool); 14184 ts_params->session_mpool = NULL; 14185 } 14186 if (ts_params->session_priv_mpool) { 14187 rte_mempool_free(ts_params->session_priv_mpool); 14188 ts_params->session_priv_mpool = NULL; 14189 } 14190 14191 if (info.sym.max_nb_sessions != 0 && 14192 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14193 RTE_LOG(ERR, USER1, 14194 "Device does not support " 14195 "at least %u sessions\n", 14196 MAX_NB_SESSIONS); 14197 return TEST_FAILED; 14198 } 14199 /* 14200 * Create mempool with maximum number of sessions, 14201 * to include the session headers 14202 */ 14203 if (ts_params->session_mpool == NULL) { 14204 ts_params->session_mpool = 14205 rte_cryptodev_sym_session_pool_create( 14206 "test_sess_mp", 14207 MAX_NB_SESSIONS, 0, 0, 0, 14208 SOCKET_ID_ANY); 14209 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14210 "session mempool allocation failed"); 14211 } 14212 14213 /* 14214 * Create mempool with maximum number of sessions, 14215 * to include device specific session private data 14216 */ 14217 if (ts_params->session_priv_mpool == NULL) { 14218 ts_params->session_priv_mpool = rte_mempool_create( 14219 "test_sess_mp_priv", 14220 MAX_NB_SESSIONS, 14221 session_size, 14222 0, 0, NULL, NULL, NULL, 14223 NULL, SOCKET_ID_ANY, 14224 0); 14225 14226 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14227 "session mempool allocation failed"); 14228 } 14229 14230 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14231 ts_params->qp_conf.mp_session_private = 14232 ts_params->session_priv_mpool; 14233 14234 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14235 (uint8_t)i); 14236 14237 TEST_ASSERT(ret == 0, 14238 "Failed to attach device %u of pmd : %s", i, 14239 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14240 14241 aesni_ids[nb_devs_attached] = (uint8_t)i; 14242 14243 nb_devs_attached++; 14244 } 14245 14246 return 0; 14247 } 14248 14249 static int 14250 test_scheduler_detach_worker_op(void) 14251 { 14252 struct crypto_testsuite_params *ts_params = &testsuite_params; 14253 uint8_t sched_id = ts_params->valid_devs[0]; 14254 uint32_t i; 14255 int ret; 14256 14257 for (i = 0; i < 2; i++) { 14258 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14259 aesni_ids[i]); 14260 TEST_ASSERT(ret == 0, 14261 "Failed to detach device %u", aesni_ids[i]); 14262 } 14263 14264 return 0; 14265 } 14266 14267 static int 14268 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14269 { 14270 struct crypto_testsuite_params *ts_params = &testsuite_params; 14271 uint8_t sched_id = ts_params->valid_devs[0]; 14272 /* set mode */ 14273 return rte_cryptodev_scheduler_mode_set(sched_id, 14274 scheduler_mode); 14275 } 14276 14277 static int 14278 test_scheduler_mode_roundrobin_op(void) 14279 { 14280 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14281 0, "Failed to set roundrobin mode"); 14282 return 0; 14283 14284 } 14285 14286 static int 14287 test_scheduler_mode_multicore_op(void) 14288 { 14289 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14290 0, "Failed to set multicore mode"); 14291 14292 return 0; 14293 } 14294 14295 static int 14296 test_scheduler_mode_failover_op(void) 14297 { 14298 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 14299 0, "Failed to set failover mode"); 14300 14301 return 0; 14302 } 14303 14304 static int 14305 test_scheduler_mode_pkt_size_distr_op(void) 14306 { 14307 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 14308 0, "Failed to set pktsize mode"); 14309 14310 return 0; 14311 } 14312 14313 static int 14314 scheduler_multicore_testsuite_setup(void) 14315 { 14316 if (test_scheduler_attach_worker_op() < 0) 14317 return TEST_SKIPPED; 14318 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 14319 return TEST_SKIPPED; 14320 return 0; 14321 } 14322 14323 static int 14324 scheduler_roundrobin_testsuite_setup(void) 14325 { 14326 if (test_scheduler_attach_worker_op() < 0) 14327 return TEST_SKIPPED; 14328 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 14329 return TEST_SKIPPED; 14330 return 0; 14331 } 14332 14333 static int 14334 scheduler_failover_testsuite_setup(void) 14335 { 14336 if (test_scheduler_attach_worker_op() < 0) 14337 return TEST_SKIPPED; 14338 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 14339 return TEST_SKIPPED; 14340 return 0; 14341 } 14342 14343 static int 14344 scheduler_pkt_size_distr_testsuite_setup(void) 14345 { 14346 if (test_scheduler_attach_worker_op() < 0) 14347 return TEST_SKIPPED; 14348 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 14349 return TEST_SKIPPED; 14350 return 0; 14351 } 14352 14353 static void 14354 scheduler_mode_testsuite_teardown(void) 14355 { 14356 test_scheduler_detach_worker_op(); 14357 } 14358 14359 #endif /* RTE_CRYPTO_SCHEDULER */ 14360 14361 static struct unit_test_suite end_testsuite = { 14362 .suite_name = NULL, 14363 .setup = NULL, 14364 .teardown = NULL, 14365 .unit_test_suites = NULL 14366 }; 14367 14368 #ifdef RTE_LIB_SECURITY 14369 static struct unit_test_suite ipsec_proto_testsuite = { 14370 .suite_name = "IPsec Proto Unit Test Suite", 14371 .setup = ipsec_proto_testsuite_setup, 14372 .unit_test_cases = { 14373 TEST_CASE_NAMED_WITH_DATA( 14374 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14375 ut_setup_security, ut_teardown, 14376 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 14377 TEST_CASE_NAMED_WITH_DATA( 14378 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14379 ut_setup_security, ut_teardown, 14380 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 14381 TEST_CASE_NAMED_WITH_DATA( 14382 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14383 ut_setup_security, ut_teardown, 14384 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 14385 TEST_CASE_NAMED_WITH_DATA( 14386 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14387 ut_setup_security, ut_teardown, 14388 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 14389 TEST_CASE_NAMED_WITH_DATA( 14390 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14391 ut_setup_security, ut_teardown, 14392 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 14393 TEST_CASE_NAMED_WITH_DATA( 14394 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14395 ut_setup_security, ut_teardown, 14396 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 14397 TEST_CASE_NAMED_ST( 14398 "Combined test alg list", 14399 ut_setup_security, ut_teardown, 14400 test_ipsec_proto_display_list), 14401 TEST_CASE_NAMED_ST( 14402 "IV generation", 14403 ut_setup_security, ut_teardown, 14404 test_ipsec_proto_iv_gen), 14405 TEST_CASE_NAMED_ST( 14406 "UDP encapsulation", 14407 ut_setup_security, ut_teardown, 14408 test_ipsec_proto_udp_encap), 14409 TEST_CASE_NAMED_ST( 14410 "UDP encapsulation ports verification test", 14411 ut_setup_security, ut_teardown, 14412 test_ipsec_proto_udp_ports_verify), 14413 TEST_CASE_NAMED_ST( 14414 "SA expiry packets soft", 14415 ut_setup_security, ut_teardown, 14416 test_ipsec_proto_sa_exp_pkts_soft), 14417 TEST_CASE_NAMED_ST( 14418 "SA expiry packets hard", 14419 ut_setup_security, ut_teardown, 14420 test_ipsec_proto_sa_exp_pkts_hard), 14421 TEST_CASE_NAMED_ST( 14422 "Negative test: ICV corruption", 14423 ut_setup_security, ut_teardown, 14424 test_ipsec_proto_err_icv_corrupt), 14425 TEST_CASE_NAMED_ST( 14426 "Tunnel dst addr verification", 14427 ut_setup_security, ut_teardown, 14428 test_ipsec_proto_tunnel_dst_addr_verify), 14429 TEST_CASE_NAMED_ST( 14430 "Tunnel src and dst addr verification", 14431 ut_setup_security, ut_teardown, 14432 test_ipsec_proto_tunnel_src_dst_addr_verify), 14433 TEST_CASE_NAMED_ST( 14434 "Inner IP checksum", 14435 ut_setup_security, ut_teardown, 14436 test_ipsec_proto_inner_ip_csum), 14437 TEST_CASE_NAMED_ST( 14438 "Inner L4 checksum", 14439 ut_setup_security, ut_teardown, 14440 test_ipsec_proto_inner_l4_csum), 14441 TEST_CASES_END() /**< NULL terminate unit test array */ 14442 } 14443 }; 14444 14445 static struct unit_test_suite pdcp_proto_testsuite = { 14446 .suite_name = "PDCP Proto Unit Test Suite", 14447 .setup = pdcp_proto_testsuite_setup, 14448 .unit_test_cases = { 14449 TEST_CASE_ST(ut_setup_security, ut_teardown, 14450 test_PDCP_PROTO_all), 14451 TEST_CASES_END() /**< NULL terminate unit test array */ 14452 } 14453 }; 14454 14455 #define ADD_UPLINK_TESTCASE(data) \ 14456 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 14457 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 14458 14459 #define ADD_DOWNLINK_TESTCASE(data) \ 14460 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 14461 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 14462 14463 static struct unit_test_suite docsis_proto_testsuite = { 14464 .suite_name = "DOCSIS Proto Unit Test Suite", 14465 .setup = docsis_proto_testsuite_setup, 14466 .unit_test_cases = { 14467 /* Uplink */ 14468 ADD_UPLINK_TESTCASE(docsis_test_case_1) 14469 ADD_UPLINK_TESTCASE(docsis_test_case_2) 14470 ADD_UPLINK_TESTCASE(docsis_test_case_3) 14471 ADD_UPLINK_TESTCASE(docsis_test_case_4) 14472 ADD_UPLINK_TESTCASE(docsis_test_case_5) 14473 ADD_UPLINK_TESTCASE(docsis_test_case_6) 14474 ADD_UPLINK_TESTCASE(docsis_test_case_7) 14475 ADD_UPLINK_TESTCASE(docsis_test_case_8) 14476 ADD_UPLINK_TESTCASE(docsis_test_case_9) 14477 ADD_UPLINK_TESTCASE(docsis_test_case_10) 14478 ADD_UPLINK_TESTCASE(docsis_test_case_11) 14479 ADD_UPLINK_TESTCASE(docsis_test_case_12) 14480 ADD_UPLINK_TESTCASE(docsis_test_case_13) 14481 ADD_UPLINK_TESTCASE(docsis_test_case_14) 14482 ADD_UPLINK_TESTCASE(docsis_test_case_15) 14483 ADD_UPLINK_TESTCASE(docsis_test_case_16) 14484 ADD_UPLINK_TESTCASE(docsis_test_case_17) 14485 ADD_UPLINK_TESTCASE(docsis_test_case_18) 14486 ADD_UPLINK_TESTCASE(docsis_test_case_19) 14487 ADD_UPLINK_TESTCASE(docsis_test_case_20) 14488 ADD_UPLINK_TESTCASE(docsis_test_case_21) 14489 ADD_UPLINK_TESTCASE(docsis_test_case_22) 14490 ADD_UPLINK_TESTCASE(docsis_test_case_23) 14491 ADD_UPLINK_TESTCASE(docsis_test_case_24) 14492 ADD_UPLINK_TESTCASE(docsis_test_case_25) 14493 ADD_UPLINK_TESTCASE(docsis_test_case_26) 14494 /* Downlink */ 14495 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 14496 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 14497 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 14498 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 14499 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 14500 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 14501 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 14502 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 14503 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 14504 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 14505 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 14506 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 14507 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 14508 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 14509 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 14510 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 14511 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 14512 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 14513 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 14514 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 14515 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 14516 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 14517 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 14518 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 14519 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 14520 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 14521 TEST_CASES_END() /**< NULL terminate unit test array */ 14522 } 14523 }; 14524 #endif 14525 14526 static struct unit_test_suite cryptodev_gen_testsuite = { 14527 .suite_name = "Crypto General Unit Test Suite", 14528 .setup = crypto_gen_testsuite_setup, 14529 .unit_test_cases = { 14530 TEST_CASE_ST(ut_setup, ut_teardown, 14531 test_device_configure_invalid_dev_id), 14532 TEST_CASE_ST(ut_setup, ut_teardown, 14533 test_queue_pair_descriptor_setup), 14534 TEST_CASE_ST(ut_setup, ut_teardown, 14535 test_device_configure_invalid_queue_pair_ids), 14536 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 14537 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 14538 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 14539 TEST_CASES_END() /**< NULL terminate unit test array */ 14540 } 14541 }; 14542 14543 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 14544 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 14545 .setup = negative_hmac_sha1_testsuite_setup, 14546 .unit_test_cases = { 14547 /** Negative tests */ 14548 TEST_CASE_ST(ut_setup, ut_teardown, 14549 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14550 TEST_CASE_ST(ut_setup, ut_teardown, 14551 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14552 TEST_CASE_ST(ut_setup, ut_teardown, 14553 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14554 TEST_CASE_ST(ut_setup, ut_teardown, 14555 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14556 14557 TEST_CASES_END() /**< NULL terminate unit test array */ 14558 } 14559 }; 14560 14561 static struct unit_test_suite cryptodev_multi_session_testsuite = { 14562 .suite_name = "Multi Session Unit Test Suite", 14563 .setup = multi_session_testsuite_setup, 14564 .unit_test_cases = { 14565 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 14566 TEST_CASE_ST(ut_setup, ut_teardown, 14567 test_multi_session_random_usage), 14568 14569 TEST_CASES_END() /**< NULL terminate unit test array */ 14570 } 14571 }; 14572 14573 static struct unit_test_suite cryptodev_null_testsuite = { 14574 .suite_name = "NULL Test Suite", 14575 .setup = null_testsuite_setup, 14576 .unit_test_cases = { 14577 TEST_CASE_ST(ut_setup, ut_teardown, 14578 test_null_invalid_operation), 14579 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 14580 TEST_CASES_END() 14581 } 14582 }; 14583 14584 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 14585 .suite_name = "AES CCM Authenticated Test Suite", 14586 .setup = aes_ccm_auth_testsuite_setup, 14587 .unit_test_cases = { 14588 /** AES CCM Authenticated Encryption 128 bits key*/ 14589 TEST_CASE_ST(ut_setup, ut_teardown, 14590 test_AES_CCM_authenticated_encryption_test_case_128_1), 14591 TEST_CASE_ST(ut_setup, ut_teardown, 14592 test_AES_CCM_authenticated_encryption_test_case_128_2), 14593 TEST_CASE_ST(ut_setup, ut_teardown, 14594 test_AES_CCM_authenticated_encryption_test_case_128_3), 14595 14596 /** AES CCM Authenticated Decryption 128 bits key*/ 14597 TEST_CASE_ST(ut_setup, ut_teardown, 14598 test_AES_CCM_authenticated_decryption_test_case_128_1), 14599 TEST_CASE_ST(ut_setup, ut_teardown, 14600 test_AES_CCM_authenticated_decryption_test_case_128_2), 14601 TEST_CASE_ST(ut_setup, ut_teardown, 14602 test_AES_CCM_authenticated_decryption_test_case_128_3), 14603 14604 /** AES CCM Authenticated Encryption 192 bits key */ 14605 TEST_CASE_ST(ut_setup, ut_teardown, 14606 test_AES_CCM_authenticated_encryption_test_case_192_1), 14607 TEST_CASE_ST(ut_setup, ut_teardown, 14608 test_AES_CCM_authenticated_encryption_test_case_192_2), 14609 TEST_CASE_ST(ut_setup, ut_teardown, 14610 test_AES_CCM_authenticated_encryption_test_case_192_3), 14611 14612 /** AES CCM Authenticated Decryption 192 bits key*/ 14613 TEST_CASE_ST(ut_setup, ut_teardown, 14614 test_AES_CCM_authenticated_decryption_test_case_192_1), 14615 TEST_CASE_ST(ut_setup, ut_teardown, 14616 test_AES_CCM_authenticated_decryption_test_case_192_2), 14617 TEST_CASE_ST(ut_setup, ut_teardown, 14618 test_AES_CCM_authenticated_decryption_test_case_192_3), 14619 14620 /** AES CCM Authenticated Encryption 256 bits key */ 14621 TEST_CASE_ST(ut_setup, ut_teardown, 14622 test_AES_CCM_authenticated_encryption_test_case_256_1), 14623 TEST_CASE_ST(ut_setup, ut_teardown, 14624 test_AES_CCM_authenticated_encryption_test_case_256_2), 14625 TEST_CASE_ST(ut_setup, ut_teardown, 14626 test_AES_CCM_authenticated_encryption_test_case_256_3), 14627 14628 /** AES CCM Authenticated Decryption 256 bits key*/ 14629 TEST_CASE_ST(ut_setup, ut_teardown, 14630 test_AES_CCM_authenticated_decryption_test_case_256_1), 14631 TEST_CASE_ST(ut_setup, ut_teardown, 14632 test_AES_CCM_authenticated_decryption_test_case_256_2), 14633 TEST_CASE_ST(ut_setup, ut_teardown, 14634 test_AES_CCM_authenticated_decryption_test_case_256_3), 14635 TEST_CASES_END() 14636 } 14637 }; 14638 14639 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 14640 .suite_name = "AES GCM Authenticated Test Suite", 14641 .setup = aes_gcm_auth_testsuite_setup, 14642 .unit_test_cases = { 14643 /** AES GCM Authenticated Encryption */ 14644 TEST_CASE_ST(ut_setup, ut_teardown, 14645 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 14646 TEST_CASE_ST(ut_setup, ut_teardown, 14647 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 14648 TEST_CASE_ST(ut_setup, ut_teardown, 14649 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 14650 TEST_CASE_ST(ut_setup, ut_teardown, 14651 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 14652 TEST_CASE_ST(ut_setup, ut_teardown, 14653 test_AES_GCM_authenticated_encryption_test_case_1), 14654 TEST_CASE_ST(ut_setup, ut_teardown, 14655 test_AES_GCM_authenticated_encryption_test_case_2), 14656 TEST_CASE_ST(ut_setup, ut_teardown, 14657 test_AES_GCM_authenticated_encryption_test_case_3), 14658 TEST_CASE_ST(ut_setup, ut_teardown, 14659 test_AES_GCM_authenticated_encryption_test_case_4), 14660 TEST_CASE_ST(ut_setup, ut_teardown, 14661 test_AES_GCM_authenticated_encryption_test_case_5), 14662 TEST_CASE_ST(ut_setup, ut_teardown, 14663 test_AES_GCM_authenticated_encryption_test_case_6), 14664 TEST_CASE_ST(ut_setup, ut_teardown, 14665 test_AES_GCM_authenticated_encryption_test_case_7), 14666 TEST_CASE_ST(ut_setup, ut_teardown, 14667 test_AES_GCM_authenticated_encryption_test_case_8), 14668 TEST_CASE_ST(ut_setup, ut_teardown, 14669 test_AES_GCM_J0_authenticated_encryption_test_case_1), 14670 14671 /** AES GCM Authenticated Decryption */ 14672 TEST_CASE_ST(ut_setup, ut_teardown, 14673 test_AES_GCM_authenticated_decryption_test_case_1), 14674 TEST_CASE_ST(ut_setup, ut_teardown, 14675 test_AES_GCM_authenticated_decryption_test_case_2), 14676 TEST_CASE_ST(ut_setup, ut_teardown, 14677 test_AES_GCM_authenticated_decryption_test_case_3), 14678 TEST_CASE_ST(ut_setup, ut_teardown, 14679 test_AES_GCM_authenticated_decryption_test_case_4), 14680 TEST_CASE_ST(ut_setup, ut_teardown, 14681 test_AES_GCM_authenticated_decryption_test_case_5), 14682 TEST_CASE_ST(ut_setup, ut_teardown, 14683 test_AES_GCM_authenticated_decryption_test_case_6), 14684 TEST_CASE_ST(ut_setup, ut_teardown, 14685 test_AES_GCM_authenticated_decryption_test_case_7), 14686 TEST_CASE_ST(ut_setup, ut_teardown, 14687 test_AES_GCM_authenticated_decryption_test_case_8), 14688 TEST_CASE_ST(ut_setup, ut_teardown, 14689 test_AES_GCM_J0_authenticated_decryption_test_case_1), 14690 14691 /** AES GCM Authenticated Encryption 192 bits key */ 14692 TEST_CASE_ST(ut_setup, ut_teardown, 14693 test_AES_GCM_auth_encryption_test_case_192_1), 14694 TEST_CASE_ST(ut_setup, ut_teardown, 14695 test_AES_GCM_auth_encryption_test_case_192_2), 14696 TEST_CASE_ST(ut_setup, ut_teardown, 14697 test_AES_GCM_auth_encryption_test_case_192_3), 14698 TEST_CASE_ST(ut_setup, ut_teardown, 14699 test_AES_GCM_auth_encryption_test_case_192_4), 14700 TEST_CASE_ST(ut_setup, ut_teardown, 14701 test_AES_GCM_auth_encryption_test_case_192_5), 14702 TEST_CASE_ST(ut_setup, ut_teardown, 14703 test_AES_GCM_auth_encryption_test_case_192_6), 14704 TEST_CASE_ST(ut_setup, ut_teardown, 14705 test_AES_GCM_auth_encryption_test_case_192_7), 14706 14707 /** AES GCM Authenticated Decryption 192 bits key */ 14708 TEST_CASE_ST(ut_setup, ut_teardown, 14709 test_AES_GCM_auth_decryption_test_case_192_1), 14710 TEST_CASE_ST(ut_setup, ut_teardown, 14711 test_AES_GCM_auth_decryption_test_case_192_2), 14712 TEST_CASE_ST(ut_setup, ut_teardown, 14713 test_AES_GCM_auth_decryption_test_case_192_3), 14714 TEST_CASE_ST(ut_setup, ut_teardown, 14715 test_AES_GCM_auth_decryption_test_case_192_4), 14716 TEST_CASE_ST(ut_setup, ut_teardown, 14717 test_AES_GCM_auth_decryption_test_case_192_5), 14718 TEST_CASE_ST(ut_setup, ut_teardown, 14719 test_AES_GCM_auth_decryption_test_case_192_6), 14720 TEST_CASE_ST(ut_setup, ut_teardown, 14721 test_AES_GCM_auth_decryption_test_case_192_7), 14722 14723 /** AES GCM Authenticated Encryption 256 bits key */ 14724 TEST_CASE_ST(ut_setup, ut_teardown, 14725 test_AES_GCM_auth_encryption_test_case_256_1), 14726 TEST_CASE_ST(ut_setup, ut_teardown, 14727 test_AES_GCM_auth_encryption_test_case_256_2), 14728 TEST_CASE_ST(ut_setup, ut_teardown, 14729 test_AES_GCM_auth_encryption_test_case_256_3), 14730 TEST_CASE_ST(ut_setup, ut_teardown, 14731 test_AES_GCM_auth_encryption_test_case_256_4), 14732 TEST_CASE_ST(ut_setup, ut_teardown, 14733 test_AES_GCM_auth_encryption_test_case_256_5), 14734 TEST_CASE_ST(ut_setup, ut_teardown, 14735 test_AES_GCM_auth_encryption_test_case_256_6), 14736 TEST_CASE_ST(ut_setup, ut_teardown, 14737 test_AES_GCM_auth_encryption_test_case_256_7), 14738 14739 /** AES GCM Authenticated Decryption 256 bits key */ 14740 TEST_CASE_ST(ut_setup, ut_teardown, 14741 test_AES_GCM_auth_decryption_test_case_256_1), 14742 TEST_CASE_ST(ut_setup, ut_teardown, 14743 test_AES_GCM_auth_decryption_test_case_256_2), 14744 TEST_CASE_ST(ut_setup, ut_teardown, 14745 test_AES_GCM_auth_decryption_test_case_256_3), 14746 TEST_CASE_ST(ut_setup, ut_teardown, 14747 test_AES_GCM_auth_decryption_test_case_256_4), 14748 TEST_CASE_ST(ut_setup, ut_teardown, 14749 test_AES_GCM_auth_decryption_test_case_256_5), 14750 TEST_CASE_ST(ut_setup, ut_teardown, 14751 test_AES_GCM_auth_decryption_test_case_256_6), 14752 TEST_CASE_ST(ut_setup, ut_teardown, 14753 test_AES_GCM_auth_decryption_test_case_256_7), 14754 14755 /** AES GCM Authenticated Encryption big aad size */ 14756 TEST_CASE_ST(ut_setup, ut_teardown, 14757 test_AES_GCM_auth_encryption_test_case_aad_1), 14758 TEST_CASE_ST(ut_setup, ut_teardown, 14759 test_AES_GCM_auth_encryption_test_case_aad_2), 14760 14761 /** AES GCM Authenticated Decryption big aad size */ 14762 TEST_CASE_ST(ut_setup, ut_teardown, 14763 test_AES_GCM_auth_decryption_test_case_aad_1), 14764 TEST_CASE_ST(ut_setup, ut_teardown, 14765 test_AES_GCM_auth_decryption_test_case_aad_2), 14766 14767 /** Out of place tests */ 14768 TEST_CASE_ST(ut_setup, ut_teardown, 14769 test_AES_GCM_authenticated_encryption_oop_test_case_1), 14770 TEST_CASE_ST(ut_setup, ut_teardown, 14771 test_AES_GCM_authenticated_decryption_oop_test_case_1), 14772 14773 /** Session-less tests */ 14774 TEST_CASE_ST(ut_setup, ut_teardown, 14775 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 14776 TEST_CASE_ST(ut_setup, ut_teardown, 14777 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 14778 14779 TEST_CASES_END() 14780 } 14781 }; 14782 14783 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 14784 .suite_name = "AES GMAC Authentication Test Suite", 14785 .setup = aes_gmac_auth_testsuite_setup, 14786 .unit_test_cases = { 14787 TEST_CASE_ST(ut_setup, ut_teardown, 14788 test_AES_GMAC_authentication_test_case_1), 14789 TEST_CASE_ST(ut_setup, ut_teardown, 14790 test_AES_GMAC_authentication_verify_test_case_1), 14791 TEST_CASE_ST(ut_setup, ut_teardown, 14792 test_AES_GMAC_authentication_test_case_2), 14793 TEST_CASE_ST(ut_setup, ut_teardown, 14794 test_AES_GMAC_authentication_verify_test_case_2), 14795 TEST_CASE_ST(ut_setup, ut_teardown, 14796 test_AES_GMAC_authentication_test_case_3), 14797 TEST_CASE_ST(ut_setup, ut_teardown, 14798 test_AES_GMAC_authentication_verify_test_case_3), 14799 TEST_CASE_ST(ut_setup, ut_teardown, 14800 test_AES_GMAC_authentication_test_case_4), 14801 TEST_CASE_ST(ut_setup, ut_teardown, 14802 test_AES_GMAC_authentication_verify_test_case_4), 14803 TEST_CASE_ST(ut_setup, ut_teardown, 14804 test_AES_GMAC_authentication_SGL_40B), 14805 TEST_CASE_ST(ut_setup, ut_teardown, 14806 test_AES_GMAC_authentication_SGL_80B), 14807 TEST_CASE_ST(ut_setup, ut_teardown, 14808 test_AES_GMAC_authentication_SGL_2048B), 14809 TEST_CASE_ST(ut_setup, ut_teardown, 14810 test_AES_GMAC_authentication_SGL_2047B), 14811 14812 TEST_CASES_END() 14813 } 14814 }; 14815 14816 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 14817 .suite_name = "Chacha20-Poly1305 Test Suite", 14818 .setup = chacha20_poly1305_testsuite_setup, 14819 .unit_test_cases = { 14820 TEST_CASE_ST(ut_setup, ut_teardown, 14821 test_chacha20_poly1305_encrypt_test_case_rfc8439), 14822 TEST_CASE_ST(ut_setup, ut_teardown, 14823 test_chacha20_poly1305_decrypt_test_case_rfc8439), 14824 TEST_CASE_ST(ut_setup, ut_teardown, 14825 test_chacha20_poly1305_encrypt_SGL_out_of_place), 14826 TEST_CASES_END() 14827 } 14828 }; 14829 14830 static struct unit_test_suite cryptodev_snow3g_testsuite = { 14831 .suite_name = "SNOW 3G Test Suite", 14832 .setup = snow3g_testsuite_setup, 14833 .unit_test_cases = { 14834 /** SNOW 3G encrypt only (UEA2) */ 14835 TEST_CASE_ST(ut_setup, ut_teardown, 14836 test_snow3g_encryption_test_case_1), 14837 TEST_CASE_ST(ut_setup, ut_teardown, 14838 test_snow3g_encryption_test_case_2), 14839 TEST_CASE_ST(ut_setup, ut_teardown, 14840 test_snow3g_encryption_test_case_3), 14841 TEST_CASE_ST(ut_setup, ut_teardown, 14842 test_snow3g_encryption_test_case_4), 14843 TEST_CASE_ST(ut_setup, ut_teardown, 14844 test_snow3g_encryption_test_case_5), 14845 14846 TEST_CASE_ST(ut_setup, ut_teardown, 14847 test_snow3g_encryption_test_case_1_oop), 14848 TEST_CASE_ST(ut_setup, ut_teardown, 14849 test_snow3g_encryption_test_case_1_oop_sgl), 14850 TEST_CASE_ST(ut_setup, ut_teardown, 14851 test_snow3g_encryption_test_case_1_offset_oop), 14852 TEST_CASE_ST(ut_setup, ut_teardown, 14853 test_snow3g_decryption_test_case_1_oop), 14854 14855 /** SNOW 3G generate auth, then encrypt (UEA2) */ 14856 TEST_CASE_ST(ut_setup, ut_teardown, 14857 test_snow3g_auth_cipher_test_case_1), 14858 TEST_CASE_ST(ut_setup, ut_teardown, 14859 test_snow3g_auth_cipher_test_case_2), 14860 TEST_CASE_ST(ut_setup, ut_teardown, 14861 test_snow3g_auth_cipher_test_case_2_oop), 14862 TEST_CASE_ST(ut_setup, ut_teardown, 14863 test_snow3g_auth_cipher_part_digest_enc), 14864 TEST_CASE_ST(ut_setup, ut_teardown, 14865 test_snow3g_auth_cipher_part_digest_enc_oop), 14866 TEST_CASE_ST(ut_setup, ut_teardown, 14867 test_snow3g_auth_cipher_test_case_3_sgl), 14868 TEST_CASE_ST(ut_setup, ut_teardown, 14869 test_snow3g_auth_cipher_test_case_3_oop_sgl), 14870 TEST_CASE_ST(ut_setup, ut_teardown, 14871 test_snow3g_auth_cipher_part_digest_enc_sgl), 14872 TEST_CASE_ST(ut_setup, ut_teardown, 14873 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 14874 14875 /** SNOW 3G decrypt (UEA2), then verify auth */ 14876 TEST_CASE_ST(ut_setup, ut_teardown, 14877 test_snow3g_auth_cipher_verify_test_case_1), 14878 TEST_CASE_ST(ut_setup, ut_teardown, 14879 test_snow3g_auth_cipher_verify_test_case_2), 14880 TEST_CASE_ST(ut_setup, ut_teardown, 14881 test_snow3g_auth_cipher_verify_test_case_2_oop), 14882 TEST_CASE_ST(ut_setup, ut_teardown, 14883 test_snow3g_auth_cipher_verify_part_digest_enc), 14884 TEST_CASE_ST(ut_setup, ut_teardown, 14885 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 14886 TEST_CASE_ST(ut_setup, ut_teardown, 14887 test_snow3g_auth_cipher_verify_test_case_3_sgl), 14888 TEST_CASE_ST(ut_setup, ut_teardown, 14889 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 14890 TEST_CASE_ST(ut_setup, ut_teardown, 14891 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 14892 TEST_CASE_ST(ut_setup, ut_teardown, 14893 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 14894 14895 /** SNOW 3G decrypt only (UEA2) */ 14896 TEST_CASE_ST(ut_setup, ut_teardown, 14897 test_snow3g_decryption_test_case_1), 14898 TEST_CASE_ST(ut_setup, ut_teardown, 14899 test_snow3g_decryption_test_case_2), 14900 TEST_CASE_ST(ut_setup, ut_teardown, 14901 test_snow3g_decryption_test_case_3), 14902 TEST_CASE_ST(ut_setup, ut_teardown, 14903 test_snow3g_decryption_test_case_4), 14904 TEST_CASE_ST(ut_setup, ut_teardown, 14905 test_snow3g_decryption_test_case_5), 14906 TEST_CASE_ST(ut_setup, ut_teardown, 14907 test_snow3g_decryption_with_digest_test_case_1), 14908 TEST_CASE_ST(ut_setup, ut_teardown, 14909 test_snow3g_hash_generate_test_case_1), 14910 TEST_CASE_ST(ut_setup, ut_teardown, 14911 test_snow3g_hash_generate_test_case_2), 14912 TEST_CASE_ST(ut_setup, ut_teardown, 14913 test_snow3g_hash_generate_test_case_3), 14914 14915 /* Tests with buffers which length is not byte-aligned */ 14916 TEST_CASE_ST(ut_setup, ut_teardown, 14917 test_snow3g_hash_generate_test_case_4), 14918 TEST_CASE_ST(ut_setup, ut_teardown, 14919 test_snow3g_hash_generate_test_case_5), 14920 TEST_CASE_ST(ut_setup, ut_teardown, 14921 test_snow3g_hash_generate_test_case_6), 14922 TEST_CASE_ST(ut_setup, ut_teardown, 14923 test_snow3g_hash_verify_test_case_1), 14924 TEST_CASE_ST(ut_setup, ut_teardown, 14925 test_snow3g_hash_verify_test_case_2), 14926 TEST_CASE_ST(ut_setup, ut_teardown, 14927 test_snow3g_hash_verify_test_case_3), 14928 14929 /* Tests with buffers which length is not byte-aligned */ 14930 TEST_CASE_ST(ut_setup, ut_teardown, 14931 test_snow3g_hash_verify_test_case_4), 14932 TEST_CASE_ST(ut_setup, ut_teardown, 14933 test_snow3g_hash_verify_test_case_5), 14934 TEST_CASE_ST(ut_setup, ut_teardown, 14935 test_snow3g_hash_verify_test_case_6), 14936 TEST_CASE_ST(ut_setup, ut_teardown, 14937 test_snow3g_cipher_auth_test_case_1), 14938 TEST_CASE_ST(ut_setup, ut_teardown, 14939 test_snow3g_auth_cipher_with_digest_test_case_1), 14940 TEST_CASES_END() 14941 } 14942 }; 14943 14944 static struct unit_test_suite cryptodev_zuc_testsuite = { 14945 .suite_name = "ZUC Test Suite", 14946 .setup = zuc_testsuite_setup, 14947 .unit_test_cases = { 14948 /** ZUC encrypt only (EEA3) */ 14949 TEST_CASE_ST(ut_setup, ut_teardown, 14950 test_zuc_encryption_test_case_1), 14951 TEST_CASE_ST(ut_setup, ut_teardown, 14952 test_zuc_encryption_test_case_2), 14953 TEST_CASE_ST(ut_setup, ut_teardown, 14954 test_zuc_encryption_test_case_3), 14955 TEST_CASE_ST(ut_setup, ut_teardown, 14956 test_zuc_encryption_test_case_4), 14957 TEST_CASE_ST(ut_setup, ut_teardown, 14958 test_zuc_encryption_test_case_5), 14959 TEST_CASE_ST(ut_setup, ut_teardown, 14960 test_zuc_encryption_test_case_6_sgl), 14961 14962 /** ZUC authenticate (EIA3) */ 14963 TEST_CASE_ST(ut_setup, ut_teardown, 14964 test_zuc_hash_generate_test_case_1), 14965 TEST_CASE_ST(ut_setup, ut_teardown, 14966 test_zuc_hash_generate_test_case_2), 14967 TEST_CASE_ST(ut_setup, ut_teardown, 14968 test_zuc_hash_generate_test_case_3), 14969 TEST_CASE_ST(ut_setup, ut_teardown, 14970 test_zuc_hash_generate_test_case_4), 14971 TEST_CASE_ST(ut_setup, ut_teardown, 14972 test_zuc_hash_generate_test_case_5), 14973 TEST_CASE_ST(ut_setup, ut_teardown, 14974 test_zuc_hash_generate_test_case_6), 14975 TEST_CASE_ST(ut_setup, ut_teardown, 14976 test_zuc_hash_generate_test_case_7), 14977 TEST_CASE_ST(ut_setup, ut_teardown, 14978 test_zuc_hash_generate_test_case_8), 14979 TEST_CASE_ST(ut_setup, ut_teardown, 14980 test_zuc_hash_generate_test_case_9), 14981 TEST_CASE_ST(ut_setup, ut_teardown, 14982 test_zuc_hash_generate_test_case_10), 14983 TEST_CASE_ST(ut_setup, ut_teardown, 14984 test_zuc_hash_generate_test_case_11), 14985 14986 14987 /** ZUC alg-chain (EEA3/EIA3) */ 14988 TEST_CASE_ST(ut_setup, ut_teardown, 14989 test_zuc_cipher_auth_test_case_1), 14990 TEST_CASE_ST(ut_setup, ut_teardown, 14991 test_zuc_cipher_auth_test_case_2), 14992 14993 /** ZUC generate auth, then encrypt (EEA3) */ 14994 TEST_CASE_ST(ut_setup, ut_teardown, 14995 test_zuc_auth_cipher_test_case_1), 14996 TEST_CASE_ST(ut_setup, ut_teardown, 14997 test_zuc_auth_cipher_test_case_1_oop), 14998 TEST_CASE_ST(ut_setup, ut_teardown, 14999 test_zuc_auth_cipher_test_case_1_sgl), 15000 TEST_CASE_ST(ut_setup, ut_teardown, 15001 test_zuc_auth_cipher_test_case_1_oop_sgl), 15002 15003 /** ZUC decrypt (EEA3), then verify auth */ 15004 TEST_CASE_ST(ut_setup, ut_teardown, 15005 test_zuc_auth_cipher_verify_test_case_1), 15006 TEST_CASE_ST(ut_setup, ut_teardown, 15007 test_zuc_auth_cipher_verify_test_case_1_oop), 15008 TEST_CASE_ST(ut_setup, ut_teardown, 15009 test_zuc_auth_cipher_verify_test_case_1_sgl), 15010 TEST_CASE_ST(ut_setup, ut_teardown, 15011 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 15012 15013 /** ZUC-256 encrypt only **/ 15014 TEST_CASE_ST(ut_setup, ut_teardown, 15015 test_zuc256_encryption_test_case_1), 15016 TEST_CASE_ST(ut_setup, ut_teardown, 15017 test_zuc256_encryption_test_case_2), 15018 15019 /** ZUC-256 authentication only **/ 15020 TEST_CASE_ST(ut_setup, ut_teardown, 15021 test_zuc256_authentication_test_case_1), 15022 TEST_CASE_ST(ut_setup, ut_teardown, 15023 test_zuc256_authentication_test_case_2), 15024 15025 TEST_CASES_END() 15026 } 15027 }; 15028 15029 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15030 .suite_name = "HMAC_MD5 Authentication Test Suite", 15031 .setup = hmac_md5_auth_testsuite_setup, 15032 .unit_test_cases = { 15033 TEST_CASE_ST(ut_setup, ut_teardown, 15034 test_MD5_HMAC_generate_case_1), 15035 TEST_CASE_ST(ut_setup, ut_teardown, 15036 test_MD5_HMAC_verify_case_1), 15037 TEST_CASE_ST(ut_setup, ut_teardown, 15038 test_MD5_HMAC_generate_case_2), 15039 TEST_CASE_ST(ut_setup, ut_teardown, 15040 test_MD5_HMAC_verify_case_2), 15041 TEST_CASES_END() 15042 } 15043 }; 15044 15045 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15046 .suite_name = "Kasumi Test Suite", 15047 .setup = kasumi_testsuite_setup, 15048 .unit_test_cases = { 15049 /** KASUMI hash only (UIA1) */ 15050 TEST_CASE_ST(ut_setup, ut_teardown, 15051 test_kasumi_hash_generate_test_case_1), 15052 TEST_CASE_ST(ut_setup, ut_teardown, 15053 test_kasumi_hash_generate_test_case_2), 15054 TEST_CASE_ST(ut_setup, ut_teardown, 15055 test_kasumi_hash_generate_test_case_3), 15056 TEST_CASE_ST(ut_setup, ut_teardown, 15057 test_kasumi_hash_generate_test_case_4), 15058 TEST_CASE_ST(ut_setup, ut_teardown, 15059 test_kasumi_hash_generate_test_case_5), 15060 TEST_CASE_ST(ut_setup, ut_teardown, 15061 test_kasumi_hash_generate_test_case_6), 15062 15063 TEST_CASE_ST(ut_setup, ut_teardown, 15064 test_kasumi_hash_verify_test_case_1), 15065 TEST_CASE_ST(ut_setup, ut_teardown, 15066 test_kasumi_hash_verify_test_case_2), 15067 TEST_CASE_ST(ut_setup, ut_teardown, 15068 test_kasumi_hash_verify_test_case_3), 15069 TEST_CASE_ST(ut_setup, ut_teardown, 15070 test_kasumi_hash_verify_test_case_4), 15071 TEST_CASE_ST(ut_setup, ut_teardown, 15072 test_kasumi_hash_verify_test_case_5), 15073 15074 /** KASUMI encrypt only (UEA1) */ 15075 TEST_CASE_ST(ut_setup, ut_teardown, 15076 test_kasumi_encryption_test_case_1), 15077 TEST_CASE_ST(ut_setup, ut_teardown, 15078 test_kasumi_encryption_test_case_1_sgl), 15079 TEST_CASE_ST(ut_setup, ut_teardown, 15080 test_kasumi_encryption_test_case_1_oop), 15081 TEST_CASE_ST(ut_setup, ut_teardown, 15082 test_kasumi_encryption_test_case_1_oop_sgl), 15083 TEST_CASE_ST(ut_setup, ut_teardown, 15084 test_kasumi_encryption_test_case_2), 15085 TEST_CASE_ST(ut_setup, ut_teardown, 15086 test_kasumi_encryption_test_case_3), 15087 TEST_CASE_ST(ut_setup, ut_teardown, 15088 test_kasumi_encryption_test_case_4), 15089 TEST_CASE_ST(ut_setup, ut_teardown, 15090 test_kasumi_encryption_test_case_5), 15091 15092 /** KASUMI decrypt only (UEA1) */ 15093 TEST_CASE_ST(ut_setup, ut_teardown, 15094 test_kasumi_decryption_test_case_1), 15095 TEST_CASE_ST(ut_setup, ut_teardown, 15096 test_kasumi_decryption_test_case_2), 15097 TEST_CASE_ST(ut_setup, ut_teardown, 15098 test_kasumi_decryption_test_case_3), 15099 TEST_CASE_ST(ut_setup, ut_teardown, 15100 test_kasumi_decryption_test_case_4), 15101 TEST_CASE_ST(ut_setup, ut_teardown, 15102 test_kasumi_decryption_test_case_5), 15103 TEST_CASE_ST(ut_setup, ut_teardown, 15104 test_kasumi_decryption_test_case_1_oop), 15105 TEST_CASE_ST(ut_setup, ut_teardown, 15106 test_kasumi_cipher_auth_test_case_1), 15107 15108 /** KASUMI generate auth, then encrypt (F8) */ 15109 TEST_CASE_ST(ut_setup, ut_teardown, 15110 test_kasumi_auth_cipher_test_case_1), 15111 TEST_CASE_ST(ut_setup, ut_teardown, 15112 test_kasumi_auth_cipher_test_case_2), 15113 TEST_CASE_ST(ut_setup, ut_teardown, 15114 test_kasumi_auth_cipher_test_case_2_oop), 15115 TEST_CASE_ST(ut_setup, ut_teardown, 15116 test_kasumi_auth_cipher_test_case_2_sgl), 15117 TEST_CASE_ST(ut_setup, ut_teardown, 15118 test_kasumi_auth_cipher_test_case_2_oop_sgl), 15119 15120 /** KASUMI decrypt (F8), then verify auth */ 15121 TEST_CASE_ST(ut_setup, ut_teardown, 15122 test_kasumi_auth_cipher_verify_test_case_1), 15123 TEST_CASE_ST(ut_setup, ut_teardown, 15124 test_kasumi_auth_cipher_verify_test_case_2), 15125 TEST_CASE_ST(ut_setup, ut_teardown, 15126 test_kasumi_auth_cipher_verify_test_case_2_oop), 15127 TEST_CASE_ST(ut_setup, ut_teardown, 15128 test_kasumi_auth_cipher_verify_test_case_2_sgl), 15129 TEST_CASE_ST(ut_setup, ut_teardown, 15130 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 15131 15132 TEST_CASES_END() 15133 } 15134 }; 15135 15136 static struct unit_test_suite cryptodev_esn_testsuite = { 15137 .suite_name = "ESN Test Suite", 15138 .setup = esn_testsuite_setup, 15139 .unit_test_cases = { 15140 TEST_CASE_ST(ut_setup, ut_teardown, 15141 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 15142 TEST_CASE_ST(ut_setup, ut_teardown, 15143 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 15144 TEST_CASES_END() 15145 } 15146 }; 15147 15148 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 15149 .suite_name = "Negative AES GCM Test Suite", 15150 .setup = negative_aes_gcm_testsuite_setup, 15151 .unit_test_cases = { 15152 TEST_CASE_ST(ut_setup, ut_teardown, 15153 test_AES_GCM_auth_encryption_fail_iv_corrupt), 15154 TEST_CASE_ST(ut_setup, ut_teardown, 15155 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 15156 TEST_CASE_ST(ut_setup, ut_teardown, 15157 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 15158 TEST_CASE_ST(ut_setup, ut_teardown, 15159 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 15160 TEST_CASE_ST(ut_setup, ut_teardown, 15161 test_AES_GCM_auth_encryption_fail_aad_corrupt), 15162 TEST_CASE_ST(ut_setup, ut_teardown, 15163 test_AES_GCM_auth_encryption_fail_tag_corrupt), 15164 TEST_CASE_ST(ut_setup, ut_teardown, 15165 test_AES_GCM_auth_decryption_fail_iv_corrupt), 15166 TEST_CASE_ST(ut_setup, ut_teardown, 15167 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 15168 TEST_CASE_ST(ut_setup, ut_teardown, 15169 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 15170 TEST_CASE_ST(ut_setup, ut_teardown, 15171 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 15172 TEST_CASE_ST(ut_setup, ut_teardown, 15173 test_AES_GCM_auth_decryption_fail_aad_corrupt), 15174 TEST_CASE_ST(ut_setup, ut_teardown, 15175 test_AES_GCM_auth_decryption_fail_tag_corrupt), 15176 15177 TEST_CASES_END() 15178 } 15179 }; 15180 15181 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 15182 .suite_name = "Negative AES GMAC Test Suite", 15183 .setup = negative_aes_gmac_testsuite_setup, 15184 .unit_test_cases = { 15185 TEST_CASE_ST(ut_setup, ut_teardown, 15186 authentication_verify_AES128_GMAC_fail_data_corrupt), 15187 TEST_CASE_ST(ut_setup, ut_teardown, 15188 authentication_verify_AES128_GMAC_fail_tag_corrupt), 15189 15190 TEST_CASES_END() 15191 } 15192 }; 15193 15194 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 15195 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 15196 .setup = mixed_cipher_hash_testsuite_setup, 15197 .unit_test_cases = { 15198 /** AUTH AES CMAC + CIPHER AES CTR */ 15199 TEST_CASE_ST(ut_setup, ut_teardown, 15200 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 15201 TEST_CASE_ST(ut_setup, ut_teardown, 15202 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15203 TEST_CASE_ST(ut_setup, ut_teardown, 15204 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15205 TEST_CASE_ST(ut_setup, ut_teardown, 15206 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15207 TEST_CASE_ST(ut_setup, ut_teardown, 15208 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 15209 TEST_CASE_ST(ut_setup, ut_teardown, 15210 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15211 TEST_CASE_ST(ut_setup, ut_teardown, 15212 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15213 TEST_CASE_ST(ut_setup, ut_teardown, 15214 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15215 15216 /** AUTH ZUC + CIPHER SNOW3G */ 15217 TEST_CASE_ST(ut_setup, ut_teardown, 15218 test_auth_zuc_cipher_snow_test_case_1), 15219 TEST_CASE_ST(ut_setup, ut_teardown, 15220 test_verify_auth_zuc_cipher_snow_test_case_1), 15221 /** AUTH AES CMAC + CIPHER SNOW3G */ 15222 TEST_CASE_ST(ut_setup, ut_teardown, 15223 test_auth_aes_cmac_cipher_snow_test_case_1), 15224 TEST_CASE_ST(ut_setup, ut_teardown, 15225 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 15226 /** AUTH ZUC + CIPHER AES CTR */ 15227 TEST_CASE_ST(ut_setup, ut_teardown, 15228 test_auth_zuc_cipher_aes_ctr_test_case_1), 15229 TEST_CASE_ST(ut_setup, ut_teardown, 15230 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 15231 /** AUTH SNOW3G + CIPHER AES CTR */ 15232 TEST_CASE_ST(ut_setup, ut_teardown, 15233 test_auth_snow_cipher_aes_ctr_test_case_1), 15234 TEST_CASE_ST(ut_setup, ut_teardown, 15235 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 15236 /** AUTH SNOW3G + CIPHER ZUC */ 15237 TEST_CASE_ST(ut_setup, ut_teardown, 15238 test_auth_snow_cipher_zuc_test_case_1), 15239 TEST_CASE_ST(ut_setup, ut_teardown, 15240 test_verify_auth_snow_cipher_zuc_test_case_1), 15241 /** AUTH AES CMAC + CIPHER ZUC */ 15242 TEST_CASE_ST(ut_setup, ut_teardown, 15243 test_auth_aes_cmac_cipher_zuc_test_case_1), 15244 TEST_CASE_ST(ut_setup, ut_teardown, 15245 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 15246 15247 /** AUTH NULL + CIPHER SNOW3G */ 15248 TEST_CASE_ST(ut_setup, ut_teardown, 15249 test_auth_null_cipher_snow_test_case_1), 15250 TEST_CASE_ST(ut_setup, ut_teardown, 15251 test_verify_auth_null_cipher_snow_test_case_1), 15252 /** AUTH NULL + CIPHER ZUC */ 15253 TEST_CASE_ST(ut_setup, ut_teardown, 15254 test_auth_null_cipher_zuc_test_case_1), 15255 TEST_CASE_ST(ut_setup, ut_teardown, 15256 test_verify_auth_null_cipher_zuc_test_case_1), 15257 /** AUTH SNOW3G + CIPHER NULL */ 15258 TEST_CASE_ST(ut_setup, ut_teardown, 15259 test_auth_snow_cipher_null_test_case_1), 15260 TEST_CASE_ST(ut_setup, ut_teardown, 15261 test_verify_auth_snow_cipher_null_test_case_1), 15262 /** AUTH ZUC + CIPHER NULL */ 15263 TEST_CASE_ST(ut_setup, ut_teardown, 15264 test_auth_zuc_cipher_null_test_case_1), 15265 TEST_CASE_ST(ut_setup, ut_teardown, 15266 test_verify_auth_zuc_cipher_null_test_case_1), 15267 /** AUTH NULL + CIPHER AES CTR */ 15268 TEST_CASE_ST(ut_setup, ut_teardown, 15269 test_auth_null_cipher_aes_ctr_test_case_1), 15270 TEST_CASE_ST(ut_setup, ut_teardown, 15271 test_verify_auth_null_cipher_aes_ctr_test_case_1), 15272 /** AUTH AES CMAC + CIPHER NULL */ 15273 TEST_CASE_ST(ut_setup, ut_teardown, 15274 test_auth_aes_cmac_cipher_null_test_case_1), 15275 TEST_CASE_ST(ut_setup, ut_teardown, 15276 test_verify_auth_aes_cmac_cipher_null_test_case_1), 15277 TEST_CASES_END() 15278 } 15279 }; 15280 15281 static int 15282 run_cryptodev_testsuite(const char *pmd_name) 15283 { 15284 uint8_t ret, j, i = 0, blk_start_idx = 0; 15285 const enum blockcipher_test_type blk_suites[] = { 15286 BLKCIPHER_AES_CHAIN_TYPE, 15287 BLKCIPHER_AES_CIPHERONLY_TYPE, 15288 BLKCIPHER_AES_DOCSIS_TYPE, 15289 BLKCIPHER_3DES_CHAIN_TYPE, 15290 BLKCIPHER_3DES_CIPHERONLY_TYPE, 15291 BLKCIPHER_DES_CIPHERONLY_TYPE, 15292 BLKCIPHER_DES_DOCSIS_TYPE, 15293 BLKCIPHER_AUTHONLY_TYPE}; 15294 struct unit_test_suite *static_suites[] = { 15295 &cryptodev_multi_session_testsuite, 15296 &cryptodev_null_testsuite, 15297 &cryptodev_aes_ccm_auth_testsuite, 15298 &cryptodev_aes_gcm_auth_testsuite, 15299 &cryptodev_aes_gmac_auth_testsuite, 15300 &cryptodev_snow3g_testsuite, 15301 &cryptodev_chacha20_poly1305_testsuite, 15302 &cryptodev_zuc_testsuite, 15303 &cryptodev_hmac_md5_auth_testsuite, 15304 &cryptodev_kasumi_testsuite, 15305 &cryptodev_esn_testsuite, 15306 &cryptodev_negative_aes_gcm_testsuite, 15307 &cryptodev_negative_aes_gmac_testsuite, 15308 &cryptodev_mixed_cipher_hash_testsuite, 15309 &cryptodev_negative_hmac_sha1_testsuite, 15310 &cryptodev_gen_testsuite, 15311 #ifdef RTE_LIB_SECURITY 15312 &ipsec_proto_testsuite, 15313 &pdcp_proto_testsuite, 15314 &docsis_proto_testsuite, 15315 #endif 15316 &end_testsuite 15317 }; 15318 static struct unit_test_suite ts = { 15319 .suite_name = "Cryptodev Unit Test Suite", 15320 .setup = testsuite_setup, 15321 .teardown = testsuite_teardown, 15322 .unit_test_cases = {TEST_CASES_END()} 15323 }; 15324 15325 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 15326 15327 if (gbl_driver_id == -1) { 15328 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 15329 return TEST_SKIPPED; 15330 } 15331 15332 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15333 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 15334 15335 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 15336 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15337 ret = unit_test_suite_runner(&ts); 15338 15339 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 15340 free(ts.unit_test_suites); 15341 return ret; 15342 } 15343 15344 static int 15345 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 15346 { 15347 struct rte_cryptodev_info dev_info; 15348 uint8_t i, nb_devs; 15349 int driver_id; 15350 15351 driver_id = rte_cryptodev_driver_id_get(pmd_name); 15352 if (driver_id == -1) { 15353 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 15354 return TEST_SKIPPED; 15355 } 15356 15357 nb_devs = rte_cryptodev_count(); 15358 if (nb_devs < 1) { 15359 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 15360 return TEST_SKIPPED; 15361 } 15362 15363 for (i = 0; i < nb_devs; i++) { 15364 rte_cryptodev_info_get(i, &dev_info); 15365 if (dev_info.driver_id == driver_id) { 15366 if (!(dev_info.feature_flags & flag)) { 15367 RTE_LOG(INFO, USER1, "%s not supported\n", 15368 flag_name); 15369 return TEST_SKIPPED; 15370 } 15371 return 0; /* found */ 15372 } 15373 } 15374 15375 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 15376 return TEST_SKIPPED; 15377 } 15378 15379 static int 15380 test_cryptodev_qat(void) 15381 { 15382 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 15383 } 15384 15385 static int 15386 test_cryptodev_virtio(void) 15387 { 15388 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 15389 } 15390 15391 static int 15392 test_cryptodev_aesni_mb(void) 15393 { 15394 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15395 } 15396 15397 static int 15398 test_cryptodev_cpu_aesni_mb(void) 15399 { 15400 int32_t rc; 15401 enum rte_security_session_action_type at = gbl_action_type; 15402 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15403 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15404 gbl_action_type = at; 15405 return rc; 15406 } 15407 15408 static int 15409 test_cryptodev_chacha_poly_mb(void) 15410 { 15411 int32_t rc; 15412 enum rte_security_session_action_type at = gbl_action_type; 15413 rc = run_cryptodev_testsuite( 15414 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 15415 gbl_action_type = at; 15416 return rc; 15417 } 15418 15419 static int 15420 test_cryptodev_openssl(void) 15421 { 15422 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 15423 } 15424 15425 static int 15426 test_cryptodev_aesni_gcm(void) 15427 { 15428 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15429 } 15430 15431 static int 15432 test_cryptodev_cpu_aesni_gcm(void) 15433 { 15434 int32_t rc; 15435 enum rte_security_session_action_type at = gbl_action_type; 15436 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15437 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15438 gbl_action_type = at; 15439 return rc; 15440 } 15441 15442 static int 15443 test_cryptodev_mlx5(void) 15444 { 15445 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 15446 } 15447 15448 static int 15449 test_cryptodev_null(void) 15450 { 15451 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 15452 } 15453 15454 static int 15455 test_cryptodev_sw_snow3g(void) 15456 { 15457 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 15458 } 15459 15460 static int 15461 test_cryptodev_sw_kasumi(void) 15462 { 15463 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 15464 } 15465 15466 static int 15467 test_cryptodev_sw_zuc(void) 15468 { 15469 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 15470 } 15471 15472 static int 15473 test_cryptodev_armv8(void) 15474 { 15475 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 15476 } 15477 15478 static int 15479 test_cryptodev_mrvl(void) 15480 { 15481 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 15482 } 15483 15484 #ifdef RTE_CRYPTO_SCHEDULER 15485 15486 static int 15487 test_cryptodev_scheduler(void) 15488 { 15489 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 15490 const enum blockcipher_test_type blk_suites[] = { 15491 BLKCIPHER_AES_CHAIN_TYPE, 15492 BLKCIPHER_AES_CIPHERONLY_TYPE, 15493 BLKCIPHER_AUTHONLY_TYPE 15494 }; 15495 static struct unit_test_suite scheduler_multicore = { 15496 .suite_name = "Scheduler Multicore Unit Test Suite", 15497 .setup = scheduler_multicore_testsuite_setup, 15498 .teardown = scheduler_mode_testsuite_teardown, 15499 .unit_test_cases = {TEST_CASES_END()} 15500 }; 15501 static struct unit_test_suite scheduler_round_robin = { 15502 .suite_name = "Scheduler Round Robin Unit Test Suite", 15503 .setup = scheduler_roundrobin_testsuite_setup, 15504 .teardown = scheduler_mode_testsuite_teardown, 15505 .unit_test_cases = {TEST_CASES_END()} 15506 }; 15507 static struct unit_test_suite scheduler_failover = { 15508 .suite_name = "Scheduler Failover Unit Test Suite", 15509 .setup = scheduler_failover_testsuite_setup, 15510 .teardown = scheduler_mode_testsuite_teardown, 15511 .unit_test_cases = {TEST_CASES_END()} 15512 }; 15513 static struct unit_test_suite scheduler_pkt_size_distr = { 15514 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 15515 .setup = scheduler_pkt_size_distr_testsuite_setup, 15516 .teardown = scheduler_mode_testsuite_teardown, 15517 .unit_test_cases = {TEST_CASES_END()} 15518 }; 15519 struct unit_test_suite *sched_mode_suites[] = { 15520 &scheduler_multicore, 15521 &scheduler_round_robin, 15522 &scheduler_failover, 15523 &scheduler_pkt_size_distr 15524 }; 15525 static struct unit_test_suite scheduler_config = { 15526 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 15527 .unit_test_cases = { 15528 TEST_CASE(test_scheduler_attach_worker_op), 15529 TEST_CASE(test_scheduler_mode_multicore_op), 15530 TEST_CASE(test_scheduler_mode_roundrobin_op), 15531 TEST_CASE(test_scheduler_mode_failover_op), 15532 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 15533 TEST_CASE(test_scheduler_detach_worker_op), 15534 15535 TEST_CASES_END() /**< NULL terminate array */ 15536 } 15537 }; 15538 struct unit_test_suite *static_suites[] = { 15539 &scheduler_config, 15540 &end_testsuite 15541 }; 15542 static struct unit_test_suite ts = { 15543 .suite_name = "Scheduler Unit Test Suite", 15544 .setup = scheduler_testsuite_setup, 15545 .teardown = testsuite_teardown, 15546 .unit_test_cases = {TEST_CASES_END()} 15547 }; 15548 15549 gbl_driver_id = rte_cryptodev_driver_id_get( 15550 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15551 15552 if (gbl_driver_id == -1) { 15553 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 15554 return TEST_SKIPPED; 15555 } 15556 15557 if (rte_cryptodev_driver_id_get( 15558 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 15559 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 15560 return TEST_SKIPPED; 15561 } 15562 15563 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15564 uint8_t blk_i = 0; 15565 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 15566 (struct unit_test_suite *) * 15567 (RTE_DIM(blk_suites) + 1)); 15568 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 15569 blk_suites, RTE_DIM(blk_suites)); 15570 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 15571 } 15572 15573 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15574 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 15575 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 15576 RTE_DIM(sched_mode_suites)); 15577 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15578 ret = unit_test_suite_runner(&ts); 15579 15580 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15581 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 15582 (*sched_mode_suites[sched_i]), 15583 RTE_DIM(blk_suites)); 15584 free(sched_mode_suites[sched_i]->unit_test_suites); 15585 } 15586 free(ts.unit_test_suites); 15587 return ret; 15588 } 15589 15590 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 15591 15592 #endif 15593 15594 static int 15595 test_cryptodev_dpaa2_sec(void) 15596 { 15597 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 15598 } 15599 15600 static int 15601 test_cryptodev_dpaa_sec(void) 15602 { 15603 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 15604 } 15605 15606 static int 15607 test_cryptodev_ccp(void) 15608 { 15609 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 15610 } 15611 15612 static int 15613 test_cryptodev_octeontx(void) 15614 { 15615 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 15616 } 15617 15618 static int 15619 test_cryptodev_octeontx2(void) 15620 { 15621 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 15622 } 15623 15624 static int 15625 test_cryptodev_caam_jr(void) 15626 { 15627 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 15628 } 15629 15630 static int 15631 test_cryptodev_nitrox(void) 15632 { 15633 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 15634 } 15635 15636 static int 15637 test_cryptodev_bcmfs(void) 15638 { 15639 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 15640 } 15641 15642 static int 15643 test_cryptodev_qat_raw_api(void) 15644 { 15645 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 15646 int ret; 15647 15648 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15649 "RAW API"); 15650 if (ret) 15651 return ret; 15652 15653 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15654 ret = run_cryptodev_testsuite(pmd_name); 15655 global_api_test_type = CRYPTODEV_API_TEST; 15656 15657 return ret; 15658 } 15659 15660 static int 15661 test_cryptodev_cn9k(void) 15662 { 15663 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 15664 } 15665 15666 static int 15667 test_cryptodev_cn10k(void) 15668 { 15669 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 15670 } 15671 15672 static int 15673 test_cryptodev_dpaa2_sec_raw_api(void) 15674 { 15675 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15676 int ret; 15677 15678 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15679 "RAW API"); 15680 if (ret) 15681 return ret; 15682 15683 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15684 ret = run_cryptodev_testsuite(pmd_name); 15685 global_api_test_type = CRYPTODEV_API_TEST; 15686 15687 return ret; 15688 } 15689 15690 static int 15691 test_cryptodev_dpaa_sec_raw_api(void) 15692 { 15693 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15694 int ret; 15695 15696 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15697 "RAW API"); 15698 if (ret) 15699 return ret; 15700 15701 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15702 ret = run_cryptodev_testsuite(pmd_name); 15703 global_api_test_type = CRYPTODEV_API_TEST; 15704 15705 return ret; 15706 } 15707 15708 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 15709 test_cryptodev_dpaa2_sec_raw_api); 15710 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 15711 test_cryptodev_dpaa_sec_raw_api); 15712 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 15713 test_cryptodev_qat_raw_api); 15714 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 15715 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 15716 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 15717 test_cryptodev_cpu_aesni_mb); 15718 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 15719 test_cryptodev_chacha_poly_mb); 15720 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 15721 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 15722 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 15723 test_cryptodev_cpu_aesni_gcm); 15724 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 15725 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 15726 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 15727 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 15728 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 15729 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 15730 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 15731 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 15732 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 15733 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 15734 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 15735 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 15736 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 15737 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 15738 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 15739 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 15740 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 15741 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 15742