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 struct rte_cryptodev_stats stats; 1421 1422 /* free crypto session structure */ 1423 #ifdef RTE_LIB_SECURITY 1424 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1425 if (ut_params->sec_session) { 1426 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1427 (ts_params->valid_devs[0]), 1428 ut_params->sec_session); 1429 ut_params->sec_session = NULL; 1430 } 1431 } else 1432 #endif 1433 { 1434 if (ut_params->sess) { 1435 rte_cryptodev_sym_session_clear( 1436 ts_params->valid_devs[0], 1437 ut_params->sess); 1438 rte_cryptodev_sym_session_free(ut_params->sess); 1439 ut_params->sess = NULL; 1440 } 1441 } 1442 1443 /* free crypto operation structure */ 1444 if (ut_params->op) 1445 rte_crypto_op_free(ut_params->op); 1446 1447 /* 1448 * free mbuf - both obuf and ibuf are usually the same, 1449 * so check if they point at the same address is necessary, 1450 * to avoid freeing the mbuf twice. 1451 */ 1452 if (ut_params->obuf) { 1453 rte_pktmbuf_free(ut_params->obuf); 1454 if (ut_params->ibuf == ut_params->obuf) 1455 ut_params->ibuf = 0; 1456 ut_params->obuf = 0; 1457 } 1458 if (ut_params->ibuf) { 1459 rte_pktmbuf_free(ut_params->ibuf); 1460 ut_params->ibuf = 0; 1461 } 1462 1463 if (ts_params->mbuf_pool != NULL) 1464 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1465 rte_mempool_avail_count(ts_params->mbuf_pool)); 1466 1467 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 1468 1469 /* Stop the device */ 1470 rte_cryptodev_stop(ts_params->valid_devs[0]); 1471 } 1472 1473 static int 1474 test_device_configure_invalid_dev_id(void) 1475 { 1476 struct crypto_testsuite_params *ts_params = &testsuite_params; 1477 uint16_t dev_id, num_devs = 0; 1478 1479 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1480 "Need at least %d devices for test", 1); 1481 1482 /* valid dev_id values */ 1483 dev_id = ts_params->valid_devs[0]; 1484 1485 /* Stop the device in case it's started so it can be configured */ 1486 rte_cryptodev_stop(dev_id); 1487 1488 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1489 "Failed test for rte_cryptodev_configure: " 1490 "invalid dev_num %u", dev_id); 1491 1492 /* invalid dev_id values */ 1493 dev_id = num_devs; 1494 1495 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1496 "Failed test for rte_cryptodev_configure: " 1497 "invalid dev_num %u", dev_id); 1498 1499 dev_id = 0xff; 1500 1501 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1502 "Failed test for rte_cryptodev_configure:" 1503 "invalid dev_num %u", dev_id); 1504 1505 return TEST_SUCCESS; 1506 } 1507 1508 static int 1509 test_device_configure_invalid_queue_pair_ids(void) 1510 { 1511 struct crypto_testsuite_params *ts_params = &testsuite_params; 1512 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1513 1514 /* Stop the device in case it's started so it can be configured */ 1515 rte_cryptodev_stop(ts_params->valid_devs[0]); 1516 1517 /* valid - max value queue pairs */ 1518 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1519 1520 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1521 &ts_params->conf), 1522 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1523 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1524 1525 /* valid - one queue pairs */ 1526 ts_params->conf.nb_queue_pairs = 1; 1527 1528 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1529 &ts_params->conf), 1530 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1531 ts_params->valid_devs[0], 1532 ts_params->conf.nb_queue_pairs); 1533 1534 1535 /* invalid - zero queue pairs */ 1536 ts_params->conf.nb_queue_pairs = 0; 1537 1538 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1539 &ts_params->conf), 1540 "Failed test for rte_cryptodev_configure, dev_id %u," 1541 " invalid qps: %u", 1542 ts_params->valid_devs[0], 1543 ts_params->conf.nb_queue_pairs); 1544 1545 1546 /* invalid - max value supported by field queue pairs */ 1547 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1548 1549 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1550 &ts_params->conf), 1551 "Failed test for rte_cryptodev_configure, dev_id %u," 1552 " invalid qps: %u", 1553 ts_params->valid_devs[0], 1554 ts_params->conf.nb_queue_pairs); 1555 1556 1557 /* invalid - max value + 1 queue pairs */ 1558 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1559 1560 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1561 &ts_params->conf), 1562 "Failed test for rte_cryptodev_configure, dev_id %u," 1563 " invalid qps: %u", 1564 ts_params->valid_devs[0], 1565 ts_params->conf.nb_queue_pairs); 1566 1567 /* revert to original testsuite value */ 1568 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1569 1570 return TEST_SUCCESS; 1571 } 1572 1573 static int 1574 test_queue_pair_descriptor_setup(void) 1575 { 1576 struct crypto_testsuite_params *ts_params = &testsuite_params; 1577 struct rte_cryptodev_qp_conf qp_conf = { 1578 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1579 }; 1580 uint16_t qp_id; 1581 1582 /* Stop the device in case it's started so it can be configured */ 1583 rte_cryptodev_stop(ts_params->valid_devs[0]); 1584 1585 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1586 &ts_params->conf), 1587 "Failed to configure cryptodev %u", 1588 ts_params->valid_devs[0]); 1589 1590 /* 1591 * Test various ring sizes on this device. memzones can't be 1592 * freed so are re-used if ring is released and re-created. 1593 */ 1594 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1595 qp_conf.mp_session = ts_params->session_mpool; 1596 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1597 1598 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1599 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1600 ts_params->valid_devs[0], qp_id, &qp_conf, 1601 rte_cryptodev_socket_id( 1602 ts_params->valid_devs[0])), 1603 "Failed test for " 1604 "rte_cryptodev_queue_pair_setup: num_inflights " 1605 "%u on qp %u on cryptodev %u", 1606 qp_conf.nb_descriptors, qp_id, 1607 ts_params->valid_devs[0]); 1608 } 1609 1610 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1611 1612 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1613 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1614 ts_params->valid_devs[0], qp_id, &qp_conf, 1615 rte_cryptodev_socket_id( 1616 ts_params->valid_devs[0])), 1617 "Failed test for" 1618 " rte_cryptodev_queue_pair_setup: num_inflights" 1619 " %u on qp %u on cryptodev %u", 1620 qp_conf.nb_descriptors, qp_id, 1621 ts_params->valid_devs[0]); 1622 } 1623 1624 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1625 1626 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1627 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1628 ts_params->valid_devs[0], qp_id, &qp_conf, 1629 rte_cryptodev_socket_id( 1630 ts_params->valid_devs[0])), 1631 "Failed test for " 1632 "rte_cryptodev_queue_pair_setup: num_inflights" 1633 " %u on qp %u on cryptodev %u", 1634 qp_conf.nb_descriptors, qp_id, 1635 ts_params->valid_devs[0]); 1636 } 1637 1638 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1639 1640 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1641 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1642 ts_params->valid_devs[0], qp_id, &qp_conf, 1643 rte_cryptodev_socket_id( 1644 ts_params->valid_devs[0])), 1645 "Failed test for" 1646 " rte_cryptodev_queue_pair_setup:" 1647 "num_inflights %u on qp %u on cryptodev %u", 1648 qp_conf.nb_descriptors, qp_id, 1649 ts_params->valid_devs[0]); 1650 } 1651 1652 /* test invalid queue pair id */ 1653 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1654 1655 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1656 1657 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1658 ts_params->valid_devs[0], 1659 qp_id, &qp_conf, 1660 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1661 "Failed test for rte_cryptodev_queue_pair_setup:" 1662 "invalid qp %u on cryptodev %u", 1663 qp_id, ts_params->valid_devs[0]); 1664 1665 qp_id = 0xffff; /*invalid*/ 1666 1667 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1668 ts_params->valid_devs[0], 1669 qp_id, &qp_conf, 1670 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1671 "Failed test for rte_cryptodev_queue_pair_setup:" 1672 "invalid qp %u on cryptodev %u", 1673 qp_id, ts_params->valid_devs[0]); 1674 1675 return TEST_SUCCESS; 1676 } 1677 1678 /* ***** Plaintext data for tests ***** */ 1679 1680 const char catch_22_quote_1[] = 1681 "There was only one catch and that was Catch-22, which " 1682 "specified that a concern for one's safety in the face of " 1683 "dangers that were real and immediate was the process of a " 1684 "rational mind. Orr was crazy and could be grounded. All he " 1685 "had to do was ask; and as soon as he did, he would no longer " 1686 "be crazy and would have to fly more missions. Orr would be " 1687 "crazy to fly more missions and sane if he didn't, but if he " 1688 "was sane he had to fly them. If he flew them he was crazy " 1689 "and didn't have to; but if he didn't want to he was sane and " 1690 "had to. Yossarian was moved very deeply by the absolute " 1691 "simplicity of this clause of Catch-22 and let out a " 1692 "respectful whistle. \"That's some catch, that Catch-22\", he " 1693 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1694 1695 const char catch_22_quote[] = 1696 "What a lousy earth! He wondered how many people were " 1697 "destitute that same night even in his own prosperous country, " 1698 "how many homes were shanties, how many husbands were drunk " 1699 "and wives socked, and how many children were bullied, abused, " 1700 "or abandoned. How many families hungered for food they could " 1701 "not afford to buy? How many hearts were broken? How many " 1702 "suicides would take place that same night, how many people " 1703 "would go insane? How many cockroaches and landlords would " 1704 "triumph? How many winners were losers, successes failures, " 1705 "and rich men poor men? How many wise guys were stupid? How " 1706 "many happy endings were unhappy endings? How many honest men " 1707 "were liars, brave men cowards, loyal men traitors, how many " 1708 "sainted men were corrupt, how many people in positions of " 1709 "trust had sold their souls to bodyguards, how many had never " 1710 "had souls? How many straight-and-narrow paths were crooked " 1711 "paths? How many best families were worst families and how " 1712 "many good people were bad people? When you added them all up " 1713 "and then subtracted, you might be left with only the children, " 1714 "and perhaps with Albert Einstein and an old violinist or " 1715 "sculptor somewhere."; 1716 1717 #define QUOTE_480_BYTES (480) 1718 #define QUOTE_512_BYTES (512) 1719 #define QUOTE_768_BYTES (768) 1720 #define QUOTE_1024_BYTES (1024) 1721 1722 1723 1724 /* ***** SHA1 Hash Tests ***** */ 1725 1726 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1727 1728 static uint8_t hmac_sha1_key[] = { 1729 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1730 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1731 0xDE, 0xF4, 0xDE, 0xAD }; 1732 1733 /* ***** SHA224 Hash Tests ***** */ 1734 1735 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1736 1737 1738 /* ***** AES-CBC Cipher Tests ***** */ 1739 1740 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1741 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1742 1743 static uint8_t aes_cbc_key[] = { 1744 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1745 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1746 1747 static uint8_t aes_cbc_iv[] = { 1748 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1749 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1750 1751 1752 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1753 1754 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1755 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1756 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1757 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1758 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1759 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1760 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1761 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1762 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1763 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1764 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1765 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1766 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1767 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1768 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1769 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1770 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1771 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1772 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1773 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1774 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1775 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1776 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1777 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1778 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1779 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1780 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1781 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1782 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1783 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1784 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1785 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1786 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1787 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1788 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1789 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1790 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1791 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1792 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1793 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1794 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1795 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1796 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1797 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1798 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1799 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1800 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1801 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1802 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1803 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1804 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1805 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1806 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1807 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1808 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1809 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1810 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1811 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1812 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1813 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1814 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1815 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1816 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1817 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1818 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1819 }; 1820 1821 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1822 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1823 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1824 0x18, 0x8c, 0x1d, 0x32 1825 }; 1826 1827 1828 /* Multisession Vector context Test */ 1829 /*Begin Session 0 */ 1830 static uint8_t ms_aes_cbc_key0[] = { 1831 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1832 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1833 }; 1834 1835 static uint8_t ms_aes_cbc_iv0[] = { 1836 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1837 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1838 }; 1839 1840 static const uint8_t ms_aes_cbc_cipher0[] = { 1841 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1842 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1843 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1844 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1845 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1846 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1847 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1848 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1849 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1850 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1851 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1852 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1853 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1854 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1855 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1856 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1857 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1858 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1859 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1860 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1861 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1862 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1863 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1864 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1865 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1866 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1867 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1868 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1869 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1870 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1871 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1872 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1873 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1874 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1875 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1876 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1877 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1878 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1879 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1880 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1881 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1882 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1883 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1884 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1885 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1886 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1887 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1888 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1889 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1890 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1891 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1892 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1893 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1894 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1895 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1896 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1897 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1898 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1899 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1900 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1901 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1902 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1903 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1904 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1905 }; 1906 1907 1908 static uint8_t ms_hmac_key0[] = { 1909 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1910 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1911 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1912 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1913 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1914 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1915 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1916 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1917 }; 1918 1919 static const uint8_t ms_hmac_digest0[] = { 1920 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1921 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1922 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1923 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1924 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1925 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1926 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1927 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1928 }; 1929 1930 /* End Session 0 */ 1931 /* Begin session 1 */ 1932 1933 static uint8_t ms_aes_cbc_key1[] = { 1934 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1935 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1936 }; 1937 1938 static uint8_t ms_aes_cbc_iv1[] = { 1939 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1940 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1941 }; 1942 1943 static const uint8_t ms_aes_cbc_cipher1[] = { 1944 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1945 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1946 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1947 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1948 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1949 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1950 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1951 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1952 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1953 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1954 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1955 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1956 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1957 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1958 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1959 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1960 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1961 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1962 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1963 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1964 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1965 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1966 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1967 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1968 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1969 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1970 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1971 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1972 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1973 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1974 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1975 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1976 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1977 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1978 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1979 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1980 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1981 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1982 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1983 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1984 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1985 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1986 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1987 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1988 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1989 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1990 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1991 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1992 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1993 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1994 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1995 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1996 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1997 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1998 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1999 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2000 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2001 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2002 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2003 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2004 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2005 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2006 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2007 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2008 2009 }; 2010 2011 static uint8_t ms_hmac_key1[] = { 2012 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2013 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2014 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2015 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2016 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2017 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2018 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2019 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2020 }; 2021 2022 static const uint8_t ms_hmac_digest1[] = { 2023 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2024 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2025 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2026 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2027 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2028 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2029 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2030 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2031 }; 2032 /* End Session 1 */ 2033 /* Begin Session 2 */ 2034 static uint8_t ms_aes_cbc_key2[] = { 2035 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2036 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2037 }; 2038 2039 static uint8_t ms_aes_cbc_iv2[] = { 2040 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2041 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2042 }; 2043 2044 static const uint8_t ms_aes_cbc_cipher2[] = { 2045 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2046 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2047 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2048 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2049 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2050 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2051 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2052 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2053 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2054 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2055 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2056 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2057 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2058 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2059 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2060 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2061 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2062 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2063 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2064 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2065 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2066 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2067 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2068 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2069 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2070 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2071 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2072 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2073 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2074 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2075 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2076 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2077 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2078 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2079 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2080 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2081 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2082 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2083 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2084 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2085 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2086 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2087 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2088 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2089 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2090 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2091 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2092 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2093 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2094 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2095 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2096 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2097 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2098 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2099 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2100 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2101 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2102 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2103 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2104 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2105 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2106 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2107 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2108 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2109 }; 2110 2111 static uint8_t ms_hmac_key2[] = { 2112 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2113 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2114 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2115 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2116 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2117 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2118 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2119 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2120 }; 2121 2122 static const uint8_t ms_hmac_digest2[] = { 2123 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2124 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2125 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2126 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2127 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2128 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2129 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2130 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2131 }; 2132 2133 /* End Session 2 */ 2134 2135 2136 static int 2137 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2138 { 2139 struct crypto_testsuite_params *ts_params = &testsuite_params; 2140 struct crypto_unittest_params *ut_params = &unittest_params; 2141 int status; 2142 2143 /* Verify the capabilities */ 2144 struct rte_cryptodev_sym_capability_idx cap_idx; 2145 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2146 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2147 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2148 &cap_idx) == NULL) 2149 return TEST_SKIPPED; 2150 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2151 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2152 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2153 &cap_idx) == NULL) 2154 return TEST_SKIPPED; 2155 2156 /* Generate test mbuf data and space for digest */ 2157 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2158 catch_22_quote, QUOTE_512_BYTES, 0); 2159 2160 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2161 DIGEST_BYTE_LENGTH_SHA1); 2162 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2163 2164 /* Setup Cipher Parameters */ 2165 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2166 ut_params->cipher_xform.next = &ut_params->auth_xform; 2167 2168 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2169 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2170 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2171 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2172 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2173 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2174 2175 /* Setup HMAC Parameters */ 2176 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2177 2178 ut_params->auth_xform.next = NULL; 2179 2180 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2181 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2182 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2183 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2184 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2185 2186 ut_params->sess = rte_cryptodev_sym_session_create( 2187 ts_params->session_mpool); 2188 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2189 2190 /* Create crypto session*/ 2191 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2192 ut_params->sess, &ut_params->cipher_xform, 2193 ts_params->session_priv_mpool); 2194 2195 if (status == -ENOTSUP) 2196 return TEST_SKIPPED; 2197 2198 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 2199 2200 /* Generate crypto op data structure */ 2201 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2202 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2203 TEST_ASSERT_NOT_NULL(ut_params->op, 2204 "Failed to allocate symmetric crypto operation struct"); 2205 2206 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2207 2208 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2209 2210 /* set crypto operation source mbuf */ 2211 sym_op->m_src = ut_params->ibuf; 2212 2213 /* Set crypto operation authentication parameters */ 2214 sym_op->auth.digest.data = ut_params->digest; 2215 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2216 ut_params->ibuf, QUOTE_512_BYTES); 2217 2218 sym_op->auth.data.offset = 0; 2219 sym_op->auth.data.length = QUOTE_512_BYTES; 2220 2221 /* Copy IV at the end of the crypto operation */ 2222 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2223 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2224 2225 /* Set crypto operation cipher parameters */ 2226 sym_op->cipher.data.offset = 0; 2227 sym_op->cipher.data.length = QUOTE_512_BYTES; 2228 2229 /* Process crypto operation */ 2230 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2231 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2232 ut_params->op); 2233 else 2234 TEST_ASSERT_NOT_NULL( 2235 process_crypto_request(ts_params->valid_devs[0], 2236 ut_params->op), 2237 "failed to process sym crypto op"); 2238 2239 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2240 "crypto op processing failed"); 2241 2242 /* Validate obuf */ 2243 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2244 uint8_t *); 2245 2246 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2247 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2248 QUOTE_512_BYTES, 2249 "ciphertext data not as expected"); 2250 2251 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2252 2253 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2254 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2255 gbl_driver_id == rte_cryptodev_driver_id_get( 2256 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2257 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2258 DIGEST_BYTE_LENGTH_SHA1, 2259 "Generated digest data not as expected"); 2260 2261 return TEST_SUCCESS; 2262 } 2263 2264 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2265 2266 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2267 2268 static uint8_t hmac_sha512_key[] = { 2269 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2270 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2271 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2272 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2273 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2274 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2275 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2276 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2277 2278 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2279 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2280 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2281 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2282 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2283 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2284 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2285 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2286 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2287 2288 2289 2290 static int 2291 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2292 struct crypto_unittest_params *ut_params, 2293 uint8_t *cipher_key, 2294 uint8_t *hmac_key); 2295 2296 static int 2297 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2298 struct crypto_unittest_params *ut_params, 2299 struct crypto_testsuite_params *ts_params, 2300 const uint8_t *cipher, 2301 const uint8_t *digest, 2302 const uint8_t *iv); 2303 2304 2305 static int 2306 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2307 struct crypto_unittest_params *ut_params, 2308 uint8_t *cipher_key, 2309 uint8_t *hmac_key) 2310 { 2311 2312 /* Setup Cipher Parameters */ 2313 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2314 ut_params->cipher_xform.next = NULL; 2315 2316 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2317 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2318 ut_params->cipher_xform.cipher.key.data = cipher_key; 2319 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2320 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2321 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2322 2323 /* Setup HMAC Parameters */ 2324 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2325 ut_params->auth_xform.next = &ut_params->cipher_xform; 2326 2327 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2328 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2329 ut_params->auth_xform.auth.key.data = hmac_key; 2330 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2331 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2332 2333 return TEST_SUCCESS; 2334 } 2335 2336 2337 static int 2338 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2339 struct crypto_unittest_params *ut_params, 2340 struct crypto_testsuite_params *ts_params, 2341 const uint8_t *cipher, 2342 const uint8_t *digest, 2343 const uint8_t *iv) 2344 { 2345 /* Generate test mbuf data and digest */ 2346 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2347 (const char *) 2348 cipher, 2349 QUOTE_512_BYTES, 0); 2350 2351 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2352 DIGEST_BYTE_LENGTH_SHA512); 2353 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2354 2355 rte_memcpy(ut_params->digest, 2356 digest, 2357 DIGEST_BYTE_LENGTH_SHA512); 2358 2359 /* Generate Crypto op data structure */ 2360 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2361 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2362 TEST_ASSERT_NOT_NULL(ut_params->op, 2363 "Failed to allocate symmetric crypto operation struct"); 2364 2365 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2366 2367 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2368 2369 /* set crypto operation source mbuf */ 2370 sym_op->m_src = ut_params->ibuf; 2371 2372 sym_op->auth.digest.data = ut_params->digest; 2373 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2374 ut_params->ibuf, QUOTE_512_BYTES); 2375 2376 sym_op->auth.data.offset = 0; 2377 sym_op->auth.data.length = QUOTE_512_BYTES; 2378 2379 /* Copy IV at the end of the crypto operation */ 2380 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2381 iv, CIPHER_IV_LENGTH_AES_CBC); 2382 2383 sym_op->cipher.data.offset = 0; 2384 sym_op->cipher.data.length = QUOTE_512_BYTES; 2385 2386 /* Process crypto operation */ 2387 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2388 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2389 ut_params->op); 2390 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2391 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2392 ut_params->op, 1, 1, 0, 0); 2393 else 2394 TEST_ASSERT_NOT_NULL( 2395 process_crypto_request(ts_params->valid_devs[0], 2396 ut_params->op), 2397 "failed to process sym crypto op"); 2398 2399 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2400 "crypto op processing failed"); 2401 2402 ut_params->obuf = ut_params->op->sym->m_src; 2403 2404 /* Validate obuf */ 2405 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2406 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2407 catch_22_quote, 2408 QUOTE_512_BYTES, 2409 "Plaintext data not as expected"); 2410 2411 /* Validate obuf */ 2412 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2413 "Digest verification failed"); 2414 2415 return TEST_SUCCESS; 2416 } 2417 2418 /* ***** SNOW 3G Tests ***** */ 2419 static int 2420 create_wireless_algo_hash_session(uint8_t dev_id, 2421 const uint8_t *key, const uint8_t key_len, 2422 const uint8_t iv_len, const uint8_t auth_len, 2423 enum rte_crypto_auth_operation op, 2424 enum rte_crypto_auth_algorithm algo) 2425 { 2426 uint8_t hash_key[key_len]; 2427 int status; 2428 2429 struct crypto_testsuite_params *ts_params = &testsuite_params; 2430 struct crypto_unittest_params *ut_params = &unittest_params; 2431 2432 memcpy(hash_key, key, key_len); 2433 2434 debug_hexdump(stdout, "key:", key, key_len); 2435 2436 /* Setup Authentication Parameters */ 2437 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2438 ut_params->auth_xform.next = NULL; 2439 2440 ut_params->auth_xform.auth.op = op; 2441 ut_params->auth_xform.auth.algo = algo; 2442 ut_params->auth_xform.auth.key.length = key_len; 2443 ut_params->auth_xform.auth.key.data = hash_key; 2444 ut_params->auth_xform.auth.digest_length = auth_len; 2445 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2446 ut_params->auth_xform.auth.iv.length = iv_len; 2447 ut_params->sess = rte_cryptodev_sym_session_create( 2448 ts_params->session_mpool); 2449 2450 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2451 &ut_params->auth_xform, 2452 ts_params->session_priv_mpool); 2453 if (status == -ENOTSUP) 2454 return TEST_SKIPPED; 2455 2456 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2457 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2458 return 0; 2459 } 2460 2461 static int 2462 create_wireless_algo_cipher_session(uint8_t dev_id, 2463 enum rte_crypto_cipher_operation op, 2464 enum rte_crypto_cipher_algorithm algo, 2465 const uint8_t *key, const uint8_t key_len, 2466 uint8_t iv_len) 2467 { 2468 uint8_t cipher_key[key_len]; 2469 int status; 2470 struct crypto_testsuite_params *ts_params = &testsuite_params; 2471 struct crypto_unittest_params *ut_params = &unittest_params; 2472 2473 memcpy(cipher_key, key, key_len); 2474 2475 /* Setup Cipher Parameters */ 2476 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2477 ut_params->cipher_xform.next = NULL; 2478 2479 ut_params->cipher_xform.cipher.algo = algo; 2480 ut_params->cipher_xform.cipher.op = op; 2481 ut_params->cipher_xform.cipher.key.data = cipher_key; 2482 ut_params->cipher_xform.cipher.key.length = key_len; 2483 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2484 ut_params->cipher_xform.cipher.iv.length = iv_len; 2485 2486 debug_hexdump(stdout, "key:", key, key_len); 2487 2488 /* Create Crypto session */ 2489 ut_params->sess = rte_cryptodev_sym_session_create( 2490 ts_params->session_mpool); 2491 2492 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2493 &ut_params->cipher_xform, 2494 ts_params->session_priv_mpool); 2495 if (status == -ENOTSUP) 2496 return TEST_SKIPPED; 2497 2498 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2499 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2500 return 0; 2501 } 2502 2503 static int 2504 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2505 unsigned int cipher_len, 2506 unsigned int cipher_offset) 2507 { 2508 struct crypto_testsuite_params *ts_params = &testsuite_params; 2509 struct crypto_unittest_params *ut_params = &unittest_params; 2510 2511 /* Generate Crypto op data structure */ 2512 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2513 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2514 TEST_ASSERT_NOT_NULL(ut_params->op, 2515 "Failed to allocate pktmbuf offload"); 2516 2517 /* Set crypto operation data parameters */ 2518 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2519 2520 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2521 2522 /* set crypto operation source mbuf */ 2523 sym_op->m_src = ut_params->ibuf; 2524 2525 /* iv */ 2526 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2527 iv, iv_len); 2528 sym_op->cipher.data.length = cipher_len; 2529 sym_op->cipher.data.offset = cipher_offset; 2530 return 0; 2531 } 2532 2533 static int 2534 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2535 unsigned int cipher_len, 2536 unsigned int cipher_offset) 2537 { 2538 struct crypto_testsuite_params *ts_params = &testsuite_params; 2539 struct crypto_unittest_params *ut_params = &unittest_params; 2540 2541 /* Generate Crypto op data structure */ 2542 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2543 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2544 TEST_ASSERT_NOT_NULL(ut_params->op, 2545 "Failed to allocate pktmbuf offload"); 2546 2547 /* Set crypto operation data parameters */ 2548 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2549 2550 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2551 2552 /* set crypto operation source mbuf */ 2553 sym_op->m_src = ut_params->ibuf; 2554 sym_op->m_dst = ut_params->obuf; 2555 2556 /* iv */ 2557 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2558 iv, iv_len); 2559 sym_op->cipher.data.length = cipher_len; 2560 sym_op->cipher.data.offset = cipher_offset; 2561 return 0; 2562 } 2563 2564 static int 2565 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2566 enum rte_crypto_cipher_operation cipher_op, 2567 enum rte_crypto_auth_operation auth_op, 2568 enum rte_crypto_auth_algorithm auth_algo, 2569 enum rte_crypto_cipher_algorithm cipher_algo, 2570 const uint8_t *key, uint8_t key_len, 2571 uint8_t auth_iv_len, uint8_t auth_len, 2572 uint8_t cipher_iv_len) 2573 2574 { 2575 uint8_t cipher_auth_key[key_len]; 2576 int status; 2577 2578 struct crypto_testsuite_params *ts_params = &testsuite_params; 2579 struct crypto_unittest_params *ut_params = &unittest_params; 2580 2581 memcpy(cipher_auth_key, key, key_len); 2582 2583 /* Setup Authentication Parameters */ 2584 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2585 ut_params->auth_xform.next = NULL; 2586 2587 ut_params->auth_xform.auth.op = auth_op; 2588 ut_params->auth_xform.auth.algo = auth_algo; 2589 ut_params->auth_xform.auth.key.length = key_len; 2590 /* Hash key = cipher key */ 2591 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2592 ut_params->auth_xform.auth.digest_length = auth_len; 2593 /* Auth IV will be after cipher IV */ 2594 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2595 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2596 2597 /* Setup Cipher Parameters */ 2598 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2599 ut_params->cipher_xform.next = &ut_params->auth_xform; 2600 2601 ut_params->cipher_xform.cipher.algo = cipher_algo; 2602 ut_params->cipher_xform.cipher.op = cipher_op; 2603 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2604 ut_params->cipher_xform.cipher.key.length = key_len; 2605 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2606 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2607 2608 debug_hexdump(stdout, "key:", key, key_len); 2609 2610 /* Create Crypto session*/ 2611 ut_params->sess = rte_cryptodev_sym_session_create( 2612 ts_params->session_mpool); 2613 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2614 2615 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2616 &ut_params->cipher_xform, 2617 ts_params->session_priv_mpool); 2618 if (status == -ENOTSUP) 2619 return TEST_SKIPPED; 2620 2621 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2622 return 0; 2623 } 2624 2625 static int 2626 create_wireless_cipher_auth_session(uint8_t dev_id, 2627 enum rte_crypto_cipher_operation cipher_op, 2628 enum rte_crypto_auth_operation auth_op, 2629 enum rte_crypto_auth_algorithm auth_algo, 2630 enum rte_crypto_cipher_algorithm cipher_algo, 2631 const struct wireless_test_data *tdata) 2632 { 2633 const uint8_t key_len = tdata->key.len; 2634 uint8_t cipher_auth_key[key_len]; 2635 int status; 2636 2637 struct crypto_testsuite_params *ts_params = &testsuite_params; 2638 struct crypto_unittest_params *ut_params = &unittest_params; 2639 const uint8_t *key = tdata->key.data; 2640 const uint8_t auth_len = tdata->digest.len; 2641 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2642 uint8_t auth_iv_len = tdata->auth_iv.len; 2643 2644 memcpy(cipher_auth_key, key, key_len); 2645 2646 /* Setup Authentication Parameters */ 2647 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2648 ut_params->auth_xform.next = NULL; 2649 2650 ut_params->auth_xform.auth.op = auth_op; 2651 ut_params->auth_xform.auth.algo = auth_algo; 2652 ut_params->auth_xform.auth.key.length = key_len; 2653 /* Hash key = cipher key */ 2654 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2655 ut_params->auth_xform.auth.digest_length = auth_len; 2656 /* Auth IV will be after cipher IV */ 2657 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2658 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2659 2660 /* Setup Cipher Parameters */ 2661 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2662 ut_params->cipher_xform.next = &ut_params->auth_xform; 2663 2664 ut_params->cipher_xform.cipher.algo = cipher_algo; 2665 ut_params->cipher_xform.cipher.op = cipher_op; 2666 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2667 ut_params->cipher_xform.cipher.key.length = key_len; 2668 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2669 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2670 2671 2672 debug_hexdump(stdout, "key:", key, key_len); 2673 2674 /* Create Crypto session*/ 2675 ut_params->sess = rte_cryptodev_sym_session_create( 2676 ts_params->session_mpool); 2677 2678 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2679 &ut_params->cipher_xform, 2680 ts_params->session_priv_mpool); 2681 if (status == -ENOTSUP) 2682 return TEST_SKIPPED; 2683 2684 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2685 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2686 return 0; 2687 } 2688 2689 static int 2690 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2691 const struct wireless_test_data *tdata) 2692 { 2693 return create_wireless_cipher_auth_session(dev_id, 2694 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2695 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2696 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2697 } 2698 2699 static int 2700 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2701 enum rte_crypto_cipher_operation cipher_op, 2702 enum rte_crypto_auth_operation auth_op, 2703 enum rte_crypto_auth_algorithm auth_algo, 2704 enum rte_crypto_cipher_algorithm cipher_algo, 2705 const uint8_t *key, const uint8_t key_len, 2706 uint8_t auth_iv_len, uint8_t auth_len, 2707 uint8_t cipher_iv_len) 2708 { 2709 uint8_t auth_cipher_key[key_len]; 2710 int status; 2711 struct crypto_testsuite_params *ts_params = &testsuite_params; 2712 struct crypto_unittest_params *ut_params = &unittest_params; 2713 2714 memcpy(auth_cipher_key, key, key_len); 2715 2716 /* Setup Authentication Parameters */ 2717 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2718 ut_params->auth_xform.auth.op = auth_op; 2719 ut_params->auth_xform.next = &ut_params->cipher_xform; 2720 ut_params->auth_xform.auth.algo = auth_algo; 2721 ut_params->auth_xform.auth.key.length = key_len; 2722 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2723 ut_params->auth_xform.auth.digest_length = auth_len; 2724 /* Auth IV will be after cipher IV */ 2725 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2726 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2727 2728 /* Setup Cipher Parameters */ 2729 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2730 ut_params->cipher_xform.next = NULL; 2731 ut_params->cipher_xform.cipher.algo = cipher_algo; 2732 ut_params->cipher_xform.cipher.op = cipher_op; 2733 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2734 ut_params->cipher_xform.cipher.key.length = key_len; 2735 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2736 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2737 2738 debug_hexdump(stdout, "key:", key, key_len); 2739 2740 /* Create Crypto session*/ 2741 ut_params->sess = rte_cryptodev_sym_session_create( 2742 ts_params->session_mpool); 2743 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2744 2745 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2746 ut_params->auth_xform.next = NULL; 2747 ut_params->cipher_xform.next = &ut_params->auth_xform; 2748 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2749 &ut_params->cipher_xform, 2750 ts_params->session_priv_mpool); 2751 2752 } else 2753 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2754 &ut_params->auth_xform, 2755 ts_params->session_priv_mpool); 2756 2757 if (status == -ENOTSUP) 2758 return TEST_SKIPPED; 2759 2760 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2761 2762 return 0; 2763 } 2764 2765 static int 2766 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2767 unsigned int auth_tag_len, 2768 const uint8_t *iv, unsigned int iv_len, 2769 unsigned int data_pad_len, 2770 enum rte_crypto_auth_operation op, 2771 unsigned int auth_len, unsigned int auth_offset) 2772 { 2773 struct crypto_testsuite_params *ts_params = &testsuite_params; 2774 2775 struct crypto_unittest_params *ut_params = &unittest_params; 2776 2777 /* Generate Crypto op data structure */ 2778 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2779 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2780 TEST_ASSERT_NOT_NULL(ut_params->op, 2781 "Failed to allocate pktmbuf offload"); 2782 2783 /* Set crypto operation data parameters */ 2784 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2785 2786 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2787 2788 /* set crypto operation source mbuf */ 2789 sym_op->m_src = ut_params->ibuf; 2790 2791 /* iv */ 2792 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2793 iv, iv_len); 2794 /* digest */ 2795 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2796 ut_params->ibuf, auth_tag_len); 2797 2798 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2799 "no room to append auth tag"); 2800 ut_params->digest = sym_op->auth.digest.data; 2801 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2802 ut_params->ibuf, data_pad_len); 2803 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2804 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2805 else 2806 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2807 2808 debug_hexdump(stdout, "digest:", 2809 sym_op->auth.digest.data, 2810 auth_tag_len); 2811 2812 sym_op->auth.data.length = auth_len; 2813 sym_op->auth.data.offset = auth_offset; 2814 2815 return 0; 2816 } 2817 2818 static int 2819 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2820 enum rte_crypto_auth_operation op) 2821 { 2822 struct crypto_testsuite_params *ts_params = &testsuite_params; 2823 struct crypto_unittest_params *ut_params = &unittest_params; 2824 2825 const uint8_t *auth_tag = tdata->digest.data; 2826 const unsigned int auth_tag_len = tdata->digest.len; 2827 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2828 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2829 2830 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2831 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2832 const uint8_t *auth_iv = tdata->auth_iv.data; 2833 const uint8_t auth_iv_len = tdata->auth_iv.len; 2834 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2835 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2836 2837 /* Generate Crypto op data structure */ 2838 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2839 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2840 TEST_ASSERT_NOT_NULL(ut_params->op, 2841 "Failed to allocate pktmbuf offload"); 2842 /* Set crypto operation data parameters */ 2843 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2844 2845 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2846 2847 /* set crypto operation source mbuf */ 2848 sym_op->m_src = ut_params->ibuf; 2849 2850 /* digest */ 2851 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2852 ut_params->ibuf, auth_tag_len); 2853 2854 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2855 "no room to append auth tag"); 2856 ut_params->digest = sym_op->auth.digest.data; 2857 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2858 ut_params->ibuf, data_pad_len); 2859 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2860 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2861 else 2862 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2863 2864 debug_hexdump(stdout, "digest:", 2865 sym_op->auth.digest.data, 2866 auth_tag_len); 2867 2868 /* Copy cipher and auth IVs at the end of the crypto operation */ 2869 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2870 IV_OFFSET); 2871 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2872 iv_ptr += cipher_iv_len; 2873 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2874 2875 sym_op->cipher.data.length = cipher_len; 2876 sym_op->cipher.data.offset = 0; 2877 sym_op->auth.data.length = auth_len; 2878 sym_op->auth.data.offset = 0; 2879 2880 return 0; 2881 } 2882 2883 static int 2884 create_zuc_cipher_hash_generate_operation( 2885 const struct wireless_test_data *tdata) 2886 { 2887 return create_wireless_cipher_hash_operation(tdata, 2888 RTE_CRYPTO_AUTH_OP_GENERATE); 2889 } 2890 2891 static int 2892 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2893 const unsigned auth_tag_len, 2894 const uint8_t *auth_iv, uint8_t auth_iv_len, 2895 unsigned data_pad_len, 2896 enum rte_crypto_auth_operation op, 2897 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2898 const unsigned cipher_len, const unsigned cipher_offset, 2899 const unsigned auth_len, const unsigned auth_offset) 2900 { 2901 struct crypto_testsuite_params *ts_params = &testsuite_params; 2902 struct crypto_unittest_params *ut_params = &unittest_params; 2903 2904 enum rte_crypto_cipher_algorithm cipher_algo = 2905 ut_params->cipher_xform.cipher.algo; 2906 enum rte_crypto_auth_algorithm auth_algo = 2907 ut_params->auth_xform.auth.algo; 2908 2909 /* Generate Crypto op data structure */ 2910 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2911 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2912 TEST_ASSERT_NOT_NULL(ut_params->op, 2913 "Failed to allocate pktmbuf offload"); 2914 /* Set crypto operation data parameters */ 2915 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2916 2917 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2918 2919 /* set crypto operation source mbuf */ 2920 sym_op->m_src = ut_params->ibuf; 2921 2922 /* digest */ 2923 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2924 ut_params->ibuf, auth_tag_len); 2925 2926 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2927 "no room to append auth tag"); 2928 ut_params->digest = sym_op->auth.digest.data; 2929 2930 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2931 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2932 ut_params->ibuf, data_pad_len); 2933 } else { 2934 struct rte_mbuf *m = ut_params->ibuf; 2935 unsigned int offset = data_pad_len; 2936 2937 while (offset > m->data_len && m->next != NULL) { 2938 offset -= m->data_len; 2939 m = m->next; 2940 } 2941 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2942 m, offset); 2943 } 2944 2945 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2946 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2947 else 2948 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2949 2950 debug_hexdump(stdout, "digest:", 2951 sym_op->auth.digest.data, 2952 auth_tag_len); 2953 2954 /* Copy cipher and auth IVs at the end of the crypto operation */ 2955 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2956 IV_OFFSET); 2957 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2958 iv_ptr += cipher_iv_len; 2959 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2960 2961 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2962 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2963 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2964 sym_op->cipher.data.length = cipher_len; 2965 sym_op->cipher.data.offset = cipher_offset; 2966 } else { 2967 sym_op->cipher.data.length = cipher_len >> 3; 2968 sym_op->cipher.data.offset = cipher_offset >> 3; 2969 } 2970 2971 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2972 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2973 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2974 sym_op->auth.data.length = auth_len; 2975 sym_op->auth.data.offset = auth_offset; 2976 } else { 2977 sym_op->auth.data.length = auth_len >> 3; 2978 sym_op->auth.data.offset = auth_offset >> 3; 2979 } 2980 2981 return 0; 2982 } 2983 2984 static int 2985 create_wireless_algo_auth_cipher_operation( 2986 const uint8_t *auth_tag, unsigned int auth_tag_len, 2987 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2988 const uint8_t *auth_iv, uint8_t auth_iv_len, 2989 unsigned int data_pad_len, 2990 unsigned int cipher_len, unsigned int cipher_offset, 2991 unsigned int auth_len, unsigned int auth_offset, 2992 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2993 { 2994 struct crypto_testsuite_params *ts_params = &testsuite_params; 2995 struct crypto_unittest_params *ut_params = &unittest_params; 2996 2997 enum rte_crypto_cipher_algorithm cipher_algo = 2998 ut_params->cipher_xform.cipher.algo; 2999 enum rte_crypto_auth_algorithm auth_algo = 3000 ut_params->auth_xform.auth.algo; 3001 3002 /* Generate Crypto op data structure */ 3003 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3004 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3005 TEST_ASSERT_NOT_NULL(ut_params->op, 3006 "Failed to allocate pktmbuf offload"); 3007 3008 /* Set crypto operation data parameters */ 3009 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3010 3011 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3012 3013 /* set crypto operation mbufs */ 3014 sym_op->m_src = ut_params->ibuf; 3015 if (op_mode == OUT_OF_PLACE) 3016 sym_op->m_dst = ut_params->obuf; 3017 3018 /* digest */ 3019 if (!do_sgl) { 3020 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3021 (op_mode == IN_PLACE ? 3022 ut_params->ibuf : ut_params->obuf), 3023 uint8_t *, data_pad_len); 3024 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3025 (op_mode == IN_PLACE ? 3026 ut_params->ibuf : ut_params->obuf), 3027 data_pad_len); 3028 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3029 } else { 3030 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3031 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3032 sym_op->m_src : sym_op->m_dst); 3033 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3034 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3035 sgl_buf = sgl_buf->next; 3036 } 3037 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3038 uint8_t *, remaining_off); 3039 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3040 remaining_off); 3041 memset(sym_op->auth.digest.data, 0, remaining_off); 3042 while (sgl_buf->next != NULL) { 3043 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3044 0, rte_pktmbuf_data_len(sgl_buf)); 3045 sgl_buf = sgl_buf->next; 3046 } 3047 } 3048 3049 /* Copy digest for the verification */ 3050 if (verify) 3051 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3052 3053 /* Copy cipher and auth IVs at the end of the crypto operation */ 3054 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3055 ut_params->op, uint8_t *, IV_OFFSET); 3056 3057 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3058 iv_ptr += cipher_iv_len; 3059 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3060 3061 /* Only copy over the offset data needed from src to dst in OOP, 3062 * if the auth and cipher offsets are not aligned 3063 */ 3064 if (op_mode == OUT_OF_PLACE) { 3065 if (cipher_offset > auth_offset) 3066 rte_memcpy( 3067 rte_pktmbuf_mtod_offset( 3068 sym_op->m_dst, 3069 uint8_t *, auth_offset >> 3), 3070 rte_pktmbuf_mtod_offset( 3071 sym_op->m_src, 3072 uint8_t *, auth_offset >> 3), 3073 ((cipher_offset >> 3) - (auth_offset >> 3))); 3074 } 3075 3076 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3077 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3078 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3079 sym_op->cipher.data.length = cipher_len; 3080 sym_op->cipher.data.offset = cipher_offset; 3081 } else { 3082 sym_op->cipher.data.length = cipher_len >> 3; 3083 sym_op->cipher.data.offset = cipher_offset >> 3; 3084 } 3085 3086 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3087 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3088 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3089 sym_op->auth.data.length = auth_len; 3090 sym_op->auth.data.offset = auth_offset; 3091 } else { 3092 sym_op->auth.data.length = auth_len >> 3; 3093 sym_op->auth.data.offset = auth_offset >> 3; 3094 } 3095 3096 return 0; 3097 } 3098 3099 static int 3100 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3101 { 3102 struct crypto_testsuite_params *ts_params = &testsuite_params; 3103 struct crypto_unittest_params *ut_params = &unittest_params; 3104 3105 int retval; 3106 unsigned plaintext_pad_len; 3107 unsigned plaintext_len; 3108 uint8_t *plaintext; 3109 struct rte_cryptodev_info dev_info; 3110 3111 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3112 uint64_t feat_flags = dev_info.feature_flags; 3113 3114 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3115 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3116 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3117 return TEST_SKIPPED; 3118 } 3119 3120 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3121 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3122 printf("Device doesn't support RAW data-path APIs.\n"); 3123 return TEST_SKIPPED; 3124 } 3125 3126 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3127 return TEST_SKIPPED; 3128 3129 /* Verify the capabilities */ 3130 struct rte_cryptodev_sym_capability_idx cap_idx; 3131 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3132 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3133 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3134 &cap_idx) == NULL) 3135 return TEST_SKIPPED; 3136 3137 /* Create SNOW 3G session */ 3138 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3139 tdata->key.data, tdata->key.len, 3140 tdata->auth_iv.len, tdata->digest.len, 3141 RTE_CRYPTO_AUTH_OP_GENERATE, 3142 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3143 if (retval < 0) 3144 return retval; 3145 3146 /* alloc mbuf and set payload */ 3147 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3148 3149 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3150 rte_pktmbuf_tailroom(ut_params->ibuf)); 3151 3152 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3153 /* Append data which is padded to a multiple of */ 3154 /* the algorithms block size */ 3155 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3156 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3157 plaintext_pad_len); 3158 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3159 3160 /* Create SNOW 3G operation */ 3161 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3162 tdata->auth_iv.data, tdata->auth_iv.len, 3163 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3164 tdata->validAuthLenInBits.len, 3165 0); 3166 if (retval < 0) 3167 return retval; 3168 3169 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3170 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3171 ut_params->op, 0, 1, 1, 0); 3172 else 3173 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3174 ut_params->op); 3175 ut_params->obuf = ut_params->op->sym->m_src; 3176 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3177 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3178 + plaintext_pad_len; 3179 3180 /* Validate obuf */ 3181 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3182 ut_params->digest, 3183 tdata->digest.data, 3184 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3185 "SNOW 3G Generated auth tag not as expected"); 3186 3187 return 0; 3188 } 3189 3190 static int 3191 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3192 { 3193 struct crypto_testsuite_params *ts_params = &testsuite_params; 3194 struct crypto_unittest_params *ut_params = &unittest_params; 3195 3196 int retval; 3197 unsigned plaintext_pad_len; 3198 unsigned plaintext_len; 3199 uint8_t *plaintext; 3200 struct rte_cryptodev_info dev_info; 3201 3202 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3203 uint64_t feat_flags = dev_info.feature_flags; 3204 3205 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3206 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3207 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3208 return TEST_SKIPPED; 3209 } 3210 3211 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3212 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3213 printf("Device doesn't support RAW data-path APIs.\n"); 3214 return TEST_SKIPPED; 3215 } 3216 3217 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3218 return TEST_SKIPPED; 3219 3220 /* Verify the capabilities */ 3221 struct rte_cryptodev_sym_capability_idx cap_idx; 3222 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3223 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3224 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3225 &cap_idx) == NULL) 3226 return TEST_SKIPPED; 3227 3228 /* Create SNOW 3G session */ 3229 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3230 tdata->key.data, tdata->key.len, 3231 tdata->auth_iv.len, tdata->digest.len, 3232 RTE_CRYPTO_AUTH_OP_VERIFY, 3233 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3234 if (retval < 0) 3235 return retval; 3236 /* alloc mbuf and set payload */ 3237 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3238 3239 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3240 rte_pktmbuf_tailroom(ut_params->ibuf)); 3241 3242 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3243 /* Append data which is padded to a multiple of */ 3244 /* the algorithms block size */ 3245 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3246 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3247 plaintext_pad_len); 3248 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3249 3250 /* Create SNOW 3G operation */ 3251 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3252 tdata->digest.len, 3253 tdata->auth_iv.data, tdata->auth_iv.len, 3254 plaintext_pad_len, 3255 RTE_CRYPTO_AUTH_OP_VERIFY, 3256 tdata->validAuthLenInBits.len, 3257 0); 3258 if (retval < 0) 3259 return retval; 3260 3261 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3262 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3263 ut_params->op, 0, 1, 1, 0); 3264 else 3265 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3266 ut_params->op); 3267 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3268 ut_params->obuf = ut_params->op->sym->m_src; 3269 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3270 + plaintext_pad_len; 3271 3272 /* Validate obuf */ 3273 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3274 return 0; 3275 else 3276 return -1; 3277 3278 return 0; 3279 } 3280 3281 static int 3282 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3283 { 3284 struct crypto_testsuite_params *ts_params = &testsuite_params; 3285 struct crypto_unittest_params *ut_params = &unittest_params; 3286 3287 int retval; 3288 unsigned plaintext_pad_len; 3289 unsigned plaintext_len; 3290 uint8_t *plaintext; 3291 struct rte_cryptodev_info dev_info; 3292 3293 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3294 uint64_t feat_flags = dev_info.feature_flags; 3295 3296 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3297 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3298 printf("Device doesn't support RAW data-path APIs.\n"); 3299 return TEST_SKIPPED; 3300 } 3301 3302 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3303 return TEST_SKIPPED; 3304 3305 /* Verify the capabilities */ 3306 struct rte_cryptodev_sym_capability_idx cap_idx; 3307 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3308 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3309 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3310 &cap_idx) == NULL) 3311 return TEST_SKIPPED; 3312 3313 /* Create KASUMI session */ 3314 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3315 tdata->key.data, tdata->key.len, 3316 0, tdata->digest.len, 3317 RTE_CRYPTO_AUTH_OP_GENERATE, 3318 RTE_CRYPTO_AUTH_KASUMI_F9); 3319 if (retval < 0) 3320 return retval; 3321 3322 /* alloc mbuf and set payload */ 3323 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3324 3325 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3326 rte_pktmbuf_tailroom(ut_params->ibuf)); 3327 3328 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3329 /* Append data which is padded to a multiple of */ 3330 /* the algorithms block size */ 3331 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3332 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3333 plaintext_pad_len); 3334 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3335 3336 /* Create KASUMI operation */ 3337 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3338 NULL, 0, 3339 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3340 tdata->plaintext.len, 3341 0); 3342 if (retval < 0) 3343 return retval; 3344 3345 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3346 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3347 ut_params->op); 3348 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3349 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3350 ut_params->op, 0, 1, 1, 0); 3351 else 3352 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3353 ut_params->op); 3354 3355 ut_params->obuf = ut_params->op->sym->m_src; 3356 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3357 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3358 + plaintext_pad_len; 3359 3360 /* Validate obuf */ 3361 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3362 ut_params->digest, 3363 tdata->digest.data, 3364 DIGEST_BYTE_LENGTH_KASUMI_F9, 3365 "KASUMI Generated auth tag not as expected"); 3366 3367 return 0; 3368 } 3369 3370 static int 3371 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3372 { 3373 struct crypto_testsuite_params *ts_params = &testsuite_params; 3374 struct crypto_unittest_params *ut_params = &unittest_params; 3375 3376 int retval; 3377 unsigned plaintext_pad_len; 3378 unsigned plaintext_len; 3379 uint8_t *plaintext; 3380 struct rte_cryptodev_info dev_info; 3381 3382 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3383 uint64_t feat_flags = dev_info.feature_flags; 3384 3385 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3386 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3387 printf("Device doesn't support RAW data-path APIs.\n"); 3388 return TEST_SKIPPED; 3389 } 3390 3391 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3392 return TEST_SKIPPED; 3393 3394 /* Verify the capabilities */ 3395 struct rte_cryptodev_sym_capability_idx cap_idx; 3396 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3397 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3398 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3399 &cap_idx) == NULL) 3400 return TEST_SKIPPED; 3401 3402 /* Create KASUMI session */ 3403 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3404 tdata->key.data, tdata->key.len, 3405 0, tdata->digest.len, 3406 RTE_CRYPTO_AUTH_OP_VERIFY, 3407 RTE_CRYPTO_AUTH_KASUMI_F9); 3408 if (retval < 0) 3409 return retval; 3410 /* alloc mbuf and set payload */ 3411 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3412 3413 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3414 rte_pktmbuf_tailroom(ut_params->ibuf)); 3415 3416 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3417 /* Append data which is padded to a multiple */ 3418 /* of the algorithms block size */ 3419 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3420 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3421 plaintext_pad_len); 3422 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3423 3424 /* Create KASUMI operation */ 3425 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3426 tdata->digest.len, 3427 NULL, 0, 3428 plaintext_pad_len, 3429 RTE_CRYPTO_AUTH_OP_VERIFY, 3430 tdata->plaintext.len, 3431 0); 3432 if (retval < 0) 3433 return retval; 3434 3435 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3436 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3437 ut_params->op, 0, 1, 1, 0); 3438 else 3439 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3440 ut_params->op); 3441 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3442 ut_params->obuf = ut_params->op->sym->m_src; 3443 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3444 + plaintext_pad_len; 3445 3446 /* Validate obuf */ 3447 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3448 return 0; 3449 else 3450 return -1; 3451 3452 return 0; 3453 } 3454 3455 static int 3456 test_snow3g_hash_generate_test_case_1(void) 3457 { 3458 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3459 } 3460 3461 static int 3462 test_snow3g_hash_generate_test_case_2(void) 3463 { 3464 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3465 } 3466 3467 static int 3468 test_snow3g_hash_generate_test_case_3(void) 3469 { 3470 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3471 } 3472 3473 static int 3474 test_snow3g_hash_generate_test_case_4(void) 3475 { 3476 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3477 } 3478 3479 static int 3480 test_snow3g_hash_generate_test_case_5(void) 3481 { 3482 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3483 } 3484 3485 static int 3486 test_snow3g_hash_generate_test_case_6(void) 3487 { 3488 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3489 } 3490 3491 static int 3492 test_snow3g_hash_verify_test_case_1(void) 3493 { 3494 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3495 3496 } 3497 3498 static int 3499 test_snow3g_hash_verify_test_case_2(void) 3500 { 3501 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3502 } 3503 3504 static int 3505 test_snow3g_hash_verify_test_case_3(void) 3506 { 3507 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3508 } 3509 3510 static int 3511 test_snow3g_hash_verify_test_case_4(void) 3512 { 3513 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3514 } 3515 3516 static int 3517 test_snow3g_hash_verify_test_case_5(void) 3518 { 3519 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3520 } 3521 3522 static int 3523 test_snow3g_hash_verify_test_case_6(void) 3524 { 3525 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3526 } 3527 3528 static int 3529 test_kasumi_hash_generate_test_case_1(void) 3530 { 3531 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3532 } 3533 3534 static int 3535 test_kasumi_hash_generate_test_case_2(void) 3536 { 3537 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3538 } 3539 3540 static int 3541 test_kasumi_hash_generate_test_case_3(void) 3542 { 3543 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3544 } 3545 3546 static int 3547 test_kasumi_hash_generate_test_case_4(void) 3548 { 3549 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3550 } 3551 3552 static int 3553 test_kasumi_hash_generate_test_case_5(void) 3554 { 3555 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3556 } 3557 3558 static int 3559 test_kasumi_hash_generate_test_case_6(void) 3560 { 3561 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3562 } 3563 3564 static int 3565 test_kasumi_hash_verify_test_case_1(void) 3566 { 3567 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3568 } 3569 3570 static int 3571 test_kasumi_hash_verify_test_case_2(void) 3572 { 3573 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3574 } 3575 3576 static int 3577 test_kasumi_hash_verify_test_case_3(void) 3578 { 3579 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3580 } 3581 3582 static int 3583 test_kasumi_hash_verify_test_case_4(void) 3584 { 3585 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3586 } 3587 3588 static int 3589 test_kasumi_hash_verify_test_case_5(void) 3590 { 3591 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3592 } 3593 3594 static int 3595 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3596 { 3597 struct crypto_testsuite_params *ts_params = &testsuite_params; 3598 struct crypto_unittest_params *ut_params = &unittest_params; 3599 3600 int retval; 3601 uint8_t *plaintext, *ciphertext; 3602 unsigned plaintext_pad_len; 3603 unsigned plaintext_len; 3604 struct rte_cryptodev_info dev_info; 3605 3606 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3607 uint64_t feat_flags = dev_info.feature_flags; 3608 3609 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3610 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3611 printf("Device doesn't support RAW data-path APIs.\n"); 3612 return TEST_SKIPPED; 3613 } 3614 3615 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3616 return TEST_SKIPPED; 3617 3618 /* Verify the capabilities */ 3619 struct rte_cryptodev_sym_capability_idx cap_idx; 3620 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3621 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3622 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3623 &cap_idx) == NULL) 3624 return TEST_SKIPPED; 3625 3626 /* Create KASUMI session */ 3627 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3628 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3629 RTE_CRYPTO_CIPHER_KASUMI_F8, 3630 tdata->key.data, tdata->key.len, 3631 tdata->cipher_iv.len); 3632 if (retval < 0) 3633 return retval; 3634 3635 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3636 3637 /* Clear mbuf payload */ 3638 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3639 rte_pktmbuf_tailroom(ut_params->ibuf)); 3640 3641 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3642 /* Append data which is padded to a multiple */ 3643 /* of the algorithms block size */ 3644 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3645 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3646 plaintext_pad_len); 3647 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3648 3649 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3650 3651 /* Create KASUMI operation */ 3652 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3653 tdata->cipher_iv.len, 3654 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3655 tdata->validCipherOffsetInBits.len); 3656 if (retval < 0) 3657 return retval; 3658 3659 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3660 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3661 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3662 else 3663 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3664 ut_params->op); 3665 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3666 3667 ut_params->obuf = ut_params->op->sym->m_dst; 3668 if (ut_params->obuf) 3669 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3670 else 3671 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3672 3673 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3674 3675 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3676 (tdata->validCipherOffsetInBits.len >> 3); 3677 /* Validate obuf */ 3678 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3679 ciphertext, 3680 reference_ciphertext, 3681 tdata->validCipherLenInBits.len, 3682 "KASUMI Ciphertext data not as expected"); 3683 return 0; 3684 } 3685 3686 static int 3687 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3688 { 3689 struct crypto_testsuite_params *ts_params = &testsuite_params; 3690 struct crypto_unittest_params *ut_params = &unittest_params; 3691 3692 int retval; 3693 3694 unsigned int plaintext_pad_len; 3695 unsigned int plaintext_len; 3696 3697 uint8_t buffer[10000]; 3698 const uint8_t *ciphertext; 3699 3700 struct rte_cryptodev_info dev_info; 3701 3702 /* Verify the capabilities */ 3703 struct rte_cryptodev_sym_capability_idx cap_idx; 3704 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3705 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3706 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3707 &cap_idx) == NULL) 3708 return TEST_SKIPPED; 3709 3710 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3711 3712 uint64_t feat_flags = dev_info.feature_flags; 3713 3714 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3715 printf("Device doesn't support in-place scatter-gather. " 3716 "Test Skipped.\n"); 3717 return TEST_SKIPPED; 3718 } 3719 3720 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3721 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3722 printf("Device doesn't support RAW data-path APIs.\n"); 3723 return TEST_SKIPPED; 3724 } 3725 3726 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3727 return TEST_SKIPPED; 3728 3729 /* Create KASUMI session */ 3730 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3731 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3732 RTE_CRYPTO_CIPHER_KASUMI_F8, 3733 tdata->key.data, tdata->key.len, 3734 tdata->cipher_iv.len); 3735 if (retval < 0) 3736 return retval; 3737 3738 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3739 3740 3741 /* Append data which is padded to a multiple */ 3742 /* of the algorithms block size */ 3743 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3744 3745 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3746 plaintext_pad_len, 10, 0); 3747 3748 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3749 3750 /* Create KASUMI operation */ 3751 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3752 tdata->cipher_iv.len, 3753 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3754 tdata->validCipherOffsetInBits.len); 3755 if (retval < 0) 3756 return retval; 3757 3758 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3759 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3760 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3761 else 3762 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3763 ut_params->op); 3764 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3765 3766 ut_params->obuf = ut_params->op->sym->m_dst; 3767 3768 if (ut_params->obuf) 3769 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3770 plaintext_len, buffer); 3771 else 3772 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3773 tdata->validCipherOffsetInBits.len >> 3, 3774 plaintext_len, buffer); 3775 3776 /* Validate obuf */ 3777 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3778 3779 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3780 (tdata->validCipherOffsetInBits.len >> 3); 3781 /* Validate obuf */ 3782 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3783 ciphertext, 3784 reference_ciphertext, 3785 tdata->validCipherLenInBits.len, 3786 "KASUMI Ciphertext data not as expected"); 3787 return 0; 3788 } 3789 3790 static int 3791 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3792 { 3793 struct crypto_testsuite_params *ts_params = &testsuite_params; 3794 struct crypto_unittest_params *ut_params = &unittest_params; 3795 3796 int retval; 3797 uint8_t *plaintext, *ciphertext; 3798 unsigned plaintext_pad_len; 3799 unsigned plaintext_len; 3800 3801 /* Verify the capabilities */ 3802 struct rte_cryptodev_sym_capability_idx cap_idx; 3803 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3804 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3805 /* Data-path service does not support OOP */ 3806 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3807 &cap_idx) == NULL) 3808 return TEST_SKIPPED; 3809 3810 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3811 return TEST_SKIPPED; 3812 3813 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3814 return TEST_SKIPPED; 3815 3816 /* Create KASUMI session */ 3817 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3818 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3819 RTE_CRYPTO_CIPHER_KASUMI_F8, 3820 tdata->key.data, tdata->key.len, 3821 tdata->cipher_iv.len); 3822 if (retval < 0) 3823 return retval; 3824 3825 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3826 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3827 3828 /* Clear mbuf payload */ 3829 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3830 rte_pktmbuf_tailroom(ut_params->ibuf)); 3831 3832 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3833 /* Append data which is padded to a multiple */ 3834 /* of the algorithms block size */ 3835 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3836 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3837 plaintext_pad_len); 3838 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3839 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3840 3841 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3842 3843 /* Create KASUMI operation */ 3844 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3845 tdata->cipher_iv.len, 3846 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3847 tdata->validCipherOffsetInBits.len); 3848 if (retval < 0) 3849 return retval; 3850 3851 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3852 ut_params->op); 3853 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3854 3855 ut_params->obuf = ut_params->op->sym->m_dst; 3856 if (ut_params->obuf) 3857 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3858 else 3859 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3860 3861 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3862 3863 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3864 (tdata->validCipherOffsetInBits.len >> 3); 3865 /* Validate obuf */ 3866 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3867 ciphertext, 3868 reference_ciphertext, 3869 tdata->validCipherLenInBits.len, 3870 "KASUMI Ciphertext data not as expected"); 3871 return 0; 3872 } 3873 3874 static int 3875 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3876 { 3877 struct crypto_testsuite_params *ts_params = &testsuite_params; 3878 struct crypto_unittest_params *ut_params = &unittest_params; 3879 3880 int retval; 3881 unsigned int plaintext_pad_len; 3882 unsigned int plaintext_len; 3883 3884 const uint8_t *ciphertext; 3885 uint8_t buffer[2048]; 3886 3887 struct rte_cryptodev_info dev_info; 3888 3889 /* Verify the capabilities */ 3890 struct rte_cryptodev_sym_capability_idx cap_idx; 3891 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3892 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3893 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3894 &cap_idx) == NULL) 3895 return TEST_SKIPPED; 3896 3897 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3898 return TEST_SKIPPED; 3899 3900 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3901 return TEST_SKIPPED; 3902 3903 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3904 3905 uint64_t feat_flags = dev_info.feature_flags; 3906 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3907 printf("Device doesn't support out-of-place scatter-gather " 3908 "in both input and output mbufs. " 3909 "Test Skipped.\n"); 3910 return TEST_SKIPPED; 3911 } 3912 3913 /* Create KASUMI session */ 3914 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3915 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3916 RTE_CRYPTO_CIPHER_KASUMI_F8, 3917 tdata->key.data, tdata->key.len, 3918 tdata->cipher_iv.len); 3919 if (retval < 0) 3920 return retval; 3921 3922 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3923 /* Append data which is padded to a multiple */ 3924 /* of the algorithms block size */ 3925 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3926 3927 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3928 plaintext_pad_len, 10, 0); 3929 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3930 plaintext_pad_len, 3, 0); 3931 3932 /* Append data which is padded to a multiple */ 3933 /* of the algorithms block size */ 3934 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3935 3936 /* Create KASUMI operation */ 3937 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3938 tdata->cipher_iv.len, 3939 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3940 tdata->validCipherOffsetInBits.len); 3941 if (retval < 0) 3942 return retval; 3943 3944 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3945 ut_params->op); 3946 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3947 3948 ut_params->obuf = ut_params->op->sym->m_dst; 3949 if (ut_params->obuf) 3950 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3951 plaintext_pad_len, buffer); 3952 else 3953 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3954 tdata->validCipherOffsetInBits.len >> 3, 3955 plaintext_pad_len, buffer); 3956 3957 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3958 (tdata->validCipherOffsetInBits.len >> 3); 3959 /* Validate obuf */ 3960 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3961 ciphertext, 3962 reference_ciphertext, 3963 tdata->validCipherLenInBits.len, 3964 "KASUMI Ciphertext data not as expected"); 3965 return 0; 3966 } 3967 3968 3969 static int 3970 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3971 { 3972 struct crypto_testsuite_params *ts_params = &testsuite_params; 3973 struct crypto_unittest_params *ut_params = &unittest_params; 3974 3975 int retval; 3976 uint8_t *ciphertext, *plaintext; 3977 unsigned ciphertext_pad_len; 3978 unsigned ciphertext_len; 3979 3980 /* Verify the capabilities */ 3981 struct rte_cryptodev_sym_capability_idx cap_idx; 3982 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3983 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3984 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3985 &cap_idx) == NULL) 3986 return TEST_SKIPPED; 3987 3988 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3989 return TEST_SKIPPED; 3990 3991 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3992 return TEST_SKIPPED; 3993 3994 /* Create KASUMI session */ 3995 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3996 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3997 RTE_CRYPTO_CIPHER_KASUMI_F8, 3998 tdata->key.data, tdata->key.len, 3999 tdata->cipher_iv.len); 4000 if (retval < 0) 4001 return retval; 4002 4003 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4004 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4005 4006 /* Clear mbuf payload */ 4007 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4008 rte_pktmbuf_tailroom(ut_params->ibuf)); 4009 4010 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4011 /* Append data which is padded to a multiple */ 4012 /* of the algorithms block size */ 4013 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4014 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4015 ciphertext_pad_len); 4016 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4017 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4018 4019 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4020 4021 /* Create KASUMI operation */ 4022 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4023 tdata->cipher_iv.len, 4024 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4025 tdata->validCipherOffsetInBits.len); 4026 if (retval < 0) 4027 return retval; 4028 4029 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4030 ut_params->op); 4031 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4032 4033 ut_params->obuf = ut_params->op->sym->m_dst; 4034 if (ut_params->obuf) 4035 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4036 else 4037 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4038 4039 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4040 4041 const uint8_t *reference_plaintext = tdata->plaintext.data + 4042 (tdata->validCipherOffsetInBits.len >> 3); 4043 /* Validate obuf */ 4044 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4045 plaintext, 4046 reference_plaintext, 4047 tdata->validCipherLenInBits.len, 4048 "KASUMI Plaintext data not as expected"); 4049 return 0; 4050 } 4051 4052 static int 4053 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4054 { 4055 struct crypto_testsuite_params *ts_params = &testsuite_params; 4056 struct crypto_unittest_params *ut_params = &unittest_params; 4057 4058 int retval; 4059 uint8_t *ciphertext, *plaintext; 4060 unsigned ciphertext_pad_len; 4061 unsigned ciphertext_len; 4062 struct rte_cryptodev_info dev_info; 4063 4064 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4065 uint64_t feat_flags = dev_info.feature_flags; 4066 4067 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4068 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4069 printf("Device doesn't support RAW data-path APIs.\n"); 4070 return TEST_SKIPPED; 4071 } 4072 4073 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4074 return TEST_SKIPPED; 4075 4076 /* Verify the capabilities */ 4077 struct rte_cryptodev_sym_capability_idx cap_idx; 4078 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4079 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4080 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4081 &cap_idx) == NULL) 4082 return TEST_SKIPPED; 4083 4084 /* Create KASUMI session */ 4085 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4086 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4087 RTE_CRYPTO_CIPHER_KASUMI_F8, 4088 tdata->key.data, tdata->key.len, 4089 tdata->cipher_iv.len); 4090 if (retval < 0) 4091 return retval; 4092 4093 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4094 4095 /* Clear mbuf payload */ 4096 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4097 rte_pktmbuf_tailroom(ut_params->ibuf)); 4098 4099 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4100 /* Append data which is padded to a multiple */ 4101 /* of the algorithms block size */ 4102 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4103 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4104 ciphertext_pad_len); 4105 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4106 4107 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4108 4109 /* Create KASUMI operation */ 4110 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4111 tdata->cipher_iv.len, 4112 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4113 tdata->validCipherOffsetInBits.len); 4114 if (retval < 0) 4115 return retval; 4116 4117 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4118 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4119 ut_params->op, 1, 0, 1, 0); 4120 else 4121 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4122 ut_params->op); 4123 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4124 4125 ut_params->obuf = ut_params->op->sym->m_dst; 4126 if (ut_params->obuf) 4127 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4128 else 4129 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4130 4131 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4132 4133 const uint8_t *reference_plaintext = tdata->plaintext.data + 4134 (tdata->validCipherOffsetInBits.len >> 3); 4135 /* Validate obuf */ 4136 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4137 plaintext, 4138 reference_plaintext, 4139 tdata->validCipherLenInBits.len, 4140 "KASUMI Plaintext data not as expected"); 4141 return 0; 4142 } 4143 4144 static int 4145 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4146 { 4147 struct crypto_testsuite_params *ts_params = &testsuite_params; 4148 struct crypto_unittest_params *ut_params = &unittest_params; 4149 4150 int retval; 4151 uint8_t *plaintext, *ciphertext; 4152 unsigned plaintext_pad_len; 4153 unsigned plaintext_len; 4154 struct rte_cryptodev_info dev_info; 4155 4156 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4157 uint64_t feat_flags = dev_info.feature_flags; 4158 4159 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4160 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4161 printf("Device doesn't support RAW data-path APIs.\n"); 4162 return TEST_SKIPPED; 4163 } 4164 4165 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4166 return TEST_SKIPPED; 4167 4168 /* Verify the capabilities */ 4169 struct rte_cryptodev_sym_capability_idx cap_idx; 4170 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4171 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4172 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4173 &cap_idx) == NULL) 4174 return TEST_SKIPPED; 4175 4176 /* Create SNOW 3G session */ 4177 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4178 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4179 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4180 tdata->key.data, tdata->key.len, 4181 tdata->cipher_iv.len); 4182 if (retval < 0) 4183 return retval; 4184 4185 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4186 4187 /* Clear mbuf payload */ 4188 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4189 rte_pktmbuf_tailroom(ut_params->ibuf)); 4190 4191 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4192 /* Append data which is padded to a multiple of */ 4193 /* the algorithms block size */ 4194 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4195 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4196 plaintext_pad_len); 4197 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4198 4199 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4200 4201 /* Create SNOW 3G operation */ 4202 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4203 tdata->cipher_iv.len, 4204 tdata->validCipherLenInBits.len, 4205 0); 4206 if (retval < 0) 4207 return retval; 4208 4209 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4210 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4211 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4212 else 4213 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4214 ut_params->op); 4215 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4216 4217 ut_params->obuf = ut_params->op->sym->m_dst; 4218 if (ut_params->obuf) 4219 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4220 else 4221 ciphertext = plaintext; 4222 4223 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4224 4225 /* Validate obuf */ 4226 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4227 ciphertext, 4228 tdata->ciphertext.data, 4229 tdata->validDataLenInBits.len, 4230 "SNOW 3G Ciphertext data not as expected"); 4231 return 0; 4232 } 4233 4234 4235 static int 4236 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4237 { 4238 struct crypto_testsuite_params *ts_params = &testsuite_params; 4239 struct crypto_unittest_params *ut_params = &unittest_params; 4240 uint8_t *plaintext, *ciphertext; 4241 4242 int retval; 4243 unsigned plaintext_pad_len; 4244 unsigned plaintext_len; 4245 struct rte_cryptodev_info dev_info; 4246 4247 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4248 uint64_t feat_flags = dev_info.feature_flags; 4249 4250 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4251 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4252 printf("Device does not support RAW data-path APIs.\n"); 4253 return -ENOTSUP; 4254 } 4255 4256 /* Verify the capabilities */ 4257 struct rte_cryptodev_sym_capability_idx cap_idx; 4258 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4259 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4260 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4261 &cap_idx) == NULL) 4262 return TEST_SKIPPED; 4263 4264 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4265 return TEST_SKIPPED; 4266 4267 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4268 return TEST_SKIPPED; 4269 4270 /* Create SNOW 3G session */ 4271 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4272 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4273 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4274 tdata->key.data, tdata->key.len, 4275 tdata->cipher_iv.len); 4276 if (retval < 0) 4277 return retval; 4278 4279 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4280 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4281 4282 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4283 "Failed to allocate input buffer in mempool"); 4284 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4285 "Failed to allocate output buffer in mempool"); 4286 4287 /* Clear mbuf payload */ 4288 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4289 rte_pktmbuf_tailroom(ut_params->ibuf)); 4290 4291 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4292 /* Append data which is padded to a multiple of */ 4293 /* the algorithms block size */ 4294 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4295 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4296 plaintext_pad_len); 4297 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4298 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4299 4300 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4301 4302 /* Create SNOW 3G operation */ 4303 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4304 tdata->cipher_iv.len, 4305 tdata->validCipherLenInBits.len, 4306 0); 4307 if (retval < 0) 4308 return retval; 4309 4310 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4311 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4312 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4313 else 4314 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4315 ut_params->op); 4316 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4317 4318 ut_params->obuf = ut_params->op->sym->m_dst; 4319 if (ut_params->obuf) 4320 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4321 else 4322 ciphertext = plaintext; 4323 4324 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4325 4326 /* Validate obuf */ 4327 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4328 ciphertext, 4329 tdata->ciphertext.data, 4330 tdata->validDataLenInBits.len, 4331 "SNOW 3G Ciphertext data not as expected"); 4332 return 0; 4333 } 4334 4335 static int 4336 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4337 { 4338 struct crypto_testsuite_params *ts_params = &testsuite_params; 4339 struct crypto_unittest_params *ut_params = &unittest_params; 4340 4341 int retval; 4342 unsigned int plaintext_pad_len; 4343 unsigned int plaintext_len; 4344 uint8_t buffer[10000]; 4345 const uint8_t *ciphertext; 4346 4347 struct rte_cryptodev_info dev_info; 4348 4349 /* Verify the capabilities */ 4350 struct rte_cryptodev_sym_capability_idx cap_idx; 4351 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4352 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4353 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4354 &cap_idx) == NULL) 4355 return TEST_SKIPPED; 4356 4357 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4358 return TEST_SKIPPED; 4359 4360 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4361 return TEST_SKIPPED; 4362 4363 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4364 4365 uint64_t feat_flags = dev_info.feature_flags; 4366 4367 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4368 printf("Device doesn't support out-of-place scatter-gather " 4369 "in both input and output mbufs. " 4370 "Test Skipped.\n"); 4371 return TEST_SKIPPED; 4372 } 4373 4374 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4375 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4376 printf("Device does not support RAW data-path APIs.\n"); 4377 return -ENOTSUP; 4378 } 4379 4380 /* Create SNOW 3G session */ 4381 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4382 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4383 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4384 tdata->key.data, tdata->key.len, 4385 tdata->cipher_iv.len); 4386 if (retval < 0) 4387 return retval; 4388 4389 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4390 /* Append data which is padded to a multiple of */ 4391 /* the algorithms block size */ 4392 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4393 4394 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4395 plaintext_pad_len, 10, 0); 4396 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4397 plaintext_pad_len, 3, 0); 4398 4399 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4400 "Failed to allocate input buffer in mempool"); 4401 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4402 "Failed to allocate output buffer in mempool"); 4403 4404 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4405 4406 /* Create SNOW 3G operation */ 4407 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4408 tdata->cipher_iv.len, 4409 tdata->validCipherLenInBits.len, 4410 0); 4411 if (retval < 0) 4412 return retval; 4413 4414 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4415 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4416 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4417 else 4418 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4419 ut_params->op); 4420 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4421 4422 ut_params->obuf = ut_params->op->sym->m_dst; 4423 if (ut_params->obuf) 4424 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4425 plaintext_len, buffer); 4426 else 4427 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4428 plaintext_len, buffer); 4429 4430 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4431 4432 /* Validate obuf */ 4433 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4434 ciphertext, 4435 tdata->ciphertext.data, 4436 tdata->validDataLenInBits.len, 4437 "SNOW 3G Ciphertext data not as expected"); 4438 4439 return 0; 4440 } 4441 4442 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4443 static void 4444 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4445 { 4446 uint8_t curr_byte, prev_byte; 4447 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4448 uint8_t lower_byte_mask = (1 << offset) - 1; 4449 unsigned i; 4450 4451 prev_byte = buffer[0]; 4452 buffer[0] >>= offset; 4453 4454 for (i = 1; i < length_in_bytes; i++) { 4455 curr_byte = buffer[i]; 4456 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4457 (curr_byte >> offset); 4458 prev_byte = curr_byte; 4459 } 4460 } 4461 4462 static int 4463 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4464 { 4465 struct crypto_testsuite_params *ts_params = &testsuite_params; 4466 struct crypto_unittest_params *ut_params = &unittest_params; 4467 uint8_t *plaintext, *ciphertext; 4468 int retval; 4469 uint32_t plaintext_len; 4470 uint32_t plaintext_pad_len; 4471 uint8_t extra_offset = 4; 4472 uint8_t *expected_ciphertext_shifted; 4473 struct rte_cryptodev_info dev_info; 4474 4475 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4476 uint64_t feat_flags = dev_info.feature_flags; 4477 4478 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4479 ((tdata->validDataLenInBits.len % 8) != 0)) { 4480 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4481 return TEST_SKIPPED; 4482 } 4483 4484 /* Verify the capabilities */ 4485 struct rte_cryptodev_sym_capability_idx cap_idx; 4486 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4487 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4488 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4489 &cap_idx) == NULL) 4490 return TEST_SKIPPED; 4491 4492 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4493 return TEST_SKIPPED; 4494 4495 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4496 return TEST_SKIPPED; 4497 4498 /* Create SNOW 3G session */ 4499 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4500 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4501 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4502 tdata->key.data, tdata->key.len, 4503 tdata->cipher_iv.len); 4504 if (retval < 0) 4505 return retval; 4506 4507 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4508 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4509 4510 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4511 "Failed to allocate input buffer in mempool"); 4512 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4513 "Failed to allocate output buffer in mempool"); 4514 4515 /* Clear mbuf payload */ 4516 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4517 rte_pktmbuf_tailroom(ut_params->ibuf)); 4518 4519 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4520 /* 4521 * Append data which is padded to a 4522 * multiple of the algorithms block size 4523 */ 4524 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4525 4526 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4527 plaintext_pad_len); 4528 4529 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4530 4531 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4532 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4533 4534 #ifdef RTE_APP_TEST_DEBUG 4535 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4536 #endif 4537 /* Create SNOW 3G operation */ 4538 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4539 tdata->cipher_iv.len, 4540 tdata->validCipherLenInBits.len, 4541 extra_offset); 4542 if (retval < 0) 4543 return retval; 4544 4545 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4546 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4547 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4548 else 4549 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4550 ut_params->op); 4551 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4552 4553 ut_params->obuf = ut_params->op->sym->m_dst; 4554 if (ut_params->obuf) 4555 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4556 else 4557 ciphertext = plaintext; 4558 4559 #ifdef RTE_APP_TEST_DEBUG 4560 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4561 #endif 4562 4563 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4564 4565 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4566 "failed to reserve memory for ciphertext shifted\n"); 4567 4568 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4569 ceil_byte_length(tdata->ciphertext.len)); 4570 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4571 extra_offset); 4572 /* Validate obuf */ 4573 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4574 ciphertext, 4575 expected_ciphertext_shifted, 4576 tdata->validDataLenInBits.len, 4577 extra_offset, 4578 "SNOW 3G Ciphertext data not as expected"); 4579 return 0; 4580 } 4581 4582 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4583 { 4584 struct crypto_testsuite_params *ts_params = &testsuite_params; 4585 struct crypto_unittest_params *ut_params = &unittest_params; 4586 4587 int retval; 4588 4589 uint8_t *plaintext, *ciphertext; 4590 unsigned ciphertext_pad_len; 4591 unsigned ciphertext_len; 4592 struct rte_cryptodev_info dev_info; 4593 4594 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4595 uint64_t feat_flags = dev_info.feature_flags; 4596 4597 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4598 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4599 printf("Device doesn't support RAW data-path APIs.\n"); 4600 return TEST_SKIPPED; 4601 } 4602 4603 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4604 return TEST_SKIPPED; 4605 4606 /* Verify the capabilities */ 4607 struct rte_cryptodev_sym_capability_idx cap_idx; 4608 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4609 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4610 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4611 &cap_idx) == NULL) 4612 return TEST_SKIPPED; 4613 4614 /* Create SNOW 3G session */ 4615 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4616 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4617 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4618 tdata->key.data, tdata->key.len, 4619 tdata->cipher_iv.len); 4620 if (retval < 0) 4621 return retval; 4622 4623 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4624 4625 /* Clear mbuf payload */ 4626 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4627 rte_pktmbuf_tailroom(ut_params->ibuf)); 4628 4629 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4630 /* Append data which is padded to a multiple of */ 4631 /* the algorithms block size */ 4632 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4633 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4634 ciphertext_pad_len); 4635 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4636 4637 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4638 4639 /* Create SNOW 3G operation */ 4640 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4641 tdata->cipher_iv.len, 4642 tdata->validCipherLenInBits.len, 4643 tdata->cipher.offset_bits); 4644 if (retval < 0) 4645 return retval; 4646 4647 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4648 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4649 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4650 else 4651 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4652 ut_params->op); 4653 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4654 ut_params->obuf = ut_params->op->sym->m_dst; 4655 if (ut_params->obuf) 4656 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4657 else 4658 plaintext = ciphertext; 4659 4660 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4661 4662 /* Validate obuf */ 4663 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4664 tdata->plaintext.data, 4665 tdata->validDataLenInBits.len, 4666 "SNOW 3G Plaintext data not as expected"); 4667 return 0; 4668 } 4669 4670 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4671 { 4672 struct crypto_testsuite_params *ts_params = &testsuite_params; 4673 struct crypto_unittest_params *ut_params = &unittest_params; 4674 4675 int retval; 4676 4677 uint8_t *plaintext, *ciphertext; 4678 unsigned ciphertext_pad_len; 4679 unsigned ciphertext_len; 4680 struct rte_cryptodev_info dev_info; 4681 4682 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4683 uint64_t feat_flags = dev_info.feature_flags; 4684 4685 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4686 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4687 printf("Device does not support RAW data-path APIs.\n"); 4688 return -ENOTSUP; 4689 } 4690 /* Verify the capabilities */ 4691 struct rte_cryptodev_sym_capability_idx cap_idx; 4692 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4693 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4694 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4695 &cap_idx) == NULL) 4696 return TEST_SKIPPED; 4697 4698 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4699 return TEST_SKIPPED; 4700 4701 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4702 return TEST_SKIPPED; 4703 4704 /* Create SNOW 3G session */ 4705 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4706 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4707 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4708 tdata->key.data, tdata->key.len, 4709 tdata->cipher_iv.len); 4710 if (retval < 0) 4711 return retval; 4712 4713 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4714 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4715 4716 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4717 "Failed to allocate input buffer"); 4718 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4719 "Failed to allocate output buffer"); 4720 4721 /* Clear mbuf payload */ 4722 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4723 rte_pktmbuf_tailroom(ut_params->ibuf)); 4724 4725 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4726 rte_pktmbuf_tailroom(ut_params->obuf)); 4727 4728 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4729 /* Append data which is padded to a multiple of */ 4730 /* the algorithms block size */ 4731 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4732 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4733 ciphertext_pad_len); 4734 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4735 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4736 4737 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4738 4739 /* Create SNOW 3G operation */ 4740 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4741 tdata->cipher_iv.len, 4742 tdata->validCipherLenInBits.len, 4743 0); 4744 if (retval < 0) 4745 return retval; 4746 4747 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4748 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4749 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4750 else 4751 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4752 ut_params->op); 4753 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4754 ut_params->obuf = ut_params->op->sym->m_dst; 4755 if (ut_params->obuf) 4756 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4757 else 4758 plaintext = ciphertext; 4759 4760 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4761 4762 /* Validate obuf */ 4763 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4764 tdata->plaintext.data, 4765 tdata->validDataLenInBits.len, 4766 "SNOW 3G Plaintext data not as expected"); 4767 return 0; 4768 } 4769 4770 static int 4771 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4772 { 4773 struct crypto_testsuite_params *ts_params = &testsuite_params; 4774 struct crypto_unittest_params *ut_params = &unittest_params; 4775 4776 int retval; 4777 4778 uint8_t *plaintext, *ciphertext; 4779 unsigned int plaintext_pad_len; 4780 unsigned int plaintext_len; 4781 4782 struct rte_cryptodev_info dev_info; 4783 struct rte_cryptodev_sym_capability_idx cap_idx; 4784 4785 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4786 uint64_t feat_flags = dev_info.feature_flags; 4787 4788 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4789 ((tdata->validAuthLenInBits.len % 8 != 0) || 4790 (tdata->validDataLenInBits.len % 8 != 0))) { 4791 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4792 return TEST_SKIPPED; 4793 } 4794 4795 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4796 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4797 printf("Device doesn't support RAW data-path APIs.\n"); 4798 return TEST_SKIPPED; 4799 } 4800 4801 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4802 return TEST_SKIPPED; 4803 4804 /* Check if device supports ZUC EEA3 */ 4805 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4806 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4807 4808 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4809 &cap_idx) == NULL) 4810 return TEST_SKIPPED; 4811 4812 /* Check if device supports ZUC EIA3 */ 4813 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4814 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4815 4816 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4817 &cap_idx) == NULL) 4818 return TEST_SKIPPED; 4819 4820 /* Create ZUC session */ 4821 retval = create_zuc_cipher_auth_encrypt_generate_session( 4822 ts_params->valid_devs[0], 4823 tdata); 4824 if (retval != 0) 4825 return retval; 4826 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4827 4828 /* clear mbuf payload */ 4829 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4830 rte_pktmbuf_tailroom(ut_params->ibuf)); 4831 4832 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4833 /* Append data which is padded to a multiple of */ 4834 /* the algorithms block size */ 4835 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4836 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4837 plaintext_pad_len); 4838 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4839 4840 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4841 4842 /* Create ZUC operation */ 4843 retval = create_zuc_cipher_hash_generate_operation(tdata); 4844 if (retval < 0) 4845 return retval; 4846 4847 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4848 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4849 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4850 else 4851 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4852 ut_params->op); 4853 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4854 ut_params->obuf = ut_params->op->sym->m_src; 4855 if (ut_params->obuf) 4856 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4857 else 4858 ciphertext = plaintext; 4859 4860 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4861 /* Validate obuf */ 4862 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4863 ciphertext, 4864 tdata->ciphertext.data, 4865 tdata->validDataLenInBits.len, 4866 "ZUC Ciphertext data not as expected"); 4867 4868 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4869 + plaintext_pad_len; 4870 4871 /* Validate obuf */ 4872 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4873 ut_params->digest, 4874 tdata->digest.data, 4875 4, 4876 "ZUC Generated auth tag not as expected"); 4877 return 0; 4878 } 4879 4880 static int 4881 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4882 { 4883 struct crypto_testsuite_params *ts_params = &testsuite_params; 4884 struct crypto_unittest_params *ut_params = &unittest_params; 4885 4886 int retval; 4887 4888 uint8_t *plaintext, *ciphertext; 4889 unsigned plaintext_pad_len; 4890 unsigned plaintext_len; 4891 struct rte_cryptodev_info dev_info; 4892 4893 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4894 uint64_t feat_flags = dev_info.feature_flags; 4895 4896 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4897 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4898 printf("Device doesn't support RAW data-path APIs.\n"); 4899 return TEST_SKIPPED; 4900 } 4901 4902 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4903 return TEST_SKIPPED; 4904 4905 /* Verify the capabilities */ 4906 struct rte_cryptodev_sym_capability_idx cap_idx; 4907 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4908 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4909 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4910 &cap_idx) == NULL) 4911 return TEST_SKIPPED; 4912 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4913 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4914 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4915 &cap_idx) == NULL) 4916 return TEST_SKIPPED; 4917 4918 /* Create SNOW 3G session */ 4919 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4920 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4921 RTE_CRYPTO_AUTH_OP_GENERATE, 4922 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4923 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4924 tdata->key.data, tdata->key.len, 4925 tdata->auth_iv.len, tdata->digest.len, 4926 tdata->cipher_iv.len); 4927 if (retval != 0) 4928 return retval; 4929 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4930 4931 /* clear mbuf payload */ 4932 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4933 rte_pktmbuf_tailroom(ut_params->ibuf)); 4934 4935 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4936 /* Append data which is padded to a multiple of */ 4937 /* the algorithms block size */ 4938 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4939 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4940 plaintext_pad_len); 4941 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4942 4943 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4944 4945 /* Create SNOW 3G operation */ 4946 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4947 tdata->digest.len, tdata->auth_iv.data, 4948 tdata->auth_iv.len, 4949 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4950 tdata->cipher_iv.data, tdata->cipher_iv.len, 4951 tdata->validCipherLenInBits.len, 4952 0, 4953 tdata->validAuthLenInBits.len, 4954 0 4955 ); 4956 if (retval < 0) 4957 return retval; 4958 4959 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4960 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4961 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4962 else 4963 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4964 ut_params->op); 4965 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4966 ut_params->obuf = ut_params->op->sym->m_src; 4967 if (ut_params->obuf) 4968 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4969 else 4970 ciphertext = plaintext; 4971 4972 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4973 /* Validate obuf */ 4974 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4975 ciphertext, 4976 tdata->ciphertext.data, 4977 tdata->validDataLenInBits.len, 4978 "SNOW 3G Ciphertext data not as expected"); 4979 4980 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4981 + plaintext_pad_len; 4982 4983 /* Validate obuf */ 4984 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4985 ut_params->digest, 4986 tdata->digest.data, 4987 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4988 "SNOW 3G Generated auth tag not as expected"); 4989 return 0; 4990 } 4991 4992 static int 4993 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4994 uint8_t op_mode, uint8_t verify) 4995 { 4996 struct crypto_testsuite_params *ts_params = &testsuite_params; 4997 struct crypto_unittest_params *ut_params = &unittest_params; 4998 4999 int retval; 5000 5001 uint8_t *plaintext = NULL, *ciphertext = NULL; 5002 unsigned int plaintext_pad_len; 5003 unsigned int plaintext_len; 5004 unsigned int ciphertext_pad_len; 5005 unsigned int ciphertext_len; 5006 5007 struct rte_cryptodev_info dev_info; 5008 5009 /* Verify the capabilities */ 5010 struct rte_cryptodev_sym_capability_idx cap_idx; 5011 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5012 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5013 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5014 &cap_idx) == NULL) 5015 return TEST_SKIPPED; 5016 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5017 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5018 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5019 &cap_idx) == NULL) 5020 return TEST_SKIPPED; 5021 5022 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5023 return TEST_SKIPPED; 5024 5025 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5026 5027 uint64_t feat_flags = dev_info.feature_flags; 5028 5029 if (op_mode == OUT_OF_PLACE) { 5030 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5031 printf("Device doesn't support digest encrypted.\n"); 5032 return TEST_SKIPPED; 5033 } 5034 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5035 return TEST_SKIPPED; 5036 } 5037 5038 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5039 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5040 printf("Device doesn't support RAW data-path APIs.\n"); 5041 return TEST_SKIPPED; 5042 } 5043 5044 /* Create SNOW 3G session */ 5045 retval = create_wireless_algo_auth_cipher_session( 5046 ts_params->valid_devs[0], 5047 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5048 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5049 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5050 : RTE_CRYPTO_AUTH_OP_GENERATE), 5051 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5052 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5053 tdata->key.data, tdata->key.len, 5054 tdata->auth_iv.len, tdata->digest.len, 5055 tdata->cipher_iv.len); 5056 if (retval != 0) 5057 return retval; 5058 5059 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5060 if (op_mode == OUT_OF_PLACE) 5061 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5062 5063 /* clear mbuf payload */ 5064 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5065 rte_pktmbuf_tailroom(ut_params->ibuf)); 5066 if (op_mode == OUT_OF_PLACE) 5067 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5068 rte_pktmbuf_tailroom(ut_params->obuf)); 5069 5070 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5071 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5072 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5073 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5074 5075 if (verify) { 5076 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5077 ciphertext_pad_len); 5078 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5079 if (op_mode == OUT_OF_PLACE) 5080 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5081 debug_hexdump(stdout, "ciphertext:", ciphertext, 5082 ciphertext_len); 5083 } else { 5084 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5085 plaintext_pad_len); 5086 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5087 if (op_mode == OUT_OF_PLACE) 5088 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5089 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5090 } 5091 5092 /* Create SNOW 3G operation */ 5093 retval = create_wireless_algo_auth_cipher_operation( 5094 tdata->digest.data, tdata->digest.len, 5095 tdata->cipher_iv.data, tdata->cipher_iv.len, 5096 tdata->auth_iv.data, tdata->auth_iv.len, 5097 (tdata->digest.offset_bytes == 0 ? 5098 (verify ? ciphertext_pad_len : plaintext_pad_len) 5099 : tdata->digest.offset_bytes), 5100 tdata->validCipherLenInBits.len, 5101 tdata->cipher.offset_bits, 5102 tdata->validAuthLenInBits.len, 5103 tdata->auth.offset_bits, 5104 op_mode, 0, verify); 5105 5106 if (retval < 0) 5107 return retval; 5108 5109 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5110 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5111 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5112 else 5113 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5114 ut_params->op); 5115 5116 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5117 5118 ut_params->obuf = (op_mode == IN_PLACE ? 5119 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5120 5121 if (verify) { 5122 if (ut_params->obuf) 5123 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5124 uint8_t *); 5125 else 5126 plaintext = ciphertext + 5127 (tdata->cipher.offset_bits >> 3); 5128 5129 debug_hexdump(stdout, "plaintext:", plaintext, 5130 (tdata->plaintext.len >> 3) - tdata->digest.len); 5131 debug_hexdump(stdout, "plaintext expected:", 5132 tdata->plaintext.data, 5133 (tdata->plaintext.len >> 3) - tdata->digest.len); 5134 } else { 5135 if (ut_params->obuf) 5136 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5137 uint8_t *); 5138 else 5139 ciphertext = plaintext; 5140 5141 debug_hexdump(stdout, "ciphertext:", ciphertext, 5142 ciphertext_len); 5143 debug_hexdump(stdout, "ciphertext expected:", 5144 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5145 5146 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5147 + (tdata->digest.offset_bytes == 0 ? 5148 plaintext_pad_len : tdata->digest.offset_bytes); 5149 5150 debug_hexdump(stdout, "digest:", ut_params->digest, 5151 tdata->digest.len); 5152 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5153 tdata->digest.len); 5154 } 5155 5156 /* Validate obuf */ 5157 if (verify) { 5158 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5159 plaintext, 5160 tdata->plaintext.data, 5161 (tdata->plaintext.len - tdata->cipher.offset_bits - 5162 (tdata->digest.len << 3)), 5163 tdata->cipher.offset_bits, 5164 "SNOW 3G Plaintext data not as expected"); 5165 } else { 5166 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5167 ciphertext, 5168 tdata->ciphertext.data, 5169 (tdata->validDataLenInBits.len - 5170 tdata->cipher.offset_bits), 5171 tdata->cipher.offset_bits, 5172 "SNOW 3G Ciphertext data not as expected"); 5173 5174 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5175 ut_params->digest, 5176 tdata->digest.data, 5177 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5178 "SNOW 3G Generated auth tag not as expected"); 5179 } 5180 return 0; 5181 } 5182 5183 static int 5184 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5185 uint8_t op_mode, uint8_t verify) 5186 { 5187 struct crypto_testsuite_params *ts_params = &testsuite_params; 5188 struct crypto_unittest_params *ut_params = &unittest_params; 5189 5190 int retval; 5191 5192 const uint8_t *plaintext = NULL; 5193 const uint8_t *ciphertext = NULL; 5194 const uint8_t *digest = NULL; 5195 unsigned int plaintext_pad_len; 5196 unsigned int plaintext_len; 5197 unsigned int ciphertext_pad_len; 5198 unsigned int ciphertext_len; 5199 uint8_t buffer[10000]; 5200 uint8_t digest_buffer[10000]; 5201 5202 struct rte_cryptodev_info dev_info; 5203 5204 /* Verify the capabilities */ 5205 struct rte_cryptodev_sym_capability_idx cap_idx; 5206 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5207 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5208 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5209 &cap_idx) == NULL) 5210 return TEST_SKIPPED; 5211 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5212 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5213 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5214 &cap_idx) == NULL) 5215 return TEST_SKIPPED; 5216 5217 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5218 return TEST_SKIPPED; 5219 5220 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5221 5222 uint64_t feat_flags = dev_info.feature_flags; 5223 5224 if (op_mode == IN_PLACE) { 5225 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5226 printf("Device doesn't support in-place scatter-gather " 5227 "in both input and output mbufs.\n"); 5228 return TEST_SKIPPED; 5229 } 5230 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5231 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5232 printf("Device doesn't support RAW data-path APIs.\n"); 5233 return TEST_SKIPPED; 5234 } 5235 } else { 5236 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5237 return TEST_SKIPPED; 5238 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5239 printf("Device doesn't support out-of-place scatter-gather " 5240 "in both input and output mbufs.\n"); 5241 return TEST_SKIPPED; 5242 } 5243 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5244 printf("Device doesn't support digest encrypted.\n"); 5245 return TEST_SKIPPED; 5246 } 5247 } 5248 5249 /* Create SNOW 3G session */ 5250 retval = create_wireless_algo_auth_cipher_session( 5251 ts_params->valid_devs[0], 5252 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5253 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5254 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5255 : RTE_CRYPTO_AUTH_OP_GENERATE), 5256 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5257 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5258 tdata->key.data, tdata->key.len, 5259 tdata->auth_iv.len, tdata->digest.len, 5260 tdata->cipher_iv.len); 5261 5262 if (retval != 0) 5263 return retval; 5264 5265 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5266 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5267 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5268 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5269 5270 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5271 plaintext_pad_len, 15, 0); 5272 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5273 "Failed to allocate input buffer in mempool"); 5274 5275 if (op_mode == OUT_OF_PLACE) { 5276 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5277 plaintext_pad_len, 15, 0); 5278 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5279 "Failed to allocate output buffer in mempool"); 5280 } 5281 5282 if (verify) { 5283 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5284 tdata->ciphertext.data); 5285 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5286 ciphertext_len, buffer); 5287 debug_hexdump(stdout, "ciphertext:", ciphertext, 5288 ciphertext_len); 5289 } else { 5290 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5291 tdata->plaintext.data); 5292 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5293 plaintext_len, buffer); 5294 debug_hexdump(stdout, "plaintext:", plaintext, 5295 plaintext_len); 5296 } 5297 memset(buffer, 0, sizeof(buffer)); 5298 5299 /* Create SNOW 3G operation */ 5300 retval = create_wireless_algo_auth_cipher_operation( 5301 tdata->digest.data, tdata->digest.len, 5302 tdata->cipher_iv.data, tdata->cipher_iv.len, 5303 tdata->auth_iv.data, tdata->auth_iv.len, 5304 (tdata->digest.offset_bytes == 0 ? 5305 (verify ? ciphertext_pad_len : plaintext_pad_len) 5306 : tdata->digest.offset_bytes), 5307 tdata->validCipherLenInBits.len, 5308 tdata->cipher.offset_bits, 5309 tdata->validAuthLenInBits.len, 5310 tdata->auth.offset_bits, 5311 op_mode, 1, verify); 5312 5313 if (retval < 0) 5314 return retval; 5315 5316 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5317 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5318 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5319 else 5320 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5321 ut_params->op); 5322 5323 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5324 5325 ut_params->obuf = (op_mode == IN_PLACE ? 5326 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5327 5328 if (verify) { 5329 if (ut_params->obuf) 5330 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5331 plaintext_len, buffer); 5332 else 5333 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5334 plaintext_len, buffer); 5335 5336 debug_hexdump(stdout, "plaintext:", plaintext, 5337 (tdata->plaintext.len >> 3) - tdata->digest.len); 5338 debug_hexdump(stdout, "plaintext expected:", 5339 tdata->plaintext.data, 5340 (tdata->plaintext.len >> 3) - tdata->digest.len); 5341 } else { 5342 if (ut_params->obuf) 5343 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5344 ciphertext_len, buffer); 5345 else 5346 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5347 ciphertext_len, buffer); 5348 5349 debug_hexdump(stdout, "ciphertext:", ciphertext, 5350 ciphertext_len); 5351 debug_hexdump(stdout, "ciphertext expected:", 5352 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5353 5354 if (ut_params->obuf) 5355 digest = rte_pktmbuf_read(ut_params->obuf, 5356 (tdata->digest.offset_bytes == 0 ? 5357 plaintext_pad_len : tdata->digest.offset_bytes), 5358 tdata->digest.len, digest_buffer); 5359 else 5360 digest = rte_pktmbuf_read(ut_params->ibuf, 5361 (tdata->digest.offset_bytes == 0 ? 5362 plaintext_pad_len : tdata->digest.offset_bytes), 5363 tdata->digest.len, digest_buffer); 5364 5365 debug_hexdump(stdout, "digest:", digest, 5366 tdata->digest.len); 5367 debug_hexdump(stdout, "digest expected:", 5368 tdata->digest.data, tdata->digest.len); 5369 } 5370 5371 /* Validate obuf */ 5372 if (verify) { 5373 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5374 plaintext, 5375 tdata->plaintext.data, 5376 (tdata->plaintext.len - tdata->cipher.offset_bits - 5377 (tdata->digest.len << 3)), 5378 tdata->cipher.offset_bits, 5379 "SNOW 3G Plaintext data not as expected"); 5380 } else { 5381 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5382 ciphertext, 5383 tdata->ciphertext.data, 5384 (tdata->validDataLenInBits.len - 5385 tdata->cipher.offset_bits), 5386 tdata->cipher.offset_bits, 5387 "SNOW 3G Ciphertext data not as expected"); 5388 5389 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5390 digest, 5391 tdata->digest.data, 5392 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5393 "SNOW 3G Generated auth tag not as expected"); 5394 } 5395 return 0; 5396 } 5397 5398 static int 5399 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5400 uint8_t op_mode, uint8_t verify) 5401 { 5402 struct crypto_testsuite_params *ts_params = &testsuite_params; 5403 struct crypto_unittest_params *ut_params = &unittest_params; 5404 5405 int retval; 5406 5407 uint8_t *plaintext = NULL, *ciphertext = NULL; 5408 unsigned int plaintext_pad_len; 5409 unsigned int plaintext_len; 5410 unsigned int ciphertext_pad_len; 5411 unsigned int ciphertext_len; 5412 5413 struct rte_cryptodev_info dev_info; 5414 5415 /* Verify the capabilities */ 5416 struct rte_cryptodev_sym_capability_idx cap_idx; 5417 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5418 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5419 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5420 &cap_idx) == NULL) 5421 return TEST_SKIPPED; 5422 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5423 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5424 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5425 &cap_idx) == NULL) 5426 return TEST_SKIPPED; 5427 5428 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5429 5430 uint64_t feat_flags = dev_info.feature_flags; 5431 5432 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5433 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5434 printf("Device doesn't support RAW data-path APIs.\n"); 5435 return TEST_SKIPPED; 5436 } 5437 5438 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5439 return TEST_SKIPPED; 5440 5441 if (op_mode == OUT_OF_PLACE) { 5442 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5443 return TEST_SKIPPED; 5444 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5445 printf("Device doesn't support digest encrypted.\n"); 5446 return TEST_SKIPPED; 5447 } 5448 } 5449 5450 /* Create KASUMI session */ 5451 retval = create_wireless_algo_auth_cipher_session( 5452 ts_params->valid_devs[0], 5453 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5454 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5455 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5456 : RTE_CRYPTO_AUTH_OP_GENERATE), 5457 RTE_CRYPTO_AUTH_KASUMI_F9, 5458 RTE_CRYPTO_CIPHER_KASUMI_F8, 5459 tdata->key.data, tdata->key.len, 5460 0, tdata->digest.len, 5461 tdata->cipher_iv.len); 5462 5463 if (retval != 0) 5464 return retval; 5465 5466 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5467 if (op_mode == OUT_OF_PLACE) 5468 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5469 5470 /* clear mbuf payload */ 5471 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5472 rte_pktmbuf_tailroom(ut_params->ibuf)); 5473 if (op_mode == OUT_OF_PLACE) 5474 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5475 rte_pktmbuf_tailroom(ut_params->obuf)); 5476 5477 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5478 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5479 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5480 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5481 5482 if (verify) { 5483 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5484 ciphertext_pad_len); 5485 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5486 if (op_mode == OUT_OF_PLACE) 5487 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5488 debug_hexdump(stdout, "ciphertext:", ciphertext, 5489 ciphertext_len); 5490 } else { 5491 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5492 plaintext_pad_len); 5493 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5494 if (op_mode == OUT_OF_PLACE) 5495 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5496 debug_hexdump(stdout, "plaintext:", plaintext, 5497 plaintext_len); 5498 } 5499 5500 /* Create KASUMI operation */ 5501 retval = create_wireless_algo_auth_cipher_operation( 5502 tdata->digest.data, tdata->digest.len, 5503 tdata->cipher_iv.data, tdata->cipher_iv.len, 5504 NULL, 0, 5505 (tdata->digest.offset_bytes == 0 ? 5506 (verify ? ciphertext_pad_len : plaintext_pad_len) 5507 : tdata->digest.offset_bytes), 5508 tdata->validCipherLenInBits.len, 5509 tdata->validCipherOffsetInBits.len, 5510 tdata->validAuthLenInBits.len, 5511 0, 5512 op_mode, 0, verify); 5513 5514 if (retval < 0) 5515 return retval; 5516 5517 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5518 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5519 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5520 else 5521 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5522 ut_params->op); 5523 5524 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5525 5526 ut_params->obuf = (op_mode == IN_PLACE ? 5527 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5528 5529 5530 if (verify) { 5531 if (ut_params->obuf) 5532 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5533 uint8_t *); 5534 else 5535 plaintext = ciphertext; 5536 5537 debug_hexdump(stdout, "plaintext:", plaintext, 5538 (tdata->plaintext.len >> 3) - tdata->digest.len); 5539 debug_hexdump(stdout, "plaintext expected:", 5540 tdata->plaintext.data, 5541 (tdata->plaintext.len >> 3) - tdata->digest.len); 5542 } else { 5543 if (ut_params->obuf) 5544 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5545 uint8_t *); 5546 else 5547 ciphertext = plaintext; 5548 5549 debug_hexdump(stdout, "ciphertext:", ciphertext, 5550 ciphertext_len); 5551 debug_hexdump(stdout, "ciphertext expected:", 5552 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5553 5554 ut_params->digest = rte_pktmbuf_mtod( 5555 ut_params->obuf, uint8_t *) + 5556 (tdata->digest.offset_bytes == 0 ? 5557 plaintext_pad_len : tdata->digest.offset_bytes); 5558 5559 debug_hexdump(stdout, "digest:", ut_params->digest, 5560 tdata->digest.len); 5561 debug_hexdump(stdout, "digest expected:", 5562 tdata->digest.data, tdata->digest.len); 5563 } 5564 5565 /* Validate obuf */ 5566 if (verify) { 5567 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5568 plaintext, 5569 tdata->plaintext.data, 5570 tdata->plaintext.len >> 3, 5571 "KASUMI Plaintext data not as expected"); 5572 } else { 5573 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5574 ciphertext, 5575 tdata->ciphertext.data, 5576 tdata->ciphertext.len >> 3, 5577 "KASUMI Ciphertext data not as expected"); 5578 5579 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5580 ut_params->digest, 5581 tdata->digest.data, 5582 DIGEST_BYTE_LENGTH_KASUMI_F9, 5583 "KASUMI Generated auth tag not as expected"); 5584 } 5585 return 0; 5586 } 5587 5588 static int 5589 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5590 uint8_t op_mode, uint8_t verify) 5591 { 5592 struct crypto_testsuite_params *ts_params = &testsuite_params; 5593 struct crypto_unittest_params *ut_params = &unittest_params; 5594 5595 int retval; 5596 5597 const uint8_t *plaintext = NULL; 5598 const uint8_t *ciphertext = NULL; 5599 const uint8_t *digest = NULL; 5600 unsigned int plaintext_pad_len; 5601 unsigned int plaintext_len; 5602 unsigned int ciphertext_pad_len; 5603 unsigned int ciphertext_len; 5604 uint8_t buffer[10000]; 5605 uint8_t digest_buffer[10000]; 5606 5607 struct rte_cryptodev_info dev_info; 5608 5609 /* Verify the capabilities */ 5610 struct rte_cryptodev_sym_capability_idx cap_idx; 5611 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5612 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5613 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5614 &cap_idx) == NULL) 5615 return TEST_SKIPPED; 5616 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5617 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5618 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5619 &cap_idx) == NULL) 5620 return TEST_SKIPPED; 5621 5622 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5623 return TEST_SKIPPED; 5624 5625 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5626 5627 uint64_t feat_flags = dev_info.feature_flags; 5628 5629 if (op_mode == IN_PLACE) { 5630 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5631 printf("Device doesn't support in-place scatter-gather " 5632 "in both input and output mbufs.\n"); 5633 return TEST_SKIPPED; 5634 } 5635 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5636 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5637 printf("Device doesn't support RAW data-path APIs.\n"); 5638 return TEST_SKIPPED; 5639 } 5640 } else { 5641 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5642 return TEST_SKIPPED; 5643 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5644 printf("Device doesn't support out-of-place scatter-gather " 5645 "in both input and output mbufs.\n"); 5646 return TEST_SKIPPED; 5647 } 5648 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5649 printf("Device doesn't support digest encrypted.\n"); 5650 return TEST_SKIPPED; 5651 } 5652 } 5653 5654 /* Create KASUMI session */ 5655 retval = create_wireless_algo_auth_cipher_session( 5656 ts_params->valid_devs[0], 5657 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5658 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5659 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5660 : RTE_CRYPTO_AUTH_OP_GENERATE), 5661 RTE_CRYPTO_AUTH_KASUMI_F9, 5662 RTE_CRYPTO_CIPHER_KASUMI_F8, 5663 tdata->key.data, tdata->key.len, 5664 0, tdata->digest.len, 5665 tdata->cipher_iv.len); 5666 5667 if (retval != 0) 5668 return retval; 5669 5670 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5671 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5672 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5673 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5674 5675 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5676 plaintext_pad_len, 15, 0); 5677 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5678 "Failed to allocate input buffer in mempool"); 5679 5680 if (op_mode == OUT_OF_PLACE) { 5681 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5682 plaintext_pad_len, 15, 0); 5683 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5684 "Failed to allocate output buffer in mempool"); 5685 } 5686 5687 if (verify) { 5688 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5689 tdata->ciphertext.data); 5690 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5691 ciphertext_len, buffer); 5692 debug_hexdump(stdout, "ciphertext:", ciphertext, 5693 ciphertext_len); 5694 } else { 5695 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5696 tdata->plaintext.data); 5697 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5698 plaintext_len, buffer); 5699 debug_hexdump(stdout, "plaintext:", plaintext, 5700 plaintext_len); 5701 } 5702 memset(buffer, 0, sizeof(buffer)); 5703 5704 /* Create KASUMI operation */ 5705 retval = create_wireless_algo_auth_cipher_operation( 5706 tdata->digest.data, tdata->digest.len, 5707 tdata->cipher_iv.data, tdata->cipher_iv.len, 5708 NULL, 0, 5709 (tdata->digest.offset_bytes == 0 ? 5710 (verify ? ciphertext_pad_len : plaintext_pad_len) 5711 : tdata->digest.offset_bytes), 5712 tdata->validCipherLenInBits.len, 5713 tdata->validCipherOffsetInBits.len, 5714 tdata->validAuthLenInBits.len, 5715 0, 5716 op_mode, 1, verify); 5717 5718 if (retval < 0) 5719 return retval; 5720 5721 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5722 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5723 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5724 else 5725 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5726 ut_params->op); 5727 5728 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5729 5730 ut_params->obuf = (op_mode == IN_PLACE ? 5731 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5732 5733 if (verify) { 5734 if (ut_params->obuf) 5735 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5736 plaintext_len, buffer); 5737 else 5738 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5739 plaintext_len, buffer); 5740 5741 debug_hexdump(stdout, "plaintext:", plaintext, 5742 (tdata->plaintext.len >> 3) - tdata->digest.len); 5743 debug_hexdump(stdout, "plaintext expected:", 5744 tdata->plaintext.data, 5745 (tdata->plaintext.len >> 3) - tdata->digest.len); 5746 } else { 5747 if (ut_params->obuf) 5748 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5749 ciphertext_len, buffer); 5750 else 5751 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5752 ciphertext_len, buffer); 5753 5754 debug_hexdump(stdout, "ciphertext:", ciphertext, 5755 ciphertext_len); 5756 debug_hexdump(stdout, "ciphertext expected:", 5757 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5758 5759 if (ut_params->obuf) 5760 digest = rte_pktmbuf_read(ut_params->obuf, 5761 (tdata->digest.offset_bytes == 0 ? 5762 plaintext_pad_len : tdata->digest.offset_bytes), 5763 tdata->digest.len, digest_buffer); 5764 else 5765 digest = rte_pktmbuf_read(ut_params->ibuf, 5766 (tdata->digest.offset_bytes == 0 ? 5767 plaintext_pad_len : tdata->digest.offset_bytes), 5768 tdata->digest.len, digest_buffer); 5769 5770 debug_hexdump(stdout, "digest:", digest, 5771 tdata->digest.len); 5772 debug_hexdump(stdout, "digest expected:", 5773 tdata->digest.data, tdata->digest.len); 5774 } 5775 5776 /* Validate obuf */ 5777 if (verify) { 5778 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5779 plaintext, 5780 tdata->plaintext.data, 5781 tdata->plaintext.len >> 3, 5782 "KASUMI Plaintext data not as expected"); 5783 } else { 5784 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5785 ciphertext, 5786 tdata->ciphertext.data, 5787 tdata->validDataLenInBits.len, 5788 "KASUMI Ciphertext data not as expected"); 5789 5790 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5791 digest, 5792 tdata->digest.data, 5793 DIGEST_BYTE_LENGTH_KASUMI_F9, 5794 "KASUMI Generated auth tag not as expected"); 5795 } 5796 return 0; 5797 } 5798 5799 static int 5800 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5801 { 5802 struct crypto_testsuite_params *ts_params = &testsuite_params; 5803 struct crypto_unittest_params *ut_params = &unittest_params; 5804 5805 int retval; 5806 5807 uint8_t *plaintext, *ciphertext; 5808 unsigned plaintext_pad_len; 5809 unsigned plaintext_len; 5810 struct rte_cryptodev_info dev_info; 5811 5812 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5813 uint64_t feat_flags = dev_info.feature_flags; 5814 5815 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5816 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5817 printf("Device doesn't support RAW data-path APIs.\n"); 5818 return TEST_SKIPPED; 5819 } 5820 5821 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5822 return TEST_SKIPPED; 5823 5824 /* Verify the capabilities */ 5825 struct rte_cryptodev_sym_capability_idx cap_idx; 5826 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5827 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5828 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5829 &cap_idx) == NULL) 5830 return TEST_SKIPPED; 5831 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5832 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5833 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5834 &cap_idx) == NULL) 5835 return TEST_SKIPPED; 5836 5837 /* Create KASUMI session */ 5838 retval = create_wireless_algo_cipher_auth_session( 5839 ts_params->valid_devs[0], 5840 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5841 RTE_CRYPTO_AUTH_OP_GENERATE, 5842 RTE_CRYPTO_AUTH_KASUMI_F9, 5843 RTE_CRYPTO_CIPHER_KASUMI_F8, 5844 tdata->key.data, tdata->key.len, 5845 0, tdata->digest.len, 5846 tdata->cipher_iv.len); 5847 if (retval != 0) 5848 return retval; 5849 5850 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5851 5852 /* clear mbuf payload */ 5853 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5854 rte_pktmbuf_tailroom(ut_params->ibuf)); 5855 5856 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5857 /* Append data which is padded to a multiple of */ 5858 /* the algorithms block size */ 5859 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5860 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5861 plaintext_pad_len); 5862 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5863 5864 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5865 5866 /* Create KASUMI operation */ 5867 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5868 tdata->digest.len, NULL, 0, 5869 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5870 tdata->cipher_iv.data, tdata->cipher_iv.len, 5871 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5872 tdata->validCipherOffsetInBits.len, 5873 tdata->validAuthLenInBits.len, 5874 0 5875 ); 5876 if (retval < 0) 5877 return retval; 5878 5879 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5880 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5881 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5882 else 5883 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5884 ut_params->op); 5885 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5886 5887 if (ut_params->op->sym->m_dst) 5888 ut_params->obuf = ut_params->op->sym->m_dst; 5889 else 5890 ut_params->obuf = ut_params->op->sym->m_src; 5891 5892 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5893 tdata->validCipherOffsetInBits.len >> 3); 5894 5895 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5896 + plaintext_pad_len; 5897 5898 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5899 (tdata->validCipherOffsetInBits.len >> 3); 5900 /* Validate obuf */ 5901 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5902 ciphertext, 5903 reference_ciphertext, 5904 tdata->validCipherLenInBits.len, 5905 "KASUMI Ciphertext data not as expected"); 5906 5907 /* Validate obuf */ 5908 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5909 ut_params->digest, 5910 tdata->digest.data, 5911 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5912 "KASUMI Generated auth tag not as expected"); 5913 return 0; 5914 } 5915 5916 static int 5917 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5918 const enum rte_crypto_cipher_algorithm cipher_algo, 5919 const uint16_t key_size, const uint16_t iv_size) 5920 { 5921 struct rte_cryptodev_sym_capability_idx cap_idx; 5922 const struct rte_cryptodev_symmetric_capability *cap; 5923 5924 /* Check if device supports the algorithm */ 5925 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5926 cap_idx.algo.cipher = cipher_algo; 5927 5928 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5929 &cap_idx); 5930 5931 if (cap == NULL) 5932 return -1; 5933 5934 /* Check if device supports key size and IV size */ 5935 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5936 iv_size) < 0) { 5937 return -1; 5938 } 5939 5940 return 0; 5941 } 5942 5943 static int 5944 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5945 const enum rte_crypto_auth_algorithm auth_algo, 5946 const uint16_t key_size, const uint16_t iv_size, 5947 const uint16_t tag_size) 5948 { 5949 struct rte_cryptodev_sym_capability_idx cap_idx; 5950 const struct rte_cryptodev_symmetric_capability *cap; 5951 5952 /* Check if device supports the algorithm */ 5953 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5954 cap_idx.algo.auth = auth_algo; 5955 5956 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5957 &cap_idx); 5958 5959 if (cap == NULL) 5960 return -1; 5961 5962 /* Check if device supports key size and IV size */ 5963 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5964 tag_size, iv_size) < 0) { 5965 return -1; 5966 } 5967 5968 return 0; 5969 } 5970 5971 static int 5972 test_zuc_encryption(const struct wireless_test_data *tdata) 5973 { 5974 struct crypto_testsuite_params *ts_params = &testsuite_params; 5975 struct crypto_unittest_params *ut_params = &unittest_params; 5976 5977 int retval; 5978 uint8_t *plaintext, *ciphertext; 5979 unsigned plaintext_pad_len; 5980 unsigned plaintext_len; 5981 struct rte_cryptodev_info dev_info; 5982 5983 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5984 uint64_t feat_flags = dev_info.feature_flags; 5985 5986 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5987 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5988 printf("Device doesn't support RAW data-path APIs.\n"); 5989 return TEST_SKIPPED; 5990 } 5991 5992 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5993 return TEST_SKIPPED; 5994 5995 /* Check if device supports ZUC EEA3 */ 5996 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5997 tdata->key.len, tdata->cipher_iv.len) < 0) 5998 return TEST_SKIPPED; 5999 6000 /* Create ZUC session */ 6001 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6002 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6003 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6004 tdata->key.data, tdata->key.len, 6005 tdata->cipher_iv.len); 6006 if (retval != 0) 6007 return retval; 6008 6009 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6010 6011 /* Clear mbuf payload */ 6012 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6013 rte_pktmbuf_tailroom(ut_params->ibuf)); 6014 6015 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6016 /* Append data which is padded to a multiple */ 6017 /* of the algorithms block size */ 6018 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6019 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6020 plaintext_pad_len); 6021 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6022 6023 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6024 6025 /* Create ZUC operation */ 6026 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6027 tdata->cipher_iv.len, 6028 tdata->plaintext.len, 6029 0); 6030 if (retval < 0) 6031 return retval; 6032 6033 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6034 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6035 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6036 else 6037 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6038 ut_params->op); 6039 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6040 6041 ut_params->obuf = ut_params->op->sym->m_dst; 6042 if (ut_params->obuf) 6043 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6044 else 6045 ciphertext = plaintext; 6046 6047 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6048 6049 /* Validate obuf */ 6050 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6051 ciphertext, 6052 tdata->ciphertext.data, 6053 tdata->validCipherLenInBits.len, 6054 "ZUC Ciphertext data not as expected"); 6055 return 0; 6056 } 6057 6058 static int 6059 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6060 { 6061 struct crypto_testsuite_params *ts_params = &testsuite_params; 6062 struct crypto_unittest_params *ut_params = &unittest_params; 6063 6064 int retval; 6065 6066 unsigned int plaintext_pad_len; 6067 unsigned int plaintext_len; 6068 const uint8_t *ciphertext; 6069 uint8_t ciphertext_buffer[2048]; 6070 struct rte_cryptodev_info dev_info; 6071 6072 /* Check if device supports ZUC EEA3 */ 6073 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6074 tdata->key.len, tdata->cipher_iv.len) < 0) 6075 return TEST_SKIPPED; 6076 6077 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6078 return TEST_SKIPPED; 6079 6080 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6081 6082 uint64_t feat_flags = dev_info.feature_flags; 6083 6084 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6085 printf("Device doesn't support in-place scatter-gather. " 6086 "Test Skipped.\n"); 6087 return TEST_SKIPPED; 6088 } 6089 6090 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6091 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6092 printf("Device doesn't support RAW data-path APIs.\n"); 6093 return TEST_SKIPPED; 6094 } 6095 6096 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6097 6098 /* Append data which is padded to a multiple */ 6099 /* of the algorithms block size */ 6100 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6101 6102 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6103 plaintext_pad_len, 10, 0); 6104 6105 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6106 tdata->plaintext.data); 6107 6108 /* Create ZUC session */ 6109 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6110 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6111 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6112 tdata->key.data, tdata->key.len, 6113 tdata->cipher_iv.len); 6114 if (retval < 0) 6115 return retval; 6116 6117 /* Clear mbuf payload */ 6118 6119 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6120 6121 /* Create ZUC operation */ 6122 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6123 tdata->cipher_iv.len, tdata->plaintext.len, 6124 0); 6125 if (retval < 0) 6126 return retval; 6127 6128 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6129 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6130 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6131 else 6132 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6133 ut_params->op); 6134 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6135 6136 ut_params->obuf = ut_params->op->sym->m_dst; 6137 if (ut_params->obuf) 6138 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6139 0, plaintext_len, ciphertext_buffer); 6140 else 6141 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6142 0, plaintext_len, ciphertext_buffer); 6143 6144 /* Validate obuf */ 6145 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6146 6147 /* Validate obuf */ 6148 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6149 ciphertext, 6150 tdata->ciphertext.data, 6151 tdata->validCipherLenInBits.len, 6152 "ZUC Ciphertext data not as expected"); 6153 6154 return 0; 6155 } 6156 6157 static int 6158 test_zuc_authentication(const struct wireless_test_data *tdata) 6159 { 6160 struct crypto_testsuite_params *ts_params = &testsuite_params; 6161 struct crypto_unittest_params *ut_params = &unittest_params; 6162 6163 int retval; 6164 unsigned plaintext_pad_len; 6165 unsigned plaintext_len; 6166 uint8_t *plaintext; 6167 6168 struct rte_cryptodev_info dev_info; 6169 6170 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6171 uint64_t feat_flags = dev_info.feature_flags; 6172 6173 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6174 (tdata->validAuthLenInBits.len % 8 != 0)) { 6175 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6176 return TEST_SKIPPED; 6177 } 6178 6179 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6180 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6181 printf("Device doesn't support RAW data-path APIs.\n"); 6182 return TEST_SKIPPED; 6183 } 6184 6185 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6186 return TEST_SKIPPED; 6187 6188 /* Check if device supports ZUC EIA3 */ 6189 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6190 tdata->key.len, tdata->auth_iv.len, 6191 tdata->digest.len) < 0) 6192 return TEST_SKIPPED; 6193 6194 /* Create ZUC session */ 6195 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6196 tdata->key.data, tdata->key.len, 6197 tdata->auth_iv.len, tdata->digest.len, 6198 RTE_CRYPTO_AUTH_OP_GENERATE, 6199 RTE_CRYPTO_AUTH_ZUC_EIA3); 6200 if (retval != 0) 6201 return retval; 6202 6203 /* alloc mbuf and set payload */ 6204 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6205 6206 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6207 rte_pktmbuf_tailroom(ut_params->ibuf)); 6208 6209 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6210 /* Append data which is padded to a multiple of */ 6211 /* the algorithms block size */ 6212 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6213 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6214 plaintext_pad_len); 6215 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6216 6217 /* Create ZUC operation */ 6218 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6219 tdata->auth_iv.data, tdata->auth_iv.len, 6220 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6221 tdata->validAuthLenInBits.len, 6222 0); 6223 if (retval < 0) 6224 return retval; 6225 6226 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6227 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6228 ut_params->op, 0, 1, 1, 0); 6229 else 6230 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6231 ut_params->op); 6232 ut_params->obuf = ut_params->op->sym->m_src; 6233 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6234 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6235 + plaintext_pad_len; 6236 6237 /* Validate obuf */ 6238 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6239 ut_params->digest, 6240 tdata->digest.data, 6241 tdata->digest.len, 6242 "ZUC Generated auth tag not as expected"); 6243 6244 return 0; 6245 } 6246 6247 static int 6248 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6249 uint8_t op_mode, uint8_t verify) 6250 { 6251 struct crypto_testsuite_params *ts_params = &testsuite_params; 6252 struct crypto_unittest_params *ut_params = &unittest_params; 6253 6254 int retval; 6255 6256 uint8_t *plaintext = NULL, *ciphertext = NULL; 6257 unsigned int plaintext_pad_len; 6258 unsigned int plaintext_len; 6259 unsigned int ciphertext_pad_len; 6260 unsigned int ciphertext_len; 6261 6262 struct rte_cryptodev_info dev_info; 6263 6264 /* Check if device supports ZUC EEA3 */ 6265 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6266 tdata->key.len, tdata->cipher_iv.len) < 0) 6267 return TEST_SKIPPED; 6268 6269 /* Check if device supports ZUC EIA3 */ 6270 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6271 tdata->key.len, tdata->auth_iv.len, 6272 tdata->digest.len) < 0) 6273 return TEST_SKIPPED; 6274 6275 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6276 6277 uint64_t feat_flags = dev_info.feature_flags; 6278 6279 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6280 printf("Device doesn't support digest encrypted.\n"); 6281 return TEST_SKIPPED; 6282 } 6283 if (op_mode == IN_PLACE) { 6284 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6285 printf("Device doesn't support in-place scatter-gather " 6286 "in both input and output mbufs.\n"); 6287 return TEST_SKIPPED; 6288 } 6289 6290 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6291 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6292 printf("Device doesn't support RAW data-path APIs.\n"); 6293 return TEST_SKIPPED; 6294 } 6295 } else { 6296 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6297 return TEST_SKIPPED; 6298 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6299 printf("Device doesn't support out-of-place scatter-gather " 6300 "in both input and output mbufs.\n"); 6301 return TEST_SKIPPED; 6302 } 6303 } 6304 6305 /* Create ZUC session */ 6306 retval = create_wireless_algo_auth_cipher_session( 6307 ts_params->valid_devs[0], 6308 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6309 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6310 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6311 : RTE_CRYPTO_AUTH_OP_GENERATE), 6312 RTE_CRYPTO_AUTH_ZUC_EIA3, 6313 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6314 tdata->key.data, tdata->key.len, 6315 tdata->auth_iv.len, tdata->digest.len, 6316 tdata->cipher_iv.len); 6317 6318 if (retval != 0) 6319 return retval; 6320 6321 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6322 if (op_mode == OUT_OF_PLACE) 6323 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6324 6325 /* clear mbuf payload */ 6326 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6327 rte_pktmbuf_tailroom(ut_params->ibuf)); 6328 if (op_mode == OUT_OF_PLACE) 6329 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6330 rte_pktmbuf_tailroom(ut_params->obuf)); 6331 6332 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6333 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6334 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6335 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6336 6337 if (verify) { 6338 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6339 ciphertext_pad_len); 6340 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6341 debug_hexdump(stdout, "ciphertext:", ciphertext, 6342 ciphertext_len); 6343 } else { 6344 /* make sure enough space to cover partial digest verify case */ 6345 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6346 ciphertext_pad_len); 6347 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6348 debug_hexdump(stdout, "plaintext:", plaintext, 6349 plaintext_len); 6350 } 6351 6352 if (op_mode == OUT_OF_PLACE) 6353 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6354 6355 /* Create ZUC operation */ 6356 retval = create_wireless_algo_auth_cipher_operation( 6357 tdata->digest.data, tdata->digest.len, 6358 tdata->cipher_iv.data, tdata->cipher_iv.len, 6359 tdata->auth_iv.data, tdata->auth_iv.len, 6360 (tdata->digest.offset_bytes == 0 ? 6361 (verify ? ciphertext_pad_len : plaintext_pad_len) 6362 : tdata->digest.offset_bytes), 6363 tdata->validCipherLenInBits.len, 6364 tdata->validCipherOffsetInBits.len, 6365 tdata->validAuthLenInBits.len, 6366 0, 6367 op_mode, 0, verify); 6368 6369 if (retval < 0) 6370 return retval; 6371 6372 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6373 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6374 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6375 else 6376 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6377 ut_params->op); 6378 6379 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6380 6381 ut_params->obuf = (op_mode == IN_PLACE ? 6382 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6383 6384 6385 if (verify) { 6386 if (ut_params->obuf) 6387 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6388 uint8_t *); 6389 else 6390 plaintext = ciphertext; 6391 6392 debug_hexdump(stdout, "plaintext:", plaintext, 6393 (tdata->plaintext.len >> 3) - tdata->digest.len); 6394 debug_hexdump(stdout, "plaintext expected:", 6395 tdata->plaintext.data, 6396 (tdata->plaintext.len >> 3) - tdata->digest.len); 6397 } else { 6398 if (ut_params->obuf) 6399 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6400 uint8_t *); 6401 else 6402 ciphertext = plaintext; 6403 6404 debug_hexdump(stdout, "ciphertext:", ciphertext, 6405 ciphertext_len); 6406 debug_hexdump(stdout, "ciphertext expected:", 6407 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6408 6409 ut_params->digest = rte_pktmbuf_mtod( 6410 ut_params->obuf, uint8_t *) + 6411 (tdata->digest.offset_bytes == 0 ? 6412 plaintext_pad_len : tdata->digest.offset_bytes); 6413 6414 debug_hexdump(stdout, "digest:", ut_params->digest, 6415 tdata->digest.len); 6416 debug_hexdump(stdout, "digest expected:", 6417 tdata->digest.data, tdata->digest.len); 6418 } 6419 6420 /* Validate obuf */ 6421 if (verify) { 6422 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6423 plaintext, 6424 tdata->plaintext.data, 6425 tdata->plaintext.len >> 3, 6426 "ZUC Plaintext data not as expected"); 6427 } else { 6428 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6429 ciphertext, 6430 tdata->ciphertext.data, 6431 tdata->ciphertext.len >> 3, 6432 "ZUC Ciphertext data not as expected"); 6433 6434 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6435 ut_params->digest, 6436 tdata->digest.data, 6437 DIGEST_BYTE_LENGTH_KASUMI_F9, 6438 "ZUC Generated auth tag not as expected"); 6439 } 6440 return 0; 6441 } 6442 6443 static int 6444 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6445 uint8_t op_mode, uint8_t verify) 6446 { 6447 struct crypto_testsuite_params *ts_params = &testsuite_params; 6448 struct crypto_unittest_params *ut_params = &unittest_params; 6449 6450 int retval; 6451 6452 const uint8_t *plaintext = NULL; 6453 const uint8_t *ciphertext = NULL; 6454 const uint8_t *digest = NULL; 6455 unsigned int plaintext_pad_len; 6456 unsigned int plaintext_len; 6457 unsigned int ciphertext_pad_len; 6458 unsigned int ciphertext_len; 6459 uint8_t buffer[10000]; 6460 uint8_t digest_buffer[10000]; 6461 6462 struct rte_cryptodev_info dev_info; 6463 6464 /* Check if device supports ZUC EEA3 */ 6465 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6466 tdata->key.len, tdata->cipher_iv.len) < 0) 6467 return TEST_SKIPPED; 6468 6469 /* Check if device supports ZUC EIA3 */ 6470 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6471 tdata->key.len, tdata->auth_iv.len, 6472 tdata->digest.len) < 0) 6473 return TEST_SKIPPED; 6474 6475 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6476 6477 uint64_t feat_flags = dev_info.feature_flags; 6478 6479 if (op_mode == IN_PLACE) { 6480 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6481 printf("Device doesn't support in-place scatter-gather " 6482 "in both input and output mbufs.\n"); 6483 return TEST_SKIPPED; 6484 } 6485 6486 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6487 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6488 printf("Device doesn't support RAW data-path APIs.\n"); 6489 return TEST_SKIPPED; 6490 } 6491 } else { 6492 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6493 return TEST_SKIPPED; 6494 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6495 printf("Device doesn't support out-of-place scatter-gather " 6496 "in both input and output mbufs.\n"); 6497 return TEST_SKIPPED; 6498 } 6499 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6500 printf("Device doesn't support digest encrypted.\n"); 6501 return TEST_SKIPPED; 6502 } 6503 } 6504 6505 /* Create ZUC session */ 6506 retval = create_wireless_algo_auth_cipher_session( 6507 ts_params->valid_devs[0], 6508 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6509 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6510 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6511 : RTE_CRYPTO_AUTH_OP_GENERATE), 6512 RTE_CRYPTO_AUTH_ZUC_EIA3, 6513 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6514 tdata->key.data, tdata->key.len, 6515 tdata->auth_iv.len, tdata->digest.len, 6516 tdata->cipher_iv.len); 6517 6518 if (retval != 0) 6519 return retval; 6520 6521 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6522 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6523 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6524 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6525 6526 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6527 plaintext_pad_len, 15, 0); 6528 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6529 "Failed to allocate input buffer in mempool"); 6530 6531 if (op_mode == OUT_OF_PLACE) { 6532 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6533 plaintext_pad_len, 15, 0); 6534 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6535 "Failed to allocate output buffer in mempool"); 6536 } 6537 6538 if (verify) { 6539 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6540 tdata->ciphertext.data); 6541 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6542 ciphertext_len, buffer); 6543 debug_hexdump(stdout, "ciphertext:", ciphertext, 6544 ciphertext_len); 6545 } else { 6546 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6547 tdata->plaintext.data); 6548 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6549 plaintext_len, buffer); 6550 debug_hexdump(stdout, "plaintext:", plaintext, 6551 plaintext_len); 6552 } 6553 memset(buffer, 0, sizeof(buffer)); 6554 6555 /* Create ZUC operation */ 6556 retval = create_wireless_algo_auth_cipher_operation( 6557 tdata->digest.data, tdata->digest.len, 6558 tdata->cipher_iv.data, tdata->cipher_iv.len, 6559 NULL, 0, 6560 (tdata->digest.offset_bytes == 0 ? 6561 (verify ? ciphertext_pad_len : plaintext_pad_len) 6562 : tdata->digest.offset_bytes), 6563 tdata->validCipherLenInBits.len, 6564 tdata->validCipherOffsetInBits.len, 6565 tdata->validAuthLenInBits.len, 6566 0, 6567 op_mode, 1, verify); 6568 6569 if (retval < 0) 6570 return retval; 6571 6572 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6573 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6574 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6575 else 6576 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6577 ut_params->op); 6578 6579 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6580 6581 ut_params->obuf = (op_mode == IN_PLACE ? 6582 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6583 6584 if (verify) { 6585 if (ut_params->obuf) 6586 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6587 plaintext_len, buffer); 6588 else 6589 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6590 plaintext_len, buffer); 6591 6592 debug_hexdump(stdout, "plaintext:", plaintext, 6593 (tdata->plaintext.len >> 3) - tdata->digest.len); 6594 debug_hexdump(stdout, "plaintext expected:", 6595 tdata->plaintext.data, 6596 (tdata->plaintext.len >> 3) - tdata->digest.len); 6597 } else { 6598 if (ut_params->obuf) 6599 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6600 ciphertext_len, buffer); 6601 else 6602 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6603 ciphertext_len, buffer); 6604 6605 debug_hexdump(stdout, "ciphertext:", ciphertext, 6606 ciphertext_len); 6607 debug_hexdump(stdout, "ciphertext expected:", 6608 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6609 6610 if (ut_params->obuf) 6611 digest = rte_pktmbuf_read(ut_params->obuf, 6612 (tdata->digest.offset_bytes == 0 ? 6613 plaintext_pad_len : tdata->digest.offset_bytes), 6614 tdata->digest.len, digest_buffer); 6615 else 6616 digest = rte_pktmbuf_read(ut_params->ibuf, 6617 (tdata->digest.offset_bytes == 0 ? 6618 plaintext_pad_len : tdata->digest.offset_bytes), 6619 tdata->digest.len, digest_buffer); 6620 6621 debug_hexdump(stdout, "digest:", digest, 6622 tdata->digest.len); 6623 debug_hexdump(stdout, "digest expected:", 6624 tdata->digest.data, tdata->digest.len); 6625 } 6626 6627 /* Validate obuf */ 6628 if (verify) { 6629 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6630 plaintext, 6631 tdata->plaintext.data, 6632 tdata->plaintext.len >> 3, 6633 "ZUC Plaintext data not as expected"); 6634 } else { 6635 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6636 ciphertext, 6637 tdata->ciphertext.data, 6638 tdata->validDataLenInBits.len, 6639 "ZUC Ciphertext data not as expected"); 6640 6641 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6642 digest, 6643 tdata->digest.data, 6644 DIGEST_BYTE_LENGTH_KASUMI_F9, 6645 "ZUC Generated auth tag not as expected"); 6646 } 6647 return 0; 6648 } 6649 6650 static int 6651 test_kasumi_encryption_test_case_1(void) 6652 { 6653 return test_kasumi_encryption(&kasumi_test_case_1); 6654 } 6655 6656 static int 6657 test_kasumi_encryption_test_case_1_sgl(void) 6658 { 6659 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6660 } 6661 6662 static int 6663 test_kasumi_encryption_test_case_1_oop(void) 6664 { 6665 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6666 } 6667 6668 static int 6669 test_kasumi_encryption_test_case_1_oop_sgl(void) 6670 { 6671 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6672 } 6673 6674 static int 6675 test_kasumi_encryption_test_case_2(void) 6676 { 6677 return test_kasumi_encryption(&kasumi_test_case_2); 6678 } 6679 6680 static int 6681 test_kasumi_encryption_test_case_3(void) 6682 { 6683 return test_kasumi_encryption(&kasumi_test_case_3); 6684 } 6685 6686 static int 6687 test_kasumi_encryption_test_case_4(void) 6688 { 6689 return test_kasumi_encryption(&kasumi_test_case_4); 6690 } 6691 6692 static int 6693 test_kasumi_encryption_test_case_5(void) 6694 { 6695 return test_kasumi_encryption(&kasumi_test_case_5); 6696 } 6697 6698 static int 6699 test_kasumi_decryption_test_case_1(void) 6700 { 6701 return test_kasumi_decryption(&kasumi_test_case_1); 6702 } 6703 6704 static int 6705 test_kasumi_decryption_test_case_1_oop(void) 6706 { 6707 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6708 } 6709 6710 static int 6711 test_kasumi_decryption_test_case_2(void) 6712 { 6713 return test_kasumi_decryption(&kasumi_test_case_2); 6714 } 6715 6716 static int 6717 test_kasumi_decryption_test_case_3(void) 6718 { 6719 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6720 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6721 return TEST_SKIPPED; 6722 return test_kasumi_decryption(&kasumi_test_case_3); 6723 } 6724 6725 static int 6726 test_kasumi_decryption_test_case_4(void) 6727 { 6728 return test_kasumi_decryption(&kasumi_test_case_4); 6729 } 6730 6731 static int 6732 test_kasumi_decryption_test_case_5(void) 6733 { 6734 return test_kasumi_decryption(&kasumi_test_case_5); 6735 } 6736 static int 6737 test_snow3g_encryption_test_case_1(void) 6738 { 6739 return test_snow3g_encryption(&snow3g_test_case_1); 6740 } 6741 6742 static int 6743 test_snow3g_encryption_test_case_1_oop(void) 6744 { 6745 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6746 } 6747 6748 static int 6749 test_snow3g_encryption_test_case_1_oop_sgl(void) 6750 { 6751 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6752 } 6753 6754 6755 static int 6756 test_snow3g_encryption_test_case_1_offset_oop(void) 6757 { 6758 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6759 } 6760 6761 static int 6762 test_snow3g_encryption_test_case_2(void) 6763 { 6764 return test_snow3g_encryption(&snow3g_test_case_2); 6765 } 6766 6767 static int 6768 test_snow3g_encryption_test_case_3(void) 6769 { 6770 return test_snow3g_encryption(&snow3g_test_case_3); 6771 } 6772 6773 static int 6774 test_snow3g_encryption_test_case_4(void) 6775 { 6776 return test_snow3g_encryption(&snow3g_test_case_4); 6777 } 6778 6779 static int 6780 test_snow3g_encryption_test_case_5(void) 6781 { 6782 return test_snow3g_encryption(&snow3g_test_case_5); 6783 } 6784 6785 static int 6786 test_snow3g_decryption_test_case_1(void) 6787 { 6788 return test_snow3g_decryption(&snow3g_test_case_1); 6789 } 6790 6791 static int 6792 test_snow3g_decryption_test_case_1_oop(void) 6793 { 6794 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6795 } 6796 6797 static int 6798 test_snow3g_decryption_test_case_2(void) 6799 { 6800 return test_snow3g_decryption(&snow3g_test_case_2); 6801 } 6802 6803 static int 6804 test_snow3g_decryption_test_case_3(void) 6805 { 6806 return test_snow3g_decryption(&snow3g_test_case_3); 6807 } 6808 6809 static int 6810 test_snow3g_decryption_test_case_4(void) 6811 { 6812 return test_snow3g_decryption(&snow3g_test_case_4); 6813 } 6814 6815 static int 6816 test_snow3g_decryption_test_case_5(void) 6817 { 6818 return test_snow3g_decryption(&snow3g_test_case_5); 6819 } 6820 6821 /* 6822 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6823 * Pattern digest from snow3g_test_data must be allocated as 6824 * 4 last bytes in plaintext. 6825 */ 6826 static void 6827 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6828 struct snow3g_hash_test_data *output) 6829 { 6830 if ((pattern != NULL) && (output != NULL)) { 6831 output->key.len = pattern->key.len; 6832 6833 memcpy(output->key.data, 6834 pattern->key.data, pattern->key.len); 6835 6836 output->auth_iv.len = pattern->auth_iv.len; 6837 6838 memcpy(output->auth_iv.data, 6839 pattern->auth_iv.data, pattern->auth_iv.len); 6840 6841 output->plaintext.len = pattern->plaintext.len; 6842 6843 memcpy(output->plaintext.data, 6844 pattern->plaintext.data, pattern->plaintext.len >> 3); 6845 6846 output->digest.len = pattern->digest.len; 6847 6848 memcpy(output->digest.data, 6849 &pattern->plaintext.data[pattern->digest.offset_bytes], 6850 pattern->digest.len); 6851 6852 output->validAuthLenInBits.len = 6853 pattern->validAuthLenInBits.len; 6854 } 6855 } 6856 6857 /* 6858 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6859 */ 6860 static int 6861 test_snow3g_decryption_with_digest_test_case_1(void) 6862 { 6863 struct snow3g_hash_test_data snow3g_hash_data; 6864 struct rte_cryptodev_info dev_info; 6865 struct crypto_testsuite_params *ts_params = &testsuite_params; 6866 6867 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6868 uint64_t feat_flags = dev_info.feature_flags; 6869 6870 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6871 printf("Device doesn't support encrypted digest operations.\n"); 6872 return TEST_SKIPPED; 6873 } 6874 6875 /* 6876 * Function prepare data for hash veryfication test case. 6877 * Digest is allocated in 4 last bytes in plaintext, pattern. 6878 */ 6879 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6880 6881 return test_snow3g_decryption(&snow3g_test_case_7) & 6882 test_snow3g_authentication_verify(&snow3g_hash_data); 6883 } 6884 6885 static int 6886 test_snow3g_cipher_auth_test_case_1(void) 6887 { 6888 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6889 } 6890 6891 static int 6892 test_snow3g_auth_cipher_test_case_1(void) 6893 { 6894 return test_snow3g_auth_cipher( 6895 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6896 } 6897 6898 static int 6899 test_snow3g_auth_cipher_test_case_2(void) 6900 { 6901 return test_snow3g_auth_cipher( 6902 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6903 } 6904 6905 static int 6906 test_snow3g_auth_cipher_test_case_2_oop(void) 6907 { 6908 return test_snow3g_auth_cipher( 6909 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6910 } 6911 6912 static int 6913 test_snow3g_auth_cipher_part_digest_enc(void) 6914 { 6915 return test_snow3g_auth_cipher( 6916 &snow3g_auth_cipher_partial_digest_encryption, 6917 IN_PLACE, 0); 6918 } 6919 6920 static int 6921 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6922 { 6923 return test_snow3g_auth_cipher( 6924 &snow3g_auth_cipher_partial_digest_encryption, 6925 OUT_OF_PLACE, 0); 6926 } 6927 6928 static int 6929 test_snow3g_auth_cipher_test_case_3_sgl(void) 6930 { 6931 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6932 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6933 return TEST_SKIPPED; 6934 return test_snow3g_auth_cipher_sgl( 6935 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6936 } 6937 6938 static int 6939 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6940 { 6941 return test_snow3g_auth_cipher_sgl( 6942 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6943 } 6944 6945 static int 6946 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6947 { 6948 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6949 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6950 return TEST_SKIPPED; 6951 return test_snow3g_auth_cipher_sgl( 6952 &snow3g_auth_cipher_partial_digest_encryption, 6953 IN_PLACE, 0); 6954 } 6955 6956 static int 6957 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6958 { 6959 return test_snow3g_auth_cipher_sgl( 6960 &snow3g_auth_cipher_partial_digest_encryption, 6961 OUT_OF_PLACE, 0); 6962 } 6963 6964 static int 6965 test_snow3g_auth_cipher_verify_test_case_1(void) 6966 { 6967 return test_snow3g_auth_cipher( 6968 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6969 } 6970 6971 static int 6972 test_snow3g_auth_cipher_verify_test_case_2(void) 6973 { 6974 return test_snow3g_auth_cipher( 6975 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6976 } 6977 6978 static int 6979 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6980 { 6981 return test_snow3g_auth_cipher( 6982 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6983 } 6984 6985 static int 6986 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6987 { 6988 return test_snow3g_auth_cipher( 6989 &snow3g_auth_cipher_partial_digest_encryption, 6990 IN_PLACE, 1); 6991 } 6992 6993 static int 6994 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6995 { 6996 return test_snow3g_auth_cipher( 6997 &snow3g_auth_cipher_partial_digest_encryption, 6998 OUT_OF_PLACE, 1); 6999 } 7000 7001 static int 7002 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7003 { 7004 return test_snow3g_auth_cipher_sgl( 7005 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7006 } 7007 7008 static int 7009 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7010 { 7011 return test_snow3g_auth_cipher_sgl( 7012 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7013 } 7014 7015 static int 7016 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7017 { 7018 return test_snow3g_auth_cipher_sgl( 7019 &snow3g_auth_cipher_partial_digest_encryption, 7020 IN_PLACE, 1); 7021 } 7022 7023 static int 7024 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7025 { 7026 return test_snow3g_auth_cipher_sgl( 7027 &snow3g_auth_cipher_partial_digest_encryption, 7028 OUT_OF_PLACE, 1); 7029 } 7030 7031 static int 7032 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7033 { 7034 return test_snow3g_auth_cipher( 7035 &snow3g_test_case_7, IN_PLACE, 0); 7036 } 7037 7038 static int 7039 test_kasumi_auth_cipher_test_case_1(void) 7040 { 7041 return test_kasumi_auth_cipher( 7042 &kasumi_test_case_3, IN_PLACE, 0); 7043 } 7044 7045 static int 7046 test_kasumi_auth_cipher_test_case_2(void) 7047 { 7048 return test_kasumi_auth_cipher( 7049 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7050 } 7051 7052 static int 7053 test_kasumi_auth_cipher_test_case_2_oop(void) 7054 { 7055 return test_kasumi_auth_cipher( 7056 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7057 } 7058 7059 static int 7060 test_kasumi_auth_cipher_test_case_2_sgl(void) 7061 { 7062 return test_kasumi_auth_cipher_sgl( 7063 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7064 } 7065 7066 static int 7067 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7068 { 7069 return test_kasumi_auth_cipher_sgl( 7070 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7071 } 7072 7073 static int 7074 test_kasumi_auth_cipher_verify_test_case_1(void) 7075 { 7076 return test_kasumi_auth_cipher( 7077 &kasumi_test_case_3, IN_PLACE, 1); 7078 } 7079 7080 static int 7081 test_kasumi_auth_cipher_verify_test_case_2(void) 7082 { 7083 return test_kasumi_auth_cipher( 7084 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7085 } 7086 7087 static int 7088 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7089 { 7090 return test_kasumi_auth_cipher( 7091 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7092 } 7093 7094 static int 7095 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7096 { 7097 return test_kasumi_auth_cipher_sgl( 7098 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7099 } 7100 7101 static int 7102 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7103 { 7104 return test_kasumi_auth_cipher_sgl( 7105 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7106 } 7107 7108 static int 7109 test_kasumi_cipher_auth_test_case_1(void) 7110 { 7111 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7112 } 7113 7114 static int 7115 test_zuc_encryption_test_case_1(void) 7116 { 7117 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7118 } 7119 7120 static int 7121 test_zuc_encryption_test_case_2(void) 7122 { 7123 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7124 } 7125 7126 static int 7127 test_zuc_encryption_test_case_3(void) 7128 { 7129 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7130 } 7131 7132 static int 7133 test_zuc_encryption_test_case_4(void) 7134 { 7135 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7136 } 7137 7138 static int 7139 test_zuc_encryption_test_case_5(void) 7140 { 7141 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7142 } 7143 7144 static int 7145 test_zuc_encryption_test_case_6_sgl(void) 7146 { 7147 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7148 } 7149 7150 static int 7151 test_zuc_hash_generate_test_case_1(void) 7152 { 7153 return test_zuc_authentication(&zuc_test_case_auth_1b); 7154 } 7155 7156 static int 7157 test_zuc_hash_generate_test_case_2(void) 7158 { 7159 return test_zuc_authentication(&zuc_test_case_auth_90b); 7160 } 7161 7162 static int 7163 test_zuc_hash_generate_test_case_3(void) 7164 { 7165 return test_zuc_authentication(&zuc_test_case_auth_577b); 7166 } 7167 7168 static int 7169 test_zuc_hash_generate_test_case_4(void) 7170 { 7171 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7172 } 7173 7174 static int 7175 test_zuc_hash_generate_test_case_5(void) 7176 { 7177 return test_zuc_authentication(&zuc_test_auth_5670b); 7178 } 7179 7180 static int 7181 test_zuc_hash_generate_test_case_6(void) 7182 { 7183 return test_zuc_authentication(&zuc_test_case_auth_128b); 7184 } 7185 7186 static int 7187 test_zuc_hash_generate_test_case_7(void) 7188 { 7189 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7190 } 7191 7192 static int 7193 test_zuc_hash_generate_test_case_8(void) 7194 { 7195 return test_zuc_authentication(&zuc_test_case_auth_584b); 7196 } 7197 7198 static int 7199 test_zuc_hash_generate_test_case_9(void) 7200 { 7201 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b); 7202 } 7203 7204 static int 7205 test_zuc_hash_generate_test_case_10(void) 7206 { 7207 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b); 7208 } 7209 7210 static int 7211 test_zuc_hash_generate_test_case_11(void) 7212 { 7213 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b); 7214 } 7215 7216 static int 7217 test_zuc_cipher_auth_test_case_1(void) 7218 { 7219 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7220 } 7221 7222 static int 7223 test_zuc_cipher_auth_test_case_2(void) 7224 { 7225 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7226 } 7227 7228 static int 7229 test_zuc_auth_cipher_test_case_1(void) 7230 { 7231 return test_zuc_auth_cipher( 7232 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7233 } 7234 7235 static int 7236 test_zuc_auth_cipher_test_case_1_oop(void) 7237 { 7238 return test_zuc_auth_cipher( 7239 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7240 } 7241 7242 static int 7243 test_zuc_auth_cipher_test_case_1_sgl(void) 7244 { 7245 return test_zuc_auth_cipher_sgl( 7246 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7247 } 7248 7249 static int 7250 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7251 { 7252 return test_zuc_auth_cipher_sgl( 7253 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7254 } 7255 7256 static int 7257 test_zuc_auth_cipher_verify_test_case_1(void) 7258 { 7259 return test_zuc_auth_cipher( 7260 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7261 } 7262 7263 static int 7264 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7265 { 7266 return test_zuc_auth_cipher( 7267 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7268 } 7269 7270 static int 7271 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7272 { 7273 return test_zuc_auth_cipher_sgl( 7274 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7275 } 7276 7277 static int 7278 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7279 { 7280 return test_zuc_auth_cipher_sgl( 7281 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7282 } 7283 7284 static int 7285 test_zuc256_encryption_test_case_1(void) 7286 { 7287 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7288 } 7289 7290 static int 7291 test_zuc256_encryption_test_case_2(void) 7292 { 7293 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7294 } 7295 7296 static int 7297 test_zuc256_authentication_test_case_1(void) 7298 { 7299 return test_zuc_authentication(&zuc256_test_case_auth_1); 7300 } 7301 7302 static int 7303 test_zuc256_authentication_test_case_2(void) 7304 { 7305 return test_zuc_authentication(&zuc256_test_case_auth_2); 7306 } 7307 7308 static int 7309 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7310 { 7311 uint8_t dev_id = testsuite_params.valid_devs[0]; 7312 7313 struct rte_cryptodev_sym_capability_idx cap_idx; 7314 7315 /* Check if device supports particular cipher algorithm */ 7316 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7317 cap_idx.algo.cipher = tdata->cipher_algo; 7318 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7319 return TEST_SKIPPED; 7320 7321 /* Check if device supports particular hash algorithm */ 7322 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7323 cap_idx.algo.auth = tdata->auth_algo; 7324 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7325 return TEST_SKIPPED; 7326 7327 return 0; 7328 } 7329 7330 static int 7331 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7332 uint8_t op_mode, uint8_t verify) 7333 { 7334 struct crypto_testsuite_params *ts_params = &testsuite_params; 7335 struct crypto_unittest_params *ut_params = &unittest_params; 7336 7337 int retval; 7338 7339 uint8_t *plaintext = NULL, *ciphertext = NULL; 7340 unsigned int plaintext_pad_len; 7341 unsigned int plaintext_len; 7342 unsigned int ciphertext_pad_len; 7343 unsigned int ciphertext_len; 7344 7345 struct rte_cryptodev_info dev_info; 7346 struct rte_crypto_op *op; 7347 7348 /* Check if device supports particular algorithms separately */ 7349 if (test_mixed_check_if_unsupported(tdata)) 7350 return TEST_SKIPPED; 7351 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7352 return TEST_SKIPPED; 7353 7354 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7355 7356 uint64_t feat_flags = dev_info.feature_flags; 7357 7358 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7359 printf("Device doesn't support digest encrypted.\n"); 7360 return TEST_SKIPPED; 7361 } 7362 7363 /* Create the session */ 7364 if (verify) 7365 retval = create_wireless_algo_cipher_auth_session( 7366 ts_params->valid_devs[0], 7367 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7368 RTE_CRYPTO_AUTH_OP_VERIFY, 7369 tdata->auth_algo, 7370 tdata->cipher_algo, 7371 tdata->auth_key.data, tdata->auth_key.len, 7372 tdata->auth_iv.len, tdata->digest_enc.len, 7373 tdata->cipher_iv.len); 7374 else 7375 retval = create_wireless_algo_auth_cipher_session( 7376 ts_params->valid_devs[0], 7377 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7378 RTE_CRYPTO_AUTH_OP_GENERATE, 7379 tdata->auth_algo, 7380 tdata->cipher_algo, 7381 tdata->auth_key.data, tdata->auth_key.len, 7382 tdata->auth_iv.len, tdata->digest_enc.len, 7383 tdata->cipher_iv.len); 7384 if (retval != 0) 7385 return retval; 7386 7387 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7388 if (op_mode == OUT_OF_PLACE) 7389 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7390 7391 /* clear mbuf payload */ 7392 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7393 rte_pktmbuf_tailroom(ut_params->ibuf)); 7394 if (op_mode == OUT_OF_PLACE) { 7395 7396 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7397 rte_pktmbuf_tailroom(ut_params->obuf)); 7398 } 7399 7400 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7401 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7402 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7403 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7404 7405 if (verify) { 7406 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7407 ciphertext_pad_len); 7408 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7409 debug_hexdump(stdout, "ciphertext:", ciphertext, 7410 ciphertext_len); 7411 } else { 7412 /* make sure enough space to cover partial digest verify case */ 7413 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7414 ciphertext_pad_len); 7415 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7416 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7417 } 7418 7419 if (op_mode == OUT_OF_PLACE) 7420 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7421 7422 /* Create the operation */ 7423 retval = create_wireless_algo_auth_cipher_operation( 7424 tdata->digest_enc.data, tdata->digest_enc.len, 7425 tdata->cipher_iv.data, tdata->cipher_iv.len, 7426 tdata->auth_iv.data, tdata->auth_iv.len, 7427 (tdata->digest_enc.offset == 0 ? 7428 plaintext_pad_len 7429 : tdata->digest_enc.offset), 7430 tdata->validCipherLen.len_bits, 7431 tdata->cipher.offset_bits, 7432 tdata->validAuthLen.len_bits, 7433 tdata->auth.offset_bits, 7434 op_mode, 0, verify); 7435 7436 if (retval < 0) 7437 return retval; 7438 7439 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7440 7441 /* Check if the op failed because the device doesn't */ 7442 /* support this particular combination of algorithms */ 7443 if (op == NULL && ut_params->op->status == 7444 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7445 printf("Device doesn't support this mixed combination. " 7446 "Test Skipped.\n"); 7447 return TEST_SKIPPED; 7448 } 7449 ut_params->op = op; 7450 7451 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7452 7453 ut_params->obuf = (op_mode == IN_PLACE ? 7454 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7455 7456 if (verify) { 7457 if (ut_params->obuf) 7458 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7459 uint8_t *); 7460 else 7461 plaintext = ciphertext + 7462 (tdata->cipher.offset_bits >> 3); 7463 7464 debug_hexdump(stdout, "plaintext:", plaintext, 7465 tdata->plaintext.len_bits >> 3); 7466 debug_hexdump(stdout, "plaintext expected:", 7467 tdata->plaintext.data, 7468 tdata->plaintext.len_bits >> 3); 7469 } else { 7470 if (ut_params->obuf) 7471 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7472 uint8_t *); 7473 else 7474 ciphertext = plaintext; 7475 7476 debug_hexdump(stdout, "ciphertext:", ciphertext, 7477 ciphertext_len); 7478 debug_hexdump(stdout, "ciphertext expected:", 7479 tdata->ciphertext.data, 7480 tdata->ciphertext.len_bits >> 3); 7481 7482 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7483 + (tdata->digest_enc.offset == 0 ? 7484 plaintext_pad_len : tdata->digest_enc.offset); 7485 7486 debug_hexdump(stdout, "digest:", ut_params->digest, 7487 tdata->digest_enc.len); 7488 debug_hexdump(stdout, "digest expected:", 7489 tdata->digest_enc.data, 7490 tdata->digest_enc.len); 7491 } 7492 7493 if (!verify) { 7494 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7495 ut_params->digest, 7496 tdata->digest_enc.data, 7497 tdata->digest_enc.len, 7498 "Generated auth tag not as expected"); 7499 } 7500 7501 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7502 if (verify) { 7503 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7504 plaintext, 7505 tdata->plaintext.data, 7506 tdata->plaintext.len_bits >> 3, 7507 "Plaintext data not as expected"); 7508 } else { 7509 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7510 ciphertext, 7511 tdata->ciphertext.data, 7512 tdata->validDataLen.len_bits, 7513 "Ciphertext data not as expected"); 7514 } 7515 } 7516 7517 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7518 "crypto op processing failed"); 7519 7520 return 0; 7521 } 7522 7523 static int 7524 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7525 uint8_t op_mode, uint8_t verify) 7526 { 7527 struct crypto_testsuite_params *ts_params = &testsuite_params; 7528 struct crypto_unittest_params *ut_params = &unittest_params; 7529 7530 int retval; 7531 7532 const uint8_t *plaintext = NULL; 7533 const uint8_t *ciphertext = NULL; 7534 const uint8_t *digest = NULL; 7535 unsigned int plaintext_pad_len; 7536 unsigned int plaintext_len; 7537 unsigned int ciphertext_pad_len; 7538 unsigned int ciphertext_len; 7539 uint8_t buffer[10000]; 7540 uint8_t digest_buffer[10000]; 7541 7542 struct rte_cryptodev_info dev_info; 7543 struct rte_crypto_op *op; 7544 7545 /* Check if device supports particular algorithms */ 7546 if (test_mixed_check_if_unsupported(tdata)) 7547 return TEST_SKIPPED; 7548 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7549 return TEST_SKIPPED; 7550 7551 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7552 7553 uint64_t feat_flags = dev_info.feature_flags; 7554 7555 if (op_mode == IN_PLACE) { 7556 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7557 printf("Device doesn't support in-place scatter-gather " 7558 "in both input and output mbufs.\n"); 7559 return TEST_SKIPPED; 7560 } 7561 } else { 7562 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7563 printf("Device doesn't support out-of-place scatter-gather " 7564 "in both input and output mbufs.\n"); 7565 return TEST_SKIPPED; 7566 } 7567 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7568 printf("Device doesn't support digest encrypted.\n"); 7569 return TEST_SKIPPED; 7570 } 7571 } 7572 7573 /* Create the session */ 7574 if (verify) 7575 retval = create_wireless_algo_cipher_auth_session( 7576 ts_params->valid_devs[0], 7577 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7578 RTE_CRYPTO_AUTH_OP_VERIFY, 7579 tdata->auth_algo, 7580 tdata->cipher_algo, 7581 tdata->auth_key.data, tdata->auth_key.len, 7582 tdata->auth_iv.len, tdata->digest_enc.len, 7583 tdata->cipher_iv.len); 7584 else 7585 retval = create_wireless_algo_auth_cipher_session( 7586 ts_params->valid_devs[0], 7587 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7588 RTE_CRYPTO_AUTH_OP_GENERATE, 7589 tdata->auth_algo, 7590 tdata->cipher_algo, 7591 tdata->auth_key.data, tdata->auth_key.len, 7592 tdata->auth_iv.len, tdata->digest_enc.len, 7593 tdata->cipher_iv.len); 7594 if (retval != 0) 7595 return retval; 7596 7597 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7598 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7599 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7600 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7601 7602 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7603 ciphertext_pad_len, 15, 0); 7604 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7605 "Failed to allocate input buffer in mempool"); 7606 7607 if (op_mode == OUT_OF_PLACE) { 7608 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7609 plaintext_pad_len, 15, 0); 7610 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7611 "Failed to allocate output buffer in mempool"); 7612 } 7613 7614 if (verify) { 7615 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7616 tdata->ciphertext.data); 7617 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7618 ciphertext_len, buffer); 7619 debug_hexdump(stdout, "ciphertext:", ciphertext, 7620 ciphertext_len); 7621 } else { 7622 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7623 tdata->plaintext.data); 7624 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7625 plaintext_len, buffer); 7626 debug_hexdump(stdout, "plaintext:", plaintext, 7627 plaintext_len); 7628 } 7629 memset(buffer, 0, sizeof(buffer)); 7630 7631 /* Create the operation */ 7632 retval = create_wireless_algo_auth_cipher_operation( 7633 tdata->digest_enc.data, tdata->digest_enc.len, 7634 tdata->cipher_iv.data, tdata->cipher_iv.len, 7635 tdata->auth_iv.data, tdata->auth_iv.len, 7636 (tdata->digest_enc.offset == 0 ? 7637 plaintext_pad_len 7638 : tdata->digest_enc.offset), 7639 tdata->validCipherLen.len_bits, 7640 tdata->cipher.offset_bits, 7641 tdata->validAuthLen.len_bits, 7642 tdata->auth.offset_bits, 7643 op_mode, 1, verify); 7644 7645 if (retval < 0) 7646 return retval; 7647 7648 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7649 7650 /* Check if the op failed because the device doesn't */ 7651 /* support this particular combination of algorithms */ 7652 if (op == NULL && ut_params->op->status == 7653 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7654 printf("Device doesn't support this mixed combination. " 7655 "Test Skipped.\n"); 7656 return TEST_SKIPPED; 7657 } 7658 ut_params->op = op; 7659 7660 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7661 7662 ut_params->obuf = (op_mode == IN_PLACE ? 7663 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7664 7665 if (verify) { 7666 if (ut_params->obuf) 7667 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7668 plaintext_len, buffer); 7669 else 7670 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7671 plaintext_len, buffer); 7672 7673 debug_hexdump(stdout, "plaintext:", plaintext, 7674 (tdata->plaintext.len_bits >> 3) - 7675 tdata->digest_enc.len); 7676 debug_hexdump(stdout, "plaintext expected:", 7677 tdata->plaintext.data, 7678 (tdata->plaintext.len_bits >> 3) - 7679 tdata->digest_enc.len); 7680 } else { 7681 if (ut_params->obuf) 7682 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7683 ciphertext_len, buffer); 7684 else 7685 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7686 ciphertext_len, buffer); 7687 7688 debug_hexdump(stdout, "ciphertext:", ciphertext, 7689 ciphertext_len); 7690 debug_hexdump(stdout, "ciphertext expected:", 7691 tdata->ciphertext.data, 7692 tdata->ciphertext.len_bits >> 3); 7693 7694 if (ut_params->obuf) 7695 digest = rte_pktmbuf_read(ut_params->obuf, 7696 (tdata->digest_enc.offset == 0 ? 7697 plaintext_pad_len : 7698 tdata->digest_enc.offset), 7699 tdata->digest_enc.len, digest_buffer); 7700 else 7701 digest = rte_pktmbuf_read(ut_params->ibuf, 7702 (tdata->digest_enc.offset == 0 ? 7703 plaintext_pad_len : 7704 tdata->digest_enc.offset), 7705 tdata->digest_enc.len, digest_buffer); 7706 7707 debug_hexdump(stdout, "digest:", digest, 7708 tdata->digest_enc.len); 7709 debug_hexdump(stdout, "digest expected:", 7710 tdata->digest_enc.data, tdata->digest_enc.len); 7711 } 7712 7713 if (!verify) { 7714 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7715 digest, 7716 tdata->digest_enc.data, 7717 tdata->digest_enc.len, 7718 "Generated auth tag not as expected"); 7719 } 7720 7721 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7722 if (verify) { 7723 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7724 plaintext, 7725 tdata->plaintext.data, 7726 tdata->plaintext.len_bits >> 3, 7727 "Plaintext data not as expected"); 7728 } else { 7729 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7730 ciphertext, 7731 tdata->ciphertext.data, 7732 tdata->validDataLen.len_bits, 7733 "Ciphertext data not as expected"); 7734 } 7735 } 7736 7737 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7738 "crypto op processing failed"); 7739 7740 return 0; 7741 } 7742 7743 /** AUTH AES CMAC + CIPHER AES CTR */ 7744 7745 static int 7746 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7747 { 7748 return test_mixed_auth_cipher( 7749 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7750 } 7751 7752 static int 7753 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7754 { 7755 return test_mixed_auth_cipher( 7756 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7757 } 7758 7759 static int 7760 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7761 { 7762 return test_mixed_auth_cipher_sgl( 7763 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7764 } 7765 7766 static int 7767 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7768 { 7769 return test_mixed_auth_cipher_sgl( 7770 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7771 } 7772 7773 static int 7774 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7775 { 7776 return test_mixed_auth_cipher( 7777 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7778 } 7779 7780 static int 7781 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7782 { 7783 return test_mixed_auth_cipher( 7784 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7785 } 7786 7787 static int 7788 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7789 { 7790 return test_mixed_auth_cipher_sgl( 7791 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7792 } 7793 7794 static int 7795 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7796 { 7797 return test_mixed_auth_cipher_sgl( 7798 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7799 } 7800 7801 /** MIXED AUTH + CIPHER */ 7802 7803 static int 7804 test_auth_zuc_cipher_snow_test_case_1(void) 7805 { 7806 return test_mixed_auth_cipher( 7807 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7808 } 7809 7810 static int 7811 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7812 { 7813 return test_mixed_auth_cipher( 7814 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7815 } 7816 7817 static int 7818 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7819 { 7820 return test_mixed_auth_cipher( 7821 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7822 } 7823 7824 static int 7825 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7826 { 7827 return test_mixed_auth_cipher( 7828 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7829 } 7830 7831 static int 7832 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7833 { 7834 return test_mixed_auth_cipher( 7835 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7836 } 7837 7838 static int 7839 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7840 { 7841 return test_mixed_auth_cipher( 7842 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7843 } 7844 7845 static int 7846 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7847 { 7848 return test_mixed_auth_cipher( 7849 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7850 } 7851 7852 static int 7853 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7854 { 7855 return test_mixed_auth_cipher( 7856 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7857 } 7858 7859 static int 7860 test_auth_snow_cipher_zuc_test_case_1(void) 7861 { 7862 return test_mixed_auth_cipher( 7863 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7864 } 7865 7866 static int 7867 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7868 { 7869 return test_mixed_auth_cipher( 7870 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7871 } 7872 7873 static int 7874 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7875 { 7876 return test_mixed_auth_cipher( 7877 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7878 } 7879 7880 static int 7881 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7882 { 7883 return test_mixed_auth_cipher( 7884 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7885 } 7886 7887 static int 7888 test_auth_null_cipher_snow_test_case_1(void) 7889 { 7890 return test_mixed_auth_cipher( 7891 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7892 } 7893 7894 static int 7895 test_verify_auth_null_cipher_snow_test_case_1(void) 7896 { 7897 return test_mixed_auth_cipher( 7898 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7899 } 7900 7901 static int 7902 test_auth_null_cipher_zuc_test_case_1(void) 7903 { 7904 return test_mixed_auth_cipher( 7905 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7906 } 7907 7908 static int 7909 test_verify_auth_null_cipher_zuc_test_case_1(void) 7910 { 7911 return test_mixed_auth_cipher( 7912 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7913 } 7914 7915 static int 7916 test_auth_snow_cipher_null_test_case_1(void) 7917 { 7918 return test_mixed_auth_cipher( 7919 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7920 } 7921 7922 static int 7923 test_verify_auth_snow_cipher_null_test_case_1(void) 7924 { 7925 return test_mixed_auth_cipher( 7926 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7927 } 7928 7929 static int 7930 test_auth_zuc_cipher_null_test_case_1(void) 7931 { 7932 return test_mixed_auth_cipher( 7933 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7934 } 7935 7936 static int 7937 test_verify_auth_zuc_cipher_null_test_case_1(void) 7938 { 7939 return test_mixed_auth_cipher( 7940 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7941 } 7942 7943 static int 7944 test_auth_null_cipher_aes_ctr_test_case_1(void) 7945 { 7946 return test_mixed_auth_cipher( 7947 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7948 } 7949 7950 static int 7951 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7952 { 7953 return test_mixed_auth_cipher( 7954 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7955 } 7956 7957 static int 7958 test_auth_aes_cmac_cipher_null_test_case_1(void) 7959 { 7960 return test_mixed_auth_cipher( 7961 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7962 } 7963 7964 static int 7965 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7966 { 7967 return test_mixed_auth_cipher( 7968 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7969 } 7970 7971 /* ***** AEAD algorithm Tests ***** */ 7972 7973 static int 7974 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7975 enum rte_crypto_aead_operation op, 7976 const uint8_t *key, const uint8_t key_len, 7977 const uint16_t aad_len, const uint8_t auth_len, 7978 uint8_t iv_len) 7979 { 7980 uint8_t aead_key[key_len]; 7981 int status; 7982 7983 struct crypto_testsuite_params *ts_params = &testsuite_params; 7984 struct crypto_unittest_params *ut_params = &unittest_params; 7985 7986 memcpy(aead_key, key, key_len); 7987 7988 /* Setup AEAD Parameters */ 7989 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7990 ut_params->aead_xform.next = NULL; 7991 ut_params->aead_xform.aead.algo = algo; 7992 ut_params->aead_xform.aead.op = op; 7993 ut_params->aead_xform.aead.key.data = aead_key; 7994 ut_params->aead_xform.aead.key.length = key_len; 7995 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7996 ut_params->aead_xform.aead.iv.length = iv_len; 7997 ut_params->aead_xform.aead.digest_length = auth_len; 7998 ut_params->aead_xform.aead.aad_length = aad_len; 7999 8000 debug_hexdump(stdout, "key:", key, key_len); 8001 8002 /* Create Crypto session*/ 8003 ut_params->sess = rte_cryptodev_sym_session_create( 8004 ts_params->session_mpool); 8005 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8006 8007 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 8008 &ut_params->aead_xform, 8009 ts_params->session_priv_mpool); 8010 8011 return status; 8012 } 8013 8014 static int 8015 create_aead_xform(struct rte_crypto_op *op, 8016 enum rte_crypto_aead_algorithm algo, 8017 enum rte_crypto_aead_operation aead_op, 8018 uint8_t *key, const uint8_t key_len, 8019 const uint8_t aad_len, const uint8_t auth_len, 8020 uint8_t iv_len) 8021 { 8022 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8023 "failed to allocate space for crypto transform"); 8024 8025 struct rte_crypto_sym_op *sym_op = op->sym; 8026 8027 /* Setup AEAD Parameters */ 8028 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8029 sym_op->xform->next = NULL; 8030 sym_op->xform->aead.algo = algo; 8031 sym_op->xform->aead.op = aead_op; 8032 sym_op->xform->aead.key.data = key; 8033 sym_op->xform->aead.key.length = key_len; 8034 sym_op->xform->aead.iv.offset = IV_OFFSET; 8035 sym_op->xform->aead.iv.length = iv_len; 8036 sym_op->xform->aead.digest_length = auth_len; 8037 sym_op->xform->aead.aad_length = aad_len; 8038 8039 debug_hexdump(stdout, "key:", key, key_len); 8040 8041 return 0; 8042 } 8043 8044 static int 8045 create_aead_operation(enum rte_crypto_aead_operation op, 8046 const struct aead_test_data *tdata) 8047 { 8048 struct crypto_testsuite_params *ts_params = &testsuite_params; 8049 struct crypto_unittest_params *ut_params = &unittest_params; 8050 8051 uint8_t *plaintext, *ciphertext; 8052 unsigned int aad_pad_len, plaintext_pad_len; 8053 8054 /* Generate Crypto op data structure */ 8055 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8056 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8057 TEST_ASSERT_NOT_NULL(ut_params->op, 8058 "Failed to allocate symmetric crypto operation struct"); 8059 8060 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8061 8062 /* Append aad data */ 8063 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8064 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8065 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8066 aad_pad_len); 8067 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8068 "no room to append aad"); 8069 8070 sym_op->aead.aad.phys_addr = 8071 rte_pktmbuf_iova(ut_params->ibuf); 8072 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8073 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8074 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8075 tdata->aad.len); 8076 8077 /* Append IV at the end of the crypto operation*/ 8078 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8079 uint8_t *, IV_OFFSET); 8080 8081 /* Copy IV 1 byte after the IV pointer, according to the API */ 8082 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8083 debug_hexdump(stdout, "iv:", iv_ptr, 8084 tdata->iv.len); 8085 } else { 8086 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8087 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8088 aad_pad_len); 8089 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8090 "no room to append aad"); 8091 8092 sym_op->aead.aad.phys_addr = 8093 rte_pktmbuf_iova(ut_params->ibuf); 8094 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8095 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8096 tdata->aad.len); 8097 8098 /* Append IV at the end of the crypto operation*/ 8099 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8100 uint8_t *, IV_OFFSET); 8101 8102 if (tdata->iv.len == 0) { 8103 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8104 debug_hexdump(stdout, "iv:", iv_ptr, 8105 AES_GCM_J0_LENGTH); 8106 } else { 8107 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8108 debug_hexdump(stdout, "iv:", iv_ptr, 8109 tdata->iv.len); 8110 } 8111 } 8112 8113 /* Append plaintext/ciphertext */ 8114 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8115 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8116 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8117 plaintext_pad_len); 8118 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8119 8120 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8121 debug_hexdump(stdout, "plaintext:", plaintext, 8122 tdata->plaintext.len); 8123 8124 if (ut_params->obuf) { 8125 ciphertext = (uint8_t *)rte_pktmbuf_append( 8126 ut_params->obuf, 8127 plaintext_pad_len + aad_pad_len); 8128 TEST_ASSERT_NOT_NULL(ciphertext, 8129 "no room to append ciphertext"); 8130 8131 memset(ciphertext + aad_pad_len, 0, 8132 tdata->ciphertext.len); 8133 } 8134 } else { 8135 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8136 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8137 plaintext_pad_len); 8138 TEST_ASSERT_NOT_NULL(ciphertext, 8139 "no room to append ciphertext"); 8140 8141 memcpy(ciphertext, tdata->ciphertext.data, 8142 tdata->ciphertext.len); 8143 debug_hexdump(stdout, "ciphertext:", ciphertext, 8144 tdata->ciphertext.len); 8145 8146 if (ut_params->obuf) { 8147 plaintext = (uint8_t *)rte_pktmbuf_append( 8148 ut_params->obuf, 8149 plaintext_pad_len + aad_pad_len); 8150 TEST_ASSERT_NOT_NULL(plaintext, 8151 "no room to append plaintext"); 8152 8153 memset(plaintext + aad_pad_len, 0, 8154 tdata->plaintext.len); 8155 } 8156 } 8157 8158 /* Append digest data */ 8159 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8160 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8161 ut_params->obuf ? ut_params->obuf : 8162 ut_params->ibuf, 8163 tdata->auth_tag.len); 8164 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8165 "no room to append digest"); 8166 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8167 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8168 ut_params->obuf ? ut_params->obuf : 8169 ut_params->ibuf, 8170 plaintext_pad_len + 8171 aad_pad_len); 8172 } else { 8173 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8174 ut_params->ibuf, tdata->auth_tag.len); 8175 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8176 "no room to append digest"); 8177 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8178 ut_params->ibuf, 8179 plaintext_pad_len + aad_pad_len); 8180 8181 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8182 tdata->auth_tag.len); 8183 debug_hexdump(stdout, "digest:", 8184 sym_op->aead.digest.data, 8185 tdata->auth_tag.len); 8186 } 8187 8188 sym_op->aead.data.length = tdata->plaintext.len; 8189 sym_op->aead.data.offset = aad_pad_len; 8190 8191 return 0; 8192 } 8193 8194 static int 8195 test_authenticated_encryption(const struct aead_test_data *tdata) 8196 { 8197 struct crypto_testsuite_params *ts_params = &testsuite_params; 8198 struct crypto_unittest_params *ut_params = &unittest_params; 8199 8200 int retval; 8201 uint8_t *ciphertext, *auth_tag; 8202 uint16_t plaintext_pad_len; 8203 uint32_t i; 8204 struct rte_cryptodev_info dev_info; 8205 8206 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8207 uint64_t feat_flags = dev_info.feature_flags; 8208 8209 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8210 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8211 printf("Device doesn't support RAW data-path APIs.\n"); 8212 return TEST_SKIPPED; 8213 } 8214 8215 /* Verify the capabilities */ 8216 struct rte_cryptodev_sym_capability_idx cap_idx; 8217 const struct rte_cryptodev_symmetric_capability *capability; 8218 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8219 cap_idx.algo.aead = tdata->algo; 8220 capability = rte_cryptodev_sym_capability_get( 8221 ts_params->valid_devs[0], &cap_idx); 8222 if (capability == NULL) 8223 return TEST_SKIPPED; 8224 if (rte_cryptodev_sym_capability_check_aead( 8225 capability, tdata->key.len, tdata->auth_tag.len, 8226 tdata->aad.len, tdata->iv.len)) 8227 return TEST_SKIPPED; 8228 8229 /* Create AEAD session */ 8230 retval = create_aead_session(ts_params->valid_devs[0], 8231 tdata->algo, 8232 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8233 tdata->key.data, tdata->key.len, 8234 tdata->aad.len, tdata->auth_tag.len, 8235 tdata->iv.len); 8236 if (retval < 0) 8237 return retval; 8238 8239 if (tdata->aad.len > MBUF_SIZE) { 8240 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8241 /* Populate full size of add data */ 8242 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8243 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8244 } else 8245 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8246 8247 /* clear mbuf payload */ 8248 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8249 rte_pktmbuf_tailroom(ut_params->ibuf)); 8250 8251 /* Create AEAD operation */ 8252 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8253 if (retval < 0) 8254 return retval; 8255 8256 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8257 8258 ut_params->op->sym->m_src = ut_params->ibuf; 8259 8260 /* Process crypto operation */ 8261 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8262 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8263 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8264 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8265 ut_params->op, 0, 0, 0, 0); 8266 else 8267 TEST_ASSERT_NOT_NULL( 8268 process_crypto_request(ts_params->valid_devs[0], 8269 ut_params->op), "failed to process sym crypto op"); 8270 8271 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8272 "crypto op processing failed"); 8273 8274 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8275 8276 if (ut_params->op->sym->m_dst) { 8277 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8278 uint8_t *); 8279 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8280 uint8_t *, plaintext_pad_len); 8281 } else { 8282 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8283 uint8_t *, 8284 ut_params->op->sym->cipher.data.offset); 8285 auth_tag = ciphertext + plaintext_pad_len; 8286 } 8287 8288 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8289 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8290 8291 /* Validate obuf */ 8292 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8293 ciphertext, 8294 tdata->ciphertext.data, 8295 tdata->ciphertext.len, 8296 "Ciphertext data not as expected"); 8297 8298 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8299 auth_tag, 8300 tdata->auth_tag.data, 8301 tdata->auth_tag.len, 8302 "Generated auth tag not as expected"); 8303 8304 return 0; 8305 8306 } 8307 8308 #ifdef RTE_LIB_SECURITY 8309 static int 8310 security_proto_supported(enum rte_security_session_action_type action, 8311 enum rte_security_session_protocol proto) 8312 { 8313 struct crypto_testsuite_params *ts_params = &testsuite_params; 8314 8315 const struct rte_security_capability *capabilities; 8316 const struct rte_security_capability *capability; 8317 uint16_t i = 0; 8318 8319 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8320 rte_cryptodev_get_sec_ctx( 8321 ts_params->valid_devs[0]); 8322 8323 8324 capabilities = rte_security_capabilities_get(ctx); 8325 8326 if (capabilities == NULL) 8327 return -ENOTSUP; 8328 8329 while ((capability = &capabilities[i++])->action != 8330 RTE_SECURITY_ACTION_TYPE_NONE) { 8331 if (capability->action == action && 8332 capability->protocol == proto) 8333 return 0; 8334 } 8335 8336 return -ENOTSUP; 8337 } 8338 8339 /* Basic algorithm run function for async inplace mode. 8340 * Creates a session from input parameters and runs one operation 8341 * on input_vec. Checks the output of the crypto operation against 8342 * output_vec. 8343 */ 8344 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8345 enum rte_crypto_auth_operation opa, 8346 const uint8_t *input_vec, unsigned int input_vec_len, 8347 const uint8_t *output_vec, 8348 unsigned int output_vec_len, 8349 enum rte_crypto_cipher_algorithm cipher_alg, 8350 const uint8_t *cipher_key, uint32_t cipher_key_len, 8351 enum rte_crypto_auth_algorithm auth_alg, 8352 const uint8_t *auth_key, uint32_t auth_key_len, 8353 uint8_t bearer, enum rte_security_pdcp_domain domain, 8354 uint8_t packet_direction, uint8_t sn_size, 8355 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8356 { 8357 struct crypto_testsuite_params *ts_params = &testsuite_params; 8358 struct crypto_unittest_params *ut_params = &unittest_params; 8359 uint8_t *plaintext; 8360 int ret = TEST_SUCCESS; 8361 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8362 rte_cryptodev_get_sec_ctx( 8363 ts_params->valid_devs[0]); 8364 8365 /* Verify the capabilities */ 8366 struct rte_security_capability_idx sec_cap_idx; 8367 8368 sec_cap_idx.action = ut_params->type; 8369 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8370 sec_cap_idx.pdcp.domain = domain; 8371 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8372 return TEST_SKIPPED; 8373 8374 /* Generate test mbuf data */ 8375 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8376 8377 /* clear mbuf payload */ 8378 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8379 rte_pktmbuf_tailroom(ut_params->ibuf)); 8380 8381 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8382 input_vec_len); 8383 memcpy(plaintext, input_vec, input_vec_len); 8384 8385 /* Out of place support */ 8386 if (oop) { 8387 /* 8388 * For out-op-place we need to alloc another mbuf 8389 */ 8390 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8391 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8392 } 8393 8394 /* Setup Cipher Parameters */ 8395 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8396 ut_params->cipher_xform.cipher.algo = cipher_alg; 8397 ut_params->cipher_xform.cipher.op = opc; 8398 ut_params->cipher_xform.cipher.key.data = cipher_key; 8399 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8400 ut_params->cipher_xform.cipher.iv.length = 8401 packet_direction ? 4 : 0; 8402 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8403 8404 /* Setup HMAC Parameters if ICV header is required */ 8405 if (auth_alg != 0) { 8406 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8407 ut_params->auth_xform.next = NULL; 8408 ut_params->auth_xform.auth.algo = auth_alg; 8409 ut_params->auth_xform.auth.op = opa; 8410 ut_params->auth_xform.auth.key.data = auth_key; 8411 ut_params->auth_xform.auth.key.length = auth_key_len; 8412 8413 ut_params->cipher_xform.next = &ut_params->auth_xform; 8414 } else { 8415 ut_params->cipher_xform.next = NULL; 8416 } 8417 8418 struct rte_security_session_conf sess_conf = { 8419 .action_type = ut_params->type, 8420 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8421 {.pdcp = { 8422 .bearer = bearer, 8423 .domain = domain, 8424 .pkt_dir = packet_direction, 8425 .sn_size = sn_size, 8426 .hfn = packet_direction ? 0 : hfn, 8427 /** 8428 * hfn can be set as pdcp_test_hfn[i] 8429 * if hfn_ovrd is not set. Here, PDCP 8430 * packet direction is just used to 8431 * run half of the cases with session 8432 * HFN and other half with per packet 8433 * HFN. 8434 */ 8435 .hfn_threshold = hfn_threshold, 8436 .hfn_ovrd = packet_direction ? 1 : 0, 8437 .sdap_enabled = sdap, 8438 } }, 8439 .crypto_xform = &ut_params->cipher_xform 8440 }; 8441 8442 /* Create security session */ 8443 ut_params->sec_session = rte_security_session_create(ctx, 8444 &sess_conf, ts_params->session_mpool, 8445 ts_params->session_priv_mpool); 8446 8447 if (!ut_params->sec_session) { 8448 printf("TestCase %s()-%d line %d failed %s: ", 8449 __func__, i, __LINE__, "Failed to allocate session"); 8450 ret = TEST_FAILED; 8451 goto on_err; 8452 } 8453 8454 /* Generate crypto op data structure */ 8455 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8456 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8457 if (!ut_params->op) { 8458 printf("TestCase %s()-%d line %d failed %s: ", 8459 __func__, i, __LINE__, 8460 "Failed to allocate symmetric crypto operation struct"); 8461 ret = TEST_FAILED; 8462 goto on_err; 8463 } 8464 8465 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8466 uint32_t *, IV_OFFSET); 8467 *per_pkt_hfn = packet_direction ? hfn : 0; 8468 8469 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8470 8471 /* set crypto operation source mbuf */ 8472 ut_params->op->sym->m_src = ut_params->ibuf; 8473 if (oop) 8474 ut_params->op->sym->m_dst = ut_params->obuf; 8475 8476 /* Process crypto operation */ 8477 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8478 == NULL) { 8479 printf("TestCase %s()-%d line %d failed %s: ", 8480 __func__, i, __LINE__, 8481 "failed to process sym crypto op"); 8482 ret = TEST_FAILED; 8483 goto on_err; 8484 } 8485 8486 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8487 printf("TestCase %s()-%d line %d failed %s: ", 8488 __func__, i, __LINE__, "crypto op processing failed"); 8489 ret = TEST_FAILED; 8490 goto on_err; 8491 } 8492 8493 /* Validate obuf */ 8494 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8495 uint8_t *); 8496 if (oop) { 8497 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8498 uint8_t *); 8499 } 8500 8501 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8502 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8503 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8504 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8505 ret = TEST_FAILED; 8506 goto on_err; 8507 } 8508 8509 on_err: 8510 rte_crypto_op_free(ut_params->op); 8511 ut_params->op = NULL; 8512 8513 if (ut_params->sec_session) 8514 rte_security_session_destroy(ctx, ut_params->sec_session); 8515 ut_params->sec_session = NULL; 8516 8517 rte_pktmbuf_free(ut_params->ibuf); 8518 ut_params->ibuf = NULL; 8519 if (oop) { 8520 rte_pktmbuf_free(ut_params->obuf); 8521 ut_params->obuf = NULL; 8522 } 8523 8524 return ret; 8525 } 8526 8527 static int 8528 test_pdcp_proto_SGL(int i, int oop, 8529 enum rte_crypto_cipher_operation opc, 8530 enum rte_crypto_auth_operation opa, 8531 uint8_t *input_vec, 8532 unsigned int input_vec_len, 8533 uint8_t *output_vec, 8534 unsigned int output_vec_len, 8535 uint32_t fragsz, 8536 uint32_t fragsz_oop) 8537 { 8538 struct crypto_testsuite_params *ts_params = &testsuite_params; 8539 struct crypto_unittest_params *ut_params = &unittest_params; 8540 uint8_t *plaintext; 8541 struct rte_mbuf *buf, *buf_oop = NULL; 8542 int ret = TEST_SUCCESS; 8543 int to_trn = 0; 8544 int to_trn_tbl[16]; 8545 int segs = 1; 8546 unsigned int trn_data = 0; 8547 struct rte_cryptodev_info dev_info; 8548 uint64_t feat_flags; 8549 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8550 rte_cryptodev_get_sec_ctx( 8551 ts_params->valid_devs[0]); 8552 struct rte_mbuf *temp_mbuf; 8553 8554 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8555 feat_flags = dev_info.feature_flags; 8556 8557 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8558 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8559 printf("Device does not support RAW data-path APIs.\n"); 8560 return -ENOTSUP; 8561 } 8562 /* Verify the capabilities */ 8563 struct rte_security_capability_idx sec_cap_idx; 8564 8565 sec_cap_idx.action = ut_params->type; 8566 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8567 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8568 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8569 return TEST_SKIPPED; 8570 8571 if (fragsz > input_vec_len) 8572 fragsz = input_vec_len; 8573 8574 uint16_t plaintext_len = fragsz; 8575 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8576 8577 if (fragsz_oop > output_vec_len) 8578 frag_size_oop = output_vec_len; 8579 8580 int ecx = 0; 8581 if (input_vec_len % fragsz != 0) { 8582 if (input_vec_len / fragsz + 1 > 16) 8583 return 1; 8584 } else if (input_vec_len / fragsz > 16) 8585 return 1; 8586 8587 /* Out of place support */ 8588 if (oop) { 8589 /* 8590 * For out-op-place we need to alloc another mbuf 8591 */ 8592 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8593 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8594 buf_oop = ut_params->obuf; 8595 } 8596 8597 /* Generate test mbuf data */ 8598 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8599 8600 /* clear mbuf payload */ 8601 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8602 rte_pktmbuf_tailroom(ut_params->ibuf)); 8603 8604 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8605 plaintext_len); 8606 memcpy(plaintext, input_vec, plaintext_len); 8607 trn_data += plaintext_len; 8608 8609 buf = ut_params->ibuf; 8610 8611 /* 8612 * Loop until no more fragments 8613 */ 8614 8615 while (trn_data < input_vec_len) { 8616 ++segs; 8617 to_trn = (input_vec_len - trn_data < fragsz) ? 8618 (input_vec_len - trn_data) : fragsz; 8619 8620 to_trn_tbl[ecx++] = to_trn; 8621 8622 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8623 buf = buf->next; 8624 8625 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8626 rte_pktmbuf_tailroom(buf)); 8627 8628 /* OOP */ 8629 if (oop && !fragsz_oop) { 8630 buf_oop->next = 8631 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8632 buf_oop = buf_oop->next; 8633 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8634 0, rte_pktmbuf_tailroom(buf_oop)); 8635 rte_pktmbuf_append(buf_oop, to_trn); 8636 } 8637 8638 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8639 to_trn); 8640 8641 memcpy(plaintext, input_vec + trn_data, to_trn); 8642 trn_data += to_trn; 8643 } 8644 8645 ut_params->ibuf->nb_segs = segs; 8646 8647 segs = 1; 8648 if (fragsz_oop && oop) { 8649 to_trn = 0; 8650 ecx = 0; 8651 8652 trn_data = frag_size_oop; 8653 while (trn_data < output_vec_len) { 8654 ++segs; 8655 to_trn = 8656 (output_vec_len - trn_data < 8657 frag_size_oop) ? 8658 (output_vec_len - trn_data) : 8659 frag_size_oop; 8660 8661 to_trn_tbl[ecx++] = to_trn; 8662 8663 buf_oop->next = 8664 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8665 buf_oop = buf_oop->next; 8666 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8667 0, rte_pktmbuf_tailroom(buf_oop)); 8668 rte_pktmbuf_append(buf_oop, to_trn); 8669 8670 trn_data += to_trn; 8671 } 8672 ut_params->obuf->nb_segs = segs; 8673 } 8674 8675 /* Setup Cipher Parameters */ 8676 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8677 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8678 ut_params->cipher_xform.cipher.op = opc; 8679 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8680 ut_params->cipher_xform.cipher.key.length = 8681 pdcp_test_params[i].cipher_key_len; 8682 ut_params->cipher_xform.cipher.iv.length = 0; 8683 8684 /* Setup HMAC Parameters if ICV header is required */ 8685 if (pdcp_test_params[i].auth_alg != 0) { 8686 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8687 ut_params->auth_xform.next = NULL; 8688 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8689 ut_params->auth_xform.auth.op = opa; 8690 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8691 ut_params->auth_xform.auth.key.length = 8692 pdcp_test_params[i].auth_key_len; 8693 8694 ut_params->cipher_xform.next = &ut_params->auth_xform; 8695 } else { 8696 ut_params->cipher_xform.next = NULL; 8697 } 8698 8699 struct rte_security_session_conf sess_conf = { 8700 .action_type = ut_params->type, 8701 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8702 {.pdcp = { 8703 .bearer = pdcp_test_bearer[i], 8704 .domain = pdcp_test_params[i].domain, 8705 .pkt_dir = pdcp_test_packet_direction[i], 8706 .sn_size = pdcp_test_data_sn_size[i], 8707 .hfn = pdcp_test_hfn[i], 8708 .hfn_threshold = pdcp_test_hfn_threshold[i], 8709 .hfn_ovrd = 0, 8710 } }, 8711 .crypto_xform = &ut_params->cipher_xform 8712 }; 8713 8714 /* Create security session */ 8715 ut_params->sec_session = rte_security_session_create(ctx, 8716 &sess_conf, ts_params->session_mpool, 8717 ts_params->session_priv_mpool); 8718 8719 if (!ut_params->sec_session) { 8720 printf("TestCase %s()-%d line %d failed %s: ", 8721 __func__, i, __LINE__, "Failed to allocate session"); 8722 ret = TEST_FAILED; 8723 goto on_err; 8724 } 8725 8726 /* Generate crypto op data structure */ 8727 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8728 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8729 if (!ut_params->op) { 8730 printf("TestCase %s()-%d line %d failed %s: ", 8731 __func__, i, __LINE__, 8732 "Failed to allocate symmetric crypto operation struct"); 8733 ret = TEST_FAILED; 8734 goto on_err; 8735 } 8736 8737 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8738 8739 /* set crypto operation source mbuf */ 8740 ut_params->op->sym->m_src = ut_params->ibuf; 8741 if (oop) 8742 ut_params->op->sym->m_dst = ut_params->obuf; 8743 8744 /* Process crypto operation */ 8745 temp_mbuf = ut_params->op->sym->m_src; 8746 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8747 /* filling lengths */ 8748 while (temp_mbuf) { 8749 ut_params->op->sym->cipher.data.length 8750 += temp_mbuf->pkt_len; 8751 ut_params->op->sym->auth.data.length 8752 += temp_mbuf->pkt_len; 8753 temp_mbuf = temp_mbuf->next; 8754 } 8755 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8756 ut_params->op, 1, 1, 0, 0); 8757 } else { 8758 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 8759 ut_params->op); 8760 } 8761 if (ut_params->op == NULL) { 8762 printf("TestCase %s()-%d line %d failed %s: ", 8763 __func__, i, __LINE__, 8764 "failed to process sym crypto op"); 8765 ret = TEST_FAILED; 8766 goto on_err; 8767 } 8768 8769 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8770 printf("TestCase %s()-%d line %d failed %s: ", 8771 __func__, i, __LINE__, "crypto op processing failed"); 8772 ret = TEST_FAILED; 8773 goto on_err; 8774 } 8775 8776 /* Validate obuf */ 8777 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8778 uint8_t *); 8779 if (oop) { 8780 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8781 uint8_t *); 8782 } 8783 if (fragsz_oop) 8784 fragsz = frag_size_oop; 8785 if (memcmp(ciphertext, output_vec, fragsz)) { 8786 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8787 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8788 rte_hexdump(stdout, "reference", output_vec, fragsz); 8789 ret = TEST_FAILED; 8790 goto on_err; 8791 } 8792 8793 buf = ut_params->op->sym->m_src->next; 8794 if (oop) 8795 buf = ut_params->op->sym->m_dst->next; 8796 8797 unsigned int off = fragsz; 8798 8799 ecx = 0; 8800 while (buf) { 8801 ciphertext = rte_pktmbuf_mtod(buf, 8802 uint8_t *); 8803 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8804 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8805 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8806 rte_hexdump(stdout, "reference", output_vec + off, 8807 to_trn_tbl[ecx]); 8808 ret = TEST_FAILED; 8809 goto on_err; 8810 } 8811 off += to_trn_tbl[ecx++]; 8812 buf = buf->next; 8813 } 8814 on_err: 8815 rte_crypto_op_free(ut_params->op); 8816 ut_params->op = NULL; 8817 8818 if (ut_params->sec_session) 8819 rte_security_session_destroy(ctx, ut_params->sec_session); 8820 ut_params->sec_session = NULL; 8821 8822 rte_pktmbuf_free(ut_params->ibuf); 8823 ut_params->ibuf = NULL; 8824 if (oop) { 8825 rte_pktmbuf_free(ut_params->obuf); 8826 ut_params->obuf = NULL; 8827 } 8828 8829 return ret; 8830 } 8831 8832 int 8833 test_pdcp_proto_cplane_encap(int i) 8834 { 8835 return test_pdcp_proto( 8836 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8837 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8838 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8839 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8840 pdcp_test_params[i].cipher_key_len, 8841 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8842 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8843 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8844 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8845 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8846 } 8847 8848 int 8849 test_pdcp_proto_uplane_encap(int i) 8850 { 8851 return test_pdcp_proto( 8852 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8853 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8854 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8855 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8856 pdcp_test_params[i].cipher_key_len, 8857 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8858 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8859 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8860 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8861 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8862 } 8863 8864 int 8865 test_pdcp_proto_uplane_encap_with_int(int i) 8866 { 8867 return test_pdcp_proto( 8868 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8869 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8870 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8871 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8872 pdcp_test_params[i].cipher_key_len, 8873 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8874 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8875 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8876 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8877 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8878 } 8879 8880 int 8881 test_pdcp_proto_cplane_decap(int i) 8882 { 8883 return test_pdcp_proto( 8884 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8885 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8886 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8887 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8888 pdcp_test_params[i].cipher_key_len, 8889 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8890 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8891 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8892 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8893 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8894 } 8895 8896 int 8897 test_pdcp_proto_uplane_decap(int i) 8898 { 8899 return test_pdcp_proto( 8900 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8901 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8902 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8903 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8904 pdcp_test_params[i].cipher_key_len, 8905 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8906 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8907 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8908 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8909 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8910 } 8911 8912 int 8913 test_pdcp_proto_uplane_decap_with_int(int i) 8914 { 8915 return test_pdcp_proto( 8916 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8917 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8918 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8919 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8920 pdcp_test_params[i].cipher_key_len, 8921 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8922 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8923 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8924 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8925 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8926 } 8927 8928 static int 8929 test_PDCP_PROTO_SGL_in_place_32B(void) 8930 { 8931 /* i can be used for running any PDCP case 8932 * In this case it is uplane 12-bit AES-SNOW DL encap 8933 */ 8934 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8935 return test_pdcp_proto_SGL(i, IN_PLACE, 8936 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8937 RTE_CRYPTO_AUTH_OP_GENERATE, 8938 pdcp_test_data_in[i], 8939 pdcp_test_data_in_len[i], 8940 pdcp_test_data_out[i], 8941 pdcp_test_data_in_len[i]+4, 8942 32, 0); 8943 } 8944 static int 8945 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8946 { 8947 /* i can be used for running any PDCP case 8948 * In this case it is uplane 18-bit NULL-NULL DL encap 8949 */ 8950 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8951 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8952 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8953 RTE_CRYPTO_AUTH_OP_GENERATE, 8954 pdcp_test_data_in[i], 8955 pdcp_test_data_in_len[i], 8956 pdcp_test_data_out[i], 8957 pdcp_test_data_in_len[i]+4, 8958 32, 128); 8959 } 8960 static int 8961 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8962 { 8963 /* i can be used for running any PDCP case 8964 * In this case it is uplane 18-bit AES DL encap 8965 */ 8966 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8967 + DOWNLINK; 8968 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8969 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8970 RTE_CRYPTO_AUTH_OP_GENERATE, 8971 pdcp_test_data_in[i], 8972 pdcp_test_data_in_len[i], 8973 pdcp_test_data_out[i], 8974 pdcp_test_data_in_len[i], 8975 32, 40); 8976 } 8977 static int 8978 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8979 { 8980 /* i can be used for running any PDCP case 8981 * In this case it is cplane 12-bit AES-ZUC DL encap 8982 */ 8983 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8984 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8985 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8986 RTE_CRYPTO_AUTH_OP_GENERATE, 8987 pdcp_test_data_in[i], 8988 pdcp_test_data_in_len[i], 8989 pdcp_test_data_out[i], 8990 pdcp_test_data_in_len[i]+4, 8991 128, 32); 8992 } 8993 8994 static int 8995 test_PDCP_SDAP_PROTO_encap_all(void) 8996 { 8997 int i = 0, size = 0; 8998 int err, all_err = TEST_SUCCESS; 8999 const struct pdcp_sdap_test *cur_test; 9000 9001 size = RTE_DIM(list_pdcp_sdap_tests); 9002 9003 for (i = 0; i < size; i++) { 9004 cur_test = &list_pdcp_sdap_tests[i]; 9005 err = test_pdcp_proto( 9006 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9007 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9008 cur_test->in_len, cur_test->data_out, 9009 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9010 cur_test->param.cipher_alg, cur_test->cipher_key, 9011 cur_test->param.cipher_key_len, 9012 cur_test->param.auth_alg, 9013 cur_test->auth_key, cur_test->param.auth_key_len, 9014 cur_test->bearer, cur_test->param.domain, 9015 cur_test->packet_direction, cur_test->sn_size, 9016 cur_test->hfn, 9017 cur_test->hfn_threshold, SDAP_ENABLED); 9018 if (err) { 9019 printf("\t%d) %s: Encapsulation failed\n", 9020 cur_test->test_idx, 9021 cur_test->param.name); 9022 err = TEST_FAILED; 9023 } else { 9024 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9025 cur_test->param.name); 9026 err = TEST_SUCCESS; 9027 } 9028 all_err += err; 9029 } 9030 9031 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9032 9033 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9034 } 9035 9036 static int 9037 test_PDCP_PROTO_short_mac(void) 9038 { 9039 int i = 0, size = 0; 9040 int err, all_err = TEST_SUCCESS; 9041 const struct pdcp_short_mac_test *cur_test; 9042 9043 size = RTE_DIM(list_pdcp_smac_tests); 9044 9045 for (i = 0; i < size; i++) { 9046 cur_test = &list_pdcp_smac_tests[i]; 9047 err = test_pdcp_proto( 9048 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9049 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9050 cur_test->in_len, cur_test->data_out, 9051 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9052 RTE_CRYPTO_CIPHER_NULL, NULL, 9053 0, cur_test->param.auth_alg, 9054 cur_test->auth_key, cur_test->param.auth_key_len, 9055 0, cur_test->param.domain, 0, 0, 9056 0, 0, 0); 9057 if (err) { 9058 printf("\t%d) %s: Short MAC test failed\n", 9059 cur_test->test_idx, 9060 cur_test->param.name); 9061 err = TEST_FAILED; 9062 } else { 9063 printf("\t%d) %s: Short MAC test PASS\n", 9064 cur_test->test_idx, 9065 cur_test->param.name); 9066 rte_hexdump(stdout, "MAC I", 9067 cur_test->data_out + cur_test->in_len + 2, 9068 2); 9069 err = TEST_SUCCESS; 9070 } 9071 all_err += err; 9072 } 9073 9074 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9075 9076 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9077 9078 } 9079 9080 static int 9081 test_PDCP_SDAP_PROTO_decap_all(void) 9082 { 9083 int i = 0, size = 0; 9084 int err, all_err = TEST_SUCCESS; 9085 const struct pdcp_sdap_test *cur_test; 9086 9087 size = RTE_DIM(list_pdcp_sdap_tests); 9088 9089 for (i = 0; i < size; i++) { 9090 cur_test = &list_pdcp_sdap_tests[i]; 9091 err = test_pdcp_proto( 9092 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9093 RTE_CRYPTO_AUTH_OP_VERIFY, 9094 cur_test->data_out, 9095 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9096 cur_test->data_in, cur_test->in_len, 9097 cur_test->param.cipher_alg, 9098 cur_test->cipher_key, cur_test->param.cipher_key_len, 9099 cur_test->param.auth_alg, cur_test->auth_key, 9100 cur_test->param.auth_key_len, cur_test->bearer, 9101 cur_test->param.domain, cur_test->packet_direction, 9102 cur_test->sn_size, cur_test->hfn, 9103 cur_test->hfn_threshold, SDAP_ENABLED); 9104 if (err) { 9105 printf("\t%d) %s: Decapsulation failed\n", 9106 cur_test->test_idx, 9107 cur_test->param.name); 9108 err = TEST_FAILED; 9109 } else { 9110 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9111 cur_test->param.name); 9112 err = TEST_SUCCESS; 9113 } 9114 all_err += err; 9115 } 9116 9117 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9118 9119 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9120 } 9121 9122 static int 9123 test_ipsec_proto_process(const struct ipsec_test_data td[], 9124 struct ipsec_test_data res_d[], 9125 int nb_td, 9126 bool silent, 9127 const struct ipsec_test_flags *flags) 9128 { 9129 struct crypto_testsuite_params *ts_params = &testsuite_params; 9130 struct crypto_unittest_params *ut_params = &unittest_params; 9131 struct rte_security_capability_idx sec_cap_idx; 9132 const struct rte_security_capability *sec_cap; 9133 struct rte_security_ipsec_xform ipsec_xform; 9134 uint8_t dev_id = ts_params->valid_devs[0]; 9135 enum rte_security_ipsec_sa_direction dir; 9136 struct ipsec_test_data *res_d_tmp = NULL; 9137 uint32_t src = RTE_IPV4(192, 168, 1, 0); 9138 uint32_t dst = RTE_IPV4(192, 168, 1, 1); 9139 int salt_len, i, ret = TEST_SUCCESS; 9140 struct rte_security_ctx *ctx; 9141 uint8_t *input_text; 9142 uint32_t verify; 9143 9144 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9145 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9146 9147 /* Use first test data to create session */ 9148 9149 /* Copy IPsec xform */ 9150 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9151 9152 dir = ipsec_xform.direction; 9153 verify = flags->tunnel_hdr_verify; 9154 9155 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9156 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9157 src += 1; 9158 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9159 dst += 1; 9160 } 9161 9162 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src)); 9163 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst)); 9164 9165 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9166 9167 sec_cap_idx.action = ut_params->type; 9168 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9169 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9170 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9171 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9172 9173 if (flags->udp_encap) 9174 ipsec_xform.options.udp_encap = 1; 9175 9176 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9177 if (sec_cap == NULL) 9178 return TEST_SKIPPED; 9179 9180 /* Copy cipher session parameters */ 9181 if (td[0].aead) { 9182 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9183 sizeof(ut_params->aead_xform)); 9184 ut_params->aead_xform.aead.key.data = td[0].key.data; 9185 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9186 9187 /* Verify crypto capabilities */ 9188 if (test_ipsec_crypto_caps_aead_verify( 9189 sec_cap, 9190 &ut_params->aead_xform) != 0) { 9191 if (!silent) 9192 RTE_LOG(INFO, USER1, 9193 "Crypto capabilities not supported\n"); 9194 return TEST_SKIPPED; 9195 } 9196 } else { 9197 /* Only AEAD supported now */ 9198 return TEST_SKIPPED; 9199 } 9200 9201 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9202 return TEST_SKIPPED; 9203 9204 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9205 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9206 9207 struct rte_security_session_conf sess_conf = { 9208 .action_type = ut_params->type, 9209 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9210 .ipsec = ipsec_xform, 9211 .crypto_xform = &ut_params->aead_xform, 9212 }; 9213 9214 /* Create security session */ 9215 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9216 ts_params->session_mpool, 9217 ts_params->session_priv_mpool); 9218 9219 if (ut_params->sec_session == NULL) 9220 return TEST_SKIPPED; 9221 9222 for (i = 0; i < nb_td; i++) { 9223 /* Setup source mbuf payload */ 9224 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9225 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9226 rte_pktmbuf_tailroom(ut_params->ibuf)); 9227 9228 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9229 td[i].input_text.len); 9230 9231 memcpy(input_text, td[i].input_text.data, 9232 td[i].input_text.len); 9233 9234 /* Generate crypto op data structure */ 9235 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9236 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9237 if (!ut_params->op) { 9238 printf("TestCase %s line %d: %s\n", 9239 __func__, __LINE__, 9240 "failed to allocate crypto op"); 9241 ret = TEST_FAILED; 9242 goto crypto_op_free; 9243 } 9244 9245 /* Attach session to operation */ 9246 rte_security_attach_session(ut_params->op, 9247 ut_params->sec_session); 9248 9249 /* Set crypto operation mbufs */ 9250 ut_params->op->sym->m_src = ut_params->ibuf; 9251 ut_params->op->sym->m_dst = NULL; 9252 9253 /* Copy IV in crypto operation when IV generation is disabled */ 9254 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9255 ipsec_xform.options.iv_gen_disable == 1) { 9256 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9257 uint8_t *, 9258 IV_OFFSET); 9259 int len; 9260 9261 if (td[i].aead) 9262 len = td[i].xform.aead.aead.iv.length; 9263 else 9264 len = td[i].xform.chain.cipher.cipher.iv.length; 9265 9266 memcpy(iv, td[i].iv.data, len); 9267 } 9268 9269 /* Process crypto operation */ 9270 process_crypto_request(dev_id, ut_params->op); 9271 9272 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1); 9273 if (ret != TEST_SUCCESS) 9274 goto crypto_op_free; 9275 9276 if (res_d != NULL) 9277 res_d_tmp = &res_d[i]; 9278 9279 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9280 res_d_tmp, silent, flags); 9281 if (ret != TEST_SUCCESS) 9282 goto crypto_op_free; 9283 9284 rte_crypto_op_free(ut_params->op); 9285 ut_params->op = NULL; 9286 9287 rte_pktmbuf_free(ut_params->ibuf); 9288 ut_params->ibuf = NULL; 9289 } 9290 9291 crypto_op_free: 9292 rte_crypto_op_free(ut_params->op); 9293 ut_params->op = NULL; 9294 9295 rte_pktmbuf_free(ut_params->ibuf); 9296 ut_params->ibuf = NULL; 9297 9298 if (ut_params->sec_session) 9299 rte_security_session_destroy(ctx, ut_params->sec_session); 9300 ut_params->sec_session = NULL; 9301 9302 return ret; 9303 } 9304 9305 static int 9306 test_ipsec_proto_known_vec(const void *test_data) 9307 { 9308 struct ipsec_test_data td_outb; 9309 struct ipsec_test_flags flags; 9310 9311 memset(&flags, 0, sizeof(flags)); 9312 9313 memcpy(&td_outb, test_data, sizeof(td_outb)); 9314 9315 /* Disable IV gen to be able to test with known vectors */ 9316 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9317 9318 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9319 } 9320 9321 static int 9322 test_ipsec_proto_known_vec_inb(const void *td_outb) 9323 { 9324 struct ipsec_test_flags flags; 9325 struct ipsec_test_data td_inb; 9326 9327 memset(&flags, 0, sizeof(flags)); 9328 9329 test_ipsec_td_in_from_out(td_outb, &td_inb); 9330 9331 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9332 } 9333 9334 static int 9335 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9336 { 9337 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9338 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9339 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9340 int ret; 9341 9342 if (flags->iv_gen || 9343 flags->sa_expiry_pkts_soft || 9344 flags->sa_expiry_pkts_hard) 9345 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9346 9347 for (i = 0; i < RTE_DIM(aead_list); i++) { 9348 test_ipsec_td_prepare(&aead_list[i], 9349 NULL, 9350 flags, 9351 td_outb, 9352 nb_pkts); 9353 9354 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9355 flags); 9356 if (ret == TEST_SKIPPED) 9357 continue; 9358 9359 if (ret == TEST_FAILED) 9360 return TEST_FAILED; 9361 9362 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9363 9364 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9365 flags); 9366 if (ret == TEST_SKIPPED) 9367 continue; 9368 9369 if (ret == TEST_FAILED) 9370 return TEST_FAILED; 9371 9372 if (flags->display_alg) 9373 test_ipsec_display_alg(&aead_list[i], NULL); 9374 9375 pass_cnt++; 9376 } 9377 9378 if (pass_cnt > 0) 9379 return TEST_SUCCESS; 9380 else 9381 return TEST_SKIPPED; 9382 } 9383 9384 static int 9385 test_ipsec_proto_display_list(const void *data __rte_unused) 9386 { 9387 struct ipsec_test_flags flags; 9388 9389 memset(&flags, 0, sizeof(flags)); 9390 9391 flags.display_alg = true; 9392 9393 return test_ipsec_proto_all(&flags); 9394 } 9395 9396 static int 9397 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9398 { 9399 struct ipsec_test_flags flags; 9400 9401 memset(&flags, 0, sizeof(flags)); 9402 9403 flags.iv_gen = true; 9404 9405 return test_ipsec_proto_all(&flags); 9406 } 9407 9408 static int 9409 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9410 { 9411 struct ipsec_test_flags flags; 9412 9413 memset(&flags, 0, sizeof(flags)); 9414 9415 flags.sa_expiry_pkts_soft = true; 9416 9417 return test_ipsec_proto_all(&flags); 9418 } 9419 9420 static int 9421 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9422 { 9423 struct ipsec_test_flags flags; 9424 9425 memset(&flags, 0, sizeof(flags)); 9426 9427 flags.sa_expiry_pkts_hard = true; 9428 9429 return test_ipsec_proto_all(&flags); 9430 } 9431 9432 static int 9433 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9434 { 9435 struct ipsec_test_flags flags; 9436 9437 memset(&flags, 0, sizeof(flags)); 9438 9439 flags.icv_corrupt = true; 9440 9441 return test_ipsec_proto_all(&flags); 9442 } 9443 9444 static int 9445 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9446 { 9447 struct ipsec_test_flags flags; 9448 9449 memset(&flags, 0, sizeof(flags)); 9450 9451 flags.udp_encap = true; 9452 9453 return test_ipsec_proto_all(&flags); 9454 } 9455 9456 static int 9457 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9458 { 9459 struct ipsec_test_flags flags; 9460 9461 memset(&flags, 0, sizeof(flags)); 9462 9463 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9464 9465 return test_ipsec_proto_all(&flags); 9466 } 9467 9468 static int 9469 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9470 { 9471 struct ipsec_test_flags flags; 9472 9473 memset(&flags, 0, sizeof(flags)); 9474 9475 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9476 9477 return test_ipsec_proto_all(&flags); 9478 } 9479 9480 static int 9481 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9482 { 9483 struct ipsec_test_flags flags; 9484 9485 memset(&flags, 0, sizeof(flags)); 9486 9487 flags.udp_encap = true; 9488 flags.udp_ports_verify = true; 9489 9490 return test_ipsec_proto_all(&flags); 9491 } 9492 9493 static int 9494 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9495 { 9496 struct ipsec_test_flags flags; 9497 9498 memset(&flags, 0, sizeof(flags)); 9499 9500 flags.ip_csum = true; 9501 9502 return test_ipsec_proto_all(&flags); 9503 } 9504 9505 static int 9506 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9507 { 9508 struct ipsec_test_flags flags; 9509 9510 memset(&flags, 0, sizeof(flags)); 9511 9512 flags.l4_csum = true; 9513 9514 return test_ipsec_proto_all(&flags); 9515 } 9516 9517 static int 9518 test_PDCP_PROTO_all(void) 9519 { 9520 struct crypto_testsuite_params *ts_params = &testsuite_params; 9521 struct crypto_unittest_params *ut_params = &unittest_params; 9522 struct rte_cryptodev_info dev_info; 9523 int status; 9524 9525 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9526 uint64_t feat_flags = dev_info.feature_flags; 9527 9528 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 9529 return TEST_SKIPPED; 9530 9531 /* Set action type */ 9532 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9533 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9534 gbl_action_type; 9535 9536 if (security_proto_supported(ut_params->type, 9537 RTE_SECURITY_PROTOCOL_PDCP) < 0) 9538 return TEST_SKIPPED; 9539 9540 status = test_PDCP_PROTO_cplane_encap_all(); 9541 status += test_PDCP_PROTO_cplane_decap_all(); 9542 status += test_PDCP_PROTO_uplane_encap_all(); 9543 status += test_PDCP_PROTO_uplane_decap_all(); 9544 status += test_PDCP_PROTO_SGL_in_place_32B(); 9545 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 9546 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 9547 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 9548 status += test_PDCP_SDAP_PROTO_encap_all(); 9549 status += test_PDCP_SDAP_PROTO_decap_all(); 9550 status += test_PDCP_PROTO_short_mac(); 9551 9552 if (status) 9553 return TEST_FAILED; 9554 else 9555 return TEST_SUCCESS; 9556 } 9557 9558 static int 9559 test_docsis_proto_uplink(const void *data) 9560 { 9561 const struct docsis_test_data *d_td = data; 9562 struct crypto_testsuite_params *ts_params = &testsuite_params; 9563 struct crypto_unittest_params *ut_params = &unittest_params; 9564 uint8_t *plaintext = NULL; 9565 uint8_t *ciphertext = NULL; 9566 uint8_t *iv_ptr; 9567 int32_t cipher_len, crc_len; 9568 uint32_t crc_data_len; 9569 int ret = TEST_SUCCESS; 9570 9571 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9572 rte_cryptodev_get_sec_ctx( 9573 ts_params->valid_devs[0]); 9574 9575 /* Verify the capabilities */ 9576 struct rte_security_capability_idx sec_cap_idx; 9577 const struct rte_security_capability *sec_cap; 9578 const struct rte_cryptodev_capabilities *crypto_cap; 9579 const struct rte_cryptodev_symmetric_capability *sym_cap; 9580 int j = 0; 9581 9582 /* Set action type */ 9583 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9584 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9585 gbl_action_type; 9586 9587 if (security_proto_supported(ut_params->type, 9588 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9589 return TEST_SKIPPED; 9590 9591 sec_cap_idx.action = ut_params->type; 9592 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9593 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 9594 9595 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9596 if (sec_cap == NULL) 9597 return TEST_SKIPPED; 9598 9599 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9600 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9601 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9602 crypto_cap->sym.xform_type == 9603 RTE_CRYPTO_SYM_XFORM_CIPHER && 9604 crypto_cap->sym.cipher.algo == 9605 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9606 sym_cap = &crypto_cap->sym; 9607 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9608 d_td->key.len, 9609 d_td->iv.len) == 0) 9610 break; 9611 } 9612 } 9613 9614 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9615 return TEST_SKIPPED; 9616 9617 /* Setup source mbuf payload */ 9618 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9619 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9620 rte_pktmbuf_tailroom(ut_params->ibuf)); 9621 9622 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9623 d_td->ciphertext.len); 9624 9625 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 9626 9627 /* Setup cipher session parameters */ 9628 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9629 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9630 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 9631 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9632 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9633 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9634 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9635 ut_params->cipher_xform.next = NULL; 9636 9637 /* Setup DOCSIS session parameters */ 9638 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 9639 9640 struct rte_security_session_conf sess_conf = { 9641 .action_type = ut_params->type, 9642 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9643 .docsis = ut_params->docsis_xform, 9644 .crypto_xform = &ut_params->cipher_xform, 9645 }; 9646 9647 /* Create security session */ 9648 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9649 ts_params->session_mpool, 9650 ts_params->session_priv_mpool); 9651 9652 if (!ut_params->sec_session) { 9653 printf("Test function %s line %u: failed to allocate session\n", 9654 __func__, __LINE__); 9655 ret = TEST_FAILED; 9656 goto on_err; 9657 } 9658 9659 /* Generate crypto op data structure */ 9660 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9661 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9662 if (!ut_params->op) { 9663 printf("Test function %s line %u: failed to allocate symmetric " 9664 "crypto operation\n", __func__, __LINE__); 9665 ret = TEST_FAILED; 9666 goto on_err; 9667 } 9668 9669 /* Setup CRC operation parameters */ 9670 crc_len = d_td->ciphertext.no_crc == false ? 9671 (d_td->ciphertext.len - 9672 d_td->ciphertext.crc_offset - 9673 RTE_ETHER_CRC_LEN) : 9674 0; 9675 crc_len = crc_len > 0 ? crc_len : 0; 9676 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 9677 ut_params->op->sym->auth.data.length = crc_len; 9678 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 9679 9680 /* Setup cipher operation parameters */ 9681 cipher_len = d_td->ciphertext.no_cipher == false ? 9682 (d_td->ciphertext.len - 9683 d_td->ciphertext.cipher_offset) : 9684 0; 9685 cipher_len = cipher_len > 0 ? cipher_len : 0; 9686 ut_params->op->sym->cipher.data.length = cipher_len; 9687 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 9688 9689 /* Setup cipher IV */ 9690 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9691 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9692 9693 /* Attach session to operation */ 9694 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9695 9696 /* Set crypto operation mbufs */ 9697 ut_params->op->sym->m_src = ut_params->ibuf; 9698 ut_params->op->sym->m_dst = NULL; 9699 9700 /* Process crypto operation */ 9701 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9702 NULL) { 9703 printf("Test function %s line %u: failed to process security " 9704 "crypto op\n", __func__, __LINE__); 9705 ret = TEST_FAILED; 9706 goto on_err; 9707 } 9708 9709 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9710 printf("Test function %s line %u: failed to process crypto op\n", 9711 __func__, __LINE__); 9712 ret = TEST_FAILED; 9713 goto on_err; 9714 } 9715 9716 /* Validate plaintext */ 9717 plaintext = ciphertext; 9718 9719 if (memcmp(plaintext, d_td->plaintext.data, 9720 d_td->plaintext.len - crc_data_len)) { 9721 printf("Test function %s line %u: plaintext not as expected\n", 9722 __func__, __LINE__); 9723 rte_hexdump(stdout, "expected", d_td->plaintext.data, 9724 d_td->plaintext.len); 9725 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 9726 ret = TEST_FAILED; 9727 goto on_err; 9728 } 9729 9730 on_err: 9731 rte_crypto_op_free(ut_params->op); 9732 ut_params->op = NULL; 9733 9734 if (ut_params->sec_session) 9735 rte_security_session_destroy(ctx, ut_params->sec_session); 9736 ut_params->sec_session = NULL; 9737 9738 rte_pktmbuf_free(ut_params->ibuf); 9739 ut_params->ibuf = NULL; 9740 9741 return ret; 9742 } 9743 9744 static int 9745 test_docsis_proto_downlink(const void *data) 9746 { 9747 const struct docsis_test_data *d_td = data; 9748 struct crypto_testsuite_params *ts_params = &testsuite_params; 9749 struct crypto_unittest_params *ut_params = &unittest_params; 9750 uint8_t *plaintext = NULL; 9751 uint8_t *ciphertext = NULL; 9752 uint8_t *iv_ptr; 9753 int32_t cipher_len, crc_len; 9754 int ret = TEST_SUCCESS; 9755 9756 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9757 rte_cryptodev_get_sec_ctx( 9758 ts_params->valid_devs[0]); 9759 9760 /* Verify the capabilities */ 9761 struct rte_security_capability_idx sec_cap_idx; 9762 const struct rte_security_capability *sec_cap; 9763 const struct rte_cryptodev_capabilities *crypto_cap; 9764 const struct rte_cryptodev_symmetric_capability *sym_cap; 9765 int j = 0; 9766 9767 /* Set action type */ 9768 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9769 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9770 gbl_action_type; 9771 9772 if (security_proto_supported(ut_params->type, 9773 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9774 return TEST_SKIPPED; 9775 9776 sec_cap_idx.action = ut_params->type; 9777 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9778 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9779 9780 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9781 if (sec_cap == NULL) 9782 return TEST_SKIPPED; 9783 9784 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9785 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9786 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9787 crypto_cap->sym.xform_type == 9788 RTE_CRYPTO_SYM_XFORM_CIPHER && 9789 crypto_cap->sym.cipher.algo == 9790 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9791 sym_cap = &crypto_cap->sym; 9792 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9793 d_td->key.len, 9794 d_td->iv.len) == 0) 9795 break; 9796 } 9797 } 9798 9799 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9800 return TEST_SKIPPED; 9801 9802 /* Setup source mbuf payload */ 9803 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9804 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9805 rte_pktmbuf_tailroom(ut_params->ibuf)); 9806 9807 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9808 d_td->plaintext.len); 9809 9810 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 9811 9812 /* Setup cipher session parameters */ 9813 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9814 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9815 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9816 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9817 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9818 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9819 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9820 ut_params->cipher_xform.next = NULL; 9821 9822 /* Setup DOCSIS session parameters */ 9823 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9824 9825 struct rte_security_session_conf sess_conf = { 9826 .action_type = ut_params->type, 9827 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9828 .docsis = ut_params->docsis_xform, 9829 .crypto_xform = &ut_params->cipher_xform, 9830 }; 9831 9832 /* Create security session */ 9833 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9834 ts_params->session_mpool, 9835 ts_params->session_priv_mpool); 9836 9837 if (!ut_params->sec_session) { 9838 printf("Test function %s line %u: failed to allocate session\n", 9839 __func__, __LINE__); 9840 ret = TEST_FAILED; 9841 goto on_err; 9842 } 9843 9844 /* Generate crypto op data structure */ 9845 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9846 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9847 if (!ut_params->op) { 9848 printf("Test function %s line %u: failed to allocate symmetric " 9849 "crypto operation\n", __func__, __LINE__); 9850 ret = TEST_FAILED; 9851 goto on_err; 9852 } 9853 9854 /* Setup CRC operation parameters */ 9855 crc_len = d_td->plaintext.no_crc == false ? 9856 (d_td->plaintext.len - 9857 d_td->plaintext.crc_offset - 9858 RTE_ETHER_CRC_LEN) : 9859 0; 9860 crc_len = crc_len > 0 ? crc_len : 0; 9861 ut_params->op->sym->auth.data.length = crc_len; 9862 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 9863 9864 /* Setup cipher operation parameters */ 9865 cipher_len = d_td->plaintext.no_cipher == false ? 9866 (d_td->plaintext.len - 9867 d_td->plaintext.cipher_offset) : 9868 0; 9869 cipher_len = cipher_len > 0 ? cipher_len : 0; 9870 ut_params->op->sym->cipher.data.length = cipher_len; 9871 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 9872 9873 /* Setup cipher IV */ 9874 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9875 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9876 9877 /* Attach session to operation */ 9878 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9879 9880 /* Set crypto operation mbufs */ 9881 ut_params->op->sym->m_src = ut_params->ibuf; 9882 ut_params->op->sym->m_dst = NULL; 9883 9884 /* Process crypto operation */ 9885 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9886 NULL) { 9887 printf("Test function %s line %u: failed to process crypto op\n", 9888 __func__, __LINE__); 9889 ret = TEST_FAILED; 9890 goto on_err; 9891 } 9892 9893 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9894 printf("Test function %s line %u: crypto op processing failed\n", 9895 __func__, __LINE__); 9896 ret = TEST_FAILED; 9897 goto on_err; 9898 } 9899 9900 /* Validate ciphertext */ 9901 ciphertext = plaintext; 9902 9903 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 9904 printf("Test function %s line %u: plaintext not as expected\n", 9905 __func__, __LINE__); 9906 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 9907 d_td->ciphertext.len); 9908 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 9909 ret = TEST_FAILED; 9910 goto on_err; 9911 } 9912 9913 on_err: 9914 rte_crypto_op_free(ut_params->op); 9915 ut_params->op = NULL; 9916 9917 if (ut_params->sec_session) 9918 rte_security_session_destroy(ctx, ut_params->sec_session); 9919 ut_params->sec_session = NULL; 9920 9921 rte_pktmbuf_free(ut_params->ibuf); 9922 ut_params->ibuf = NULL; 9923 9924 return ret; 9925 } 9926 #endif 9927 9928 static int 9929 test_AES_GCM_authenticated_encryption_test_case_1(void) 9930 { 9931 return test_authenticated_encryption(&gcm_test_case_1); 9932 } 9933 9934 static int 9935 test_AES_GCM_authenticated_encryption_test_case_2(void) 9936 { 9937 return test_authenticated_encryption(&gcm_test_case_2); 9938 } 9939 9940 static int 9941 test_AES_GCM_authenticated_encryption_test_case_3(void) 9942 { 9943 return test_authenticated_encryption(&gcm_test_case_3); 9944 } 9945 9946 static int 9947 test_AES_GCM_authenticated_encryption_test_case_4(void) 9948 { 9949 return test_authenticated_encryption(&gcm_test_case_4); 9950 } 9951 9952 static int 9953 test_AES_GCM_authenticated_encryption_test_case_5(void) 9954 { 9955 return test_authenticated_encryption(&gcm_test_case_5); 9956 } 9957 9958 static int 9959 test_AES_GCM_authenticated_encryption_test_case_6(void) 9960 { 9961 return test_authenticated_encryption(&gcm_test_case_6); 9962 } 9963 9964 static int 9965 test_AES_GCM_authenticated_encryption_test_case_7(void) 9966 { 9967 return test_authenticated_encryption(&gcm_test_case_7); 9968 } 9969 9970 static int 9971 test_AES_GCM_authenticated_encryption_test_case_8(void) 9972 { 9973 return test_authenticated_encryption(&gcm_test_case_8); 9974 } 9975 9976 static int 9977 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 9978 { 9979 return test_authenticated_encryption(&gcm_J0_test_case_1); 9980 } 9981 9982 static int 9983 test_AES_GCM_auth_encryption_test_case_192_1(void) 9984 { 9985 return test_authenticated_encryption(&gcm_test_case_192_1); 9986 } 9987 9988 static int 9989 test_AES_GCM_auth_encryption_test_case_192_2(void) 9990 { 9991 return test_authenticated_encryption(&gcm_test_case_192_2); 9992 } 9993 9994 static int 9995 test_AES_GCM_auth_encryption_test_case_192_3(void) 9996 { 9997 return test_authenticated_encryption(&gcm_test_case_192_3); 9998 } 9999 10000 static int 10001 test_AES_GCM_auth_encryption_test_case_192_4(void) 10002 { 10003 return test_authenticated_encryption(&gcm_test_case_192_4); 10004 } 10005 10006 static int 10007 test_AES_GCM_auth_encryption_test_case_192_5(void) 10008 { 10009 return test_authenticated_encryption(&gcm_test_case_192_5); 10010 } 10011 10012 static int 10013 test_AES_GCM_auth_encryption_test_case_192_6(void) 10014 { 10015 return test_authenticated_encryption(&gcm_test_case_192_6); 10016 } 10017 10018 static int 10019 test_AES_GCM_auth_encryption_test_case_192_7(void) 10020 { 10021 return test_authenticated_encryption(&gcm_test_case_192_7); 10022 } 10023 10024 static int 10025 test_AES_GCM_auth_encryption_test_case_256_1(void) 10026 { 10027 return test_authenticated_encryption(&gcm_test_case_256_1); 10028 } 10029 10030 static int 10031 test_AES_GCM_auth_encryption_test_case_256_2(void) 10032 { 10033 return test_authenticated_encryption(&gcm_test_case_256_2); 10034 } 10035 10036 static int 10037 test_AES_GCM_auth_encryption_test_case_256_3(void) 10038 { 10039 return test_authenticated_encryption(&gcm_test_case_256_3); 10040 } 10041 10042 static int 10043 test_AES_GCM_auth_encryption_test_case_256_4(void) 10044 { 10045 return test_authenticated_encryption(&gcm_test_case_256_4); 10046 } 10047 10048 static int 10049 test_AES_GCM_auth_encryption_test_case_256_5(void) 10050 { 10051 return test_authenticated_encryption(&gcm_test_case_256_5); 10052 } 10053 10054 static int 10055 test_AES_GCM_auth_encryption_test_case_256_6(void) 10056 { 10057 return test_authenticated_encryption(&gcm_test_case_256_6); 10058 } 10059 10060 static int 10061 test_AES_GCM_auth_encryption_test_case_256_7(void) 10062 { 10063 return test_authenticated_encryption(&gcm_test_case_256_7); 10064 } 10065 10066 static int 10067 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10068 { 10069 return test_authenticated_encryption(&gcm_test_case_aad_1); 10070 } 10071 10072 static int 10073 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10074 { 10075 return test_authenticated_encryption(&gcm_test_case_aad_2); 10076 } 10077 10078 static int 10079 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10080 { 10081 struct aead_test_data tdata; 10082 int res; 10083 10084 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10085 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10086 tdata.iv.data[0] += 1; 10087 res = test_authenticated_encryption(&tdata); 10088 if (res == TEST_SKIPPED) 10089 return res; 10090 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10091 return TEST_SUCCESS; 10092 } 10093 10094 static int 10095 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10096 { 10097 struct aead_test_data tdata; 10098 int res; 10099 10100 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10101 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10102 tdata.plaintext.data[0] += 1; 10103 res = test_authenticated_encryption(&tdata); 10104 if (res == TEST_SKIPPED) 10105 return res; 10106 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10107 return TEST_SUCCESS; 10108 } 10109 10110 static int 10111 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10112 { 10113 struct aead_test_data tdata; 10114 int res; 10115 10116 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10117 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10118 tdata.ciphertext.data[0] += 1; 10119 res = test_authenticated_encryption(&tdata); 10120 if (res == TEST_SKIPPED) 10121 return res; 10122 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10123 return TEST_SUCCESS; 10124 } 10125 10126 static int 10127 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10128 { 10129 struct aead_test_data tdata; 10130 int res; 10131 10132 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10133 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10134 tdata.aad.len += 1; 10135 res = test_authenticated_encryption(&tdata); 10136 if (res == TEST_SKIPPED) 10137 return res; 10138 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10139 return TEST_SUCCESS; 10140 } 10141 10142 static int 10143 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10144 { 10145 struct aead_test_data tdata; 10146 uint8_t aad[gcm_test_case_7.aad.len]; 10147 int res; 10148 10149 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10150 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10151 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10152 aad[0] += 1; 10153 tdata.aad.data = aad; 10154 res = test_authenticated_encryption(&tdata); 10155 if (res == TEST_SKIPPED) 10156 return res; 10157 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10158 return TEST_SUCCESS; 10159 } 10160 10161 static int 10162 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10163 { 10164 struct aead_test_data tdata; 10165 int res; 10166 10167 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10168 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10169 tdata.auth_tag.data[0] += 1; 10170 res = test_authenticated_encryption(&tdata); 10171 if (res == TEST_SKIPPED) 10172 return res; 10173 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10174 return TEST_SUCCESS; 10175 } 10176 10177 static int 10178 test_authenticated_decryption(const struct aead_test_data *tdata) 10179 { 10180 struct crypto_testsuite_params *ts_params = &testsuite_params; 10181 struct crypto_unittest_params *ut_params = &unittest_params; 10182 10183 int retval; 10184 uint8_t *plaintext; 10185 uint32_t i; 10186 struct rte_cryptodev_info dev_info; 10187 10188 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10189 uint64_t feat_flags = dev_info.feature_flags; 10190 10191 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10192 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10193 printf("Device doesn't support RAW data-path APIs.\n"); 10194 return TEST_SKIPPED; 10195 } 10196 10197 /* Verify the capabilities */ 10198 struct rte_cryptodev_sym_capability_idx cap_idx; 10199 const struct rte_cryptodev_symmetric_capability *capability; 10200 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10201 cap_idx.algo.aead = tdata->algo; 10202 capability = rte_cryptodev_sym_capability_get( 10203 ts_params->valid_devs[0], &cap_idx); 10204 if (capability == NULL) 10205 return TEST_SKIPPED; 10206 if (rte_cryptodev_sym_capability_check_aead( 10207 capability, tdata->key.len, tdata->auth_tag.len, 10208 tdata->aad.len, tdata->iv.len)) 10209 return TEST_SKIPPED; 10210 10211 /* Create AEAD session */ 10212 retval = create_aead_session(ts_params->valid_devs[0], 10213 tdata->algo, 10214 RTE_CRYPTO_AEAD_OP_DECRYPT, 10215 tdata->key.data, tdata->key.len, 10216 tdata->aad.len, tdata->auth_tag.len, 10217 tdata->iv.len); 10218 if (retval < 0) 10219 return retval; 10220 10221 /* alloc mbuf and set payload */ 10222 if (tdata->aad.len > MBUF_SIZE) { 10223 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10224 /* Populate full size of add data */ 10225 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10226 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10227 } else 10228 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10229 10230 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10231 rte_pktmbuf_tailroom(ut_params->ibuf)); 10232 10233 /* Create AEAD operation */ 10234 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10235 if (retval < 0) 10236 return retval; 10237 10238 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10239 10240 ut_params->op->sym->m_src = ut_params->ibuf; 10241 10242 /* Process crypto operation */ 10243 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10244 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10245 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10246 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10247 ut_params->op, 0, 0, 0, 0); 10248 else 10249 TEST_ASSERT_NOT_NULL( 10250 process_crypto_request(ts_params->valid_devs[0], 10251 ut_params->op), "failed to process sym crypto op"); 10252 10253 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10254 "crypto op processing failed"); 10255 10256 if (ut_params->op->sym->m_dst) 10257 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10258 uint8_t *); 10259 else 10260 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10261 uint8_t *, 10262 ut_params->op->sym->cipher.data.offset); 10263 10264 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10265 10266 /* Validate obuf */ 10267 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10268 plaintext, 10269 tdata->plaintext.data, 10270 tdata->plaintext.len, 10271 "Plaintext data not as expected"); 10272 10273 TEST_ASSERT_EQUAL(ut_params->op->status, 10274 RTE_CRYPTO_OP_STATUS_SUCCESS, 10275 "Authentication failed"); 10276 10277 return 0; 10278 } 10279 10280 static int 10281 test_AES_GCM_authenticated_decryption_test_case_1(void) 10282 { 10283 return test_authenticated_decryption(&gcm_test_case_1); 10284 } 10285 10286 static int 10287 test_AES_GCM_authenticated_decryption_test_case_2(void) 10288 { 10289 return test_authenticated_decryption(&gcm_test_case_2); 10290 } 10291 10292 static int 10293 test_AES_GCM_authenticated_decryption_test_case_3(void) 10294 { 10295 return test_authenticated_decryption(&gcm_test_case_3); 10296 } 10297 10298 static int 10299 test_AES_GCM_authenticated_decryption_test_case_4(void) 10300 { 10301 return test_authenticated_decryption(&gcm_test_case_4); 10302 } 10303 10304 static int 10305 test_AES_GCM_authenticated_decryption_test_case_5(void) 10306 { 10307 return test_authenticated_decryption(&gcm_test_case_5); 10308 } 10309 10310 static int 10311 test_AES_GCM_authenticated_decryption_test_case_6(void) 10312 { 10313 return test_authenticated_decryption(&gcm_test_case_6); 10314 } 10315 10316 static int 10317 test_AES_GCM_authenticated_decryption_test_case_7(void) 10318 { 10319 return test_authenticated_decryption(&gcm_test_case_7); 10320 } 10321 10322 static int 10323 test_AES_GCM_authenticated_decryption_test_case_8(void) 10324 { 10325 return test_authenticated_decryption(&gcm_test_case_8); 10326 } 10327 10328 static int 10329 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 10330 { 10331 return test_authenticated_decryption(&gcm_J0_test_case_1); 10332 } 10333 10334 static int 10335 test_AES_GCM_auth_decryption_test_case_192_1(void) 10336 { 10337 return test_authenticated_decryption(&gcm_test_case_192_1); 10338 } 10339 10340 static int 10341 test_AES_GCM_auth_decryption_test_case_192_2(void) 10342 { 10343 return test_authenticated_decryption(&gcm_test_case_192_2); 10344 } 10345 10346 static int 10347 test_AES_GCM_auth_decryption_test_case_192_3(void) 10348 { 10349 return test_authenticated_decryption(&gcm_test_case_192_3); 10350 } 10351 10352 static int 10353 test_AES_GCM_auth_decryption_test_case_192_4(void) 10354 { 10355 return test_authenticated_decryption(&gcm_test_case_192_4); 10356 } 10357 10358 static int 10359 test_AES_GCM_auth_decryption_test_case_192_5(void) 10360 { 10361 return test_authenticated_decryption(&gcm_test_case_192_5); 10362 } 10363 10364 static int 10365 test_AES_GCM_auth_decryption_test_case_192_6(void) 10366 { 10367 return test_authenticated_decryption(&gcm_test_case_192_6); 10368 } 10369 10370 static int 10371 test_AES_GCM_auth_decryption_test_case_192_7(void) 10372 { 10373 return test_authenticated_decryption(&gcm_test_case_192_7); 10374 } 10375 10376 static int 10377 test_AES_GCM_auth_decryption_test_case_256_1(void) 10378 { 10379 return test_authenticated_decryption(&gcm_test_case_256_1); 10380 } 10381 10382 static int 10383 test_AES_GCM_auth_decryption_test_case_256_2(void) 10384 { 10385 return test_authenticated_decryption(&gcm_test_case_256_2); 10386 } 10387 10388 static int 10389 test_AES_GCM_auth_decryption_test_case_256_3(void) 10390 { 10391 return test_authenticated_decryption(&gcm_test_case_256_3); 10392 } 10393 10394 static int 10395 test_AES_GCM_auth_decryption_test_case_256_4(void) 10396 { 10397 return test_authenticated_decryption(&gcm_test_case_256_4); 10398 } 10399 10400 static int 10401 test_AES_GCM_auth_decryption_test_case_256_5(void) 10402 { 10403 return test_authenticated_decryption(&gcm_test_case_256_5); 10404 } 10405 10406 static int 10407 test_AES_GCM_auth_decryption_test_case_256_6(void) 10408 { 10409 return test_authenticated_decryption(&gcm_test_case_256_6); 10410 } 10411 10412 static int 10413 test_AES_GCM_auth_decryption_test_case_256_7(void) 10414 { 10415 return test_authenticated_decryption(&gcm_test_case_256_7); 10416 } 10417 10418 static int 10419 test_AES_GCM_auth_decryption_test_case_aad_1(void) 10420 { 10421 return test_authenticated_decryption(&gcm_test_case_aad_1); 10422 } 10423 10424 static int 10425 test_AES_GCM_auth_decryption_test_case_aad_2(void) 10426 { 10427 return test_authenticated_decryption(&gcm_test_case_aad_2); 10428 } 10429 10430 static int 10431 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 10432 { 10433 struct aead_test_data tdata; 10434 int res; 10435 10436 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10437 tdata.iv.data[0] += 1; 10438 res = test_authenticated_decryption(&tdata); 10439 if (res == TEST_SKIPPED) 10440 return res; 10441 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10442 return TEST_SUCCESS; 10443 } 10444 10445 static int 10446 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 10447 { 10448 struct aead_test_data tdata; 10449 int res; 10450 10451 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10452 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10453 tdata.plaintext.data[0] += 1; 10454 res = test_authenticated_decryption(&tdata); 10455 if (res == TEST_SKIPPED) 10456 return res; 10457 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10458 return TEST_SUCCESS; 10459 } 10460 10461 static int 10462 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 10463 { 10464 struct aead_test_data tdata; 10465 int res; 10466 10467 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10468 tdata.ciphertext.data[0] += 1; 10469 res = test_authenticated_decryption(&tdata); 10470 if (res == TEST_SKIPPED) 10471 return res; 10472 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10473 return TEST_SUCCESS; 10474 } 10475 10476 static int 10477 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 10478 { 10479 struct aead_test_data tdata; 10480 int res; 10481 10482 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10483 tdata.aad.len += 1; 10484 res = test_authenticated_decryption(&tdata); 10485 if (res == TEST_SKIPPED) 10486 return res; 10487 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10488 return TEST_SUCCESS; 10489 } 10490 10491 static int 10492 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 10493 { 10494 struct aead_test_data tdata; 10495 uint8_t aad[gcm_test_case_7.aad.len]; 10496 int res; 10497 10498 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10499 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10500 aad[0] += 1; 10501 tdata.aad.data = aad; 10502 res = test_authenticated_decryption(&tdata); 10503 if (res == TEST_SKIPPED) 10504 return res; 10505 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10506 return TEST_SUCCESS; 10507 } 10508 10509 static int 10510 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 10511 { 10512 struct aead_test_data tdata; 10513 int res; 10514 10515 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10516 tdata.auth_tag.data[0] += 1; 10517 res = test_authenticated_decryption(&tdata); 10518 if (res == TEST_SKIPPED) 10519 return res; 10520 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 10521 return TEST_SUCCESS; 10522 } 10523 10524 static int 10525 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 10526 { 10527 struct crypto_testsuite_params *ts_params = &testsuite_params; 10528 struct crypto_unittest_params *ut_params = &unittest_params; 10529 10530 int retval; 10531 uint8_t *ciphertext, *auth_tag; 10532 uint16_t plaintext_pad_len; 10533 struct rte_cryptodev_info dev_info; 10534 10535 /* Verify the capabilities */ 10536 struct rte_cryptodev_sym_capability_idx cap_idx; 10537 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10538 cap_idx.algo.aead = tdata->algo; 10539 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10540 &cap_idx) == NULL) 10541 return TEST_SKIPPED; 10542 10543 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10544 uint64_t feat_flags = dev_info.feature_flags; 10545 10546 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10547 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 10548 return TEST_SKIPPED; 10549 10550 /* not supported with CPU crypto */ 10551 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10552 return TEST_SKIPPED; 10553 10554 /* Create AEAD session */ 10555 retval = create_aead_session(ts_params->valid_devs[0], 10556 tdata->algo, 10557 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10558 tdata->key.data, tdata->key.len, 10559 tdata->aad.len, tdata->auth_tag.len, 10560 tdata->iv.len); 10561 if (retval < 0) 10562 return retval; 10563 10564 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10565 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10566 10567 /* clear mbuf payload */ 10568 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10569 rte_pktmbuf_tailroom(ut_params->ibuf)); 10570 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10571 rte_pktmbuf_tailroom(ut_params->obuf)); 10572 10573 /* Create AEAD operation */ 10574 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10575 if (retval < 0) 10576 return retval; 10577 10578 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10579 10580 ut_params->op->sym->m_src = ut_params->ibuf; 10581 ut_params->op->sym->m_dst = ut_params->obuf; 10582 10583 /* Process crypto operation */ 10584 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10585 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10586 ut_params->op, 0, 0, 0, 0); 10587 else 10588 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10589 ut_params->op), "failed to process sym crypto op"); 10590 10591 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10592 "crypto op processing failed"); 10593 10594 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10595 10596 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10597 ut_params->op->sym->cipher.data.offset); 10598 auth_tag = ciphertext + plaintext_pad_len; 10599 10600 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10601 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10602 10603 /* Validate obuf */ 10604 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10605 ciphertext, 10606 tdata->ciphertext.data, 10607 tdata->ciphertext.len, 10608 "Ciphertext data not as expected"); 10609 10610 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10611 auth_tag, 10612 tdata->auth_tag.data, 10613 tdata->auth_tag.len, 10614 "Generated auth tag not as expected"); 10615 10616 return 0; 10617 10618 } 10619 10620 static int 10621 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 10622 { 10623 return test_authenticated_encryption_oop(&gcm_test_case_5); 10624 } 10625 10626 static int 10627 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 10628 { 10629 struct crypto_testsuite_params *ts_params = &testsuite_params; 10630 struct crypto_unittest_params *ut_params = &unittest_params; 10631 10632 int retval; 10633 uint8_t *plaintext; 10634 struct rte_cryptodev_info dev_info; 10635 10636 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10637 uint64_t feat_flags = dev_info.feature_flags; 10638 10639 /* Verify the capabilities */ 10640 struct rte_cryptodev_sym_capability_idx cap_idx; 10641 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10642 cap_idx.algo.aead = tdata->algo; 10643 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10644 &cap_idx) == NULL) 10645 return TEST_SKIPPED; 10646 10647 /* not supported with CPU crypto and raw data-path APIs*/ 10648 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 10649 global_api_test_type == CRYPTODEV_RAW_API_TEST) 10650 return TEST_SKIPPED; 10651 10652 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10653 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10654 printf("Device does not support RAW data-path APIs.\n"); 10655 return TEST_SKIPPED; 10656 } 10657 10658 /* Create AEAD session */ 10659 retval = create_aead_session(ts_params->valid_devs[0], 10660 tdata->algo, 10661 RTE_CRYPTO_AEAD_OP_DECRYPT, 10662 tdata->key.data, tdata->key.len, 10663 tdata->aad.len, tdata->auth_tag.len, 10664 tdata->iv.len); 10665 if (retval < 0) 10666 return retval; 10667 10668 /* alloc mbuf and set payload */ 10669 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10670 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10671 10672 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10673 rte_pktmbuf_tailroom(ut_params->ibuf)); 10674 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10675 rte_pktmbuf_tailroom(ut_params->obuf)); 10676 10677 /* Create AEAD operation */ 10678 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10679 if (retval < 0) 10680 return retval; 10681 10682 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10683 10684 ut_params->op->sym->m_src = ut_params->ibuf; 10685 ut_params->op->sym->m_dst = ut_params->obuf; 10686 10687 /* Process crypto operation */ 10688 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10689 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10690 ut_params->op, 0, 0, 0, 0); 10691 else 10692 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10693 ut_params->op), "failed to process sym crypto op"); 10694 10695 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10696 "crypto op processing failed"); 10697 10698 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10699 ut_params->op->sym->cipher.data.offset); 10700 10701 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10702 10703 /* Validate obuf */ 10704 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10705 plaintext, 10706 tdata->plaintext.data, 10707 tdata->plaintext.len, 10708 "Plaintext data not as expected"); 10709 10710 TEST_ASSERT_EQUAL(ut_params->op->status, 10711 RTE_CRYPTO_OP_STATUS_SUCCESS, 10712 "Authentication failed"); 10713 return 0; 10714 } 10715 10716 static int 10717 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 10718 { 10719 return test_authenticated_decryption_oop(&gcm_test_case_5); 10720 } 10721 10722 static int 10723 test_authenticated_encryption_sessionless( 10724 const struct aead_test_data *tdata) 10725 { 10726 struct crypto_testsuite_params *ts_params = &testsuite_params; 10727 struct crypto_unittest_params *ut_params = &unittest_params; 10728 10729 int retval; 10730 uint8_t *ciphertext, *auth_tag; 10731 uint16_t plaintext_pad_len; 10732 uint8_t key[tdata->key.len + 1]; 10733 struct rte_cryptodev_info dev_info; 10734 10735 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10736 uint64_t feat_flags = dev_info.feature_flags; 10737 10738 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10739 printf("Device doesn't support Sessionless ops.\n"); 10740 return TEST_SKIPPED; 10741 } 10742 10743 /* not supported with CPU crypto */ 10744 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10745 return TEST_SKIPPED; 10746 10747 /* Verify the capabilities */ 10748 struct rte_cryptodev_sym_capability_idx cap_idx; 10749 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10750 cap_idx.algo.aead = tdata->algo; 10751 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10752 &cap_idx) == NULL) 10753 return TEST_SKIPPED; 10754 10755 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10756 10757 /* clear mbuf payload */ 10758 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10759 rte_pktmbuf_tailroom(ut_params->ibuf)); 10760 10761 /* Create AEAD operation */ 10762 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10763 if (retval < 0) 10764 return retval; 10765 10766 /* Create GCM xform */ 10767 memcpy(key, tdata->key.data, tdata->key.len); 10768 retval = create_aead_xform(ut_params->op, 10769 tdata->algo, 10770 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10771 key, tdata->key.len, 10772 tdata->aad.len, tdata->auth_tag.len, 10773 tdata->iv.len); 10774 if (retval < 0) 10775 return retval; 10776 10777 ut_params->op->sym->m_src = ut_params->ibuf; 10778 10779 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10780 RTE_CRYPTO_OP_SESSIONLESS, 10781 "crypto op session type not sessionless"); 10782 10783 /* Process crypto operation */ 10784 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10785 ut_params->op), "failed to process sym crypto op"); 10786 10787 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10788 10789 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10790 "crypto op status not success"); 10791 10792 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10793 10794 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10795 ut_params->op->sym->cipher.data.offset); 10796 auth_tag = ciphertext + plaintext_pad_len; 10797 10798 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10799 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10800 10801 /* Validate obuf */ 10802 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10803 ciphertext, 10804 tdata->ciphertext.data, 10805 tdata->ciphertext.len, 10806 "Ciphertext data not as expected"); 10807 10808 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10809 auth_tag, 10810 tdata->auth_tag.data, 10811 tdata->auth_tag.len, 10812 "Generated auth tag not as expected"); 10813 10814 return 0; 10815 10816 } 10817 10818 static int 10819 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 10820 { 10821 return test_authenticated_encryption_sessionless( 10822 &gcm_test_case_5); 10823 } 10824 10825 static int 10826 test_authenticated_decryption_sessionless( 10827 const struct aead_test_data *tdata) 10828 { 10829 struct crypto_testsuite_params *ts_params = &testsuite_params; 10830 struct crypto_unittest_params *ut_params = &unittest_params; 10831 10832 int retval; 10833 uint8_t *plaintext; 10834 uint8_t key[tdata->key.len + 1]; 10835 struct rte_cryptodev_info dev_info; 10836 10837 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10838 uint64_t feat_flags = dev_info.feature_flags; 10839 10840 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10841 printf("Device doesn't support Sessionless ops.\n"); 10842 return TEST_SKIPPED; 10843 } 10844 10845 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10846 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10847 printf("Device doesn't support RAW data-path APIs.\n"); 10848 return TEST_SKIPPED; 10849 } 10850 10851 /* not supported with CPU crypto */ 10852 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10853 return TEST_SKIPPED; 10854 10855 /* Verify the capabilities */ 10856 struct rte_cryptodev_sym_capability_idx cap_idx; 10857 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10858 cap_idx.algo.aead = tdata->algo; 10859 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10860 &cap_idx) == NULL) 10861 return TEST_SKIPPED; 10862 10863 /* alloc mbuf and set payload */ 10864 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10865 10866 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10867 rte_pktmbuf_tailroom(ut_params->ibuf)); 10868 10869 /* Create AEAD operation */ 10870 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10871 if (retval < 0) 10872 return retval; 10873 10874 /* Create AEAD xform */ 10875 memcpy(key, tdata->key.data, tdata->key.len); 10876 retval = create_aead_xform(ut_params->op, 10877 tdata->algo, 10878 RTE_CRYPTO_AEAD_OP_DECRYPT, 10879 key, tdata->key.len, 10880 tdata->aad.len, tdata->auth_tag.len, 10881 tdata->iv.len); 10882 if (retval < 0) 10883 return retval; 10884 10885 ut_params->op->sym->m_src = ut_params->ibuf; 10886 10887 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10888 RTE_CRYPTO_OP_SESSIONLESS, 10889 "crypto op session type not sessionless"); 10890 10891 /* Process crypto operation */ 10892 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10893 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10894 ut_params->op, 0, 0, 0, 0); 10895 else 10896 TEST_ASSERT_NOT_NULL(process_crypto_request( 10897 ts_params->valid_devs[0], ut_params->op), 10898 "failed to process sym crypto op"); 10899 10900 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10901 10902 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10903 "crypto op status not success"); 10904 10905 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10906 ut_params->op->sym->cipher.data.offset); 10907 10908 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10909 10910 /* Validate obuf */ 10911 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10912 plaintext, 10913 tdata->plaintext.data, 10914 tdata->plaintext.len, 10915 "Plaintext data not as expected"); 10916 10917 TEST_ASSERT_EQUAL(ut_params->op->status, 10918 RTE_CRYPTO_OP_STATUS_SUCCESS, 10919 "Authentication failed"); 10920 return 0; 10921 } 10922 10923 static int 10924 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 10925 { 10926 return test_authenticated_decryption_sessionless( 10927 &gcm_test_case_5); 10928 } 10929 10930 static int 10931 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 10932 { 10933 return test_authenticated_encryption(&ccm_test_case_128_1); 10934 } 10935 10936 static int 10937 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 10938 { 10939 return test_authenticated_encryption(&ccm_test_case_128_2); 10940 } 10941 10942 static int 10943 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 10944 { 10945 return test_authenticated_encryption(&ccm_test_case_128_3); 10946 } 10947 10948 static int 10949 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 10950 { 10951 return test_authenticated_decryption(&ccm_test_case_128_1); 10952 } 10953 10954 static int 10955 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 10956 { 10957 return test_authenticated_decryption(&ccm_test_case_128_2); 10958 } 10959 10960 static int 10961 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 10962 { 10963 return test_authenticated_decryption(&ccm_test_case_128_3); 10964 } 10965 10966 static int 10967 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 10968 { 10969 return test_authenticated_encryption(&ccm_test_case_192_1); 10970 } 10971 10972 static int 10973 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 10974 { 10975 return test_authenticated_encryption(&ccm_test_case_192_2); 10976 } 10977 10978 static int 10979 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 10980 { 10981 return test_authenticated_encryption(&ccm_test_case_192_3); 10982 } 10983 10984 static int 10985 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 10986 { 10987 return test_authenticated_decryption(&ccm_test_case_192_1); 10988 } 10989 10990 static int 10991 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 10992 { 10993 return test_authenticated_decryption(&ccm_test_case_192_2); 10994 } 10995 10996 static int 10997 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 10998 { 10999 return test_authenticated_decryption(&ccm_test_case_192_3); 11000 } 11001 11002 static int 11003 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11004 { 11005 return test_authenticated_encryption(&ccm_test_case_256_1); 11006 } 11007 11008 static int 11009 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11010 { 11011 return test_authenticated_encryption(&ccm_test_case_256_2); 11012 } 11013 11014 static int 11015 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11016 { 11017 return test_authenticated_encryption(&ccm_test_case_256_3); 11018 } 11019 11020 static int 11021 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11022 { 11023 return test_authenticated_decryption(&ccm_test_case_256_1); 11024 } 11025 11026 static int 11027 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11028 { 11029 return test_authenticated_decryption(&ccm_test_case_256_2); 11030 } 11031 11032 static int 11033 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11034 { 11035 return test_authenticated_decryption(&ccm_test_case_256_3); 11036 } 11037 11038 static int 11039 test_stats(void) 11040 { 11041 struct crypto_testsuite_params *ts_params = &testsuite_params; 11042 struct rte_cryptodev_stats stats; 11043 11044 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11045 return TEST_SKIPPED; 11046 11047 /* Verify the capabilities */ 11048 struct rte_cryptodev_sym_capability_idx cap_idx; 11049 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11050 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11051 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11052 &cap_idx) == NULL) 11053 return TEST_SKIPPED; 11054 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11055 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11056 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11057 &cap_idx) == NULL) 11058 return TEST_SKIPPED; 11059 11060 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11061 == -ENOTSUP) 11062 return TEST_SKIPPED; 11063 11064 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11065 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11066 &stats) == -ENODEV), 11067 "rte_cryptodev_stats_get invalid dev failed"); 11068 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11069 "rte_cryptodev_stats_get invalid Param failed"); 11070 11071 /* Test expected values */ 11072 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11073 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11074 &stats), 11075 "rte_cryptodev_stats_get failed"); 11076 TEST_ASSERT((stats.enqueued_count == 1), 11077 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11078 TEST_ASSERT((stats.dequeued_count == 1), 11079 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11080 TEST_ASSERT((stats.enqueue_err_count == 0), 11081 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11082 TEST_ASSERT((stats.dequeue_err_count == 0), 11083 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11084 11085 /* invalid device but should ignore and not reset device stats*/ 11086 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11087 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11088 &stats), 11089 "rte_cryptodev_stats_get failed"); 11090 TEST_ASSERT((stats.enqueued_count == 1), 11091 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11092 11093 /* check that a valid reset clears stats */ 11094 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11095 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11096 &stats), 11097 "rte_cryptodev_stats_get failed"); 11098 TEST_ASSERT((stats.enqueued_count == 0), 11099 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11100 TEST_ASSERT((stats.dequeued_count == 0), 11101 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11102 11103 return TEST_SUCCESS; 11104 } 11105 11106 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11107 struct crypto_unittest_params *ut_params, 11108 enum rte_crypto_auth_operation op, 11109 const struct HMAC_MD5_vector *test_case) 11110 { 11111 uint8_t key[64]; 11112 int status; 11113 11114 memcpy(key, test_case->key.data, test_case->key.len); 11115 11116 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11117 ut_params->auth_xform.next = NULL; 11118 ut_params->auth_xform.auth.op = op; 11119 11120 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11121 11122 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11123 ut_params->auth_xform.auth.key.length = test_case->key.len; 11124 ut_params->auth_xform.auth.key.data = key; 11125 11126 ut_params->sess = rte_cryptodev_sym_session_create( 11127 ts_params->session_mpool); 11128 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11129 if (ut_params->sess == NULL) 11130 return TEST_FAILED; 11131 11132 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11133 ut_params->sess, &ut_params->auth_xform, 11134 ts_params->session_priv_mpool); 11135 if (status == -ENOTSUP) 11136 return TEST_SKIPPED; 11137 11138 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11139 11140 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11141 rte_pktmbuf_tailroom(ut_params->ibuf)); 11142 11143 return 0; 11144 } 11145 11146 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11147 const struct HMAC_MD5_vector *test_case, 11148 uint8_t **plaintext) 11149 { 11150 uint16_t plaintext_pad_len; 11151 11152 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11153 11154 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11155 16); 11156 11157 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11158 plaintext_pad_len); 11159 memcpy(*plaintext, test_case->plaintext.data, 11160 test_case->plaintext.len); 11161 11162 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11163 ut_params->ibuf, MD5_DIGEST_LEN); 11164 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11165 "no room to append digest"); 11166 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11167 ut_params->ibuf, plaintext_pad_len); 11168 11169 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11170 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11171 test_case->auth_tag.len); 11172 } 11173 11174 sym_op->auth.data.offset = 0; 11175 sym_op->auth.data.length = test_case->plaintext.len; 11176 11177 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11178 ut_params->op->sym->m_src = ut_params->ibuf; 11179 11180 return 0; 11181 } 11182 11183 static int 11184 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11185 { 11186 uint16_t plaintext_pad_len; 11187 uint8_t *plaintext, *auth_tag; 11188 11189 struct crypto_testsuite_params *ts_params = &testsuite_params; 11190 struct crypto_unittest_params *ut_params = &unittest_params; 11191 struct rte_cryptodev_info dev_info; 11192 11193 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11194 uint64_t feat_flags = dev_info.feature_flags; 11195 11196 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11197 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11198 printf("Device doesn't support RAW data-path APIs.\n"); 11199 return TEST_SKIPPED; 11200 } 11201 11202 /* Verify the capabilities */ 11203 struct rte_cryptodev_sym_capability_idx cap_idx; 11204 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11205 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11206 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11207 &cap_idx) == NULL) 11208 return TEST_SKIPPED; 11209 11210 if (MD5_HMAC_create_session(ts_params, ut_params, 11211 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11212 return TEST_FAILED; 11213 11214 /* Generate Crypto op data structure */ 11215 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11216 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11217 TEST_ASSERT_NOT_NULL(ut_params->op, 11218 "Failed to allocate symmetric crypto operation struct"); 11219 11220 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11221 16); 11222 11223 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11224 return TEST_FAILED; 11225 11226 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11227 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11228 ut_params->op); 11229 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11230 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11231 ut_params->op, 0, 1, 0, 0); 11232 else 11233 TEST_ASSERT_NOT_NULL( 11234 process_crypto_request(ts_params->valid_devs[0], 11235 ut_params->op), 11236 "failed to process sym crypto op"); 11237 11238 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11239 "crypto op processing failed"); 11240 11241 if (ut_params->op->sym->m_dst) { 11242 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11243 uint8_t *, plaintext_pad_len); 11244 } else { 11245 auth_tag = plaintext + plaintext_pad_len; 11246 } 11247 11248 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11249 auth_tag, 11250 test_case->auth_tag.data, 11251 test_case->auth_tag.len, 11252 "HMAC_MD5 generated tag not as expected"); 11253 11254 return TEST_SUCCESS; 11255 } 11256 11257 static int 11258 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11259 { 11260 uint8_t *plaintext; 11261 11262 struct crypto_testsuite_params *ts_params = &testsuite_params; 11263 struct crypto_unittest_params *ut_params = &unittest_params; 11264 struct rte_cryptodev_info dev_info; 11265 11266 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11267 uint64_t feat_flags = dev_info.feature_flags; 11268 11269 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11270 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11271 printf("Device doesn't support RAW data-path APIs.\n"); 11272 return TEST_SKIPPED; 11273 } 11274 11275 /* Verify the capabilities */ 11276 struct rte_cryptodev_sym_capability_idx cap_idx; 11277 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11278 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11279 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11280 &cap_idx) == NULL) 11281 return TEST_SKIPPED; 11282 11283 if (MD5_HMAC_create_session(ts_params, ut_params, 11284 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11285 return TEST_FAILED; 11286 } 11287 11288 /* Generate Crypto op data structure */ 11289 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11290 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11291 TEST_ASSERT_NOT_NULL(ut_params->op, 11292 "Failed to allocate symmetric crypto operation struct"); 11293 11294 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11295 return TEST_FAILED; 11296 11297 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11298 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11299 ut_params->op); 11300 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11301 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11302 ut_params->op, 0, 1, 0, 0); 11303 else 11304 TEST_ASSERT_NOT_NULL( 11305 process_crypto_request(ts_params->valid_devs[0], 11306 ut_params->op), 11307 "failed to process sym crypto op"); 11308 11309 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11310 "HMAC_MD5 crypto op processing failed"); 11311 11312 return TEST_SUCCESS; 11313 } 11314 11315 static int 11316 test_MD5_HMAC_generate_case_1(void) 11317 { 11318 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 11319 } 11320 11321 static int 11322 test_MD5_HMAC_verify_case_1(void) 11323 { 11324 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 11325 } 11326 11327 static int 11328 test_MD5_HMAC_generate_case_2(void) 11329 { 11330 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 11331 } 11332 11333 static int 11334 test_MD5_HMAC_verify_case_2(void) 11335 { 11336 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 11337 } 11338 11339 static int 11340 test_multi_session(void) 11341 { 11342 struct crypto_testsuite_params *ts_params = &testsuite_params; 11343 struct crypto_unittest_params *ut_params = &unittest_params; 11344 11345 struct rte_cryptodev_info dev_info; 11346 struct rte_cryptodev_sym_session **sessions; 11347 11348 uint16_t i; 11349 int status; 11350 11351 /* Verify the capabilities */ 11352 struct rte_cryptodev_sym_capability_idx cap_idx; 11353 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11354 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11355 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11356 &cap_idx) == NULL) 11357 return TEST_SKIPPED; 11358 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11359 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11360 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11361 &cap_idx) == NULL) 11362 return TEST_SKIPPED; 11363 11364 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 11365 aes_cbc_key, hmac_sha512_key); 11366 11367 11368 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11369 11370 sessions = rte_malloc(NULL, 11371 sizeof(struct rte_cryptodev_sym_session *) * 11372 (MAX_NB_SESSIONS + 1), 0); 11373 11374 /* Create multiple crypto sessions*/ 11375 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11376 11377 sessions[i] = rte_cryptodev_sym_session_create( 11378 ts_params->session_mpool); 11379 TEST_ASSERT_NOT_NULL(sessions[i], 11380 "Session creation failed at session number %u", 11381 i); 11382 11383 status = rte_cryptodev_sym_session_init( 11384 ts_params->valid_devs[0], 11385 sessions[i], &ut_params->auth_xform, 11386 ts_params->session_priv_mpool); 11387 if (status == -ENOTSUP) 11388 return TEST_SKIPPED; 11389 11390 /* Attempt to send a request on each session */ 11391 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 11392 sessions[i], 11393 ut_params, 11394 ts_params, 11395 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 11396 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 11397 aes_cbc_iv), 11398 "Failed to perform decrypt on request number %u.", i); 11399 /* free crypto operation structure */ 11400 if (ut_params->op) 11401 rte_crypto_op_free(ut_params->op); 11402 11403 /* 11404 * free mbuf - both obuf and ibuf are usually the same, 11405 * so check if they point at the same address is necessary, 11406 * to avoid freeing the mbuf twice. 11407 */ 11408 if (ut_params->obuf) { 11409 rte_pktmbuf_free(ut_params->obuf); 11410 if (ut_params->ibuf == ut_params->obuf) 11411 ut_params->ibuf = 0; 11412 ut_params->obuf = 0; 11413 } 11414 if (ut_params->ibuf) { 11415 rte_pktmbuf_free(ut_params->ibuf); 11416 ut_params->ibuf = 0; 11417 } 11418 } 11419 11420 sessions[i] = NULL; 11421 /* Next session create should fail */ 11422 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11423 sessions[i], &ut_params->auth_xform, 11424 ts_params->session_priv_mpool); 11425 TEST_ASSERT_NULL(sessions[i], 11426 "Session creation succeeded unexpectedly!"); 11427 11428 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11429 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11430 sessions[i]); 11431 rte_cryptodev_sym_session_free(sessions[i]); 11432 } 11433 11434 rte_free(sessions); 11435 11436 return TEST_SUCCESS; 11437 } 11438 11439 struct multi_session_params { 11440 struct crypto_unittest_params ut_params; 11441 uint8_t *cipher_key; 11442 uint8_t *hmac_key; 11443 const uint8_t *cipher; 11444 const uint8_t *digest; 11445 uint8_t *iv; 11446 }; 11447 11448 #define MB_SESSION_NUMBER 3 11449 11450 static int 11451 test_multi_session_random_usage(void) 11452 { 11453 struct crypto_testsuite_params *ts_params = &testsuite_params; 11454 struct rte_cryptodev_info dev_info; 11455 struct rte_cryptodev_sym_session **sessions; 11456 uint32_t i, j; 11457 struct multi_session_params ut_paramz[] = { 11458 11459 { 11460 .cipher_key = ms_aes_cbc_key0, 11461 .hmac_key = ms_hmac_key0, 11462 .cipher = ms_aes_cbc_cipher0, 11463 .digest = ms_hmac_digest0, 11464 .iv = ms_aes_cbc_iv0 11465 }, 11466 { 11467 .cipher_key = ms_aes_cbc_key1, 11468 .hmac_key = ms_hmac_key1, 11469 .cipher = ms_aes_cbc_cipher1, 11470 .digest = ms_hmac_digest1, 11471 .iv = ms_aes_cbc_iv1 11472 }, 11473 { 11474 .cipher_key = ms_aes_cbc_key2, 11475 .hmac_key = ms_hmac_key2, 11476 .cipher = ms_aes_cbc_cipher2, 11477 .digest = ms_hmac_digest2, 11478 .iv = ms_aes_cbc_iv2 11479 }, 11480 11481 }; 11482 int status; 11483 11484 /* Verify the capabilities */ 11485 struct rte_cryptodev_sym_capability_idx cap_idx; 11486 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11487 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11488 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11489 &cap_idx) == NULL) 11490 return TEST_SKIPPED; 11491 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11492 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11493 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11494 &cap_idx) == NULL) 11495 return TEST_SKIPPED; 11496 11497 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11498 11499 sessions = rte_malloc(NULL, 11500 (sizeof(struct rte_cryptodev_sym_session *) 11501 * MAX_NB_SESSIONS) + 1, 0); 11502 11503 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11504 sessions[i] = rte_cryptodev_sym_session_create( 11505 ts_params->session_mpool); 11506 TEST_ASSERT_NOT_NULL(sessions[i], 11507 "Session creation failed at session number %u", 11508 i); 11509 11510 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 11511 sizeof(struct crypto_unittest_params)); 11512 11513 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 11514 &ut_paramz[i].ut_params, 11515 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 11516 11517 /* Create multiple crypto sessions*/ 11518 status = rte_cryptodev_sym_session_init( 11519 ts_params->valid_devs[0], 11520 sessions[i], 11521 &ut_paramz[i].ut_params.auth_xform, 11522 ts_params->session_priv_mpool); 11523 11524 if (status == -ENOTSUP) 11525 return TEST_SKIPPED; 11526 11527 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11528 } 11529 11530 srand(time(NULL)); 11531 for (i = 0; i < 40000; i++) { 11532 11533 j = rand() % MB_SESSION_NUMBER; 11534 11535 TEST_ASSERT_SUCCESS( 11536 test_AES_CBC_HMAC_SHA512_decrypt_perform( 11537 sessions[j], 11538 &ut_paramz[j].ut_params, 11539 ts_params, ut_paramz[j].cipher, 11540 ut_paramz[j].digest, 11541 ut_paramz[j].iv), 11542 "Failed to perform decrypt on request number %u.", i); 11543 11544 if (ut_paramz[j].ut_params.op) 11545 rte_crypto_op_free(ut_paramz[j].ut_params.op); 11546 11547 /* 11548 * free mbuf - both obuf and ibuf are usually the same, 11549 * so check if they point at the same address is necessary, 11550 * to avoid freeing the mbuf twice. 11551 */ 11552 if (ut_paramz[j].ut_params.obuf) { 11553 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 11554 if (ut_paramz[j].ut_params.ibuf 11555 == ut_paramz[j].ut_params.obuf) 11556 ut_paramz[j].ut_params.ibuf = 0; 11557 ut_paramz[j].ut_params.obuf = 0; 11558 } 11559 if (ut_paramz[j].ut_params.ibuf) { 11560 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 11561 ut_paramz[j].ut_params.ibuf = 0; 11562 } 11563 } 11564 11565 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11566 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11567 sessions[i]); 11568 rte_cryptodev_sym_session_free(sessions[i]); 11569 } 11570 11571 rte_free(sessions); 11572 11573 return TEST_SUCCESS; 11574 } 11575 11576 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 11577 0xab, 0xab, 0xab, 0xab, 11578 0xab, 0xab, 0xab, 0xab, 11579 0xab, 0xab, 0xab, 0xab}; 11580 11581 static int 11582 test_null_invalid_operation(void) 11583 { 11584 struct crypto_testsuite_params *ts_params = &testsuite_params; 11585 struct crypto_unittest_params *ut_params = &unittest_params; 11586 int ret; 11587 11588 /* This test is for NULL PMD only */ 11589 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11590 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11591 return TEST_SKIPPED; 11592 11593 /* Setup Cipher Parameters */ 11594 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11595 ut_params->cipher_xform.next = NULL; 11596 11597 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 11598 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11599 11600 ut_params->sess = rte_cryptodev_sym_session_create( 11601 ts_params->session_mpool); 11602 11603 /* Create Crypto session*/ 11604 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11605 ut_params->sess, &ut_params->cipher_xform, 11606 ts_params->session_priv_mpool); 11607 TEST_ASSERT(ret < 0, 11608 "Session creation succeeded unexpectedly"); 11609 11610 11611 /* Setup HMAC Parameters */ 11612 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11613 ut_params->auth_xform.next = NULL; 11614 11615 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 11616 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11617 11618 ut_params->sess = rte_cryptodev_sym_session_create( 11619 ts_params->session_mpool); 11620 11621 /* Create Crypto session*/ 11622 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11623 ut_params->sess, &ut_params->auth_xform, 11624 ts_params->session_priv_mpool); 11625 TEST_ASSERT(ret < 0, 11626 "Session creation succeeded unexpectedly"); 11627 11628 return TEST_SUCCESS; 11629 } 11630 11631 11632 #define NULL_BURST_LENGTH (32) 11633 11634 static int 11635 test_null_burst_operation(void) 11636 { 11637 struct crypto_testsuite_params *ts_params = &testsuite_params; 11638 struct crypto_unittest_params *ut_params = &unittest_params; 11639 int status; 11640 11641 unsigned i, burst_len = NULL_BURST_LENGTH; 11642 11643 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 11644 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 11645 11646 /* This test is for NULL PMD only */ 11647 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11648 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11649 return TEST_SKIPPED; 11650 11651 /* Setup Cipher Parameters */ 11652 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11653 ut_params->cipher_xform.next = &ut_params->auth_xform; 11654 11655 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 11656 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11657 11658 /* Setup HMAC Parameters */ 11659 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11660 ut_params->auth_xform.next = NULL; 11661 11662 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 11663 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11664 11665 ut_params->sess = rte_cryptodev_sym_session_create( 11666 ts_params->session_mpool); 11667 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11668 11669 /* Create Crypto session*/ 11670 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11671 ut_params->sess, &ut_params->cipher_xform, 11672 ts_params->session_priv_mpool); 11673 11674 if (status == -ENOTSUP) 11675 return TEST_SKIPPED; 11676 11677 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11678 11679 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 11680 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 11681 burst_len, "failed to generate burst of crypto ops"); 11682 11683 /* Generate an operation for each mbuf in burst */ 11684 for (i = 0; i < burst_len; i++) { 11685 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11686 11687 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 11688 11689 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 11690 sizeof(unsigned)); 11691 *data = i; 11692 11693 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 11694 11695 burst[i]->sym->m_src = m; 11696 } 11697 11698 /* Process crypto operation */ 11699 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 11700 0, burst, burst_len), 11701 burst_len, 11702 "Error enqueuing burst"); 11703 11704 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 11705 0, burst_dequeued, burst_len), 11706 burst_len, 11707 "Error dequeuing burst"); 11708 11709 11710 for (i = 0; i < burst_len; i++) { 11711 TEST_ASSERT_EQUAL( 11712 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 11713 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 11714 uint32_t *), 11715 "data not as expected"); 11716 11717 rte_pktmbuf_free(burst[i]->sym->m_src); 11718 rte_crypto_op_free(burst[i]); 11719 } 11720 11721 return TEST_SUCCESS; 11722 } 11723 11724 static uint16_t 11725 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11726 uint16_t nb_ops, void *user_param) 11727 { 11728 RTE_SET_USED(dev_id); 11729 RTE_SET_USED(qp_id); 11730 RTE_SET_USED(ops); 11731 RTE_SET_USED(user_param); 11732 11733 printf("crypto enqueue callback called\n"); 11734 return nb_ops; 11735 } 11736 11737 static uint16_t 11738 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11739 uint16_t nb_ops, void *user_param) 11740 { 11741 RTE_SET_USED(dev_id); 11742 RTE_SET_USED(qp_id); 11743 RTE_SET_USED(ops); 11744 RTE_SET_USED(user_param); 11745 11746 printf("crypto dequeue callback called\n"); 11747 return nb_ops; 11748 } 11749 11750 /* 11751 * Thread using enqueue/dequeue callback with RCU. 11752 */ 11753 static int 11754 test_enqdeq_callback_thread(void *arg) 11755 { 11756 RTE_SET_USED(arg); 11757 /* DP thread calls rte_cryptodev_enqueue_burst()/ 11758 * rte_cryptodev_dequeue_burst() and invokes callback. 11759 */ 11760 test_null_burst_operation(); 11761 return 0; 11762 } 11763 11764 static int 11765 test_enq_callback_setup(void) 11766 { 11767 struct crypto_testsuite_params *ts_params = &testsuite_params; 11768 struct rte_cryptodev_info dev_info; 11769 struct rte_cryptodev_qp_conf qp_conf = { 11770 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11771 }; 11772 11773 struct rte_cryptodev_cb *cb; 11774 uint16_t qp_id = 0; 11775 11776 /* Stop the device in case it's started so it can be configured */ 11777 rte_cryptodev_stop(ts_params->valid_devs[0]); 11778 11779 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11780 11781 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11782 &ts_params->conf), 11783 "Failed to configure cryptodev %u", 11784 ts_params->valid_devs[0]); 11785 11786 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11787 qp_conf.mp_session = ts_params->session_mpool; 11788 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11789 11790 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11791 ts_params->valid_devs[0], qp_id, &qp_conf, 11792 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11793 "Failed test for " 11794 "rte_cryptodev_queue_pair_setup: num_inflights " 11795 "%u on qp %u on cryptodev %u", 11796 qp_conf.nb_descriptors, qp_id, 11797 ts_params->valid_devs[0]); 11798 11799 /* Test with invalid crypto device */ 11800 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 11801 qp_id, test_enq_callback, NULL); 11802 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11803 "cryptodev %u did not fail", 11804 qp_id, RTE_CRYPTO_MAX_DEVS); 11805 11806 /* Test with invalid queue pair */ 11807 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11808 dev_info.max_nb_queue_pairs + 1, 11809 test_enq_callback, NULL); 11810 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11811 "cryptodev %u did not fail", 11812 dev_info.max_nb_queue_pairs + 1, 11813 ts_params->valid_devs[0]); 11814 11815 /* Test with NULL callback */ 11816 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11817 qp_id, NULL, NULL); 11818 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11819 "cryptodev %u did not fail", 11820 qp_id, ts_params->valid_devs[0]); 11821 11822 /* Test with valid configuration */ 11823 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11824 qp_id, test_enq_callback, NULL); 11825 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11826 "qp %u on cryptodev %u", 11827 qp_id, ts_params->valid_devs[0]); 11828 11829 rte_cryptodev_start(ts_params->valid_devs[0]); 11830 11831 /* Launch a thread */ 11832 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11833 rte_get_next_lcore(-1, 1, 0)); 11834 11835 /* Wait until reader exited. */ 11836 rte_eal_mp_wait_lcore(); 11837 11838 /* Test with invalid crypto device */ 11839 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11840 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11841 "Expected call to fail as crypto device is invalid"); 11842 11843 /* Test with invalid queue pair */ 11844 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11845 ts_params->valid_devs[0], 11846 dev_info.max_nb_queue_pairs + 1, cb), 11847 "Expected call to fail as queue pair is invalid"); 11848 11849 /* Test with NULL callback */ 11850 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11851 ts_params->valid_devs[0], qp_id, NULL), 11852 "Expected call to fail as callback is NULL"); 11853 11854 /* Test with valid configuration */ 11855 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 11856 ts_params->valid_devs[0], qp_id, cb), 11857 "Failed test to remove callback on " 11858 "qp %u on cryptodev %u", 11859 qp_id, ts_params->valid_devs[0]); 11860 11861 return TEST_SUCCESS; 11862 } 11863 11864 static int 11865 test_deq_callback_setup(void) 11866 { 11867 struct crypto_testsuite_params *ts_params = &testsuite_params; 11868 struct rte_cryptodev_info dev_info; 11869 struct rte_cryptodev_qp_conf qp_conf = { 11870 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11871 }; 11872 11873 struct rte_cryptodev_cb *cb; 11874 uint16_t qp_id = 0; 11875 11876 /* Stop the device in case it's started so it can be configured */ 11877 rte_cryptodev_stop(ts_params->valid_devs[0]); 11878 11879 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11880 11881 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11882 &ts_params->conf), 11883 "Failed to configure cryptodev %u", 11884 ts_params->valid_devs[0]); 11885 11886 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11887 qp_conf.mp_session = ts_params->session_mpool; 11888 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11889 11890 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11891 ts_params->valid_devs[0], qp_id, &qp_conf, 11892 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11893 "Failed test for " 11894 "rte_cryptodev_queue_pair_setup: num_inflights " 11895 "%u on qp %u on cryptodev %u", 11896 qp_conf.nb_descriptors, qp_id, 11897 ts_params->valid_devs[0]); 11898 11899 /* Test with invalid crypto device */ 11900 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 11901 qp_id, test_deq_callback, NULL); 11902 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11903 "cryptodev %u did not fail", 11904 qp_id, RTE_CRYPTO_MAX_DEVS); 11905 11906 /* Test with invalid queue pair */ 11907 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11908 dev_info.max_nb_queue_pairs + 1, 11909 test_deq_callback, NULL); 11910 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11911 "cryptodev %u did not fail", 11912 dev_info.max_nb_queue_pairs + 1, 11913 ts_params->valid_devs[0]); 11914 11915 /* Test with NULL callback */ 11916 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11917 qp_id, NULL, NULL); 11918 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11919 "cryptodev %u did not fail", 11920 qp_id, ts_params->valid_devs[0]); 11921 11922 /* Test with valid configuration */ 11923 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11924 qp_id, test_deq_callback, NULL); 11925 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11926 "qp %u on cryptodev %u", 11927 qp_id, ts_params->valid_devs[0]); 11928 11929 rte_cryptodev_start(ts_params->valid_devs[0]); 11930 11931 /* Launch a thread */ 11932 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11933 rte_get_next_lcore(-1, 1, 0)); 11934 11935 /* Wait until reader exited. */ 11936 rte_eal_mp_wait_lcore(); 11937 11938 /* Test with invalid crypto device */ 11939 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11940 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11941 "Expected call to fail as crypto device is invalid"); 11942 11943 /* Test with invalid queue pair */ 11944 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11945 ts_params->valid_devs[0], 11946 dev_info.max_nb_queue_pairs + 1, cb), 11947 "Expected call to fail as queue pair is invalid"); 11948 11949 /* Test with NULL callback */ 11950 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11951 ts_params->valid_devs[0], qp_id, NULL), 11952 "Expected call to fail as callback is NULL"); 11953 11954 /* Test with valid configuration */ 11955 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 11956 ts_params->valid_devs[0], qp_id, cb), 11957 "Failed test to remove callback on " 11958 "qp %u on cryptodev %u", 11959 qp_id, ts_params->valid_devs[0]); 11960 11961 return TEST_SUCCESS; 11962 } 11963 11964 static void 11965 generate_gmac_large_plaintext(uint8_t *data) 11966 { 11967 uint16_t i; 11968 11969 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 11970 memcpy(&data[i], &data[0], 32); 11971 } 11972 11973 static int 11974 create_gmac_operation(enum rte_crypto_auth_operation op, 11975 const struct gmac_test_data *tdata) 11976 { 11977 struct crypto_testsuite_params *ts_params = &testsuite_params; 11978 struct crypto_unittest_params *ut_params = &unittest_params; 11979 struct rte_crypto_sym_op *sym_op; 11980 11981 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11982 11983 /* Generate Crypto op data structure */ 11984 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11985 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11986 TEST_ASSERT_NOT_NULL(ut_params->op, 11987 "Failed to allocate symmetric crypto operation struct"); 11988 11989 sym_op = ut_params->op->sym; 11990 11991 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11992 ut_params->ibuf, tdata->gmac_tag.len); 11993 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11994 "no room to append digest"); 11995 11996 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11997 ut_params->ibuf, plaintext_pad_len); 11998 11999 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12000 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12001 tdata->gmac_tag.len); 12002 debug_hexdump(stdout, "digest:", 12003 sym_op->auth.digest.data, 12004 tdata->gmac_tag.len); 12005 } 12006 12007 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12008 uint8_t *, IV_OFFSET); 12009 12010 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12011 12012 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12013 12014 sym_op->cipher.data.length = 0; 12015 sym_op->cipher.data.offset = 0; 12016 12017 sym_op->auth.data.offset = 0; 12018 sym_op->auth.data.length = tdata->plaintext.len; 12019 12020 return 0; 12021 } 12022 12023 static int 12024 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12025 const struct gmac_test_data *tdata, 12026 void *digest_mem, uint64_t digest_phys) 12027 { 12028 struct crypto_testsuite_params *ts_params = &testsuite_params; 12029 struct crypto_unittest_params *ut_params = &unittest_params; 12030 struct rte_crypto_sym_op *sym_op; 12031 12032 /* Generate Crypto op data structure */ 12033 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12034 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12035 TEST_ASSERT_NOT_NULL(ut_params->op, 12036 "Failed to allocate symmetric crypto operation struct"); 12037 12038 sym_op = ut_params->op->sym; 12039 12040 sym_op->auth.digest.data = digest_mem; 12041 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12042 "no room to append digest"); 12043 12044 sym_op->auth.digest.phys_addr = digest_phys; 12045 12046 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12047 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12048 tdata->gmac_tag.len); 12049 debug_hexdump(stdout, "digest:", 12050 sym_op->auth.digest.data, 12051 tdata->gmac_tag.len); 12052 } 12053 12054 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12055 uint8_t *, IV_OFFSET); 12056 12057 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12058 12059 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12060 12061 sym_op->cipher.data.length = 0; 12062 sym_op->cipher.data.offset = 0; 12063 12064 sym_op->auth.data.offset = 0; 12065 sym_op->auth.data.length = tdata->plaintext.len; 12066 12067 return 0; 12068 } 12069 12070 static int create_gmac_session(uint8_t dev_id, 12071 const struct gmac_test_data *tdata, 12072 enum rte_crypto_auth_operation auth_op) 12073 { 12074 uint8_t auth_key[tdata->key.len]; 12075 int status; 12076 12077 struct crypto_testsuite_params *ts_params = &testsuite_params; 12078 struct crypto_unittest_params *ut_params = &unittest_params; 12079 12080 memcpy(auth_key, tdata->key.data, tdata->key.len); 12081 12082 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12083 ut_params->auth_xform.next = NULL; 12084 12085 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12086 ut_params->auth_xform.auth.op = auth_op; 12087 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12088 ut_params->auth_xform.auth.key.length = tdata->key.len; 12089 ut_params->auth_xform.auth.key.data = auth_key; 12090 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12091 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12092 12093 12094 ut_params->sess = rte_cryptodev_sym_session_create( 12095 ts_params->session_mpool); 12096 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12097 12098 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12099 &ut_params->auth_xform, 12100 ts_params->session_priv_mpool); 12101 12102 return status; 12103 } 12104 12105 static int 12106 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12107 { 12108 struct crypto_testsuite_params *ts_params = &testsuite_params; 12109 struct crypto_unittest_params *ut_params = &unittest_params; 12110 struct rte_cryptodev_info dev_info; 12111 12112 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12113 uint64_t feat_flags = dev_info.feature_flags; 12114 12115 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12116 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12117 printf("Device doesn't support RAW data-path APIs.\n"); 12118 return TEST_SKIPPED; 12119 } 12120 12121 int retval; 12122 12123 uint8_t *auth_tag, *plaintext; 12124 uint16_t plaintext_pad_len; 12125 12126 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12127 "No GMAC length in the source data"); 12128 12129 /* Verify the capabilities */ 12130 struct rte_cryptodev_sym_capability_idx cap_idx; 12131 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12132 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12133 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12134 &cap_idx) == NULL) 12135 return TEST_SKIPPED; 12136 12137 retval = create_gmac_session(ts_params->valid_devs[0], 12138 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12139 12140 if (retval == -ENOTSUP) 12141 return TEST_SKIPPED; 12142 if (retval < 0) 12143 return retval; 12144 12145 if (tdata->plaintext.len > MBUF_SIZE) 12146 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12147 else 12148 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12149 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12150 "Failed to allocate input buffer in mempool"); 12151 12152 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12153 rte_pktmbuf_tailroom(ut_params->ibuf)); 12154 12155 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12156 /* 12157 * Runtime generate the large plain text instead of use hard code 12158 * plain text vector. It is done to avoid create huge source file 12159 * with the test vector. 12160 */ 12161 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12162 generate_gmac_large_plaintext(tdata->plaintext.data); 12163 12164 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12165 plaintext_pad_len); 12166 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12167 12168 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12169 debug_hexdump(stdout, "plaintext:", plaintext, 12170 tdata->plaintext.len); 12171 12172 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12173 tdata); 12174 12175 if (retval < 0) 12176 return retval; 12177 12178 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12179 12180 ut_params->op->sym->m_src = ut_params->ibuf; 12181 12182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12183 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12184 ut_params->op); 12185 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12186 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12187 ut_params->op, 0, 1, 0, 0); 12188 else 12189 TEST_ASSERT_NOT_NULL( 12190 process_crypto_request(ts_params->valid_devs[0], 12191 ut_params->op), "failed to process sym crypto op"); 12192 12193 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12194 "crypto op processing failed"); 12195 12196 if (ut_params->op->sym->m_dst) { 12197 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12198 uint8_t *, plaintext_pad_len); 12199 } else { 12200 auth_tag = plaintext + plaintext_pad_len; 12201 } 12202 12203 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12204 12205 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12206 auth_tag, 12207 tdata->gmac_tag.data, 12208 tdata->gmac_tag.len, 12209 "GMAC Generated auth tag not as expected"); 12210 12211 return 0; 12212 } 12213 12214 static int 12215 test_AES_GMAC_authentication_test_case_1(void) 12216 { 12217 return test_AES_GMAC_authentication(&gmac_test_case_1); 12218 } 12219 12220 static int 12221 test_AES_GMAC_authentication_test_case_2(void) 12222 { 12223 return test_AES_GMAC_authentication(&gmac_test_case_2); 12224 } 12225 12226 static int 12227 test_AES_GMAC_authentication_test_case_3(void) 12228 { 12229 return test_AES_GMAC_authentication(&gmac_test_case_3); 12230 } 12231 12232 static int 12233 test_AES_GMAC_authentication_test_case_4(void) 12234 { 12235 return test_AES_GMAC_authentication(&gmac_test_case_4); 12236 } 12237 12238 static int 12239 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12240 { 12241 struct crypto_testsuite_params *ts_params = &testsuite_params; 12242 struct crypto_unittest_params *ut_params = &unittest_params; 12243 int retval; 12244 uint32_t plaintext_pad_len; 12245 uint8_t *plaintext; 12246 struct rte_cryptodev_info dev_info; 12247 12248 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12249 uint64_t feat_flags = dev_info.feature_flags; 12250 12251 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12252 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12253 printf("Device doesn't support RAW data-path APIs.\n"); 12254 return TEST_SKIPPED; 12255 } 12256 12257 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12258 "No GMAC length in the source data"); 12259 12260 /* Verify the capabilities */ 12261 struct rte_cryptodev_sym_capability_idx cap_idx; 12262 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12263 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12264 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12265 &cap_idx) == NULL) 12266 return TEST_SKIPPED; 12267 12268 retval = create_gmac_session(ts_params->valid_devs[0], 12269 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12270 12271 if (retval == -ENOTSUP) 12272 return TEST_SKIPPED; 12273 if (retval < 0) 12274 return retval; 12275 12276 if (tdata->plaintext.len > MBUF_SIZE) 12277 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12278 else 12279 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12280 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12281 "Failed to allocate input buffer in mempool"); 12282 12283 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12284 rte_pktmbuf_tailroom(ut_params->ibuf)); 12285 12286 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12287 12288 /* 12289 * Runtime generate the large plain text instead of use hard code 12290 * plain text vector. It is done to avoid create huge source file 12291 * with the test vector. 12292 */ 12293 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12294 generate_gmac_large_plaintext(tdata->plaintext.data); 12295 12296 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12297 plaintext_pad_len); 12298 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12299 12300 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12301 debug_hexdump(stdout, "plaintext:", plaintext, 12302 tdata->plaintext.len); 12303 12304 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 12305 tdata); 12306 12307 if (retval < 0) 12308 return retval; 12309 12310 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12311 12312 ut_params->op->sym->m_src = ut_params->ibuf; 12313 12314 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12315 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12316 ut_params->op); 12317 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12318 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12319 ut_params->op, 0, 1, 0, 0); 12320 else 12321 TEST_ASSERT_NOT_NULL( 12322 process_crypto_request(ts_params->valid_devs[0], 12323 ut_params->op), "failed to process sym crypto op"); 12324 12325 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12326 "crypto op processing failed"); 12327 12328 return 0; 12329 12330 } 12331 12332 static int 12333 test_AES_GMAC_authentication_verify_test_case_1(void) 12334 { 12335 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 12336 } 12337 12338 static int 12339 test_AES_GMAC_authentication_verify_test_case_2(void) 12340 { 12341 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 12342 } 12343 12344 static int 12345 test_AES_GMAC_authentication_verify_test_case_3(void) 12346 { 12347 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 12348 } 12349 12350 static int 12351 test_AES_GMAC_authentication_verify_test_case_4(void) 12352 { 12353 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 12354 } 12355 12356 static int 12357 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 12358 uint32_t fragsz) 12359 { 12360 struct crypto_testsuite_params *ts_params = &testsuite_params; 12361 struct crypto_unittest_params *ut_params = &unittest_params; 12362 struct rte_cryptodev_info dev_info; 12363 uint64_t feature_flags; 12364 unsigned int trn_data = 0; 12365 void *digest_mem = NULL; 12366 uint32_t segs = 1; 12367 unsigned int to_trn = 0; 12368 struct rte_mbuf *buf = NULL; 12369 uint8_t *auth_tag, *plaintext; 12370 int retval; 12371 12372 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12373 "No GMAC length in the source data"); 12374 12375 /* Verify the capabilities */ 12376 struct rte_cryptodev_sym_capability_idx cap_idx; 12377 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12378 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12379 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12380 &cap_idx) == NULL) 12381 return TEST_SKIPPED; 12382 12383 /* Check for any input SGL support */ 12384 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12385 feature_flags = dev_info.feature_flags; 12386 12387 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 12388 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 12389 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 12390 return TEST_SKIPPED; 12391 12392 if (fragsz > tdata->plaintext.len) 12393 fragsz = tdata->plaintext.len; 12394 12395 uint16_t plaintext_len = fragsz; 12396 12397 retval = create_gmac_session(ts_params->valid_devs[0], 12398 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12399 12400 if (retval == -ENOTSUP) 12401 return TEST_SKIPPED; 12402 if (retval < 0) 12403 return retval; 12404 12405 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12406 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12407 "Failed to allocate input buffer in mempool"); 12408 12409 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12410 rte_pktmbuf_tailroom(ut_params->ibuf)); 12411 12412 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12413 plaintext_len); 12414 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12415 12416 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12417 12418 trn_data += plaintext_len; 12419 12420 buf = ut_params->ibuf; 12421 12422 /* 12423 * Loop until no more fragments 12424 */ 12425 12426 while (trn_data < tdata->plaintext.len) { 12427 ++segs; 12428 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12429 (tdata->plaintext.len - trn_data) : fragsz; 12430 12431 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12432 buf = buf->next; 12433 12434 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12435 rte_pktmbuf_tailroom(buf)); 12436 12437 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12438 to_trn); 12439 12440 memcpy(plaintext, tdata->plaintext.data + trn_data, 12441 to_trn); 12442 trn_data += to_trn; 12443 if (trn_data == tdata->plaintext.len) 12444 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12445 tdata->gmac_tag.len); 12446 } 12447 ut_params->ibuf->nb_segs = segs; 12448 12449 /* 12450 * Place digest at the end of the last buffer 12451 */ 12452 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12453 12454 if (!digest_mem) { 12455 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12456 + tdata->gmac_tag.len); 12457 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12458 tdata->plaintext.len); 12459 } 12460 12461 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 12462 tdata, digest_mem, digest_phys); 12463 12464 if (retval < 0) 12465 return retval; 12466 12467 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12468 12469 ut_params->op->sym->m_src = ut_params->ibuf; 12470 12471 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12472 return TEST_SKIPPED; 12473 12474 TEST_ASSERT_NOT_NULL( 12475 process_crypto_request(ts_params->valid_devs[0], 12476 ut_params->op), "failed to process sym crypto op"); 12477 12478 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12479 "crypto op processing failed"); 12480 12481 auth_tag = digest_mem; 12482 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12483 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12484 auth_tag, 12485 tdata->gmac_tag.data, 12486 tdata->gmac_tag.len, 12487 "GMAC Generated auth tag not as expected"); 12488 12489 return 0; 12490 } 12491 12492 /* Segment size not multiple of block size (16B) */ 12493 static int 12494 test_AES_GMAC_authentication_SGL_40B(void) 12495 { 12496 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 12497 } 12498 12499 static int 12500 test_AES_GMAC_authentication_SGL_80B(void) 12501 { 12502 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 12503 } 12504 12505 static int 12506 test_AES_GMAC_authentication_SGL_2048B(void) 12507 { 12508 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 12509 } 12510 12511 /* Segment size not multiple of block size (16B) */ 12512 static int 12513 test_AES_GMAC_authentication_SGL_2047B(void) 12514 { 12515 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 12516 } 12517 12518 struct test_crypto_vector { 12519 enum rte_crypto_cipher_algorithm crypto_algo; 12520 unsigned int cipher_offset; 12521 unsigned int cipher_len; 12522 12523 struct { 12524 uint8_t data[64]; 12525 unsigned int len; 12526 } cipher_key; 12527 12528 struct { 12529 uint8_t data[64]; 12530 unsigned int len; 12531 } iv; 12532 12533 struct { 12534 const uint8_t *data; 12535 unsigned int len; 12536 } plaintext; 12537 12538 struct { 12539 const uint8_t *data; 12540 unsigned int len; 12541 } ciphertext; 12542 12543 enum rte_crypto_auth_algorithm auth_algo; 12544 unsigned int auth_offset; 12545 12546 struct { 12547 uint8_t data[128]; 12548 unsigned int len; 12549 } auth_key; 12550 12551 struct { 12552 const uint8_t *data; 12553 unsigned int len; 12554 } aad; 12555 12556 struct { 12557 uint8_t data[128]; 12558 unsigned int len; 12559 } digest; 12560 }; 12561 12562 static const struct test_crypto_vector 12563 hmac_sha1_test_crypto_vector = { 12564 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12565 .plaintext = { 12566 .data = plaintext_hash, 12567 .len = 512 12568 }, 12569 .auth_key = { 12570 .data = { 12571 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12572 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12573 0xDE, 0xF4, 0xDE, 0xAD 12574 }, 12575 .len = 20 12576 }, 12577 .digest = { 12578 .data = { 12579 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 12580 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 12581 0x3F, 0x91, 0x64, 0x59 12582 }, 12583 .len = 20 12584 } 12585 }; 12586 12587 static const struct test_crypto_vector 12588 aes128_gmac_test_vector = { 12589 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 12590 .plaintext = { 12591 .data = plaintext_hash, 12592 .len = 512 12593 }, 12594 .iv = { 12595 .data = { 12596 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12597 0x08, 0x09, 0x0A, 0x0B 12598 }, 12599 .len = 12 12600 }, 12601 .auth_key = { 12602 .data = { 12603 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12604 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 12605 }, 12606 .len = 16 12607 }, 12608 .digest = { 12609 .data = { 12610 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 12611 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 12612 }, 12613 .len = 16 12614 } 12615 }; 12616 12617 static const struct test_crypto_vector 12618 aes128cbc_hmac_sha1_test_vector = { 12619 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12620 .cipher_offset = 0, 12621 .cipher_len = 512, 12622 .cipher_key = { 12623 .data = { 12624 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12625 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12626 }, 12627 .len = 16 12628 }, 12629 .iv = { 12630 .data = { 12631 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12632 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12633 }, 12634 .len = 16 12635 }, 12636 .plaintext = { 12637 .data = plaintext_hash, 12638 .len = 512 12639 }, 12640 .ciphertext = { 12641 .data = ciphertext512_aes128cbc, 12642 .len = 512 12643 }, 12644 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12645 .auth_offset = 0, 12646 .auth_key = { 12647 .data = { 12648 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12649 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12650 0xDE, 0xF4, 0xDE, 0xAD 12651 }, 12652 .len = 20 12653 }, 12654 .digest = { 12655 .data = { 12656 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 12657 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12658 0x18, 0x8C, 0x1D, 0x32 12659 }, 12660 .len = 20 12661 } 12662 }; 12663 12664 static const struct test_crypto_vector 12665 aes128cbc_hmac_sha1_aad_test_vector = { 12666 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12667 .cipher_offset = 8, 12668 .cipher_len = 496, 12669 .cipher_key = { 12670 .data = { 12671 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12672 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12673 }, 12674 .len = 16 12675 }, 12676 .iv = { 12677 .data = { 12678 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12679 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12680 }, 12681 .len = 16 12682 }, 12683 .plaintext = { 12684 .data = plaintext_hash, 12685 .len = 512 12686 }, 12687 .ciphertext = { 12688 .data = ciphertext512_aes128cbc_aad, 12689 .len = 512 12690 }, 12691 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12692 .auth_offset = 0, 12693 .auth_key = { 12694 .data = { 12695 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12696 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12697 0xDE, 0xF4, 0xDE, 0xAD 12698 }, 12699 .len = 20 12700 }, 12701 .digest = { 12702 .data = { 12703 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 12704 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 12705 0x62, 0x0F, 0xFB, 0x10 12706 }, 12707 .len = 20 12708 } 12709 }; 12710 12711 static void 12712 data_corruption(uint8_t *data) 12713 { 12714 data[0] += 1; 12715 } 12716 12717 static void 12718 tag_corruption(uint8_t *data, unsigned int tag_offset) 12719 { 12720 data[tag_offset] += 1; 12721 } 12722 12723 static int 12724 create_auth_session(struct crypto_unittest_params *ut_params, 12725 uint8_t dev_id, 12726 const struct test_crypto_vector *reference, 12727 enum rte_crypto_auth_operation auth_op) 12728 { 12729 struct crypto_testsuite_params *ts_params = &testsuite_params; 12730 uint8_t auth_key[reference->auth_key.len + 1]; 12731 int status; 12732 12733 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12734 12735 /* Setup Authentication Parameters */ 12736 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12737 ut_params->auth_xform.auth.op = auth_op; 12738 ut_params->auth_xform.next = NULL; 12739 ut_params->auth_xform.auth.algo = reference->auth_algo; 12740 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12741 ut_params->auth_xform.auth.key.data = auth_key; 12742 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12743 12744 /* Create Crypto session*/ 12745 ut_params->sess = rte_cryptodev_sym_session_create( 12746 ts_params->session_mpool); 12747 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12748 12749 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12750 &ut_params->auth_xform, 12751 ts_params->session_priv_mpool); 12752 12753 return status; 12754 } 12755 12756 static int 12757 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 12758 uint8_t dev_id, 12759 const struct test_crypto_vector *reference, 12760 enum rte_crypto_auth_operation auth_op, 12761 enum rte_crypto_cipher_operation cipher_op) 12762 { 12763 struct crypto_testsuite_params *ts_params = &testsuite_params; 12764 uint8_t cipher_key[reference->cipher_key.len + 1]; 12765 uint8_t auth_key[reference->auth_key.len + 1]; 12766 int status; 12767 12768 memcpy(cipher_key, reference->cipher_key.data, 12769 reference->cipher_key.len); 12770 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12771 12772 /* Setup Authentication Parameters */ 12773 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12774 ut_params->auth_xform.auth.op = auth_op; 12775 ut_params->auth_xform.auth.algo = reference->auth_algo; 12776 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12777 ut_params->auth_xform.auth.key.data = auth_key; 12778 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12779 12780 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 12781 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12782 ut_params->auth_xform.auth.iv.length = reference->iv.len; 12783 } else { 12784 ut_params->auth_xform.next = &ut_params->cipher_xform; 12785 12786 /* Setup Cipher Parameters */ 12787 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12788 ut_params->cipher_xform.next = NULL; 12789 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12790 ut_params->cipher_xform.cipher.op = cipher_op; 12791 ut_params->cipher_xform.cipher.key.data = cipher_key; 12792 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12793 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12794 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12795 } 12796 12797 /* Create Crypto session*/ 12798 ut_params->sess = rte_cryptodev_sym_session_create( 12799 ts_params->session_mpool); 12800 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12801 12802 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12803 &ut_params->auth_xform, 12804 ts_params->session_priv_mpool); 12805 12806 return status; 12807 } 12808 12809 static int 12810 create_auth_operation(struct crypto_testsuite_params *ts_params, 12811 struct crypto_unittest_params *ut_params, 12812 const struct test_crypto_vector *reference, 12813 unsigned int auth_generate) 12814 { 12815 /* Generate Crypto op data structure */ 12816 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12817 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12818 TEST_ASSERT_NOT_NULL(ut_params->op, 12819 "Failed to allocate pktmbuf offload"); 12820 12821 /* Set crypto operation data parameters */ 12822 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12823 12824 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12825 12826 /* set crypto operation source mbuf */ 12827 sym_op->m_src = ut_params->ibuf; 12828 12829 /* digest */ 12830 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12831 ut_params->ibuf, reference->digest.len); 12832 12833 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12834 "no room to append auth tag"); 12835 12836 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12837 ut_params->ibuf, reference->plaintext.len); 12838 12839 if (auth_generate) 12840 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12841 else 12842 memcpy(sym_op->auth.digest.data, 12843 reference->digest.data, 12844 reference->digest.len); 12845 12846 debug_hexdump(stdout, "digest:", 12847 sym_op->auth.digest.data, 12848 reference->digest.len); 12849 12850 sym_op->auth.data.length = reference->plaintext.len; 12851 sym_op->auth.data.offset = 0; 12852 12853 return 0; 12854 } 12855 12856 static int 12857 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 12858 struct crypto_unittest_params *ut_params, 12859 const struct test_crypto_vector *reference, 12860 unsigned int auth_generate) 12861 { 12862 /* Generate Crypto op data structure */ 12863 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12864 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12865 TEST_ASSERT_NOT_NULL(ut_params->op, 12866 "Failed to allocate pktmbuf offload"); 12867 12868 /* Set crypto operation data parameters */ 12869 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12870 12871 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12872 12873 /* set crypto operation source mbuf */ 12874 sym_op->m_src = ut_params->ibuf; 12875 12876 /* digest */ 12877 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12878 ut_params->ibuf, reference->digest.len); 12879 12880 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12881 "no room to append auth tag"); 12882 12883 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12884 ut_params->ibuf, reference->ciphertext.len); 12885 12886 if (auth_generate) 12887 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12888 else 12889 memcpy(sym_op->auth.digest.data, 12890 reference->digest.data, 12891 reference->digest.len); 12892 12893 debug_hexdump(stdout, "digest:", 12894 sym_op->auth.digest.data, 12895 reference->digest.len); 12896 12897 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12898 reference->iv.data, reference->iv.len); 12899 12900 sym_op->cipher.data.length = 0; 12901 sym_op->cipher.data.offset = 0; 12902 12903 sym_op->auth.data.length = reference->plaintext.len; 12904 sym_op->auth.data.offset = 0; 12905 12906 return 0; 12907 } 12908 12909 static int 12910 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 12911 struct crypto_unittest_params *ut_params, 12912 const struct test_crypto_vector *reference, 12913 unsigned int auth_generate) 12914 { 12915 /* Generate Crypto op data structure */ 12916 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12917 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12918 TEST_ASSERT_NOT_NULL(ut_params->op, 12919 "Failed to allocate pktmbuf offload"); 12920 12921 /* Set crypto operation data parameters */ 12922 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12923 12924 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12925 12926 /* set crypto operation source mbuf */ 12927 sym_op->m_src = ut_params->ibuf; 12928 12929 /* digest */ 12930 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12931 ut_params->ibuf, reference->digest.len); 12932 12933 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12934 "no room to append auth tag"); 12935 12936 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12937 ut_params->ibuf, reference->ciphertext.len); 12938 12939 if (auth_generate) 12940 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12941 else 12942 memcpy(sym_op->auth.digest.data, 12943 reference->digest.data, 12944 reference->digest.len); 12945 12946 debug_hexdump(stdout, "digest:", 12947 sym_op->auth.digest.data, 12948 reference->digest.len); 12949 12950 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12951 reference->iv.data, reference->iv.len); 12952 12953 sym_op->cipher.data.length = reference->cipher_len; 12954 sym_op->cipher.data.offset = reference->cipher_offset; 12955 12956 sym_op->auth.data.length = reference->plaintext.len; 12957 sym_op->auth.data.offset = reference->auth_offset; 12958 12959 return 0; 12960 } 12961 12962 static int 12963 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 12964 struct crypto_unittest_params *ut_params, 12965 const struct test_crypto_vector *reference) 12966 { 12967 return create_auth_operation(ts_params, ut_params, reference, 0); 12968 } 12969 12970 static int 12971 create_auth_verify_GMAC_operation( 12972 struct crypto_testsuite_params *ts_params, 12973 struct crypto_unittest_params *ut_params, 12974 const struct test_crypto_vector *reference) 12975 { 12976 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 12977 } 12978 12979 static int 12980 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 12981 struct crypto_unittest_params *ut_params, 12982 const struct test_crypto_vector *reference) 12983 { 12984 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 12985 } 12986 12987 static int 12988 test_authentication_verify_fail_when_data_corruption( 12989 struct crypto_testsuite_params *ts_params, 12990 struct crypto_unittest_params *ut_params, 12991 const struct test_crypto_vector *reference, 12992 unsigned int data_corrupted) 12993 { 12994 int retval; 12995 12996 uint8_t *plaintext; 12997 struct rte_cryptodev_info dev_info; 12998 12999 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13000 uint64_t feat_flags = dev_info.feature_flags; 13001 13002 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13003 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13004 printf("Device doesn't support RAW data-path APIs.\n"); 13005 return TEST_SKIPPED; 13006 } 13007 13008 /* Verify the capabilities */ 13009 struct rte_cryptodev_sym_capability_idx cap_idx; 13010 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13011 cap_idx.algo.auth = reference->auth_algo; 13012 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13013 &cap_idx) == NULL) 13014 return TEST_SKIPPED; 13015 13016 13017 /* Create session */ 13018 retval = create_auth_session(ut_params, 13019 ts_params->valid_devs[0], 13020 reference, 13021 RTE_CRYPTO_AUTH_OP_VERIFY); 13022 13023 if (retval == -ENOTSUP) 13024 return TEST_SKIPPED; 13025 if (retval < 0) 13026 return retval; 13027 13028 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13029 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13030 "Failed to allocate input buffer in mempool"); 13031 13032 /* clear mbuf payload */ 13033 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13034 rte_pktmbuf_tailroom(ut_params->ibuf)); 13035 13036 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13037 reference->plaintext.len); 13038 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13039 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13040 13041 debug_hexdump(stdout, "plaintext:", plaintext, 13042 reference->plaintext.len); 13043 13044 /* Create operation */ 13045 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13046 13047 if (retval < 0) 13048 return retval; 13049 13050 if (data_corrupted) 13051 data_corruption(plaintext); 13052 else 13053 tag_corruption(plaintext, reference->plaintext.len); 13054 13055 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13056 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13057 ut_params->op); 13058 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13059 RTE_CRYPTO_OP_STATUS_SUCCESS, 13060 "authentication not failed"); 13061 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13062 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13063 ut_params->op, 0, 1, 0, 0); 13064 else { 13065 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13066 ut_params->op); 13067 } 13068 if (ut_params->op == NULL) 13069 return 0; 13070 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13071 return 0; 13072 13073 return -1; 13074 } 13075 13076 static int 13077 test_authentication_verify_GMAC_fail_when_corruption( 13078 struct crypto_testsuite_params *ts_params, 13079 struct crypto_unittest_params *ut_params, 13080 const struct test_crypto_vector *reference, 13081 unsigned int data_corrupted) 13082 { 13083 int retval; 13084 uint8_t *plaintext; 13085 struct rte_cryptodev_info dev_info; 13086 13087 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13088 uint64_t feat_flags = dev_info.feature_flags; 13089 13090 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13091 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13092 printf("Device doesn't support RAW data-path APIs.\n"); 13093 return TEST_SKIPPED; 13094 } 13095 13096 /* Verify the capabilities */ 13097 struct rte_cryptodev_sym_capability_idx cap_idx; 13098 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13099 cap_idx.algo.auth = reference->auth_algo; 13100 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13101 &cap_idx) == NULL) 13102 return TEST_SKIPPED; 13103 13104 /* Create session */ 13105 retval = create_auth_cipher_session(ut_params, 13106 ts_params->valid_devs[0], 13107 reference, 13108 RTE_CRYPTO_AUTH_OP_VERIFY, 13109 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13110 if (retval < 0) 13111 return retval; 13112 13113 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13114 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13115 "Failed to allocate input buffer in mempool"); 13116 13117 /* clear mbuf payload */ 13118 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13119 rte_pktmbuf_tailroom(ut_params->ibuf)); 13120 13121 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13122 reference->plaintext.len); 13123 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13124 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13125 13126 debug_hexdump(stdout, "plaintext:", plaintext, 13127 reference->plaintext.len); 13128 13129 /* Create operation */ 13130 retval = create_auth_verify_GMAC_operation(ts_params, 13131 ut_params, 13132 reference); 13133 13134 if (retval < 0) 13135 return retval; 13136 13137 if (data_corrupted) 13138 data_corruption(plaintext); 13139 else 13140 tag_corruption(plaintext, reference->aad.len); 13141 13142 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13143 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13144 ut_params->op); 13145 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13146 RTE_CRYPTO_OP_STATUS_SUCCESS, 13147 "authentication not failed"); 13148 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13149 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13150 ut_params->op, 0, 1, 0, 0); 13151 else { 13152 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13153 ut_params->op); 13154 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13155 } 13156 13157 return 0; 13158 } 13159 13160 static int 13161 test_authenticated_decryption_fail_when_corruption( 13162 struct crypto_testsuite_params *ts_params, 13163 struct crypto_unittest_params *ut_params, 13164 const struct test_crypto_vector *reference, 13165 unsigned int data_corrupted) 13166 { 13167 int retval; 13168 13169 uint8_t *ciphertext; 13170 struct rte_cryptodev_info dev_info; 13171 13172 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13173 uint64_t feat_flags = dev_info.feature_flags; 13174 13175 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13176 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13177 printf("Device doesn't support RAW data-path APIs.\n"); 13178 return TEST_SKIPPED; 13179 } 13180 13181 /* Verify the capabilities */ 13182 struct rte_cryptodev_sym_capability_idx cap_idx; 13183 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13184 cap_idx.algo.auth = reference->auth_algo; 13185 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13186 &cap_idx) == NULL) 13187 return TEST_SKIPPED; 13188 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13189 cap_idx.algo.cipher = reference->crypto_algo; 13190 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13191 &cap_idx) == NULL) 13192 return TEST_SKIPPED; 13193 13194 /* Create session */ 13195 retval = create_auth_cipher_session(ut_params, 13196 ts_params->valid_devs[0], 13197 reference, 13198 RTE_CRYPTO_AUTH_OP_VERIFY, 13199 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13200 13201 if (retval == -ENOTSUP) 13202 return TEST_SKIPPED; 13203 if (retval < 0) 13204 return retval; 13205 13206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13207 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13208 "Failed to allocate input buffer in mempool"); 13209 13210 /* clear mbuf payload */ 13211 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13212 rte_pktmbuf_tailroom(ut_params->ibuf)); 13213 13214 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13215 reference->ciphertext.len); 13216 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13217 memcpy(ciphertext, reference->ciphertext.data, 13218 reference->ciphertext.len); 13219 13220 /* Create operation */ 13221 retval = create_cipher_auth_verify_operation(ts_params, 13222 ut_params, 13223 reference); 13224 13225 if (retval < 0) 13226 return retval; 13227 13228 if (data_corrupted) 13229 data_corruption(ciphertext); 13230 else 13231 tag_corruption(ciphertext, reference->ciphertext.len); 13232 13233 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13234 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13235 ut_params->op); 13236 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13237 RTE_CRYPTO_OP_STATUS_SUCCESS, 13238 "authentication not failed"); 13239 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13240 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13241 ut_params->op, 1, 1, 0, 0); 13242 else { 13243 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13244 ut_params->op); 13245 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13246 } 13247 13248 return 0; 13249 } 13250 13251 static int 13252 test_authenticated_encrypt_with_esn( 13253 struct crypto_testsuite_params *ts_params, 13254 struct crypto_unittest_params *ut_params, 13255 const struct test_crypto_vector *reference) 13256 { 13257 int retval; 13258 13259 uint8_t *authciphertext, *plaintext, *auth_tag; 13260 uint16_t plaintext_pad_len; 13261 uint8_t cipher_key[reference->cipher_key.len + 1]; 13262 uint8_t auth_key[reference->auth_key.len + 1]; 13263 struct rte_cryptodev_info dev_info; 13264 int status; 13265 13266 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13267 uint64_t feat_flags = dev_info.feature_flags; 13268 13269 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13270 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13271 printf("Device doesn't support RAW data-path APIs.\n"); 13272 return TEST_SKIPPED; 13273 } 13274 13275 /* Verify the capabilities */ 13276 struct rte_cryptodev_sym_capability_idx cap_idx; 13277 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13278 cap_idx.algo.auth = reference->auth_algo; 13279 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13280 &cap_idx) == NULL) 13281 return TEST_SKIPPED; 13282 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13283 cap_idx.algo.cipher = reference->crypto_algo; 13284 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13285 &cap_idx) == NULL) 13286 return TEST_SKIPPED; 13287 13288 /* Create session */ 13289 memcpy(cipher_key, reference->cipher_key.data, 13290 reference->cipher_key.len); 13291 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13292 13293 /* Setup Cipher Parameters */ 13294 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13295 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13296 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13297 ut_params->cipher_xform.cipher.key.data = cipher_key; 13298 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13299 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13300 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13301 13302 ut_params->cipher_xform.next = &ut_params->auth_xform; 13303 13304 /* Setup Authentication Parameters */ 13305 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13306 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13307 ut_params->auth_xform.auth.algo = reference->auth_algo; 13308 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13309 ut_params->auth_xform.auth.key.data = auth_key; 13310 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13311 ut_params->auth_xform.next = NULL; 13312 13313 /* Create Crypto session*/ 13314 ut_params->sess = rte_cryptodev_sym_session_create( 13315 ts_params->session_mpool); 13316 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13317 13318 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13319 ut_params->sess, 13320 &ut_params->cipher_xform, 13321 ts_params->session_priv_mpool); 13322 13323 if (status == -ENOTSUP) 13324 return TEST_SKIPPED; 13325 13326 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 13327 13328 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13329 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13330 "Failed to allocate input buffer in mempool"); 13331 13332 /* clear mbuf payload */ 13333 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13334 rte_pktmbuf_tailroom(ut_params->ibuf)); 13335 13336 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13337 reference->plaintext.len); 13338 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13339 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13340 13341 /* Create operation */ 13342 retval = create_cipher_auth_operation(ts_params, 13343 ut_params, 13344 reference, 0); 13345 13346 if (retval < 0) 13347 return retval; 13348 13349 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13350 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13351 ut_params->op); 13352 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13353 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13354 ut_params->op, 1, 1, 0, 0); 13355 else 13356 ut_params->op = process_crypto_request( 13357 ts_params->valid_devs[0], ut_params->op); 13358 13359 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 13360 13361 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13362 "crypto op processing failed"); 13363 13364 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 13365 13366 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13367 ut_params->op->sym->auth.data.offset); 13368 auth_tag = authciphertext + plaintext_pad_len; 13369 debug_hexdump(stdout, "ciphertext:", authciphertext, 13370 reference->ciphertext.len); 13371 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 13372 13373 /* Validate obuf */ 13374 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13375 authciphertext, 13376 reference->ciphertext.data, 13377 reference->ciphertext.len, 13378 "Ciphertext data not as expected"); 13379 13380 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13381 auth_tag, 13382 reference->digest.data, 13383 reference->digest.len, 13384 "Generated digest not as expected"); 13385 13386 return TEST_SUCCESS; 13387 13388 } 13389 13390 static int 13391 test_authenticated_decrypt_with_esn( 13392 struct crypto_testsuite_params *ts_params, 13393 struct crypto_unittest_params *ut_params, 13394 const struct test_crypto_vector *reference) 13395 { 13396 int retval; 13397 13398 uint8_t *ciphertext; 13399 uint8_t cipher_key[reference->cipher_key.len + 1]; 13400 uint8_t auth_key[reference->auth_key.len + 1]; 13401 struct rte_cryptodev_info dev_info; 13402 13403 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13404 uint64_t feat_flags = dev_info.feature_flags; 13405 13406 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13407 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13408 printf("Device doesn't support RAW data-path APIs.\n"); 13409 return TEST_SKIPPED; 13410 } 13411 13412 /* Verify the capabilities */ 13413 struct rte_cryptodev_sym_capability_idx cap_idx; 13414 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13415 cap_idx.algo.auth = reference->auth_algo; 13416 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13417 &cap_idx) == NULL) 13418 return TEST_SKIPPED; 13419 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13420 cap_idx.algo.cipher = reference->crypto_algo; 13421 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13422 &cap_idx) == NULL) 13423 return TEST_SKIPPED; 13424 13425 /* Create session */ 13426 memcpy(cipher_key, reference->cipher_key.data, 13427 reference->cipher_key.len); 13428 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13429 13430 /* Setup Authentication Parameters */ 13431 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13432 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 13433 ut_params->auth_xform.auth.algo = reference->auth_algo; 13434 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13435 ut_params->auth_xform.auth.key.data = auth_key; 13436 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13437 ut_params->auth_xform.next = &ut_params->cipher_xform; 13438 13439 /* Setup Cipher Parameters */ 13440 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13441 ut_params->cipher_xform.next = NULL; 13442 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13443 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 13444 ut_params->cipher_xform.cipher.key.data = cipher_key; 13445 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13446 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13447 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13448 13449 /* Create Crypto session*/ 13450 ut_params->sess = rte_cryptodev_sym_session_create( 13451 ts_params->session_mpool); 13452 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13453 13454 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13455 ut_params->sess, 13456 &ut_params->auth_xform, 13457 ts_params->session_priv_mpool); 13458 13459 if (retval == -ENOTSUP) 13460 return TEST_SKIPPED; 13461 13462 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 13463 13464 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13465 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13466 "Failed to allocate input buffer in mempool"); 13467 13468 /* clear mbuf payload */ 13469 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13470 rte_pktmbuf_tailroom(ut_params->ibuf)); 13471 13472 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13473 reference->ciphertext.len); 13474 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13475 memcpy(ciphertext, reference->ciphertext.data, 13476 reference->ciphertext.len); 13477 13478 /* Create operation */ 13479 retval = create_cipher_auth_verify_operation(ts_params, 13480 ut_params, 13481 reference); 13482 13483 if (retval < 0) 13484 return retval; 13485 13486 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13487 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13488 ut_params->op); 13489 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13490 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13491 ut_params->op, 1, 1, 0, 0); 13492 else 13493 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13494 ut_params->op); 13495 13496 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13497 TEST_ASSERT_EQUAL(ut_params->op->status, 13498 RTE_CRYPTO_OP_STATUS_SUCCESS, 13499 "crypto op processing passed"); 13500 13501 ut_params->obuf = ut_params->op->sym->m_src; 13502 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 13503 13504 return 0; 13505 } 13506 13507 static int 13508 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 13509 const struct aead_test_data *tdata, 13510 void *digest_mem, uint64_t digest_phys) 13511 { 13512 struct crypto_testsuite_params *ts_params = &testsuite_params; 13513 struct crypto_unittest_params *ut_params = &unittest_params; 13514 13515 const unsigned int auth_tag_len = tdata->auth_tag.len; 13516 const unsigned int iv_len = tdata->iv.len; 13517 unsigned int aad_len = tdata->aad.len; 13518 unsigned int aad_len_pad = 0; 13519 13520 /* Generate Crypto op data structure */ 13521 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13522 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13523 TEST_ASSERT_NOT_NULL(ut_params->op, 13524 "Failed to allocate symmetric crypto operation struct"); 13525 13526 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13527 13528 sym_op->aead.digest.data = digest_mem; 13529 13530 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 13531 "no room to append digest"); 13532 13533 sym_op->aead.digest.phys_addr = digest_phys; 13534 13535 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 13536 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 13537 auth_tag_len); 13538 debug_hexdump(stdout, "digest:", 13539 sym_op->aead.digest.data, 13540 auth_tag_len); 13541 } 13542 13543 /* Append aad data */ 13544 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 13545 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13546 uint8_t *, IV_OFFSET); 13547 13548 /* Copy IV 1 byte after the IV pointer, according to the API */ 13549 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 13550 13551 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 13552 13553 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13554 ut_params->ibuf, aad_len); 13555 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13556 "no room to prepend aad"); 13557 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13558 ut_params->ibuf); 13559 13560 memset(sym_op->aead.aad.data, 0, aad_len); 13561 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 13562 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13563 13564 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13565 debug_hexdump(stdout, "aad:", 13566 sym_op->aead.aad.data, aad_len); 13567 } else { 13568 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13569 uint8_t *, IV_OFFSET); 13570 13571 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 13572 13573 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 13574 13575 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13576 ut_params->ibuf, aad_len_pad); 13577 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13578 "no room to prepend aad"); 13579 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13580 ut_params->ibuf); 13581 13582 memset(sym_op->aead.aad.data, 0, aad_len); 13583 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13584 13585 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13586 debug_hexdump(stdout, "aad:", 13587 sym_op->aead.aad.data, aad_len); 13588 } 13589 13590 sym_op->aead.data.length = tdata->plaintext.len; 13591 sym_op->aead.data.offset = aad_len_pad; 13592 13593 return 0; 13594 } 13595 13596 #define SGL_MAX_NO 16 13597 13598 static int 13599 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 13600 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 13601 { 13602 struct crypto_testsuite_params *ts_params = &testsuite_params; 13603 struct crypto_unittest_params *ut_params = &unittest_params; 13604 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 13605 int retval; 13606 int to_trn = 0; 13607 int to_trn_tbl[SGL_MAX_NO]; 13608 int segs = 1; 13609 unsigned int trn_data = 0; 13610 uint8_t *plaintext, *ciphertext, *auth_tag; 13611 struct rte_cryptodev_info dev_info; 13612 13613 /* Verify the capabilities */ 13614 struct rte_cryptodev_sym_capability_idx cap_idx; 13615 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13616 cap_idx.algo.aead = tdata->algo; 13617 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13618 &cap_idx) == NULL) 13619 return TEST_SKIPPED; 13620 13621 /* OOP not supported with CPU crypto */ 13622 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13623 return TEST_SKIPPED; 13624 13625 /* Detailed check for the particular SGL support flag */ 13626 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13627 if (!oop) { 13628 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13629 if (sgl_in && (!(dev_info.feature_flags & 13630 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 13631 return TEST_SKIPPED; 13632 13633 uint64_t feat_flags = dev_info.feature_flags; 13634 13635 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13636 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13637 printf("Device doesn't support RAW data-path APIs.\n"); 13638 return TEST_SKIPPED; 13639 } 13640 } else { 13641 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13642 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 13643 tdata->plaintext.len; 13644 /* Raw data path API does not support OOP */ 13645 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13646 return TEST_SKIPPED; 13647 if (sgl_in && !sgl_out) { 13648 if (!(dev_info.feature_flags & 13649 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 13650 return TEST_SKIPPED; 13651 } else if (!sgl_in && sgl_out) { 13652 if (!(dev_info.feature_flags & 13653 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 13654 return TEST_SKIPPED; 13655 } else if (sgl_in && sgl_out) { 13656 if (!(dev_info.feature_flags & 13657 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 13658 return TEST_SKIPPED; 13659 } 13660 } 13661 13662 if (fragsz > tdata->plaintext.len) 13663 fragsz = tdata->plaintext.len; 13664 13665 uint16_t plaintext_len = fragsz; 13666 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 13667 13668 if (fragsz_oop > tdata->plaintext.len) 13669 frag_size_oop = tdata->plaintext.len; 13670 13671 int ecx = 0; 13672 void *digest_mem = NULL; 13673 13674 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 13675 13676 if (tdata->plaintext.len % fragsz != 0) { 13677 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 13678 return 1; 13679 } else { 13680 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 13681 return 1; 13682 } 13683 13684 /* 13685 * For out-op-place we need to alloc another mbuf 13686 */ 13687 if (oop) { 13688 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13689 rte_pktmbuf_append(ut_params->obuf, 13690 frag_size_oop + prepend_len); 13691 buf_oop = ut_params->obuf; 13692 } 13693 13694 /* Create AEAD session */ 13695 retval = create_aead_session(ts_params->valid_devs[0], 13696 tdata->algo, 13697 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13698 tdata->key.data, tdata->key.len, 13699 tdata->aad.len, tdata->auth_tag.len, 13700 tdata->iv.len); 13701 if (retval < 0) 13702 return retval; 13703 13704 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13705 13706 /* clear mbuf payload */ 13707 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13708 rte_pktmbuf_tailroom(ut_params->ibuf)); 13709 13710 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13711 plaintext_len); 13712 13713 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13714 13715 trn_data += plaintext_len; 13716 13717 buf = ut_params->ibuf; 13718 13719 /* 13720 * Loop until no more fragments 13721 */ 13722 13723 while (trn_data < tdata->plaintext.len) { 13724 ++segs; 13725 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13726 (tdata->plaintext.len - trn_data) : fragsz; 13727 13728 to_trn_tbl[ecx++] = to_trn; 13729 13730 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13731 buf = buf->next; 13732 13733 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13734 rte_pktmbuf_tailroom(buf)); 13735 13736 /* OOP */ 13737 if (oop && !fragsz_oop) { 13738 buf_last_oop = buf_oop->next = 13739 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13740 buf_oop = buf_oop->next; 13741 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13742 0, rte_pktmbuf_tailroom(buf_oop)); 13743 rte_pktmbuf_append(buf_oop, to_trn); 13744 } 13745 13746 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13747 to_trn); 13748 13749 memcpy(plaintext, tdata->plaintext.data + trn_data, 13750 to_trn); 13751 trn_data += to_trn; 13752 if (trn_data == tdata->plaintext.len) { 13753 if (oop) { 13754 if (!fragsz_oop) 13755 digest_mem = rte_pktmbuf_append(buf_oop, 13756 tdata->auth_tag.len); 13757 } else 13758 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13759 tdata->auth_tag.len); 13760 } 13761 } 13762 13763 uint64_t digest_phys = 0; 13764 13765 ut_params->ibuf->nb_segs = segs; 13766 13767 segs = 1; 13768 if (fragsz_oop && oop) { 13769 to_trn = 0; 13770 ecx = 0; 13771 13772 if (frag_size_oop == tdata->plaintext.len) { 13773 digest_mem = rte_pktmbuf_append(ut_params->obuf, 13774 tdata->auth_tag.len); 13775 13776 digest_phys = rte_pktmbuf_iova_offset( 13777 ut_params->obuf, 13778 tdata->plaintext.len + prepend_len); 13779 } 13780 13781 trn_data = frag_size_oop; 13782 while (trn_data < tdata->plaintext.len) { 13783 ++segs; 13784 to_trn = 13785 (tdata->plaintext.len - trn_data < 13786 frag_size_oop) ? 13787 (tdata->plaintext.len - trn_data) : 13788 frag_size_oop; 13789 13790 to_trn_tbl[ecx++] = to_trn; 13791 13792 buf_last_oop = buf_oop->next = 13793 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13794 buf_oop = buf_oop->next; 13795 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13796 0, rte_pktmbuf_tailroom(buf_oop)); 13797 rte_pktmbuf_append(buf_oop, to_trn); 13798 13799 trn_data += to_trn; 13800 13801 if (trn_data == tdata->plaintext.len) { 13802 digest_mem = rte_pktmbuf_append(buf_oop, 13803 tdata->auth_tag.len); 13804 } 13805 } 13806 13807 ut_params->obuf->nb_segs = segs; 13808 } 13809 13810 /* 13811 * Place digest at the end of the last buffer 13812 */ 13813 if (!digest_phys) 13814 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13815 if (oop && buf_last_oop) 13816 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 13817 13818 if (!digest_mem && !oop) { 13819 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13820 + tdata->auth_tag.len); 13821 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13822 tdata->plaintext.len); 13823 } 13824 13825 /* Create AEAD operation */ 13826 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 13827 tdata, digest_mem, digest_phys); 13828 13829 if (retval < 0) 13830 return retval; 13831 13832 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13833 13834 ut_params->op->sym->m_src = ut_params->ibuf; 13835 if (oop) 13836 ut_params->op->sym->m_dst = ut_params->obuf; 13837 13838 /* Process crypto operation */ 13839 if (oop == IN_PLACE && 13840 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13841 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 13842 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13843 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13844 ut_params->op, 0, 0, 0, 0); 13845 else 13846 TEST_ASSERT_NOT_NULL( 13847 process_crypto_request(ts_params->valid_devs[0], 13848 ut_params->op), "failed to process sym crypto op"); 13849 13850 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13851 "crypto op processing failed"); 13852 13853 13854 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 13855 uint8_t *, prepend_len); 13856 if (oop) { 13857 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13858 uint8_t *, prepend_len); 13859 } 13860 13861 if (fragsz_oop) 13862 fragsz = fragsz_oop; 13863 13864 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13865 ciphertext, 13866 tdata->ciphertext.data, 13867 fragsz, 13868 "Ciphertext data not as expected"); 13869 13870 buf = ut_params->op->sym->m_src->next; 13871 if (oop) 13872 buf = ut_params->op->sym->m_dst->next; 13873 13874 unsigned int off = fragsz; 13875 13876 ecx = 0; 13877 while (buf) { 13878 ciphertext = rte_pktmbuf_mtod(buf, 13879 uint8_t *); 13880 13881 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13882 ciphertext, 13883 tdata->ciphertext.data + off, 13884 to_trn_tbl[ecx], 13885 "Ciphertext data not as expected"); 13886 13887 off += to_trn_tbl[ecx++]; 13888 buf = buf->next; 13889 } 13890 13891 auth_tag = digest_mem; 13892 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13893 auth_tag, 13894 tdata->auth_tag.data, 13895 tdata->auth_tag.len, 13896 "Generated auth tag not as expected"); 13897 13898 return 0; 13899 } 13900 13901 static int 13902 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 13903 { 13904 return test_authenticated_encryption_SGL( 13905 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 13906 } 13907 13908 static int 13909 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 13910 { 13911 return test_authenticated_encryption_SGL( 13912 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 13913 } 13914 13915 static int 13916 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 13917 { 13918 return test_authenticated_encryption_SGL( 13919 &gcm_test_case_8, OUT_OF_PLACE, 400, 13920 gcm_test_case_8.plaintext.len); 13921 } 13922 13923 static int 13924 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 13925 { 13926 /* This test is not for OPENSSL PMD */ 13927 if (gbl_driver_id == rte_cryptodev_driver_id_get( 13928 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 13929 return TEST_SKIPPED; 13930 13931 return test_authenticated_encryption_SGL( 13932 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 13933 } 13934 13935 static int 13936 test_authentication_verify_fail_when_data_corrupted( 13937 struct crypto_testsuite_params *ts_params, 13938 struct crypto_unittest_params *ut_params, 13939 const struct test_crypto_vector *reference) 13940 { 13941 return test_authentication_verify_fail_when_data_corruption( 13942 ts_params, ut_params, reference, 1); 13943 } 13944 13945 static int 13946 test_authentication_verify_fail_when_tag_corrupted( 13947 struct crypto_testsuite_params *ts_params, 13948 struct crypto_unittest_params *ut_params, 13949 const struct test_crypto_vector *reference) 13950 { 13951 return test_authentication_verify_fail_when_data_corruption( 13952 ts_params, ut_params, reference, 0); 13953 } 13954 13955 static int 13956 test_authentication_verify_GMAC_fail_when_data_corrupted( 13957 struct crypto_testsuite_params *ts_params, 13958 struct crypto_unittest_params *ut_params, 13959 const struct test_crypto_vector *reference) 13960 { 13961 return test_authentication_verify_GMAC_fail_when_corruption( 13962 ts_params, ut_params, reference, 1); 13963 } 13964 13965 static int 13966 test_authentication_verify_GMAC_fail_when_tag_corrupted( 13967 struct crypto_testsuite_params *ts_params, 13968 struct crypto_unittest_params *ut_params, 13969 const struct test_crypto_vector *reference) 13970 { 13971 return test_authentication_verify_GMAC_fail_when_corruption( 13972 ts_params, ut_params, reference, 0); 13973 } 13974 13975 static int 13976 test_authenticated_decryption_fail_when_data_corrupted( 13977 struct crypto_testsuite_params *ts_params, 13978 struct crypto_unittest_params *ut_params, 13979 const struct test_crypto_vector *reference) 13980 { 13981 return test_authenticated_decryption_fail_when_corruption( 13982 ts_params, ut_params, reference, 1); 13983 } 13984 13985 static int 13986 test_authenticated_decryption_fail_when_tag_corrupted( 13987 struct crypto_testsuite_params *ts_params, 13988 struct crypto_unittest_params *ut_params, 13989 const struct test_crypto_vector *reference) 13990 { 13991 return test_authenticated_decryption_fail_when_corruption( 13992 ts_params, ut_params, reference, 0); 13993 } 13994 13995 static int 13996 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 13997 { 13998 return test_authentication_verify_fail_when_data_corrupted( 13999 &testsuite_params, &unittest_params, 14000 &hmac_sha1_test_crypto_vector); 14001 } 14002 14003 static int 14004 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14005 { 14006 return test_authentication_verify_fail_when_tag_corrupted( 14007 &testsuite_params, &unittest_params, 14008 &hmac_sha1_test_crypto_vector); 14009 } 14010 14011 static int 14012 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14013 { 14014 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14015 &testsuite_params, &unittest_params, 14016 &aes128_gmac_test_vector); 14017 } 14018 14019 static int 14020 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14021 { 14022 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14023 &testsuite_params, &unittest_params, 14024 &aes128_gmac_test_vector); 14025 } 14026 14027 static int 14028 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14029 { 14030 return test_authenticated_decryption_fail_when_data_corrupted( 14031 &testsuite_params, 14032 &unittest_params, 14033 &aes128cbc_hmac_sha1_test_vector); 14034 } 14035 14036 static int 14037 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14038 { 14039 return test_authenticated_decryption_fail_when_tag_corrupted( 14040 &testsuite_params, 14041 &unittest_params, 14042 &aes128cbc_hmac_sha1_test_vector); 14043 } 14044 14045 static int 14046 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14047 { 14048 return test_authenticated_encrypt_with_esn( 14049 &testsuite_params, 14050 &unittest_params, 14051 &aes128cbc_hmac_sha1_aad_test_vector); 14052 } 14053 14054 static int 14055 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14056 { 14057 return test_authenticated_decrypt_with_esn( 14058 &testsuite_params, 14059 &unittest_params, 14060 &aes128cbc_hmac_sha1_aad_test_vector); 14061 } 14062 14063 static int 14064 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14065 { 14066 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14067 } 14068 14069 static int 14070 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14071 { 14072 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14073 } 14074 14075 static int 14076 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14077 { 14078 return test_authenticated_encryption_SGL( 14079 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14080 chacha20_poly1305_case_2.plaintext.len); 14081 } 14082 14083 #ifdef RTE_CRYPTO_SCHEDULER 14084 14085 /* global AESNI worker IDs for the scheduler test */ 14086 uint8_t aesni_ids[2]; 14087 14088 static int 14089 scheduler_testsuite_setup(void) 14090 { 14091 uint32_t i = 0; 14092 int32_t nb_devs, ret; 14093 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14094 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14095 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14096 uint16_t worker_core_count = 0; 14097 uint16_t socket_id = 0; 14098 14099 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14100 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14101 14102 /* Identify the Worker Cores 14103 * Use 2 worker cores for the device args 14104 */ 14105 RTE_LCORE_FOREACH_WORKER(i) { 14106 if (worker_core_count > 1) 14107 break; 14108 snprintf(vdev_args, sizeof(vdev_args), 14109 "%s%d", temp_str, i); 14110 strcpy(temp_str, vdev_args); 14111 strlcat(temp_str, ";", sizeof(temp_str)); 14112 worker_core_count++; 14113 socket_id = rte_lcore_to_socket_id(i); 14114 } 14115 if (worker_core_count != 2) { 14116 RTE_LOG(ERR, USER1, 14117 "Cryptodev scheduler test require at least " 14118 "two worker cores to run. " 14119 "Please use the correct coremask.\n"); 14120 return TEST_FAILED; 14121 } 14122 strcpy(temp_str, vdev_args); 14123 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14124 temp_str, socket_id); 14125 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14126 nb_devs = rte_cryptodev_device_count_by_driver( 14127 rte_cryptodev_driver_id_get( 14128 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14129 if (nb_devs < 1) { 14130 ret = rte_vdev_init( 14131 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14132 vdev_args); 14133 TEST_ASSERT(ret == 0, 14134 "Failed to create instance %u of pmd : %s", 14135 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14136 } 14137 } 14138 return testsuite_setup(); 14139 } 14140 14141 static int 14142 test_scheduler_attach_worker_op(void) 14143 { 14144 struct crypto_testsuite_params *ts_params = &testsuite_params; 14145 uint8_t sched_id = ts_params->valid_devs[0]; 14146 uint32_t i, nb_devs_attached = 0; 14147 int ret; 14148 char vdev_name[32]; 14149 unsigned int count = rte_cryptodev_count(); 14150 14151 /* create 2 AESNI_MB vdevs on top of existing devices */ 14152 for (i = count; i < count + 2; i++) { 14153 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14154 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14155 i); 14156 ret = rte_vdev_init(vdev_name, NULL); 14157 14158 TEST_ASSERT(ret == 0, 14159 "Failed to create instance %u of" 14160 " pmd : %s", 14161 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14162 14163 if (ret < 0) { 14164 RTE_LOG(ERR, USER1, 14165 "Failed to create 2 AESNI MB PMDs.\n"); 14166 return TEST_SKIPPED; 14167 } 14168 } 14169 14170 /* attach 2 AESNI_MB cdevs */ 14171 for (i = count; i < count + 2; i++) { 14172 struct rte_cryptodev_info info; 14173 unsigned int session_size; 14174 14175 rte_cryptodev_info_get(i, &info); 14176 if (info.driver_id != rte_cryptodev_driver_id_get( 14177 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14178 continue; 14179 14180 session_size = rte_cryptodev_sym_get_private_session_size(i); 14181 /* 14182 * Create the session mempool again, since now there are new devices 14183 * to use the mempool. 14184 */ 14185 if (ts_params->session_mpool) { 14186 rte_mempool_free(ts_params->session_mpool); 14187 ts_params->session_mpool = NULL; 14188 } 14189 if (ts_params->session_priv_mpool) { 14190 rte_mempool_free(ts_params->session_priv_mpool); 14191 ts_params->session_priv_mpool = NULL; 14192 } 14193 14194 if (info.sym.max_nb_sessions != 0 && 14195 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14196 RTE_LOG(ERR, USER1, 14197 "Device does not support " 14198 "at least %u sessions\n", 14199 MAX_NB_SESSIONS); 14200 return TEST_FAILED; 14201 } 14202 /* 14203 * Create mempool with maximum number of sessions, 14204 * to include the session headers 14205 */ 14206 if (ts_params->session_mpool == NULL) { 14207 ts_params->session_mpool = 14208 rte_cryptodev_sym_session_pool_create( 14209 "test_sess_mp", 14210 MAX_NB_SESSIONS, 0, 0, 0, 14211 SOCKET_ID_ANY); 14212 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14213 "session mempool allocation failed"); 14214 } 14215 14216 /* 14217 * Create mempool with maximum number of sessions, 14218 * to include device specific session private data 14219 */ 14220 if (ts_params->session_priv_mpool == NULL) { 14221 ts_params->session_priv_mpool = rte_mempool_create( 14222 "test_sess_mp_priv", 14223 MAX_NB_SESSIONS, 14224 session_size, 14225 0, 0, NULL, NULL, NULL, 14226 NULL, SOCKET_ID_ANY, 14227 0); 14228 14229 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14230 "session mempool allocation failed"); 14231 } 14232 14233 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14234 ts_params->qp_conf.mp_session_private = 14235 ts_params->session_priv_mpool; 14236 14237 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14238 (uint8_t)i); 14239 14240 TEST_ASSERT(ret == 0, 14241 "Failed to attach device %u of pmd : %s", i, 14242 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14243 14244 aesni_ids[nb_devs_attached] = (uint8_t)i; 14245 14246 nb_devs_attached++; 14247 } 14248 14249 return 0; 14250 } 14251 14252 static int 14253 test_scheduler_detach_worker_op(void) 14254 { 14255 struct crypto_testsuite_params *ts_params = &testsuite_params; 14256 uint8_t sched_id = ts_params->valid_devs[0]; 14257 uint32_t i; 14258 int ret; 14259 14260 for (i = 0; i < 2; i++) { 14261 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14262 aesni_ids[i]); 14263 TEST_ASSERT(ret == 0, 14264 "Failed to detach device %u", aesni_ids[i]); 14265 } 14266 14267 return 0; 14268 } 14269 14270 static int 14271 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14272 { 14273 struct crypto_testsuite_params *ts_params = &testsuite_params; 14274 uint8_t sched_id = ts_params->valid_devs[0]; 14275 /* set mode */ 14276 return rte_cryptodev_scheduler_mode_set(sched_id, 14277 scheduler_mode); 14278 } 14279 14280 static int 14281 test_scheduler_mode_roundrobin_op(void) 14282 { 14283 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14284 0, "Failed to set roundrobin mode"); 14285 return 0; 14286 14287 } 14288 14289 static int 14290 test_scheduler_mode_multicore_op(void) 14291 { 14292 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14293 0, "Failed to set multicore mode"); 14294 14295 return 0; 14296 } 14297 14298 static int 14299 test_scheduler_mode_failover_op(void) 14300 { 14301 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 14302 0, "Failed to set failover mode"); 14303 14304 return 0; 14305 } 14306 14307 static int 14308 test_scheduler_mode_pkt_size_distr_op(void) 14309 { 14310 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 14311 0, "Failed to set pktsize mode"); 14312 14313 return 0; 14314 } 14315 14316 static int 14317 scheduler_multicore_testsuite_setup(void) 14318 { 14319 if (test_scheduler_attach_worker_op() < 0) 14320 return TEST_SKIPPED; 14321 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 14322 return TEST_SKIPPED; 14323 return 0; 14324 } 14325 14326 static int 14327 scheduler_roundrobin_testsuite_setup(void) 14328 { 14329 if (test_scheduler_attach_worker_op() < 0) 14330 return TEST_SKIPPED; 14331 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 14332 return TEST_SKIPPED; 14333 return 0; 14334 } 14335 14336 static int 14337 scheduler_failover_testsuite_setup(void) 14338 { 14339 if (test_scheduler_attach_worker_op() < 0) 14340 return TEST_SKIPPED; 14341 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 14342 return TEST_SKIPPED; 14343 return 0; 14344 } 14345 14346 static int 14347 scheduler_pkt_size_distr_testsuite_setup(void) 14348 { 14349 if (test_scheduler_attach_worker_op() < 0) 14350 return TEST_SKIPPED; 14351 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 14352 return TEST_SKIPPED; 14353 return 0; 14354 } 14355 14356 static void 14357 scheduler_mode_testsuite_teardown(void) 14358 { 14359 test_scheduler_detach_worker_op(); 14360 } 14361 14362 #endif /* RTE_CRYPTO_SCHEDULER */ 14363 14364 static struct unit_test_suite end_testsuite = { 14365 .suite_name = NULL, 14366 .setup = NULL, 14367 .teardown = NULL, 14368 .unit_test_suites = NULL 14369 }; 14370 14371 #ifdef RTE_LIB_SECURITY 14372 static struct unit_test_suite ipsec_proto_testsuite = { 14373 .suite_name = "IPsec Proto Unit Test Suite", 14374 .setup = ipsec_proto_testsuite_setup, 14375 .unit_test_cases = { 14376 TEST_CASE_NAMED_WITH_DATA( 14377 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14378 ut_setup_security, ut_teardown, 14379 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 14380 TEST_CASE_NAMED_WITH_DATA( 14381 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14382 ut_setup_security, ut_teardown, 14383 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 14384 TEST_CASE_NAMED_WITH_DATA( 14385 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14386 ut_setup_security, ut_teardown, 14387 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 14388 TEST_CASE_NAMED_WITH_DATA( 14389 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14390 ut_setup_security, ut_teardown, 14391 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 14392 TEST_CASE_NAMED_WITH_DATA( 14393 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14394 ut_setup_security, ut_teardown, 14395 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 14396 TEST_CASE_NAMED_WITH_DATA( 14397 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14398 ut_setup_security, ut_teardown, 14399 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 14400 TEST_CASE_NAMED_ST( 14401 "Combined test alg list", 14402 ut_setup_security, ut_teardown, 14403 test_ipsec_proto_display_list), 14404 TEST_CASE_NAMED_ST( 14405 "IV generation", 14406 ut_setup_security, ut_teardown, 14407 test_ipsec_proto_iv_gen), 14408 TEST_CASE_NAMED_ST( 14409 "UDP encapsulation", 14410 ut_setup_security, ut_teardown, 14411 test_ipsec_proto_udp_encap), 14412 TEST_CASE_NAMED_ST( 14413 "UDP encapsulation ports verification test", 14414 ut_setup_security, ut_teardown, 14415 test_ipsec_proto_udp_ports_verify), 14416 TEST_CASE_NAMED_ST( 14417 "SA expiry packets soft", 14418 ut_setup_security, ut_teardown, 14419 test_ipsec_proto_sa_exp_pkts_soft), 14420 TEST_CASE_NAMED_ST( 14421 "SA expiry packets hard", 14422 ut_setup_security, ut_teardown, 14423 test_ipsec_proto_sa_exp_pkts_hard), 14424 TEST_CASE_NAMED_ST( 14425 "Negative test: ICV corruption", 14426 ut_setup_security, ut_teardown, 14427 test_ipsec_proto_err_icv_corrupt), 14428 TEST_CASE_NAMED_ST( 14429 "Tunnel dst addr verification", 14430 ut_setup_security, ut_teardown, 14431 test_ipsec_proto_tunnel_dst_addr_verify), 14432 TEST_CASE_NAMED_ST( 14433 "Tunnel src and dst addr verification", 14434 ut_setup_security, ut_teardown, 14435 test_ipsec_proto_tunnel_src_dst_addr_verify), 14436 TEST_CASE_NAMED_ST( 14437 "Inner IP checksum", 14438 ut_setup_security, ut_teardown, 14439 test_ipsec_proto_inner_ip_csum), 14440 TEST_CASE_NAMED_ST( 14441 "Inner L4 checksum", 14442 ut_setup_security, ut_teardown, 14443 test_ipsec_proto_inner_l4_csum), 14444 TEST_CASES_END() /**< NULL terminate unit test array */ 14445 } 14446 }; 14447 14448 static struct unit_test_suite pdcp_proto_testsuite = { 14449 .suite_name = "PDCP Proto Unit Test Suite", 14450 .setup = pdcp_proto_testsuite_setup, 14451 .unit_test_cases = { 14452 TEST_CASE_ST(ut_setup_security, ut_teardown, 14453 test_PDCP_PROTO_all), 14454 TEST_CASES_END() /**< NULL terminate unit test array */ 14455 } 14456 }; 14457 14458 #define ADD_UPLINK_TESTCASE(data) \ 14459 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 14460 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 14461 14462 #define ADD_DOWNLINK_TESTCASE(data) \ 14463 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 14464 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 14465 14466 static struct unit_test_suite docsis_proto_testsuite = { 14467 .suite_name = "DOCSIS Proto Unit Test Suite", 14468 .setup = docsis_proto_testsuite_setup, 14469 .unit_test_cases = { 14470 /* Uplink */ 14471 ADD_UPLINK_TESTCASE(docsis_test_case_1) 14472 ADD_UPLINK_TESTCASE(docsis_test_case_2) 14473 ADD_UPLINK_TESTCASE(docsis_test_case_3) 14474 ADD_UPLINK_TESTCASE(docsis_test_case_4) 14475 ADD_UPLINK_TESTCASE(docsis_test_case_5) 14476 ADD_UPLINK_TESTCASE(docsis_test_case_6) 14477 ADD_UPLINK_TESTCASE(docsis_test_case_7) 14478 ADD_UPLINK_TESTCASE(docsis_test_case_8) 14479 ADD_UPLINK_TESTCASE(docsis_test_case_9) 14480 ADD_UPLINK_TESTCASE(docsis_test_case_10) 14481 ADD_UPLINK_TESTCASE(docsis_test_case_11) 14482 ADD_UPLINK_TESTCASE(docsis_test_case_12) 14483 ADD_UPLINK_TESTCASE(docsis_test_case_13) 14484 ADD_UPLINK_TESTCASE(docsis_test_case_14) 14485 ADD_UPLINK_TESTCASE(docsis_test_case_15) 14486 ADD_UPLINK_TESTCASE(docsis_test_case_16) 14487 ADD_UPLINK_TESTCASE(docsis_test_case_17) 14488 ADD_UPLINK_TESTCASE(docsis_test_case_18) 14489 ADD_UPLINK_TESTCASE(docsis_test_case_19) 14490 ADD_UPLINK_TESTCASE(docsis_test_case_20) 14491 ADD_UPLINK_TESTCASE(docsis_test_case_21) 14492 ADD_UPLINK_TESTCASE(docsis_test_case_22) 14493 ADD_UPLINK_TESTCASE(docsis_test_case_23) 14494 ADD_UPLINK_TESTCASE(docsis_test_case_24) 14495 ADD_UPLINK_TESTCASE(docsis_test_case_25) 14496 ADD_UPLINK_TESTCASE(docsis_test_case_26) 14497 /* Downlink */ 14498 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 14499 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 14500 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 14501 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 14502 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 14503 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 14504 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 14505 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 14506 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 14507 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 14508 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 14509 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 14510 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 14511 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 14512 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 14513 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 14514 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 14515 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 14516 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 14517 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 14518 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 14519 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 14520 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 14521 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 14522 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 14523 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 14524 TEST_CASES_END() /**< NULL terminate unit test array */ 14525 } 14526 }; 14527 #endif 14528 14529 static struct unit_test_suite cryptodev_gen_testsuite = { 14530 .suite_name = "Crypto General Unit Test Suite", 14531 .setup = crypto_gen_testsuite_setup, 14532 .unit_test_cases = { 14533 TEST_CASE_ST(ut_setup, ut_teardown, 14534 test_device_configure_invalid_dev_id), 14535 TEST_CASE_ST(ut_setup, ut_teardown, 14536 test_queue_pair_descriptor_setup), 14537 TEST_CASE_ST(ut_setup, ut_teardown, 14538 test_device_configure_invalid_queue_pair_ids), 14539 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 14540 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 14541 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 14542 TEST_CASES_END() /**< NULL terminate unit test array */ 14543 } 14544 }; 14545 14546 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 14547 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 14548 .setup = negative_hmac_sha1_testsuite_setup, 14549 .unit_test_cases = { 14550 /** Negative tests */ 14551 TEST_CASE_ST(ut_setup, ut_teardown, 14552 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14553 TEST_CASE_ST(ut_setup, ut_teardown, 14554 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14555 TEST_CASE_ST(ut_setup, ut_teardown, 14556 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14557 TEST_CASE_ST(ut_setup, ut_teardown, 14558 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14559 14560 TEST_CASES_END() /**< NULL terminate unit test array */ 14561 } 14562 }; 14563 14564 static struct unit_test_suite cryptodev_multi_session_testsuite = { 14565 .suite_name = "Multi Session Unit Test Suite", 14566 .setup = multi_session_testsuite_setup, 14567 .unit_test_cases = { 14568 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 14569 TEST_CASE_ST(ut_setup, ut_teardown, 14570 test_multi_session_random_usage), 14571 14572 TEST_CASES_END() /**< NULL terminate unit test array */ 14573 } 14574 }; 14575 14576 static struct unit_test_suite cryptodev_null_testsuite = { 14577 .suite_name = "NULL Test Suite", 14578 .setup = null_testsuite_setup, 14579 .unit_test_cases = { 14580 TEST_CASE_ST(ut_setup, ut_teardown, 14581 test_null_invalid_operation), 14582 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 14583 TEST_CASES_END() 14584 } 14585 }; 14586 14587 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 14588 .suite_name = "AES CCM Authenticated Test Suite", 14589 .setup = aes_ccm_auth_testsuite_setup, 14590 .unit_test_cases = { 14591 /** AES CCM Authenticated Encryption 128 bits key*/ 14592 TEST_CASE_ST(ut_setup, ut_teardown, 14593 test_AES_CCM_authenticated_encryption_test_case_128_1), 14594 TEST_CASE_ST(ut_setup, ut_teardown, 14595 test_AES_CCM_authenticated_encryption_test_case_128_2), 14596 TEST_CASE_ST(ut_setup, ut_teardown, 14597 test_AES_CCM_authenticated_encryption_test_case_128_3), 14598 14599 /** AES CCM Authenticated Decryption 128 bits key*/ 14600 TEST_CASE_ST(ut_setup, ut_teardown, 14601 test_AES_CCM_authenticated_decryption_test_case_128_1), 14602 TEST_CASE_ST(ut_setup, ut_teardown, 14603 test_AES_CCM_authenticated_decryption_test_case_128_2), 14604 TEST_CASE_ST(ut_setup, ut_teardown, 14605 test_AES_CCM_authenticated_decryption_test_case_128_3), 14606 14607 /** AES CCM Authenticated Encryption 192 bits key */ 14608 TEST_CASE_ST(ut_setup, ut_teardown, 14609 test_AES_CCM_authenticated_encryption_test_case_192_1), 14610 TEST_CASE_ST(ut_setup, ut_teardown, 14611 test_AES_CCM_authenticated_encryption_test_case_192_2), 14612 TEST_CASE_ST(ut_setup, ut_teardown, 14613 test_AES_CCM_authenticated_encryption_test_case_192_3), 14614 14615 /** AES CCM Authenticated Decryption 192 bits key*/ 14616 TEST_CASE_ST(ut_setup, ut_teardown, 14617 test_AES_CCM_authenticated_decryption_test_case_192_1), 14618 TEST_CASE_ST(ut_setup, ut_teardown, 14619 test_AES_CCM_authenticated_decryption_test_case_192_2), 14620 TEST_CASE_ST(ut_setup, ut_teardown, 14621 test_AES_CCM_authenticated_decryption_test_case_192_3), 14622 14623 /** AES CCM Authenticated Encryption 256 bits key */ 14624 TEST_CASE_ST(ut_setup, ut_teardown, 14625 test_AES_CCM_authenticated_encryption_test_case_256_1), 14626 TEST_CASE_ST(ut_setup, ut_teardown, 14627 test_AES_CCM_authenticated_encryption_test_case_256_2), 14628 TEST_CASE_ST(ut_setup, ut_teardown, 14629 test_AES_CCM_authenticated_encryption_test_case_256_3), 14630 14631 /** AES CCM Authenticated Decryption 256 bits key*/ 14632 TEST_CASE_ST(ut_setup, ut_teardown, 14633 test_AES_CCM_authenticated_decryption_test_case_256_1), 14634 TEST_CASE_ST(ut_setup, ut_teardown, 14635 test_AES_CCM_authenticated_decryption_test_case_256_2), 14636 TEST_CASE_ST(ut_setup, ut_teardown, 14637 test_AES_CCM_authenticated_decryption_test_case_256_3), 14638 TEST_CASES_END() 14639 } 14640 }; 14641 14642 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 14643 .suite_name = "AES GCM Authenticated Test Suite", 14644 .setup = aes_gcm_auth_testsuite_setup, 14645 .unit_test_cases = { 14646 /** AES GCM Authenticated Encryption */ 14647 TEST_CASE_ST(ut_setup, ut_teardown, 14648 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 14649 TEST_CASE_ST(ut_setup, ut_teardown, 14650 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 14651 TEST_CASE_ST(ut_setup, ut_teardown, 14652 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 14653 TEST_CASE_ST(ut_setup, ut_teardown, 14654 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 14655 TEST_CASE_ST(ut_setup, ut_teardown, 14656 test_AES_GCM_authenticated_encryption_test_case_1), 14657 TEST_CASE_ST(ut_setup, ut_teardown, 14658 test_AES_GCM_authenticated_encryption_test_case_2), 14659 TEST_CASE_ST(ut_setup, ut_teardown, 14660 test_AES_GCM_authenticated_encryption_test_case_3), 14661 TEST_CASE_ST(ut_setup, ut_teardown, 14662 test_AES_GCM_authenticated_encryption_test_case_4), 14663 TEST_CASE_ST(ut_setup, ut_teardown, 14664 test_AES_GCM_authenticated_encryption_test_case_5), 14665 TEST_CASE_ST(ut_setup, ut_teardown, 14666 test_AES_GCM_authenticated_encryption_test_case_6), 14667 TEST_CASE_ST(ut_setup, ut_teardown, 14668 test_AES_GCM_authenticated_encryption_test_case_7), 14669 TEST_CASE_ST(ut_setup, ut_teardown, 14670 test_AES_GCM_authenticated_encryption_test_case_8), 14671 TEST_CASE_ST(ut_setup, ut_teardown, 14672 test_AES_GCM_J0_authenticated_encryption_test_case_1), 14673 14674 /** AES GCM Authenticated Decryption */ 14675 TEST_CASE_ST(ut_setup, ut_teardown, 14676 test_AES_GCM_authenticated_decryption_test_case_1), 14677 TEST_CASE_ST(ut_setup, ut_teardown, 14678 test_AES_GCM_authenticated_decryption_test_case_2), 14679 TEST_CASE_ST(ut_setup, ut_teardown, 14680 test_AES_GCM_authenticated_decryption_test_case_3), 14681 TEST_CASE_ST(ut_setup, ut_teardown, 14682 test_AES_GCM_authenticated_decryption_test_case_4), 14683 TEST_CASE_ST(ut_setup, ut_teardown, 14684 test_AES_GCM_authenticated_decryption_test_case_5), 14685 TEST_CASE_ST(ut_setup, ut_teardown, 14686 test_AES_GCM_authenticated_decryption_test_case_6), 14687 TEST_CASE_ST(ut_setup, ut_teardown, 14688 test_AES_GCM_authenticated_decryption_test_case_7), 14689 TEST_CASE_ST(ut_setup, ut_teardown, 14690 test_AES_GCM_authenticated_decryption_test_case_8), 14691 TEST_CASE_ST(ut_setup, ut_teardown, 14692 test_AES_GCM_J0_authenticated_decryption_test_case_1), 14693 14694 /** AES GCM Authenticated Encryption 192 bits key */ 14695 TEST_CASE_ST(ut_setup, ut_teardown, 14696 test_AES_GCM_auth_encryption_test_case_192_1), 14697 TEST_CASE_ST(ut_setup, ut_teardown, 14698 test_AES_GCM_auth_encryption_test_case_192_2), 14699 TEST_CASE_ST(ut_setup, ut_teardown, 14700 test_AES_GCM_auth_encryption_test_case_192_3), 14701 TEST_CASE_ST(ut_setup, ut_teardown, 14702 test_AES_GCM_auth_encryption_test_case_192_4), 14703 TEST_CASE_ST(ut_setup, ut_teardown, 14704 test_AES_GCM_auth_encryption_test_case_192_5), 14705 TEST_CASE_ST(ut_setup, ut_teardown, 14706 test_AES_GCM_auth_encryption_test_case_192_6), 14707 TEST_CASE_ST(ut_setup, ut_teardown, 14708 test_AES_GCM_auth_encryption_test_case_192_7), 14709 14710 /** AES GCM Authenticated Decryption 192 bits key */ 14711 TEST_CASE_ST(ut_setup, ut_teardown, 14712 test_AES_GCM_auth_decryption_test_case_192_1), 14713 TEST_CASE_ST(ut_setup, ut_teardown, 14714 test_AES_GCM_auth_decryption_test_case_192_2), 14715 TEST_CASE_ST(ut_setup, ut_teardown, 14716 test_AES_GCM_auth_decryption_test_case_192_3), 14717 TEST_CASE_ST(ut_setup, ut_teardown, 14718 test_AES_GCM_auth_decryption_test_case_192_4), 14719 TEST_CASE_ST(ut_setup, ut_teardown, 14720 test_AES_GCM_auth_decryption_test_case_192_5), 14721 TEST_CASE_ST(ut_setup, ut_teardown, 14722 test_AES_GCM_auth_decryption_test_case_192_6), 14723 TEST_CASE_ST(ut_setup, ut_teardown, 14724 test_AES_GCM_auth_decryption_test_case_192_7), 14725 14726 /** AES GCM Authenticated Encryption 256 bits key */ 14727 TEST_CASE_ST(ut_setup, ut_teardown, 14728 test_AES_GCM_auth_encryption_test_case_256_1), 14729 TEST_CASE_ST(ut_setup, ut_teardown, 14730 test_AES_GCM_auth_encryption_test_case_256_2), 14731 TEST_CASE_ST(ut_setup, ut_teardown, 14732 test_AES_GCM_auth_encryption_test_case_256_3), 14733 TEST_CASE_ST(ut_setup, ut_teardown, 14734 test_AES_GCM_auth_encryption_test_case_256_4), 14735 TEST_CASE_ST(ut_setup, ut_teardown, 14736 test_AES_GCM_auth_encryption_test_case_256_5), 14737 TEST_CASE_ST(ut_setup, ut_teardown, 14738 test_AES_GCM_auth_encryption_test_case_256_6), 14739 TEST_CASE_ST(ut_setup, ut_teardown, 14740 test_AES_GCM_auth_encryption_test_case_256_7), 14741 14742 /** AES GCM Authenticated Decryption 256 bits key */ 14743 TEST_CASE_ST(ut_setup, ut_teardown, 14744 test_AES_GCM_auth_decryption_test_case_256_1), 14745 TEST_CASE_ST(ut_setup, ut_teardown, 14746 test_AES_GCM_auth_decryption_test_case_256_2), 14747 TEST_CASE_ST(ut_setup, ut_teardown, 14748 test_AES_GCM_auth_decryption_test_case_256_3), 14749 TEST_CASE_ST(ut_setup, ut_teardown, 14750 test_AES_GCM_auth_decryption_test_case_256_4), 14751 TEST_CASE_ST(ut_setup, ut_teardown, 14752 test_AES_GCM_auth_decryption_test_case_256_5), 14753 TEST_CASE_ST(ut_setup, ut_teardown, 14754 test_AES_GCM_auth_decryption_test_case_256_6), 14755 TEST_CASE_ST(ut_setup, ut_teardown, 14756 test_AES_GCM_auth_decryption_test_case_256_7), 14757 14758 /** AES GCM Authenticated Encryption big aad size */ 14759 TEST_CASE_ST(ut_setup, ut_teardown, 14760 test_AES_GCM_auth_encryption_test_case_aad_1), 14761 TEST_CASE_ST(ut_setup, ut_teardown, 14762 test_AES_GCM_auth_encryption_test_case_aad_2), 14763 14764 /** AES GCM Authenticated Decryption big aad size */ 14765 TEST_CASE_ST(ut_setup, ut_teardown, 14766 test_AES_GCM_auth_decryption_test_case_aad_1), 14767 TEST_CASE_ST(ut_setup, ut_teardown, 14768 test_AES_GCM_auth_decryption_test_case_aad_2), 14769 14770 /** Out of place tests */ 14771 TEST_CASE_ST(ut_setup, ut_teardown, 14772 test_AES_GCM_authenticated_encryption_oop_test_case_1), 14773 TEST_CASE_ST(ut_setup, ut_teardown, 14774 test_AES_GCM_authenticated_decryption_oop_test_case_1), 14775 14776 /** Session-less tests */ 14777 TEST_CASE_ST(ut_setup, ut_teardown, 14778 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 14779 TEST_CASE_ST(ut_setup, ut_teardown, 14780 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 14781 14782 TEST_CASES_END() 14783 } 14784 }; 14785 14786 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 14787 .suite_name = "AES GMAC Authentication Test Suite", 14788 .setup = aes_gmac_auth_testsuite_setup, 14789 .unit_test_cases = { 14790 TEST_CASE_ST(ut_setup, ut_teardown, 14791 test_AES_GMAC_authentication_test_case_1), 14792 TEST_CASE_ST(ut_setup, ut_teardown, 14793 test_AES_GMAC_authentication_verify_test_case_1), 14794 TEST_CASE_ST(ut_setup, ut_teardown, 14795 test_AES_GMAC_authentication_test_case_2), 14796 TEST_CASE_ST(ut_setup, ut_teardown, 14797 test_AES_GMAC_authentication_verify_test_case_2), 14798 TEST_CASE_ST(ut_setup, ut_teardown, 14799 test_AES_GMAC_authentication_test_case_3), 14800 TEST_CASE_ST(ut_setup, ut_teardown, 14801 test_AES_GMAC_authentication_verify_test_case_3), 14802 TEST_CASE_ST(ut_setup, ut_teardown, 14803 test_AES_GMAC_authentication_test_case_4), 14804 TEST_CASE_ST(ut_setup, ut_teardown, 14805 test_AES_GMAC_authentication_verify_test_case_4), 14806 TEST_CASE_ST(ut_setup, ut_teardown, 14807 test_AES_GMAC_authentication_SGL_40B), 14808 TEST_CASE_ST(ut_setup, ut_teardown, 14809 test_AES_GMAC_authentication_SGL_80B), 14810 TEST_CASE_ST(ut_setup, ut_teardown, 14811 test_AES_GMAC_authentication_SGL_2048B), 14812 TEST_CASE_ST(ut_setup, ut_teardown, 14813 test_AES_GMAC_authentication_SGL_2047B), 14814 14815 TEST_CASES_END() 14816 } 14817 }; 14818 14819 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 14820 .suite_name = "Chacha20-Poly1305 Test Suite", 14821 .setup = chacha20_poly1305_testsuite_setup, 14822 .unit_test_cases = { 14823 TEST_CASE_ST(ut_setup, ut_teardown, 14824 test_chacha20_poly1305_encrypt_test_case_rfc8439), 14825 TEST_CASE_ST(ut_setup, ut_teardown, 14826 test_chacha20_poly1305_decrypt_test_case_rfc8439), 14827 TEST_CASE_ST(ut_setup, ut_teardown, 14828 test_chacha20_poly1305_encrypt_SGL_out_of_place), 14829 TEST_CASES_END() 14830 } 14831 }; 14832 14833 static struct unit_test_suite cryptodev_snow3g_testsuite = { 14834 .suite_name = "SNOW 3G Test Suite", 14835 .setup = snow3g_testsuite_setup, 14836 .unit_test_cases = { 14837 /** SNOW 3G encrypt only (UEA2) */ 14838 TEST_CASE_ST(ut_setup, ut_teardown, 14839 test_snow3g_encryption_test_case_1), 14840 TEST_CASE_ST(ut_setup, ut_teardown, 14841 test_snow3g_encryption_test_case_2), 14842 TEST_CASE_ST(ut_setup, ut_teardown, 14843 test_snow3g_encryption_test_case_3), 14844 TEST_CASE_ST(ut_setup, ut_teardown, 14845 test_snow3g_encryption_test_case_4), 14846 TEST_CASE_ST(ut_setup, ut_teardown, 14847 test_snow3g_encryption_test_case_5), 14848 14849 TEST_CASE_ST(ut_setup, ut_teardown, 14850 test_snow3g_encryption_test_case_1_oop), 14851 TEST_CASE_ST(ut_setup, ut_teardown, 14852 test_snow3g_encryption_test_case_1_oop_sgl), 14853 TEST_CASE_ST(ut_setup, ut_teardown, 14854 test_snow3g_encryption_test_case_1_offset_oop), 14855 TEST_CASE_ST(ut_setup, ut_teardown, 14856 test_snow3g_decryption_test_case_1_oop), 14857 14858 /** SNOW 3G generate auth, then encrypt (UEA2) */ 14859 TEST_CASE_ST(ut_setup, ut_teardown, 14860 test_snow3g_auth_cipher_test_case_1), 14861 TEST_CASE_ST(ut_setup, ut_teardown, 14862 test_snow3g_auth_cipher_test_case_2), 14863 TEST_CASE_ST(ut_setup, ut_teardown, 14864 test_snow3g_auth_cipher_test_case_2_oop), 14865 TEST_CASE_ST(ut_setup, ut_teardown, 14866 test_snow3g_auth_cipher_part_digest_enc), 14867 TEST_CASE_ST(ut_setup, ut_teardown, 14868 test_snow3g_auth_cipher_part_digest_enc_oop), 14869 TEST_CASE_ST(ut_setup, ut_teardown, 14870 test_snow3g_auth_cipher_test_case_3_sgl), 14871 TEST_CASE_ST(ut_setup, ut_teardown, 14872 test_snow3g_auth_cipher_test_case_3_oop_sgl), 14873 TEST_CASE_ST(ut_setup, ut_teardown, 14874 test_snow3g_auth_cipher_part_digest_enc_sgl), 14875 TEST_CASE_ST(ut_setup, ut_teardown, 14876 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 14877 14878 /** SNOW 3G decrypt (UEA2), then verify auth */ 14879 TEST_CASE_ST(ut_setup, ut_teardown, 14880 test_snow3g_auth_cipher_verify_test_case_1), 14881 TEST_CASE_ST(ut_setup, ut_teardown, 14882 test_snow3g_auth_cipher_verify_test_case_2), 14883 TEST_CASE_ST(ut_setup, ut_teardown, 14884 test_snow3g_auth_cipher_verify_test_case_2_oop), 14885 TEST_CASE_ST(ut_setup, ut_teardown, 14886 test_snow3g_auth_cipher_verify_part_digest_enc), 14887 TEST_CASE_ST(ut_setup, ut_teardown, 14888 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 14889 TEST_CASE_ST(ut_setup, ut_teardown, 14890 test_snow3g_auth_cipher_verify_test_case_3_sgl), 14891 TEST_CASE_ST(ut_setup, ut_teardown, 14892 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 14893 TEST_CASE_ST(ut_setup, ut_teardown, 14894 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 14895 TEST_CASE_ST(ut_setup, ut_teardown, 14896 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 14897 14898 /** SNOW 3G decrypt only (UEA2) */ 14899 TEST_CASE_ST(ut_setup, ut_teardown, 14900 test_snow3g_decryption_test_case_1), 14901 TEST_CASE_ST(ut_setup, ut_teardown, 14902 test_snow3g_decryption_test_case_2), 14903 TEST_CASE_ST(ut_setup, ut_teardown, 14904 test_snow3g_decryption_test_case_3), 14905 TEST_CASE_ST(ut_setup, ut_teardown, 14906 test_snow3g_decryption_test_case_4), 14907 TEST_CASE_ST(ut_setup, ut_teardown, 14908 test_snow3g_decryption_test_case_5), 14909 TEST_CASE_ST(ut_setup, ut_teardown, 14910 test_snow3g_decryption_with_digest_test_case_1), 14911 TEST_CASE_ST(ut_setup, ut_teardown, 14912 test_snow3g_hash_generate_test_case_1), 14913 TEST_CASE_ST(ut_setup, ut_teardown, 14914 test_snow3g_hash_generate_test_case_2), 14915 TEST_CASE_ST(ut_setup, ut_teardown, 14916 test_snow3g_hash_generate_test_case_3), 14917 14918 /* Tests with buffers which length is not byte-aligned */ 14919 TEST_CASE_ST(ut_setup, ut_teardown, 14920 test_snow3g_hash_generate_test_case_4), 14921 TEST_CASE_ST(ut_setup, ut_teardown, 14922 test_snow3g_hash_generate_test_case_5), 14923 TEST_CASE_ST(ut_setup, ut_teardown, 14924 test_snow3g_hash_generate_test_case_6), 14925 TEST_CASE_ST(ut_setup, ut_teardown, 14926 test_snow3g_hash_verify_test_case_1), 14927 TEST_CASE_ST(ut_setup, ut_teardown, 14928 test_snow3g_hash_verify_test_case_2), 14929 TEST_CASE_ST(ut_setup, ut_teardown, 14930 test_snow3g_hash_verify_test_case_3), 14931 14932 /* Tests with buffers which length is not byte-aligned */ 14933 TEST_CASE_ST(ut_setup, ut_teardown, 14934 test_snow3g_hash_verify_test_case_4), 14935 TEST_CASE_ST(ut_setup, ut_teardown, 14936 test_snow3g_hash_verify_test_case_5), 14937 TEST_CASE_ST(ut_setup, ut_teardown, 14938 test_snow3g_hash_verify_test_case_6), 14939 TEST_CASE_ST(ut_setup, ut_teardown, 14940 test_snow3g_cipher_auth_test_case_1), 14941 TEST_CASE_ST(ut_setup, ut_teardown, 14942 test_snow3g_auth_cipher_with_digest_test_case_1), 14943 TEST_CASES_END() 14944 } 14945 }; 14946 14947 static struct unit_test_suite cryptodev_zuc_testsuite = { 14948 .suite_name = "ZUC Test Suite", 14949 .setup = zuc_testsuite_setup, 14950 .unit_test_cases = { 14951 /** ZUC encrypt only (EEA3) */ 14952 TEST_CASE_ST(ut_setup, ut_teardown, 14953 test_zuc_encryption_test_case_1), 14954 TEST_CASE_ST(ut_setup, ut_teardown, 14955 test_zuc_encryption_test_case_2), 14956 TEST_CASE_ST(ut_setup, ut_teardown, 14957 test_zuc_encryption_test_case_3), 14958 TEST_CASE_ST(ut_setup, ut_teardown, 14959 test_zuc_encryption_test_case_4), 14960 TEST_CASE_ST(ut_setup, ut_teardown, 14961 test_zuc_encryption_test_case_5), 14962 TEST_CASE_ST(ut_setup, ut_teardown, 14963 test_zuc_encryption_test_case_6_sgl), 14964 14965 /** ZUC authenticate (EIA3) */ 14966 TEST_CASE_ST(ut_setup, ut_teardown, 14967 test_zuc_hash_generate_test_case_1), 14968 TEST_CASE_ST(ut_setup, ut_teardown, 14969 test_zuc_hash_generate_test_case_2), 14970 TEST_CASE_ST(ut_setup, ut_teardown, 14971 test_zuc_hash_generate_test_case_3), 14972 TEST_CASE_ST(ut_setup, ut_teardown, 14973 test_zuc_hash_generate_test_case_4), 14974 TEST_CASE_ST(ut_setup, ut_teardown, 14975 test_zuc_hash_generate_test_case_5), 14976 TEST_CASE_ST(ut_setup, ut_teardown, 14977 test_zuc_hash_generate_test_case_6), 14978 TEST_CASE_ST(ut_setup, ut_teardown, 14979 test_zuc_hash_generate_test_case_7), 14980 TEST_CASE_ST(ut_setup, ut_teardown, 14981 test_zuc_hash_generate_test_case_8), 14982 TEST_CASE_ST(ut_setup, ut_teardown, 14983 test_zuc_hash_generate_test_case_9), 14984 TEST_CASE_ST(ut_setup, ut_teardown, 14985 test_zuc_hash_generate_test_case_10), 14986 TEST_CASE_ST(ut_setup, ut_teardown, 14987 test_zuc_hash_generate_test_case_11), 14988 14989 14990 /** ZUC alg-chain (EEA3/EIA3) */ 14991 TEST_CASE_ST(ut_setup, ut_teardown, 14992 test_zuc_cipher_auth_test_case_1), 14993 TEST_CASE_ST(ut_setup, ut_teardown, 14994 test_zuc_cipher_auth_test_case_2), 14995 14996 /** ZUC generate auth, then encrypt (EEA3) */ 14997 TEST_CASE_ST(ut_setup, ut_teardown, 14998 test_zuc_auth_cipher_test_case_1), 14999 TEST_CASE_ST(ut_setup, ut_teardown, 15000 test_zuc_auth_cipher_test_case_1_oop), 15001 TEST_CASE_ST(ut_setup, ut_teardown, 15002 test_zuc_auth_cipher_test_case_1_sgl), 15003 TEST_CASE_ST(ut_setup, ut_teardown, 15004 test_zuc_auth_cipher_test_case_1_oop_sgl), 15005 15006 /** ZUC decrypt (EEA3), then verify auth */ 15007 TEST_CASE_ST(ut_setup, ut_teardown, 15008 test_zuc_auth_cipher_verify_test_case_1), 15009 TEST_CASE_ST(ut_setup, ut_teardown, 15010 test_zuc_auth_cipher_verify_test_case_1_oop), 15011 TEST_CASE_ST(ut_setup, ut_teardown, 15012 test_zuc_auth_cipher_verify_test_case_1_sgl), 15013 TEST_CASE_ST(ut_setup, ut_teardown, 15014 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 15015 15016 /** ZUC-256 encrypt only **/ 15017 TEST_CASE_ST(ut_setup, ut_teardown, 15018 test_zuc256_encryption_test_case_1), 15019 TEST_CASE_ST(ut_setup, ut_teardown, 15020 test_zuc256_encryption_test_case_2), 15021 15022 /** ZUC-256 authentication only **/ 15023 TEST_CASE_ST(ut_setup, ut_teardown, 15024 test_zuc256_authentication_test_case_1), 15025 TEST_CASE_ST(ut_setup, ut_teardown, 15026 test_zuc256_authentication_test_case_2), 15027 15028 TEST_CASES_END() 15029 } 15030 }; 15031 15032 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15033 .suite_name = "HMAC_MD5 Authentication Test Suite", 15034 .setup = hmac_md5_auth_testsuite_setup, 15035 .unit_test_cases = { 15036 TEST_CASE_ST(ut_setup, ut_teardown, 15037 test_MD5_HMAC_generate_case_1), 15038 TEST_CASE_ST(ut_setup, ut_teardown, 15039 test_MD5_HMAC_verify_case_1), 15040 TEST_CASE_ST(ut_setup, ut_teardown, 15041 test_MD5_HMAC_generate_case_2), 15042 TEST_CASE_ST(ut_setup, ut_teardown, 15043 test_MD5_HMAC_verify_case_2), 15044 TEST_CASES_END() 15045 } 15046 }; 15047 15048 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15049 .suite_name = "Kasumi Test Suite", 15050 .setup = kasumi_testsuite_setup, 15051 .unit_test_cases = { 15052 /** KASUMI hash only (UIA1) */ 15053 TEST_CASE_ST(ut_setup, ut_teardown, 15054 test_kasumi_hash_generate_test_case_1), 15055 TEST_CASE_ST(ut_setup, ut_teardown, 15056 test_kasumi_hash_generate_test_case_2), 15057 TEST_CASE_ST(ut_setup, ut_teardown, 15058 test_kasumi_hash_generate_test_case_3), 15059 TEST_CASE_ST(ut_setup, ut_teardown, 15060 test_kasumi_hash_generate_test_case_4), 15061 TEST_CASE_ST(ut_setup, ut_teardown, 15062 test_kasumi_hash_generate_test_case_5), 15063 TEST_CASE_ST(ut_setup, ut_teardown, 15064 test_kasumi_hash_generate_test_case_6), 15065 15066 TEST_CASE_ST(ut_setup, ut_teardown, 15067 test_kasumi_hash_verify_test_case_1), 15068 TEST_CASE_ST(ut_setup, ut_teardown, 15069 test_kasumi_hash_verify_test_case_2), 15070 TEST_CASE_ST(ut_setup, ut_teardown, 15071 test_kasumi_hash_verify_test_case_3), 15072 TEST_CASE_ST(ut_setup, ut_teardown, 15073 test_kasumi_hash_verify_test_case_4), 15074 TEST_CASE_ST(ut_setup, ut_teardown, 15075 test_kasumi_hash_verify_test_case_5), 15076 15077 /** KASUMI encrypt only (UEA1) */ 15078 TEST_CASE_ST(ut_setup, ut_teardown, 15079 test_kasumi_encryption_test_case_1), 15080 TEST_CASE_ST(ut_setup, ut_teardown, 15081 test_kasumi_encryption_test_case_1_sgl), 15082 TEST_CASE_ST(ut_setup, ut_teardown, 15083 test_kasumi_encryption_test_case_1_oop), 15084 TEST_CASE_ST(ut_setup, ut_teardown, 15085 test_kasumi_encryption_test_case_1_oop_sgl), 15086 TEST_CASE_ST(ut_setup, ut_teardown, 15087 test_kasumi_encryption_test_case_2), 15088 TEST_CASE_ST(ut_setup, ut_teardown, 15089 test_kasumi_encryption_test_case_3), 15090 TEST_CASE_ST(ut_setup, ut_teardown, 15091 test_kasumi_encryption_test_case_4), 15092 TEST_CASE_ST(ut_setup, ut_teardown, 15093 test_kasumi_encryption_test_case_5), 15094 15095 /** KASUMI decrypt only (UEA1) */ 15096 TEST_CASE_ST(ut_setup, ut_teardown, 15097 test_kasumi_decryption_test_case_1), 15098 TEST_CASE_ST(ut_setup, ut_teardown, 15099 test_kasumi_decryption_test_case_2), 15100 TEST_CASE_ST(ut_setup, ut_teardown, 15101 test_kasumi_decryption_test_case_3), 15102 TEST_CASE_ST(ut_setup, ut_teardown, 15103 test_kasumi_decryption_test_case_4), 15104 TEST_CASE_ST(ut_setup, ut_teardown, 15105 test_kasumi_decryption_test_case_5), 15106 TEST_CASE_ST(ut_setup, ut_teardown, 15107 test_kasumi_decryption_test_case_1_oop), 15108 TEST_CASE_ST(ut_setup, ut_teardown, 15109 test_kasumi_cipher_auth_test_case_1), 15110 15111 /** KASUMI generate auth, then encrypt (F8) */ 15112 TEST_CASE_ST(ut_setup, ut_teardown, 15113 test_kasumi_auth_cipher_test_case_1), 15114 TEST_CASE_ST(ut_setup, ut_teardown, 15115 test_kasumi_auth_cipher_test_case_2), 15116 TEST_CASE_ST(ut_setup, ut_teardown, 15117 test_kasumi_auth_cipher_test_case_2_oop), 15118 TEST_CASE_ST(ut_setup, ut_teardown, 15119 test_kasumi_auth_cipher_test_case_2_sgl), 15120 TEST_CASE_ST(ut_setup, ut_teardown, 15121 test_kasumi_auth_cipher_test_case_2_oop_sgl), 15122 15123 /** KASUMI decrypt (F8), then verify auth */ 15124 TEST_CASE_ST(ut_setup, ut_teardown, 15125 test_kasumi_auth_cipher_verify_test_case_1), 15126 TEST_CASE_ST(ut_setup, ut_teardown, 15127 test_kasumi_auth_cipher_verify_test_case_2), 15128 TEST_CASE_ST(ut_setup, ut_teardown, 15129 test_kasumi_auth_cipher_verify_test_case_2_oop), 15130 TEST_CASE_ST(ut_setup, ut_teardown, 15131 test_kasumi_auth_cipher_verify_test_case_2_sgl), 15132 TEST_CASE_ST(ut_setup, ut_teardown, 15133 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 15134 15135 TEST_CASES_END() 15136 } 15137 }; 15138 15139 static struct unit_test_suite cryptodev_esn_testsuite = { 15140 .suite_name = "ESN Test Suite", 15141 .setup = esn_testsuite_setup, 15142 .unit_test_cases = { 15143 TEST_CASE_ST(ut_setup, ut_teardown, 15144 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 15145 TEST_CASE_ST(ut_setup, ut_teardown, 15146 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 15147 TEST_CASES_END() 15148 } 15149 }; 15150 15151 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 15152 .suite_name = "Negative AES GCM Test Suite", 15153 .setup = negative_aes_gcm_testsuite_setup, 15154 .unit_test_cases = { 15155 TEST_CASE_ST(ut_setup, ut_teardown, 15156 test_AES_GCM_auth_encryption_fail_iv_corrupt), 15157 TEST_CASE_ST(ut_setup, ut_teardown, 15158 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 15159 TEST_CASE_ST(ut_setup, ut_teardown, 15160 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 15161 TEST_CASE_ST(ut_setup, ut_teardown, 15162 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 15163 TEST_CASE_ST(ut_setup, ut_teardown, 15164 test_AES_GCM_auth_encryption_fail_aad_corrupt), 15165 TEST_CASE_ST(ut_setup, ut_teardown, 15166 test_AES_GCM_auth_encryption_fail_tag_corrupt), 15167 TEST_CASE_ST(ut_setup, ut_teardown, 15168 test_AES_GCM_auth_decryption_fail_iv_corrupt), 15169 TEST_CASE_ST(ut_setup, ut_teardown, 15170 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 15171 TEST_CASE_ST(ut_setup, ut_teardown, 15172 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 15173 TEST_CASE_ST(ut_setup, ut_teardown, 15174 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 15175 TEST_CASE_ST(ut_setup, ut_teardown, 15176 test_AES_GCM_auth_decryption_fail_aad_corrupt), 15177 TEST_CASE_ST(ut_setup, ut_teardown, 15178 test_AES_GCM_auth_decryption_fail_tag_corrupt), 15179 15180 TEST_CASES_END() 15181 } 15182 }; 15183 15184 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 15185 .suite_name = "Negative AES GMAC Test Suite", 15186 .setup = negative_aes_gmac_testsuite_setup, 15187 .unit_test_cases = { 15188 TEST_CASE_ST(ut_setup, ut_teardown, 15189 authentication_verify_AES128_GMAC_fail_data_corrupt), 15190 TEST_CASE_ST(ut_setup, ut_teardown, 15191 authentication_verify_AES128_GMAC_fail_tag_corrupt), 15192 15193 TEST_CASES_END() 15194 } 15195 }; 15196 15197 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 15198 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 15199 .setup = mixed_cipher_hash_testsuite_setup, 15200 .unit_test_cases = { 15201 /** AUTH AES CMAC + CIPHER AES CTR */ 15202 TEST_CASE_ST(ut_setup, ut_teardown, 15203 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 15204 TEST_CASE_ST(ut_setup, ut_teardown, 15205 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15206 TEST_CASE_ST(ut_setup, ut_teardown, 15207 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15208 TEST_CASE_ST(ut_setup, ut_teardown, 15209 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15210 TEST_CASE_ST(ut_setup, ut_teardown, 15211 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 15212 TEST_CASE_ST(ut_setup, ut_teardown, 15213 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15214 TEST_CASE_ST(ut_setup, ut_teardown, 15215 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15216 TEST_CASE_ST(ut_setup, ut_teardown, 15217 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15218 15219 /** AUTH ZUC + CIPHER SNOW3G */ 15220 TEST_CASE_ST(ut_setup, ut_teardown, 15221 test_auth_zuc_cipher_snow_test_case_1), 15222 TEST_CASE_ST(ut_setup, ut_teardown, 15223 test_verify_auth_zuc_cipher_snow_test_case_1), 15224 /** AUTH AES CMAC + CIPHER SNOW3G */ 15225 TEST_CASE_ST(ut_setup, ut_teardown, 15226 test_auth_aes_cmac_cipher_snow_test_case_1), 15227 TEST_CASE_ST(ut_setup, ut_teardown, 15228 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 15229 /** AUTH ZUC + CIPHER AES CTR */ 15230 TEST_CASE_ST(ut_setup, ut_teardown, 15231 test_auth_zuc_cipher_aes_ctr_test_case_1), 15232 TEST_CASE_ST(ut_setup, ut_teardown, 15233 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 15234 /** AUTH SNOW3G + CIPHER AES CTR */ 15235 TEST_CASE_ST(ut_setup, ut_teardown, 15236 test_auth_snow_cipher_aes_ctr_test_case_1), 15237 TEST_CASE_ST(ut_setup, ut_teardown, 15238 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 15239 /** AUTH SNOW3G + CIPHER ZUC */ 15240 TEST_CASE_ST(ut_setup, ut_teardown, 15241 test_auth_snow_cipher_zuc_test_case_1), 15242 TEST_CASE_ST(ut_setup, ut_teardown, 15243 test_verify_auth_snow_cipher_zuc_test_case_1), 15244 /** AUTH AES CMAC + CIPHER ZUC */ 15245 TEST_CASE_ST(ut_setup, ut_teardown, 15246 test_auth_aes_cmac_cipher_zuc_test_case_1), 15247 TEST_CASE_ST(ut_setup, ut_teardown, 15248 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 15249 15250 /** AUTH NULL + CIPHER SNOW3G */ 15251 TEST_CASE_ST(ut_setup, ut_teardown, 15252 test_auth_null_cipher_snow_test_case_1), 15253 TEST_CASE_ST(ut_setup, ut_teardown, 15254 test_verify_auth_null_cipher_snow_test_case_1), 15255 /** AUTH NULL + CIPHER ZUC */ 15256 TEST_CASE_ST(ut_setup, ut_teardown, 15257 test_auth_null_cipher_zuc_test_case_1), 15258 TEST_CASE_ST(ut_setup, ut_teardown, 15259 test_verify_auth_null_cipher_zuc_test_case_1), 15260 /** AUTH SNOW3G + CIPHER NULL */ 15261 TEST_CASE_ST(ut_setup, ut_teardown, 15262 test_auth_snow_cipher_null_test_case_1), 15263 TEST_CASE_ST(ut_setup, ut_teardown, 15264 test_verify_auth_snow_cipher_null_test_case_1), 15265 /** AUTH ZUC + CIPHER NULL */ 15266 TEST_CASE_ST(ut_setup, ut_teardown, 15267 test_auth_zuc_cipher_null_test_case_1), 15268 TEST_CASE_ST(ut_setup, ut_teardown, 15269 test_verify_auth_zuc_cipher_null_test_case_1), 15270 /** AUTH NULL + CIPHER AES CTR */ 15271 TEST_CASE_ST(ut_setup, ut_teardown, 15272 test_auth_null_cipher_aes_ctr_test_case_1), 15273 TEST_CASE_ST(ut_setup, ut_teardown, 15274 test_verify_auth_null_cipher_aes_ctr_test_case_1), 15275 /** AUTH AES CMAC + CIPHER NULL */ 15276 TEST_CASE_ST(ut_setup, ut_teardown, 15277 test_auth_aes_cmac_cipher_null_test_case_1), 15278 TEST_CASE_ST(ut_setup, ut_teardown, 15279 test_verify_auth_aes_cmac_cipher_null_test_case_1), 15280 TEST_CASES_END() 15281 } 15282 }; 15283 15284 static int 15285 run_cryptodev_testsuite(const char *pmd_name) 15286 { 15287 uint8_t ret, j, i = 0, blk_start_idx = 0; 15288 const enum blockcipher_test_type blk_suites[] = { 15289 BLKCIPHER_AES_CHAIN_TYPE, 15290 BLKCIPHER_AES_CIPHERONLY_TYPE, 15291 BLKCIPHER_AES_DOCSIS_TYPE, 15292 BLKCIPHER_3DES_CHAIN_TYPE, 15293 BLKCIPHER_3DES_CIPHERONLY_TYPE, 15294 BLKCIPHER_DES_CIPHERONLY_TYPE, 15295 BLKCIPHER_DES_DOCSIS_TYPE, 15296 BLKCIPHER_AUTHONLY_TYPE}; 15297 struct unit_test_suite *static_suites[] = { 15298 &cryptodev_multi_session_testsuite, 15299 &cryptodev_null_testsuite, 15300 &cryptodev_aes_ccm_auth_testsuite, 15301 &cryptodev_aes_gcm_auth_testsuite, 15302 &cryptodev_aes_gmac_auth_testsuite, 15303 &cryptodev_snow3g_testsuite, 15304 &cryptodev_chacha20_poly1305_testsuite, 15305 &cryptodev_zuc_testsuite, 15306 &cryptodev_hmac_md5_auth_testsuite, 15307 &cryptodev_kasumi_testsuite, 15308 &cryptodev_esn_testsuite, 15309 &cryptodev_negative_aes_gcm_testsuite, 15310 &cryptodev_negative_aes_gmac_testsuite, 15311 &cryptodev_mixed_cipher_hash_testsuite, 15312 &cryptodev_negative_hmac_sha1_testsuite, 15313 &cryptodev_gen_testsuite, 15314 #ifdef RTE_LIB_SECURITY 15315 &ipsec_proto_testsuite, 15316 &pdcp_proto_testsuite, 15317 &docsis_proto_testsuite, 15318 #endif 15319 &end_testsuite 15320 }; 15321 static struct unit_test_suite ts = { 15322 .suite_name = "Cryptodev Unit Test Suite", 15323 .setup = testsuite_setup, 15324 .teardown = testsuite_teardown, 15325 .unit_test_cases = {TEST_CASES_END()} 15326 }; 15327 15328 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 15329 15330 if (gbl_driver_id == -1) { 15331 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 15332 return TEST_SKIPPED; 15333 } 15334 15335 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15336 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 15337 15338 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 15339 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15340 ret = unit_test_suite_runner(&ts); 15341 15342 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 15343 free(ts.unit_test_suites); 15344 return ret; 15345 } 15346 15347 static int 15348 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 15349 { 15350 struct rte_cryptodev_info dev_info; 15351 uint8_t i, nb_devs; 15352 int driver_id; 15353 15354 driver_id = rte_cryptodev_driver_id_get(pmd_name); 15355 if (driver_id == -1) { 15356 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 15357 return TEST_SKIPPED; 15358 } 15359 15360 nb_devs = rte_cryptodev_count(); 15361 if (nb_devs < 1) { 15362 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 15363 return TEST_SKIPPED; 15364 } 15365 15366 for (i = 0; i < nb_devs; i++) { 15367 rte_cryptodev_info_get(i, &dev_info); 15368 if (dev_info.driver_id == driver_id) { 15369 if (!(dev_info.feature_flags & flag)) { 15370 RTE_LOG(INFO, USER1, "%s not supported\n", 15371 flag_name); 15372 return TEST_SKIPPED; 15373 } 15374 return 0; /* found */ 15375 } 15376 } 15377 15378 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 15379 return TEST_SKIPPED; 15380 } 15381 15382 static int 15383 test_cryptodev_qat(void) 15384 { 15385 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 15386 } 15387 15388 static int 15389 test_cryptodev_virtio(void) 15390 { 15391 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 15392 } 15393 15394 static int 15395 test_cryptodev_aesni_mb(void) 15396 { 15397 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15398 } 15399 15400 static int 15401 test_cryptodev_cpu_aesni_mb(void) 15402 { 15403 int32_t rc; 15404 enum rte_security_session_action_type at = gbl_action_type; 15405 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15406 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15407 gbl_action_type = at; 15408 return rc; 15409 } 15410 15411 static int 15412 test_cryptodev_chacha_poly_mb(void) 15413 { 15414 int32_t rc; 15415 enum rte_security_session_action_type at = gbl_action_type; 15416 rc = run_cryptodev_testsuite( 15417 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 15418 gbl_action_type = at; 15419 return rc; 15420 } 15421 15422 static int 15423 test_cryptodev_openssl(void) 15424 { 15425 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 15426 } 15427 15428 static int 15429 test_cryptodev_aesni_gcm(void) 15430 { 15431 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15432 } 15433 15434 static int 15435 test_cryptodev_cpu_aesni_gcm(void) 15436 { 15437 int32_t rc; 15438 enum rte_security_session_action_type at = gbl_action_type; 15439 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15440 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15441 gbl_action_type = at; 15442 return rc; 15443 } 15444 15445 static int 15446 test_cryptodev_mlx5(void) 15447 { 15448 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 15449 } 15450 15451 static int 15452 test_cryptodev_null(void) 15453 { 15454 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 15455 } 15456 15457 static int 15458 test_cryptodev_sw_snow3g(void) 15459 { 15460 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 15461 } 15462 15463 static int 15464 test_cryptodev_sw_kasumi(void) 15465 { 15466 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 15467 } 15468 15469 static int 15470 test_cryptodev_sw_zuc(void) 15471 { 15472 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 15473 } 15474 15475 static int 15476 test_cryptodev_armv8(void) 15477 { 15478 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 15479 } 15480 15481 static int 15482 test_cryptodev_mrvl(void) 15483 { 15484 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 15485 } 15486 15487 #ifdef RTE_CRYPTO_SCHEDULER 15488 15489 static int 15490 test_cryptodev_scheduler(void) 15491 { 15492 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 15493 const enum blockcipher_test_type blk_suites[] = { 15494 BLKCIPHER_AES_CHAIN_TYPE, 15495 BLKCIPHER_AES_CIPHERONLY_TYPE, 15496 BLKCIPHER_AUTHONLY_TYPE 15497 }; 15498 static struct unit_test_suite scheduler_multicore = { 15499 .suite_name = "Scheduler Multicore Unit Test Suite", 15500 .setup = scheduler_multicore_testsuite_setup, 15501 .teardown = scheduler_mode_testsuite_teardown, 15502 .unit_test_cases = {TEST_CASES_END()} 15503 }; 15504 static struct unit_test_suite scheduler_round_robin = { 15505 .suite_name = "Scheduler Round Robin Unit Test Suite", 15506 .setup = scheduler_roundrobin_testsuite_setup, 15507 .teardown = scheduler_mode_testsuite_teardown, 15508 .unit_test_cases = {TEST_CASES_END()} 15509 }; 15510 static struct unit_test_suite scheduler_failover = { 15511 .suite_name = "Scheduler Failover Unit Test Suite", 15512 .setup = scheduler_failover_testsuite_setup, 15513 .teardown = scheduler_mode_testsuite_teardown, 15514 .unit_test_cases = {TEST_CASES_END()} 15515 }; 15516 static struct unit_test_suite scheduler_pkt_size_distr = { 15517 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 15518 .setup = scheduler_pkt_size_distr_testsuite_setup, 15519 .teardown = scheduler_mode_testsuite_teardown, 15520 .unit_test_cases = {TEST_CASES_END()} 15521 }; 15522 struct unit_test_suite *sched_mode_suites[] = { 15523 &scheduler_multicore, 15524 &scheduler_round_robin, 15525 &scheduler_failover, 15526 &scheduler_pkt_size_distr 15527 }; 15528 static struct unit_test_suite scheduler_config = { 15529 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 15530 .unit_test_cases = { 15531 TEST_CASE(test_scheduler_attach_worker_op), 15532 TEST_CASE(test_scheduler_mode_multicore_op), 15533 TEST_CASE(test_scheduler_mode_roundrobin_op), 15534 TEST_CASE(test_scheduler_mode_failover_op), 15535 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 15536 TEST_CASE(test_scheduler_detach_worker_op), 15537 15538 TEST_CASES_END() /**< NULL terminate array */ 15539 } 15540 }; 15541 struct unit_test_suite *static_suites[] = { 15542 &scheduler_config, 15543 &end_testsuite 15544 }; 15545 static struct unit_test_suite ts = { 15546 .suite_name = "Scheduler Unit Test Suite", 15547 .setup = scheduler_testsuite_setup, 15548 .teardown = testsuite_teardown, 15549 .unit_test_cases = {TEST_CASES_END()} 15550 }; 15551 15552 gbl_driver_id = rte_cryptodev_driver_id_get( 15553 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15554 15555 if (gbl_driver_id == -1) { 15556 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 15557 return TEST_SKIPPED; 15558 } 15559 15560 if (rte_cryptodev_driver_id_get( 15561 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 15562 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 15563 return TEST_SKIPPED; 15564 } 15565 15566 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15567 uint8_t blk_i = 0; 15568 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 15569 (struct unit_test_suite *) * 15570 (RTE_DIM(blk_suites) + 1)); 15571 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 15572 blk_suites, RTE_DIM(blk_suites)); 15573 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 15574 } 15575 15576 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15577 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 15578 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 15579 RTE_DIM(sched_mode_suites)); 15580 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15581 ret = unit_test_suite_runner(&ts); 15582 15583 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15584 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 15585 (*sched_mode_suites[sched_i]), 15586 RTE_DIM(blk_suites)); 15587 free(sched_mode_suites[sched_i]->unit_test_suites); 15588 } 15589 free(ts.unit_test_suites); 15590 return ret; 15591 } 15592 15593 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 15594 15595 #endif 15596 15597 static int 15598 test_cryptodev_dpaa2_sec(void) 15599 { 15600 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 15601 } 15602 15603 static int 15604 test_cryptodev_dpaa_sec(void) 15605 { 15606 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 15607 } 15608 15609 static int 15610 test_cryptodev_ccp(void) 15611 { 15612 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 15613 } 15614 15615 static int 15616 test_cryptodev_octeontx(void) 15617 { 15618 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 15619 } 15620 15621 static int 15622 test_cryptodev_octeontx2(void) 15623 { 15624 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 15625 } 15626 15627 static int 15628 test_cryptodev_caam_jr(void) 15629 { 15630 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 15631 } 15632 15633 static int 15634 test_cryptodev_nitrox(void) 15635 { 15636 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 15637 } 15638 15639 static int 15640 test_cryptodev_bcmfs(void) 15641 { 15642 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 15643 } 15644 15645 static int 15646 test_cryptodev_qat_raw_api(void) 15647 { 15648 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 15649 int ret; 15650 15651 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15652 "RAW API"); 15653 if (ret) 15654 return ret; 15655 15656 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15657 ret = run_cryptodev_testsuite(pmd_name); 15658 global_api_test_type = CRYPTODEV_API_TEST; 15659 15660 return ret; 15661 } 15662 15663 static int 15664 test_cryptodev_cn9k(void) 15665 { 15666 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 15667 } 15668 15669 static int 15670 test_cryptodev_cn10k(void) 15671 { 15672 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 15673 } 15674 15675 static int 15676 test_cryptodev_dpaa2_sec_raw_api(void) 15677 { 15678 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15679 int ret; 15680 15681 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15682 "RAW API"); 15683 if (ret) 15684 return ret; 15685 15686 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15687 ret = run_cryptodev_testsuite(pmd_name); 15688 global_api_test_type = CRYPTODEV_API_TEST; 15689 15690 return ret; 15691 } 15692 15693 static int 15694 test_cryptodev_dpaa_sec_raw_api(void) 15695 { 15696 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15697 int ret; 15698 15699 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15700 "RAW API"); 15701 if (ret) 15702 return ret; 15703 15704 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15705 ret = run_cryptodev_testsuite(pmd_name); 15706 global_api_test_type = CRYPTODEV_API_TEST; 15707 15708 return ret; 15709 } 15710 15711 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 15712 test_cryptodev_dpaa2_sec_raw_api); 15713 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 15714 test_cryptodev_dpaa_sec_raw_api); 15715 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 15716 test_cryptodev_qat_raw_api); 15717 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 15718 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 15719 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 15720 test_cryptodev_cpu_aesni_mb); 15721 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 15722 test_cryptodev_chacha_poly_mb); 15723 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 15724 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 15725 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 15726 test_cryptodev_cpu_aesni_gcm); 15727 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 15728 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 15729 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 15730 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 15731 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 15732 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 15733 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 15734 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 15735 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 15736 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 15737 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 15738 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 15739 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 15740 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 15741 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 15742 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 15743 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 15744 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 15745