1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 17 #include <rte_crypto.h> 18 #include <rte_cryptodev.h> 19 #include <rte_ip.h> 20 #include <rte_string_fns.h> 21 #include <rte_tcp.h> 22 #include <rte_udp.h> 23 24 #ifdef RTE_CRYPTO_SCHEDULER 25 #include <rte_cryptodev_scheduler.h> 26 #include <rte_cryptodev_scheduler_operations.h> 27 #endif 28 29 #include <rte_lcore.h> 30 31 #include "test.h" 32 #include "test_cryptodev.h" 33 34 #include "test_cryptodev_blockcipher.h" 35 #include "test_cryptodev_aes_test_vectors.h" 36 #include "test_cryptodev_des_test_vectors.h" 37 #include "test_cryptodev_hash_test_vectors.h" 38 #include "test_cryptodev_kasumi_test_vectors.h" 39 #include "test_cryptodev_kasumi_hash_test_vectors.h" 40 #include "test_cryptodev_snow3g_test_vectors.h" 41 #include "test_cryptodev_snow3g_hash_test_vectors.h" 42 #include "test_cryptodev_zuc_test_vectors.h" 43 #include "test_cryptodev_aead_test_vectors.h" 44 #include "test_cryptodev_hmac_test_vectors.h" 45 #include "test_cryptodev_mixed_test_vectors.h" 46 #ifdef RTE_LIB_SECURITY 47 #include "test_cryptodev_security_ipsec.h" 48 #include "test_cryptodev_security_ipsec_test_vectors.h" 49 #include "test_cryptodev_security_pdcp_test_vectors.h" 50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 51 #include "test_cryptodev_security_pdcp_test_func.h" 52 #include "test_cryptodev_security_docsis_test_vectors.h" 53 54 #define SDAP_DISABLED 0 55 #define SDAP_ENABLED 1 56 #endif 57 58 #define VDEV_ARGS_SIZE 100 59 #define MAX_NB_SESSIONS 4 60 61 #define MAX_DRV_SERVICE_CTX_SIZE 256 62 63 #define MAX_RAW_DEQUEUE_COUNT 65535 64 65 #define IN_PLACE 0 66 #define OUT_OF_PLACE 1 67 68 static int gbl_driver_id; 69 70 static enum rte_security_session_action_type gbl_action_type = 71 RTE_SECURITY_ACTION_TYPE_NONE; 72 73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 74 75 struct crypto_unittest_params { 76 struct rte_crypto_sym_xform cipher_xform; 77 struct rte_crypto_sym_xform auth_xform; 78 struct rte_crypto_sym_xform aead_xform; 79 #ifdef RTE_LIB_SECURITY 80 struct rte_security_docsis_xform docsis_xform; 81 #endif 82 83 union { 84 struct rte_cryptodev_sym_session *sess; 85 #ifdef RTE_LIB_SECURITY 86 struct rte_security_session *sec_session; 87 #endif 88 }; 89 #ifdef RTE_LIB_SECURITY 90 enum rte_security_session_action_type type; 91 #endif 92 struct rte_crypto_op *op; 93 94 struct rte_mbuf *obuf, *ibuf; 95 96 uint8_t *digest; 97 }; 98 99 #define ALIGN_POW2_ROUNDUP(num, align) \ 100 (((num) + (align) - 1) & ~((align) - 1)) 101 102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 103 for (j = 0; j < num_child_ts; index++, j++) \ 104 parent_ts.unit_test_suites[index] = child_ts[j] 105 106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 107 for (j = 0; j < num_blk_types; index++, j++) \ 108 parent_ts.unit_test_suites[index] = \ 109 build_blockcipher_test_suite(blk_types[j]) 110 111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 112 for (j = index; j < index + num_blk_types; j++) \ 113 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 114 115 /* 116 * Forward declarations. 117 */ 118 static int 119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 120 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 121 uint8_t *hmac_key); 122 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 125 struct crypto_unittest_params *ut_params, 126 struct crypto_testsuite_params *ts_param, 127 const uint8_t *cipher, 128 const uint8_t *digest, 129 const uint8_t *iv); 130 131 static int 132 security_proto_supported(enum rte_security_session_action_type action, 133 enum rte_security_session_protocol proto); 134 135 static int 136 dev_configure_and_start(uint64_t ff_disable); 137 138 static struct rte_mbuf * 139 setup_test_string(struct rte_mempool *mpool, 140 const char *string, size_t len, uint8_t blocksize) 141 { 142 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 143 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 144 145 if (m) { 146 char *dst; 147 148 memset(m->buf_addr, 0, m->buf_len); 149 dst = rte_pktmbuf_append(m, t_len); 150 if (!dst) { 151 rte_pktmbuf_free(m); 152 return NULL; 153 } 154 if (string != NULL) 155 rte_memcpy(dst, string, t_len); 156 else 157 memset(dst, 0, t_len); 158 } 159 160 return m; 161 } 162 163 /* Get number of bytes in X bits (rounding up) */ 164 static uint32_t 165 ceil_byte_length(uint32_t num_bits) 166 { 167 if (num_bits % 8) 168 return ((num_bits >> 3) + 1); 169 else 170 return (num_bits >> 3); 171 } 172 173 static void 174 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 175 uint8_t is_op_success) 176 { 177 struct rte_crypto_op *op = user_data; 178 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 179 RTE_CRYPTO_OP_STATUS_ERROR; 180 } 181 182 static struct crypto_testsuite_params testsuite_params = { NULL }; 183 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 184 static struct crypto_unittest_params unittest_params; 185 186 void 187 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 188 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 189 uint8_t len_in_bits, uint8_t cipher_iv_len) 190 { 191 struct rte_crypto_sym_op *sop = op->sym; 192 struct rte_crypto_op *ret_op = NULL; 193 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 194 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 195 union rte_crypto_sym_ofs ofs; 196 struct rte_crypto_sym_vec vec; 197 struct rte_crypto_sgl sgl, dest_sgl; 198 uint32_t max_len; 199 union rte_cryptodev_session_ctx sess; 200 uint64_t auth_end_iova; 201 uint32_t count = 0; 202 struct rte_crypto_raw_dp_ctx *ctx; 203 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 204 auth_len = 0; 205 int32_t n; 206 uint32_t n_success; 207 int ctx_service_size; 208 int32_t status = 0; 209 int enqueue_status, dequeue_status; 210 struct crypto_unittest_params *ut_params = &unittest_params; 211 int is_sgl = sop->m_src->nb_segs > 1; 212 213 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 214 if (ctx_service_size < 0) { 215 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 216 return; 217 } 218 219 ctx = malloc(ctx_service_size); 220 if (!ctx) { 221 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 222 return; 223 } 224 225 /* Both are enums, setting crypto_sess will suit any session type */ 226 sess.crypto_sess = op->sym->session; 227 228 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 229 op->sess_type, sess, 0) < 0) { 230 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 231 goto exit; 232 } 233 234 cipher_iv.iova = 0; 235 cipher_iv.va = NULL; 236 aad_auth_iv.iova = 0; 237 aad_auth_iv.va = NULL; 238 digest.iova = 0; 239 digest.va = NULL; 240 sgl.vec = data_vec; 241 vec.num = 1; 242 vec.src_sgl = &sgl; 243 vec.iv = &cipher_iv; 244 vec.digest = &digest; 245 vec.aad = &aad_auth_iv; 246 vec.status = &status; 247 248 ofs.raw = 0; 249 250 if (is_cipher && is_auth) { 251 cipher_offset = sop->cipher.data.offset; 252 cipher_len = sop->cipher.data.length; 253 auth_offset = sop->auth.data.offset; 254 auth_len = sop->auth.data.length; 255 max_len = RTE_MAX(cipher_offset + cipher_len, 256 auth_offset + auth_len); 257 if (len_in_bits) { 258 max_len = max_len >> 3; 259 cipher_offset = cipher_offset >> 3; 260 auth_offset = auth_offset >> 3; 261 cipher_len = cipher_len >> 3; 262 auth_len = auth_len >> 3; 263 } 264 ofs.ofs.cipher.head = cipher_offset; 265 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 266 ofs.ofs.auth.head = auth_offset; 267 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 268 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 269 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 270 aad_auth_iv.va = rte_crypto_op_ctod_offset( 271 op, void *, IV_OFFSET + cipher_iv_len); 272 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 273 cipher_iv_len); 274 digest.va = (void *)sop->auth.digest.data; 275 digest.iova = sop->auth.digest.phys_addr; 276 277 if (is_sgl) { 278 uint32_t remaining_off = auth_offset + auth_len; 279 struct rte_mbuf *sgl_buf = sop->m_src; 280 281 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 282 && sgl_buf->next != NULL) { 283 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 284 sgl_buf = sgl_buf->next; 285 } 286 287 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 288 sgl_buf, remaining_off); 289 } else { 290 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 291 auth_offset + auth_len; 292 } 293 /* Then check if digest-encrypted conditions are met */ 294 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 295 (digest.iova == auth_end_iova) && is_sgl) 296 max_len = RTE_MAX(max_len, auth_offset + auth_len + 297 ut_params->auth_xform.auth.digest_length); 298 299 } else if (is_cipher) { 300 cipher_offset = sop->cipher.data.offset; 301 cipher_len = sop->cipher.data.length; 302 max_len = cipher_len + cipher_offset; 303 if (len_in_bits) { 304 max_len = max_len >> 3; 305 cipher_offset = cipher_offset >> 3; 306 cipher_len = cipher_len >> 3; 307 } 308 ofs.ofs.cipher.head = cipher_offset; 309 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 310 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 311 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 312 313 } else if (is_auth) { 314 auth_offset = sop->auth.data.offset; 315 auth_len = sop->auth.data.length; 316 max_len = auth_len + auth_offset; 317 if (len_in_bits) { 318 max_len = max_len >> 3; 319 auth_offset = auth_offset >> 3; 320 auth_len = auth_len >> 3; 321 } 322 ofs.ofs.auth.head = auth_offset; 323 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 324 aad_auth_iv.va = rte_crypto_op_ctod_offset( 325 op, void *, IV_OFFSET + cipher_iv_len); 326 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 327 cipher_iv_len); 328 digest.va = (void *)sop->auth.digest.data; 329 digest.iova = sop->auth.digest.phys_addr; 330 331 } else { /* aead */ 332 cipher_offset = sop->aead.data.offset; 333 cipher_len = sop->aead.data.length; 334 max_len = cipher_len + cipher_offset; 335 if (len_in_bits) { 336 max_len = max_len >> 3; 337 cipher_offset = cipher_offset >> 3; 338 cipher_len = cipher_len >> 3; 339 } 340 ofs.ofs.cipher.head = cipher_offset; 341 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 342 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 343 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 344 aad_auth_iv.va = (void *)sop->aead.aad.data; 345 aad_auth_iv.iova = sop->aead.aad.phys_addr; 346 digest.va = (void *)sop->aead.digest.data; 347 digest.iova = sop->aead.digest.phys_addr; 348 } 349 350 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 351 data_vec, RTE_DIM(data_vec)); 352 if (n < 0 || n > sop->m_src->nb_segs) { 353 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 354 goto exit; 355 } 356 357 sgl.num = n; 358 /* Out of place */ 359 if (sop->m_dst != NULL) { 360 dest_sgl.vec = dest_data_vec; 361 vec.dest_sgl = &dest_sgl; 362 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 363 dest_data_vec, RTE_DIM(dest_data_vec)); 364 if (n < 0 || n > sop->m_dst->nb_segs) { 365 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 366 goto exit; 367 } 368 dest_sgl.num = n; 369 } else 370 vec.dest_sgl = NULL; 371 372 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 373 &enqueue_status) < 1) { 374 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 375 goto exit; 376 } 377 378 if (enqueue_status == 0) { 379 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 380 if (status < 0) { 381 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 382 goto exit; 383 } 384 } else if (enqueue_status < 0) { 385 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 386 goto exit; 387 } 388 389 n = n_success = 0; 390 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 391 n = rte_cryptodev_raw_dequeue_burst(ctx, 392 NULL, 1, post_process_raw_dp_op, 393 (void **)&ret_op, 0, &n_success, 394 &dequeue_status); 395 if (dequeue_status < 0) { 396 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 397 goto exit; 398 } 399 if (n == 0) 400 rte_pause(); 401 } 402 403 if (n == 1 && dequeue_status == 0) { 404 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 405 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 406 goto exit; 407 } 408 } 409 410 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 411 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 412 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 413 RTE_CRYPTO_OP_STATUS_SUCCESS; 414 415 exit: 416 free(ctx); 417 } 418 419 static void 420 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 421 { 422 int32_t n, st; 423 struct rte_crypto_sym_op *sop; 424 union rte_crypto_sym_ofs ofs; 425 struct rte_crypto_sgl sgl; 426 struct rte_crypto_sym_vec symvec; 427 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 428 struct rte_crypto_vec vec[UINT8_MAX]; 429 430 sop = op->sym; 431 432 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 433 sop->aead.data.length, vec, RTE_DIM(vec)); 434 435 if (n < 0 || n != sop->m_src->nb_segs) { 436 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 437 return; 438 } 439 440 sgl.vec = vec; 441 sgl.num = n; 442 symvec.src_sgl = &sgl; 443 symvec.iv = &iv_ptr; 444 symvec.digest = &digest_ptr; 445 symvec.aad = &aad_ptr; 446 symvec.status = &st; 447 symvec.num = 1; 448 449 /* for CPU crypto the IOVA address is not required */ 450 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 451 digest_ptr.va = (void *)sop->aead.digest.data; 452 aad_ptr.va = (void *)sop->aead.aad.data; 453 454 ofs.raw = 0; 455 456 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 457 &symvec); 458 459 if (n != 1) 460 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 461 else 462 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 463 } 464 465 static void 466 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 467 { 468 int32_t n, st; 469 struct rte_crypto_sym_op *sop; 470 union rte_crypto_sym_ofs ofs; 471 struct rte_crypto_sgl sgl; 472 struct rte_crypto_sym_vec symvec; 473 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 474 struct rte_crypto_vec vec[UINT8_MAX]; 475 476 sop = op->sym; 477 478 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 479 sop->auth.data.length, vec, RTE_DIM(vec)); 480 481 if (n < 0 || n != sop->m_src->nb_segs) { 482 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 483 return; 484 } 485 486 sgl.vec = vec; 487 sgl.num = n; 488 symvec.src_sgl = &sgl; 489 symvec.iv = &iv_ptr; 490 symvec.digest = &digest_ptr; 491 symvec.status = &st; 492 symvec.num = 1; 493 494 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 495 digest_ptr.va = (void *)sop->auth.digest.data; 496 497 ofs.raw = 0; 498 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 499 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 500 (sop->cipher.data.offset + sop->cipher.data.length); 501 502 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 503 &symvec); 504 505 if (n != 1) 506 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 507 else 508 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 509 } 510 511 static struct rte_crypto_op * 512 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 513 { 514 515 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 516 517 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 518 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 519 return NULL; 520 } 521 522 op = NULL; 523 524 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 525 rte_pause(); 526 527 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 528 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 529 return NULL; 530 } 531 532 return op; 533 } 534 535 static int 536 testsuite_setup(void) 537 { 538 struct crypto_testsuite_params *ts_params = &testsuite_params; 539 struct rte_cryptodev_info info; 540 uint32_t i = 0, nb_devs, dev_id; 541 uint16_t qp_id; 542 543 memset(ts_params, 0, sizeof(*ts_params)); 544 545 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 546 if (ts_params->mbuf_pool == NULL) { 547 /* Not already created so create */ 548 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 549 "CRYPTO_MBUFPOOL", 550 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 551 rte_socket_id()); 552 if (ts_params->mbuf_pool == NULL) { 553 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 554 return TEST_FAILED; 555 } 556 } 557 558 ts_params->large_mbuf_pool = rte_mempool_lookup( 559 "CRYPTO_LARGE_MBUFPOOL"); 560 if (ts_params->large_mbuf_pool == NULL) { 561 /* Not already created so create */ 562 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 563 "CRYPTO_LARGE_MBUFPOOL", 564 1, 0, 0, UINT16_MAX, 565 rte_socket_id()); 566 if (ts_params->large_mbuf_pool == NULL) { 567 RTE_LOG(ERR, USER1, 568 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 569 return TEST_FAILED; 570 } 571 } 572 573 ts_params->op_mpool = rte_crypto_op_pool_create( 574 "MBUF_CRYPTO_SYM_OP_POOL", 575 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 576 NUM_MBUFS, MBUF_CACHE_SIZE, 577 DEFAULT_NUM_XFORMS * 578 sizeof(struct rte_crypto_sym_xform) + 579 MAXIMUM_IV_LENGTH, 580 rte_socket_id()); 581 if (ts_params->op_mpool == NULL) { 582 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 583 return TEST_FAILED; 584 } 585 586 nb_devs = rte_cryptodev_count(); 587 if (nb_devs < 1) { 588 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 589 return TEST_SKIPPED; 590 } 591 592 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 593 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 594 rte_cryptodev_driver_name_get(gbl_driver_id)); 595 return TEST_SKIPPED; 596 } 597 598 /* Create list of valid crypto devs */ 599 for (i = 0; i < nb_devs; i++) { 600 rte_cryptodev_info_get(i, &info); 601 if (info.driver_id == gbl_driver_id) 602 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 603 } 604 605 if (ts_params->valid_dev_count < 1) 606 return TEST_FAILED; 607 608 /* Set up all the qps on the first of the valid devices found */ 609 610 dev_id = ts_params->valid_devs[0]; 611 612 rte_cryptodev_info_get(dev_id, &info); 613 614 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 615 ts_params->conf.socket_id = SOCKET_ID_ANY; 616 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 617 618 unsigned int session_size = 619 rte_cryptodev_sym_get_private_session_size(dev_id); 620 621 #ifdef RTE_LIB_SECURITY 622 unsigned int security_session_size = rte_security_session_get_size( 623 rte_cryptodev_get_sec_ctx(dev_id)); 624 625 if (session_size < security_session_size) 626 session_size = security_session_size; 627 #endif 628 /* 629 * Create mempool with maximum number of sessions. 630 */ 631 if (info.sym.max_nb_sessions != 0 && 632 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 633 RTE_LOG(ERR, USER1, "Device does not support " 634 "at least %u sessions\n", 635 MAX_NB_SESSIONS); 636 return TEST_FAILED; 637 } 638 639 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 640 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 641 SOCKET_ID_ANY); 642 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 643 "session mempool allocation failed"); 644 645 ts_params->session_priv_mpool = rte_mempool_create( 646 "test_sess_mp_priv", 647 MAX_NB_SESSIONS, 648 session_size, 649 0, 0, NULL, NULL, NULL, 650 NULL, SOCKET_ID_ANY, 651 0); 652 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 653 "session mempool allocation failed"); 654 655 656 657 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 658 &ts_params->conf), 659 "Failed to configure cryptodev %u with %u qps", 660 dev_id, ts_params->conf.nb_queue_pairs); 661 662 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 663 ts_params->qp_conf.mp_session = ts_params->session_mpool; 664 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 665 666 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 667 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 668 dev_id, qp_id, &ts_params->qp_conf, 669 rte_cryptodev_socket_id(dev_id)), 670 "Failed to setup queue pair %u on cryptodev %u", 671 qp_id, dev_id); 672 } 673 674 return TEST_SUCCESS; 675 } 676 677 static void 678 testsuite_teardown(void) 679 { 680 struct crypto_testsuite_params *ts_params = &testsuite_params; 681 int res; 682 683 if (ts_params->mbuf_pool != NULL) { 684 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 685 rte_mempool_avail_count(ts_params->mbuf_pool)); 686 } 687 688 if (ts_params->op_mpool != NULL) { 689 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 690 rte_mempool_avail_count(ts_params->op_mpool)); 691 } 692 693 /* Free session mempools */ 694 if (ts_params->session_priv_mpool != NULL) { 695 rte_mempool_free(ts_params->session_priv_mpool); 696 ts_params->session_priv_mpool = NULL; 697 } 698 699 if (ts_params->session_mpool != NULL) { 700 rte_mempool_free(ts_params->session_mpool); 701 ts_params->session_mpool = NULL; 702 } 703 704 res = rte_cryptodev_close(ts_params->valid_devs[0]); 705 if (res) 706 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 707 } 708 709 static int 710 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 711 const int *algs, uint16_t num_algs) 712 { 713 uint8_t dev_id = testsuite_params.valid_devs[0]; 714 bool some_alg_supported = FALSE; 715 uint16_t i; 716 717 for (i = 0; i < num_algs && !some_alg_supported; i++) { 718 struct rte_cryptodev_sym_capability_idx alg = { 719 type, {algs[i]} 720 }; 721 if (rte_cryptodev_sym_capability_get(dev_id, 722 &alg) != NULL) 723 some_alg_supported = TRUE; 724 } 725 if (!some_alg_supported) 726 return TEST_SKIPPED; 727 728 return 0; 729 } 730 731 int 732 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 733 uint16_t num_ciphers) 734 { 735 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 736 (const int *) ciphers, num_ciphers); 737 } 738 739 int 740 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 741 uint16_t num_auths) 742 { 743 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 744 (const int *) auths, num_auths); 745 } 746 747 int 748 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 749 uint16_t num_aeads) 750 { 751 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 752 (const int *) aeads, num_aeads); 753 } 754 755 static int 756 null_testsuite_setup(void) 757 { 758 struct crypto_testsuite_params *ts_params = &testsuite_params; 759 uint8_t dev_id = ts_params->valid_devs[0]; 760 struct rte_cryptodev_info dev_info; 761 const enum rte_crypto_cipher_algorithm ciphers[] = { 762 RTE_CRYPTO_CIPHER_NULL 763 }; 764 const enum rte_crypto_auth_algorithm auths[] = { 765 RTE_CRYPTO_AUTH_NULL 766 }; 767 768 rte_cryptodev_info_get(dev_id, &dev_info); 769 770 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 771 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 772 "testsuite not met\n"); 773 return TEST_SKIPPED; 774 } 775 776 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 777 && check_auth_capabilities_supported(auths, 778 RTE_DIM(auths)) != 0) { 779 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 780 "testsuite not met\n"); 781 return TEST_SKIPPED; 782 } 783 784 return 0; 785 } 786 787 static int 788 crypto_gen_testsuite_setup(void) 789 { 790 struct crypto_testsuite_params *ts_params = &testsuite_params; 791 uint8_t dev_id = ts_params->valid_devs[0]; 792 struct rte_cryptodev_info dev_info; 793 794 rte_cryptodev_info_get(dev_id, &dev_info); 795 796 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 797 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 798 "testsuite not met\n"); 799 return TEST_SKIPPED; 800 } 801 802 return 0; 803 } 804 805 #ifdef RTE_LIB_SECURITY 806 static int 807 ipsec_proto_testsuite_setup(void) 808 { 809 struct crypto_testsuite_params *ts_params = &testsuite_params; 810 struct crypto_unittest_params *ut_params = &unittest_params; 811 struct rte_cryptodev_info dev_info; 812 int ret = 0; 813 814 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 815 816 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 817 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 818 "testsuite not met\n"); 819 return TEST_SKIPPED; 820 } 821 822 /* Reconfigure to enable security */ 823 ret = dev_configure_and_start(0); 824 if (ret != TEST_SUCCESS) 825 return ret; 826 827 /* Set action type */ 828 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 829 830 if (security_proto_supported( 831 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 832 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 833 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 834 "test not met\n"); 835 ret = TEST_SKIPPED; 836 } 837 838 /* 839 * Stop the device. Device would be started again by individual test 840 * case setup routine. 841 */ 842 rte_cryptodev_stop(ts_params->valid_devs[0]); 843 844 return ret; 845 } 846 847 static int 848 pdcp_proto_testsuite_setup(void) 849 { 850 struct crypto_testsuite_params *ts_params = &testsuite_params; 851 uint8_t dev_id = ts_params->valid_devs[0]; 852 struct rte_cryptodev_info dev_info; 853 const enum rte_crypto_cipher_algorithm ciphers[] = { 854 RTE_CRYPTO_CIPHER_NULL, 855 RTE_CRYPTO_CIPHER_AES_CTR, 856 RTE_CRYPTO_CIPHER_ZUC_EEA3, 857 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 858 }; 859 const enum rte_crypto_auth_algorithm auths[] = { 860 RTE_CRYPTO_AUTH_NULL, 861 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 862 RTE_CRYPTO_AUTH_AES_CMAC, 863 RTE_CRYPTO_AUTH_ZUC_EIA3 864 }; 865 866 rte_cryptodev_info_get(dev_id, &dev_info); 867 868 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 869 !(dev_info.feature_flags & 870 RTE_CRYPTODEV_FF_SECURITY)) { 871 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 872 "testsuite not met\n"); 873 return TEST_SKIPPED; 874 } 875 876 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 877 && check_auth_capabilities_supported(auths, 878 RTE_DIM(auths)) != 0) { 879 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 880 "testsuite not met\n"); 881 return TEST_SKIPPED; 882 } 883 884 return 0; 885 } 886 887 static int 888 docsis_proto_testsuite_setup(void) 889 { 890 struct crypto_testsuite_params *ts_params = &testsuite_params; 891 uint8_t dev_id = ts_params->valid_devs[0]; 892 struct rte_cryptodev_info dev_info; 893 const enum rte_crypto_cipher_algorithm ciphers[] = { 894 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 895 }; 896 897 rte_cryptodev_info_get(dev_id, &dev_info); 898 899 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 900 !(dev_info.feature_flags & 901 RTE_CRYPTODEV_FF_SECURITY)) { 902 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 903 "Proto testsuite not met\n"); 904 return TEST_SKIPPED; 905 } 906 907 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 908 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 909 "testsuite not met\n"); 910 return TEST_SKIPPED; 911 } 912 913 return 0; 914 } 915 #endif 916 917 static int 918 aes_ccm_auth_testsuite_setup(void) 919 { 920 struct crypto_testsuite_params *ts_params = &testsuite_params; 921 uint8_t dev_id = ts_params->valid_devs[0]; 922 struct rte_cryptodev_info dev_info; 923 const enum rte_crypto_aead_algorithm aeads[] = { 924 RTE_CRYPTO_AEAD_AES_CCM 925 }; 926 927 rte_cryptodev_info_get(dev_id, &dev_info); 928 929 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 930 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 931 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 932 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 933 "testsuite not met\n"); 934 return TEST_SKIPPED; 935 } 936 937 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 938 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 939 "testsuite not met\n"); 940 return TEST_SKIPPED; 941 } 942 943 return 0; 944 } 945 946 static int 947 aes_gcm_auth_testsuite_setup(void) 948 { 949 struct crypto_testsuite_params *ts_params = &testsuite_params; 950 uint8_t dev_id = ts_params->valid_devs[0]; 951 struct rte_cryptodev_info dev_info; 952 const enum rte_crypto_aead_algorithm aeads[] = { 953 RTE_CRYPTO_AEAD_AES_GCM 954 }; 955 956 rte_cryptodev_info_get(dev_id, &dev_info); 957 958 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 959 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 960 "testsuite not met\n"); 961 return TEST_SKIPPED; 962 } 963 964 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 965 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 966 "testsuite not met\n"); 967 return TEST_SKIPPED; 968 } 969 970 return 0; 971 } 972 973 static int 974 aes_gmac_auth_testsuite_setup(void) 975 { 976 struct crypto_testsuite_params *ts_params = &testsuite_params; 977 uint8_t dev_id = ts_params->valid_devs[0]; 978 struct rte_cryptodev_info dev_info; 979 const enum rte_crypto_auth_algorithm auths[] = { 980 RTE_CRYPTO_AUTH_AES_GMAC 981 }; 982 983 rte_cryptodev_info_get(dev_id, &dev_info); 984 985 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 986 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 987 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 988 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 989 "testsuite not met\n"); 990 return TEST_SKIPPED; 991 } 992 993 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 994 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 995 "testsuite not met\n"); 996 return TEST_SKIPPED; 997 } 998 999 return 0; 1000 } 1001 1002 static int 1003 chacha20_poly1305_testsuite_setup(void) 1004 { 1005 struct crypto_testsuite_params *ts_params = &testsuite_params; 1006 uint8_t dev_id = ts_params->valid_devs[0]; 1007 struct rte_cryptodev_info dev_info; 1008 const enum rte_crypto_aead_algorithm aeads[] = { 1009 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1010 }; 1011 1012 rte_cryptodev_info_get(dev_id, &dev_info); 1013 1014 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1015 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1016 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1017 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1018 "Chacha20-Poly1305 testsuite not met\n"); 1019 return TEST_SKIPPED; 1020 } 1021 1022 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1023 RTE_LOG(INFO, USER1, "Capability requirements for " 1024 "Chacha20-Poly1305 testsuite not met\n"); 1025 return TEST_SKIPPED; 1026 } 1027 1028 return 0; 1029 } 1030 1031 static int 1032 snow3g_testsuite_setup(void) 1033 { 1034 struct crypto_testsuite_params *ts_params = &testsuite_params; 1035 uint8_t dev_id = ts_params->valid_devs[0]; 1036 struct rte_cryptodev_info dev_info; 1037 const enum rte_crypto_cipher_algorithm ciphers[] = { 1038 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1039 1040 }; 1041 const enum rte_crypto_auth_algorithm auths[] = { 1042 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1043 }; 1044 1045 rte_cryptodev_info_get(dev_id, &dev_info); 1046 1047 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1048 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1049 "testsuite not met\n"); 1050 return TEST_SKIPPED; 1051 } 1052 1053 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1054 && check_auth_capabilities_supported(auths, 1055 RTE_DIM(auths)) != 0) { 1056 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1057 "testsuite not met\n"); 1058 return TEST_SKIPPED; 1059 } 1060 1061 return 0; 1062 } 1063 1064 static int 1065 zuc_testsuite_setup(void) 1066 { 1067 struct crypto_testsuite_params *ts_params = &testsuite_params; 1068 uint8_t dev_id = ts_params->valid_devs[0]; 1069 struct rte_cryptodev_info dev_info; 1070 const enum rte_crypto_cipher_algorithm ciphers[] = { 1071 RTE_CRYPTO_CIPHER_ZUC_EEA3 1072 }; 1073 const enum rte_crypto_auth_algorithm auths[] = { 1074 RTE_CRYPTO_AUTH_ZUC_EIA3 1075 }; 1076 1077 rte_cryptodev_info_get(dev_id, &dev_info); 1078 1079 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1080 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1081 "testsuite not met\n"); 1082 return TEST_SKIPPED; 1083 } 1084 1085 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1086 && check_auth_capabilities_supported(auths, 1087 RTE_DIM(auths)) != 0) { 1088 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1089 "testsuite not met\n"); 1090 return TEST_SKIPPED; 1091 } 1092 1093 return 0; 1094 } 1095 1096 static int 1097 hmac_md5_auth_testsuite_setup(void) 1098 { 1099 struct crypto_testsuite_params *ts_params = &testsuite_params; 1100 uint8_t dev_id = ts_params->valid_devs[0]; 1101 struct rte_cryptodev_info dev_info; 1102 const enum rte_crypto_auth_algorithm auths[] = { 1103 RTE_CRYPTO_AUTH_MD5_HMAC 1104 }; 1105 1106 rte_cryptodev_info_get(dev_id, &dev_info); 1107 1108 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1109 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1110 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1111 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1112 "Auth testsuite not met\n"); 1113 return TEST_SKIPPED; 1114 } 1115 1116 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1117 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1118 "testsuite not met\n"); 1119 return TEST_SKIPPED; 1120 } 1121 1122 return 0; 1123 } 1124 1125 static int 1126 kasumi_testsuite_setup(void) 1127 { 1128 struct crypto_testsuite_params *ts_params = &testsuite_params; 1129 uint8_t dev_id = ts_params->valid_devs[0]; 1130 struct rte_cryptodev_info dev_info; 1131 const enum rte_crypto_cipher_algorithm ciphers[] = { 1132 RTE_CRYPTO_CIPHER_KASUMI_F8 1133 }; 1134 const enum rte_crypto_auth_algorithm auths[] = { 1135 RTE_CRYPTO_AUTH_KASUMI_F9 1136 }; 1137 1138 rte_cryptodev_info_get(dev_id, &dev_info); 1139 1140 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1141 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1142 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1143 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1144 "testsuite not met\n"); 1145 return TEST_SKIPPED; 1146 } 1147 1148 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1149 && check_auth_capabilities_supported(auths, 1150 RTE_DIM(auths)) != 0) { 1151 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1152 "testsuite not met\n"); 1153 return TEST_SKIPPED; 1154 } 1155 1156 return 0; 1157 } 1158 1159 static int 1160 negative_aes_gcm_testsuite_setup(void) 1161 { 1162 struct crypto_testsuite_params *ts_params = &testsuite_params; 1163 uint8_t dev_id = ts_params->valid_devs[0]; 1164 struct rte_cryptodev_info dev_info; 1165 const enum rte_crypto_aead_algorithm aeads[] = { 1166 RTE_CRYPTO_AEAD_AES_GCM 1167 }; 1168 1169 rte_cryptodev_info_get(dev_id, &dev_info); 1170 1171 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1172 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1173 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1174 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1175 "AES GCM testsuite not met\n"); 1176 return TEST_SKIPPED; 1177 } 1178 1179 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1180 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1181 "AES GCM testsuite not met\n"); 1182 return TEST_SKIPPED; 1183 } 1184 1185 return 0; 1186 } 1187 1188 static int 1189 negative_aes_gmac_testsuite_setup(void) 1190 { 1191 struct crypto_testsuite_params *ts_params = &testsuite_params; 1192 uint8_t dev_id = ts_params->valid_devs[0]; 1193 struct rte_cryptodev_info dev_info; 1194 const enum rte_crypto_auth_algorithm auths[] = { 1195 RTE_CRYPTO_AUTH_AES_GMAC 1196 }; 1197 1198 rte_cryptodev_info_get(dev_id, &dev_info); 1199 1200 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1201 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1202 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1203 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1204 "AES GMAC testsuite not met\n"); 1205 return TEST_SKIPPED; 1206 } 1207 1208 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1209 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1210 "AES GMAC testsuite not met\n"); 1211 return TEST_SKIPPED; 1212 } 1213 1214 return 0; 1215 } 1216 1217 static int 1218 mixed_cipher_hash_testsuite_setup(void) 1219 { 1220 struct crypto_testsuite_params *ts_params = &testsuite_params; 1221 uint8_t dev_id = ts_params->valid_devs[0]; 1222 struct rte_cryptodev_info dev_info; 1223 uint64_t feat_flags; 1224 const enum rte_crypto_cipher_algorithm ciphers[] = { 1225 RTE_CRYPTO_CIPHER_NULL, 1226 RTE_CRYPTO_CIPHER_AES_CTR, 1227 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1228 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1229 }; 1230 const enum rte_crypto_auth_algorithm auths[] = { 1231 RTE_CRYPTO_AUTH_NULL, 1232 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1233 RTE_CRYPTO_AUTH_AES_CMAC, 1234 RTE_CRYPTO_AUTH_ZUC_EIA3 1235 }; 1236 1237 rte_cryptodev_info_get(dev_id, &dev_info); 1238 feat_flags = dev_info.feature_flags; 1239 1240 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1241 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1242 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1243 "Cipher Hash testsuite not met\n"); 1244 return TEST_SKIPPED; 1245 } 1246 1247 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1248 && check_auth_capabilities_supported(auths, 1249 RTE_DIM(auths)) != 0) { 1250 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1251 "Cipher Hash testsuite not met\n"); 1252 return TEST_SKIPPED; 1253 } 1254 1255 return 0; 1256 } 1257 1258 static int 1259 esn_testsuite_setup(void) 1260 { 1261 struct crypto_testsuite_params *ts_params = &testsuite_params; 1262 uint8_t dev_id = ts_params->valid_devs[0]; 1263 struct rte_cryptodev_info dev_info; 1264 const enum rte_crypto_cipher_algorithm ciphers[] = { 1265 RTE_CRYPTO_CIPHER_AES_CBC 1266 }; 1267 const enum rte_crypto_auth_algorithm auths[] = { 1268 RTE_CRYPTO_AUTH_SHA1_HMAC 1269 }; 1270 1271 rte_cryptodev_info_get(dev_id, &dev_info); 1272 1273 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1274 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1275 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1276 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1277 "testsuite not met\n"); 1278 return TEST_SKIPPED; 1279 } 1280 1281 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1282 && check_auth_capabilities_supported(auths, 1283 RTE_DIM(auths)) != 0) { 1284 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1285 "testsuite not met\n"); 1286 return TEST_SKIPPED; 1287 } 1288 1289 return 0; 1290 } 1291 1292 static int 1293 multi_session_testsuite_setup(void) 1294 { 1295 struct crypto_testsuite_params *ts_params = &testsuite_params; 1296 uint8_t dev_id = ts_params->valid_devs[0]; 1297 struct rte_cryptodev_info dev_info; 1298 const enum rte_crypto_cipher_algorithm ciphers[] = { 1299 RTE_CRYPTO_CIPHER_AES_CBC 1300 }; 1301 const enum rte_crypto_auth_algorithm auths[] = { 1302 RTE_CRYPTO_AUTH_SHA512_HMAC 1303 }; 1304 1305 rte_cryptodev_info_get(dev_id, &dev_info); 1306 1307 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1308 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1309 "Session testsuite not met\n"); 1310 return TEST_SKIPPED; 1311 } 1312 1313 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1314 && check_auth_capabilities_supported(auths, 1315 RTE_DIM(auths)) != 0) { 1316 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1317 "Session testsuite not met\n"); 1318 return TEST_SKIPPED; 1319 } 1320 1321 return 0; 1322 } 1323 1324 static int 1325 negative_hmac_sha1_testsuite_setup(void) 1326 { 1327 struct crypto_testsuite_params *ts_params = &testsuite_params; 1328 uint8_t dev_id = ts_params->valid_devs[0]; 1329 struct rte_cryptodev_info dev_info; 1330 const enum rte_crypto_cipher_algorithm ciphers[] = { 1331 RTE_CRYPTO_CIPHER_AES_CBC 1332 }; 1333 const enum rte_crypto_auth_algorithm auths[] = { 1334 RTE_CRYPTO_AUTH_SHA1_HMAC 1335 }; 1336 1337 rte_cryptodev_info_get(dev_id, &dev_info); 1338 1339 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1340 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1341 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1342 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1343 "HMAC SHA1 testsuite not met\n"); 1344 return TEST_SKIPPED; 1345 } 1346 1347 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1348 && check_auth_capabilities_supported(auths, 1349 RTE_DIM(auths)) != 0) { 1350 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1351 "HMAC SHA1 testsuite not met\n"); 1352 return TEST_SKIPPED; 1353 } 1354 1355 return 0; 1356 } 1357 1358 static int 1359 dev_configure_and_start(uint64_t ff_disable) 1360 { 1361 struct crypto_testsuite_params *ts_params = &testsuite_params; 1362 struct crypto_unittest_params *ut_params = &unittest_params; 1363 1364 uint16_t qp_id; 1365 1366 /* Clear unit test parameters before running test */ 1367 memset(ut_params, 0, sizeof(*ut_params)); 1368 1369 /* Reconfigure device to default parameters */ 1370 ts_params->conf.socket_id = SOCKET_ID_ANY; 1371 ts_params->conf.ff_disable = ff_disable; 1372 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1373 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1374 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 1375 1376 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1377 &ts_params->conf), 1378 "Failed to configure cryptodev %u", 1379 ts_params->valid_devs[0]); 1380 1381 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1382 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1383 ts_params->valid_devs[0], qp_id, 1384 &ts_params->qp_conf, 1385 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1386 "Failed to setup queue pair %u on cryptodev %u", 1387 qp_id, ts_params->valid_devs[0]); 1388 } 1389 1390 1391 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1392 1393 /* Start the device */ 1394 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1395 "Failed to start cryptodev %u", 1396 ts_params->valid_devs[0]); 1397 1398 return TEST_SUCCESS; 1399 } 1400 1401 int 1402 ut_setup(void) 1403 { 1404 /* Configure and start the device with security feature disabled */ 1405 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1406 } 1407 1408 static int 1409 ut_setup_security(void) 1410 { 1411 /* Configure and start the device with no features disabled */ 1412 return dev_configure_and_start(0); 1413 } 1414 1415 void 1416 ut_teardown(void) 1417 { 1418 struct crypto_testsuite_params *ts_params = &testsuite_params; 1419 struct crypto_unittest_params *ut_params = &unittest_params; 1420 1421 /* free crypto session structure */ 1422 #ifdef RTE_LIB_SECURITY 1423 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1424 if (ut_params->sec_session) { 1425 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1426 (ts_params->valid_devs[0]), 1427 ut_params->sec_session); 1428 ut_params->sec_session = NULL; 1429 } 1430 } else 1431 #endif 1432 { 1433 if (ut_params->sess) { 1434 rte_cryptodev_sym_session_clear( 1435 ts_params->valid_devs[0], 1436 ut_params->sess); 1437 rte_cryptodev_sym_session_free(ut_params->sess); 1438 ut_params->sess = NULL; 1439 } 1440 } 1441 1442 /* free crypto operation structure */ 1443 if (ut_params->op) 1444 rte_crypto_op_free(ut_params->op); 1445 1446 /* 1447 * free mbuf - both obuf and ibuf are usually the same, 1448 * so check if they point at the same address is necessary, 1449 * to avoid freeing the mbuf twice. 1450 */ 1451 if (ut_params->obuf) { 1452 rte_pktmbuf_free(ut_params->obuf); 1453 if (ut_params->ibuf == ut_params->obuf) 1454 ut_params->ibuf = 0; 1455 ut_params->obuf = 0; 1456 } 1457 if (ut_params->ibuf) { 1458 rte_pktmbuf_free(ut_params->ibuf); 1459 ut_params->ibuf = 0; 1460 } 1461 1462 if (ts_params->mbuf_pool != NULL) 1463 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1464 rte_mempool_avail_count(ts_params->mbuf_pool)); 1465 1466 /* Stop the device */ 1467 rte_cryptodev_stop(ts_params->valid_devs[0]); 1468 } 1469 1470 static int 1471 test_device_configure_invalid_dev_id(void) 1472 { 1473 struct crypto_testsuite_params *ts_params = &testsuite_params; 1474 uint16_t dev_id, num_devs = 0; 1475 1476 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1477 "Need at least %d devices for test", 1); 1478 1479 /* valid dev_id values */ 1480 dev_id = ts_params->valid_devs[0]; 1481 1482 /* Stop the device in case it's started so it can be configured */ 1483 rte_cryptodev_stop(dev_id); 1484 1485 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1486 "Failed test for rte_cryptodev_configure: " 1487 "invalid dev_num %u", dev_id); 1488 1489 /* invalid dev_id values */ 1490 dev_id = num_devs; 1491 1492 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1493 "Failed test for rte_cryptodev_configure: " 1494 "invalid dev_num %u", dev_id); 1495 1496 dev_id = 0xff; 1497 1498 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1499 "Failed test for rte_cryptodev_configure:" 1500 "invalid dev_num %u", dev_id); 1501 1502 return TEST_SUCCESS; 1503 } 1504 1505 static int 1506 test_device_configure_invalid_queue_pair_ids(void) 1507 { 1508 struct crypto_testsuite_params *ts_params = &testsuite_params; 1509 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1510 1511 /* Stop the device in case it's started so it can be configured */ 1512 rte_cryptodev_stop(ts_params->valid_devs[0]); 1513 1514 /* valid - max value queue pairs */ 1515 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1516 1517 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1518 &ts_params->conf), 1519 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1520 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1521 1522 /* valid - one queue pairs */ 1523 ts_params->conf.nb_queue_pairs = 1; 1524 1525 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1526 &ts_params->conf), 1527 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1528 ts_params->valid_devs[0], 1529 ts_params->conf.nb_queue_pairs); 1530 1531 1532 /* invalid - zero queue pairs */ 1533 ts_params->conf.nb_queue_pairs = 0; 1534 1535 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1536 &ts_params->conf), 1537 "Failed test for rte_cryptodev_configure, dev_id %u," 1538 " invalid qps: %u", 1539 ts_params->valid_devs[0], 1540 ts_params->conf.nb_queue_pairs); 1541 1542 1543 /* invalid - max value supported by field queue pairs */ 1544 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1545 1546 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1547 &ts_params->conf), 1548 "Failed test for rte_cryptodev_configure, dev_id %u," 1549 " invalid qps: %u", 1550 ts_params->valid_devs[0], 1551 ts_params->conf.nb_queue_pairs); 1552 1553 1554 /* invalid - max value + 1 queue pairs */ 1555 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1556 1557 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1558 &ts_params->conf), 1559 "Failed test for rte_cryptodev_configure, dev_id %u," 1560 " invalid qps: %u", 1561 ts_params->valid_devs[0], 1562 ts_params->conf.nb_queue_pairs); 1563 1564 /* revert to original testsuite value */ 1565 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1566 1567 return TEST_SUCCESS; 1568 } 1569 1570 static int 1571 test_queue_pair_descriptor_setup(void) 1572 { 1573 struct crypto_testsuite_params *ts_params = &testsuite_params; 1574 struct rte_cryptodev_qp_conf qp_conf = { 1575 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1576 }; 1577 uint16_t qp_id; 1578 1579 /* Stop the device in case it's started so it can be configured */ 1580 rte_cryptodev_stop(ts_params->valid_devs[0]); 1581 1582 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1583 &ts_params->conf), 1584 "Failed to configure cryptodev %u", 1585 ts_params->valid_devs[0]); 1586 1587 /* 1588 * Test various ring sizes on this device. memzones can't be 1589 * freed so are re-used if ring is released and re-created. 1590 */ 1591 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1592 qp_conf.mp_session = ts_params->session_mpool; 1593 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1594 1595 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1596 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1597 ts_params->valid_devs[0], qp_id, &qp_conf, 1598 rte_cryptodev_socket_id( 1599 ts_params->valid_devs[0])), 1600 "Failed test for " 1601 "rte_cryptodev_queue_pair_setup: num_inflights " 1602 "%u on qp %u on cryptodev %u", 1603 qp_conf.nb_descriptors, qp_id, 1604 ts_params->valid_devs[0]); 1605 } 1606 1607 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1608 1609 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1610 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1611 ts_params->valid_devs[0], qp_id, &qp_conf, 1612 rte_cryptodev_socket_id( 1613 ts_params->valid_devs[0])), 1614 "Failed test for" 1615 " rte_cryptodev_queue_pair_setup: num_inflights" 1616 " %u on qp %u on cryptodev %u", 1617 qp_conf.nb_descriptors, qp_id, 1618 ts_params->valid_devs[0]); 1619 } 1620 1621 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1622 1623 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1624 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1625 ts_params->valid_devs[0], qp_id, &qp_conf, 1626 rte_cryptodev_socket_id( 1627 ts_params->valid_devs[0])), 1628 "Failed test for " 1629 "rte_cryptodev_queue_pair_setup: num_inflights" 1630 " %u on qp %u on cryptodev %u", 1631 qp_conf.nb_descriptors, qp_id, 1632 ts_params->valid_devs[0]); 1633 } 1634 1635 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1636 1637 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1638 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1639 ts_params->valid_devs[0], qp_id, &qp_conf, 1640 rte_cryptodev_socket_id( 1641 ts_params->valid_devs[0])), 1642 "Failed test for" 1643 " rte_cryptodev_queue_pair_setup:" 1644 "num_inflights %u on qp %u on cryptodev %u", 1645 qp_conf.nb_descriptors, qp_id, 1646 ts_params->valid_devs[0]); 1647 } 1648 1649 /* test invalid queue pair id */ 1650 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1651 1652 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1653 1654 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1655 ts_params->valid_devs[0], 1656 qp_id, &qp_conf, 1657 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1658 "Failed test for rte_cryptodev_queue_pair_setup:" 1659 "invalid qp %u on cryptodev %u", 1660 qp_id, ts_params->valid_devs[0]); 1661 1662 qp_id = 0xffff; /*invalid*/ 1663 1664 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1665 ts_params->valid_devs[0], 1666 qp_id, &qp_conf, 1667 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1668 "Failed test for rte_cryptodev_queue_pair_setup:" 1669 "invalid qp %u on cryptodev %u", 1670 qp_id, ts_params->valid_devs[0]); 1671 1672 return TEST_SUCCESS; 1673 } 1674 1675 /* ***** Plaintext data for tests ***** */ 1676 1677 const char catch_22_quote_1[] = 1678 "There was only one catch and that was Catch-22, which " 1679 "specified that a concern for one's safety in the face of " 1680 "dangers that were real and immediate was the process of a " 1681 "rational mind. Orr was crazy and could be grounded. All he " 1682 "had to do was ask; and as soon as he did, he would no longer " 1683 "be crazy and would have to fly more missions. Orr would be " 1684 "crazy to fly more missions and sane if he didn't, but if he " 1685 "was sane he had to fly them. If he flew them he was crazy " 1686 "and didn't have to; but if he didn't want to he was sane and " 1687 "had to. Yossarian was moved very deeply by the absolute " 1688 "simplicity of this clause of Catch-22 and let out a " 1689 "respectful whistle. \"That's some catch, that Catch-22\", he " 1690 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1691 1692 const char catch_22_quote[] = 1693 "What a lousy earth! He wondered how many people were " 1694 "destitute that same night even in his own prosperous country, " 1695 "how many homes were shanties, how many husbands were drunk " 1696 "and wives socked, and how many children were bullied, abused, " 1697 "or abandoned. How many families hungered for food they could " 1698 "not afford to buy? How many hearts were broken? How many " 1699 "suicides would take place that same night, how many people " 1700 "would go insane? How many cockroaches and landlords would " 1701 "triumph? How many winners were losers, successes failures, " 1702 "and rich men poor men? How many wise guys were stupid? How " 1703 "many happy endings were unhappy endings? How many honest men " 1704 "were liars, brave men cowards, loyal men traitors, how many " 1705 "sainted men were corrupt, how many people in positions of " 1706 "trust had sold their souls to bodyguards, how many had never " 1707 "had souls? How many straight-and-narrow paths were crooked " 1708 "paths? How many best families were worst families and how " 1709 "many good people were bad people? When you added them all up " 1710 "and then subtracted, you might be left with only the children, " 1711 "and perhaps with Albert Einstein and an old violinist or " 1712 "sculptor somewhere."; 1713 1714 #define QUOTE_480_BYTES (480) 1715 #define QUOTE_512_BYTES (512) 1716 #define QUOTE_768_BYTES (768) 1717 #define QUOTE_1024_BYTES (1024) 1718 1719 1720 1721 /* ***** SHA1 Hash Tests ***** */ 1722 1723 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1724 1725 static uint8_t hmac_sha1_key[] = { 1726 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1727 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1728 0xDE, 0xF4, 0xDE, 0xAD }; 1729 1730 /* ***** SHA224 Hash Tests ***** */ 1731 1732 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1733 1734 1735 /* ***** AES-CBC Cipher Tests ***** */ 1736 1737 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1738 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1739 1740 static uint8_t aes_cbc_key[] = { 1741 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1742 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1743 1744 static uint8_t aes_cbc_iv[] = { 1745 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1746 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1747 1748 1749 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1750 1751 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1752 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1753 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1754 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1755 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1756 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1757 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1758 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1759 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1760 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1761 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1762 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1763 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1764 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1765 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1766 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1767 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1768 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1769 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1770 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1771 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1772 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1773 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1774 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1775 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1776 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1777 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1778 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1779 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1780 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1781 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1782 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1783 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1784 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1785 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1786 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1787 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1788 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1789 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1790 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1791 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1792 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1793 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1794 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1795 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1796 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1797 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1798 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1799 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1800 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1801 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1802 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1803 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1804 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1805 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1806 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1807 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1808 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1809 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1810 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1811 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1812 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1813 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1814 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1815 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1816 }; 1817 1818 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1819 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1820 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1821 0x18, 0x8c, 0x1d, 0x32 1822 }; 1823 1824 1825 /* Multisession Vector context Test */ 1826 /*Begin Session 0 */ 1827 static uint8_t ms_aes_cbc_key0[] = { 1828 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1829 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1830 }; 1831 1832 static uint8_t ms_aes_cbc_iv0[] = { 1833 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1834 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1835 }; 1836 1837 static const uint8_t ms_aes_cbc_cipher0[] = { 1838 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1839 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1840 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1841 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1842 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1843 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1844 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1845 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1846 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1847 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1848 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1849 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1850 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1851 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1852 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1853 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1854 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1855 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1856 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1857 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1858 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1859 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1860 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1861 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1862 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1863 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1864 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1865 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1866 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1867 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1868 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1869 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1870 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1871 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1872 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1873 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1874 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1875 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1876 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1877 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1878 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1879 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1880 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1881 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1882 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1883 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1884 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1885 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1886 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1887 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1888 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1889 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1890 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1891 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1892 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1893 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1894 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1895 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1896 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1897 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1898 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1899 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1900 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1901 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1902 }; 1903 1904 1905 static uint8_t ms_hmac_key0[] = { 1906 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1907 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1908 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1909 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1910 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1911 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1912 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1913 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1914 }; 1915 1916 static const uint8_t ms_hmac_digest0[] = { 1917 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1918 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1919 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1920 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1921 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1922 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1923 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1924 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1925 }; 1926 1927 /* End Session 0 */ 1928 /* Begin session 1 */ 1929 1930 static uint8_t ms_aes_cbc_key1[] = { 1931 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1932 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1933 }; 1934 1935 static uint8_t ms_aes_cbc_iv1[] = { 1936 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1937 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1938 }; 1939 1940 static const uint8_t ms_aes_cbc_cipher1[] = { 1941 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1942 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1943 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1944 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1945 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1946 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1947 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1948 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1949 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1950 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1951 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1952 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1953 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1954 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1955 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1956 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1957 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1958 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1959 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1960 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1961 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1962 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1963 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1964 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1965 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1966 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1967 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1968 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1969 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1970 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1971 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1972 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1973 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1974 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1975 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1976 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1977 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1978 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1979 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1980 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1981 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1982 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1983 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1984 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1985 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1986 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1987 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1988 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1989 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1990 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1991 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1992 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1993 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1994 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1995 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1996 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1997 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1998 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1999 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2000 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2001 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2002 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2003 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2004 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2005 2006 }; 2007 2008 static uint8_t ms_hmac_key1[] = { 2009 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2010 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2011 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2012 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2013 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2014 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2015 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2016 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2017 }; 2018 2019 static const uint8_t ms_hmac_digest1[] = { 2020 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2021 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2022 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2023 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2024 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2025 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2026 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2027 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2028 }; 2029 /* End Session 1 */ 2030 /* Begin Session 2 */ 2031 static uint8_t ms_aes_cbc_key2[] = { 2032 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2033 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2034 }; 2035 2036 static uint8_t ms_aes_cbc_iv2[] = { 2037 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2038 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2039 }; 2040 2041 static const uint8_t ms_aes_cbc_cipher2[] = { 2042 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2043 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2044 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2045 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2046 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2047 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2048 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2049 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2050 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2051 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2052 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2053 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2054 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2055 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2056 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2057 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2058 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2059 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2060 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2061 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2062 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2063 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2064 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2065 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2066 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2067 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2068 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2069 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2070 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2071 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2072 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2073 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2074 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2075 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2076 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2077 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2078 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2079 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2080 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2081 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2082 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2083 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2084 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2085 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2086 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2087 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2088 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2089 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2090 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2091 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2092 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2093 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2094 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2095 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2096 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2097 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2098 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2099 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2100 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2101 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2102 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2103 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2104 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2105 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2106 }; 2107 2108 static uint8_t ms_hmac_key2[] = { 2109 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2110 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2111 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2112 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2113 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2114 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2115 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2116 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2117 }; 2118 2119 static const uint8_t ms_hmac_digest2[] = { 2120 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2121 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2122 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2123 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2124 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2125 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2126 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2127 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2128 }; 2129 2130 /* End Session 2 */ 2131 2132 2133 static int 2134 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2135 { 2136 struct crypto_testsuite_params *ts_params = &testsuite_params; 2137 struct crypto_unittest_params *ut_params = &unittest_params; 2138 int status; 2139 2140 /* Verify the capabilities */ 2141 struct rte_cryptodev_sym_capability_idx cap_idx; 2142 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2143 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2144 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2145 &cap_idx) == NULL) 2146 return TEST_SKIPPED; 2147 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2148 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2149 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2150 &cap_idx) == NULL) 2151 return TEST_SKIPPED; 2152 2153 /* Generate test mbuf data and space for digest */ 2154 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2155 catch_22_quote, QUOTE_512_BYTES, 0); 2156 2157 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2158 DIGEST_BYTE_LENGTH_SHA1); 2159 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2160 2161 /* Setup Cipher Parameters */ 2162 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2163 ut_params->cipher_xform.next = &ut_params->auth_xform; 2164 2165 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2166 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2167 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2168 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2169 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2170 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2171 2172 /* Setup HMAC Parameters */ 2173 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2174 2175 ut_params->auth_xform.next = NULL; 2176 2177 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2178 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2179 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2180 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2181 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2182 2183 ut_params->sess = rte_cryptodev_sym_session_create( 2184 ts_params->session_mpool); 2185 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2186 2187 /* Create crypto session*/ 2188 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2189 ut_params->sess, &ut_params->cipher_xform, 2190 ts_params->session_priv_mpool); 2191 2192 if (status == -ENOTSUP) 2193 return TEST_SKIPPED; 2194 2195 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 2196 2197 /* Generate crypto op data structure */ 2198 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2199 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2200 TEST_ASSERT_NOT_NULL(ut_params->op, 2201 "Failed to allocate symmetric crypto operation struct"); 2202 2203 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2204 2205 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2206 2207 /* set crypto operation source mbuf */ 2208 sym_op->m_src = ut_params->ibuf; 2209 2210 /* Set crypto operation authentication parameters */ 2211 sym_op->auth.digest.data = ut_params->digest; 2212 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2213 ut_params->ibuf, QUOTE_512_BYTES); 2214 2215 sym_op->auth.data.offset = 0; 2216 sym_op->auth.data.length = QUOTE_512_BYTES; 2217 2218 /* Copy IV at the end of the crypto operation */ 2219 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2220 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2221 2222 /* Set crypto operation cipher parameters */ 2223 sym_op->cipher.data.offset = 0; 2224 sym_op->cipher.data.length = QUOTE_512_BYTES; 2225 2226 /* Process crypto operation */ 2227 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2228 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2229 ut_params->op); 2230 else 2231 TEST_ASSERT_NOT_NULL( 2232 process_crypto_request(ts_params->valid_devs[0], 2233 ut_params->op), 2234 "failed to process sym crypto op"); 2235 2236 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2237 "crypto op processing failed"); 2238 2239 /* Validate obuf */ 2240 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2241 uint8_t *); 2242 2243 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2244 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2245 QUOTE_512_BYTES, 2246 "ciphertext data not as expected"); 2247 2248 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2249 2250 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2251 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2252 gbl_driver_id == rte_cryptodev_driver_id_get( 2253 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2254 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2255 DIGEST_BYTE_LENGTH_SHA1, 2256 "Generated digest data not as expected"); 2257 2258 return TEST_SUCCESS; 2259 } 2260 2261 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2262 2263 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2264 2265 static uint8_t hmac_sha512_key[] = { 2266 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2267 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2268 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2269 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2270 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2271 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2272 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2273 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2274 2275 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2276 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2277 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2278 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2279 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2280 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2281 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2282 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2283 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2284 2285 2286 2287 static int 2288 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2289 struct crypto_unittest_params *ut_params, 2290 uint8_t *cipher_key, 2291 uint8_t *hmac_key); 2292 2293 static int 2294 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2295 struct crypto_unittest_params *ut_params, 2296 struct crypto_testsuite_params *ts_params, 2297 const uint8_t *cipher, 2298 const uint8_t *digest, 2299 const uint8_t *iv); 2300 2301 2302 static int 2303 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2304 struct crypto_unittest_params *ut_params, 2305 uint8_t *cipher_key, 2306 uint8_t *hmac_key) 2307 { 2308 2309 /* Setup Cipher Parameters */ 2310 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2311 ut_params->cipher_xform.next = NULL; 2312 2313 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2314 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2315 ut_params->cipher_xform.cipher.key.data = cipher_key; 2316 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2317 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2318 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2319 2320 /* Setup HMAC Parameters */ 2321 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2322 ut_params->auth_xform.next = &ut_params->cipher_xform; 2323 2324 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2325 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2326 ut_params->auth_xform.auth.key.data = hmac_key; 2327 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2328 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2329 2330 return TEST_SUCCESS; 2331 } 2332 2333 2334 static int 2335 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2336 struct crypto_unittest_params *ut_params, 2337 struct crypto_testsuite_params *ts_params, 2338 const uint8_t *cipher, 2339 const uint8_t *digest, 2340 const uint8_t *iv) 2341 { 2342 /* Generate test mbuf data and digest */ 2343 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2344 (const char *) 2345 cipher, 2346 QUOTE_512_BYTES, 0); 2347 2348 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2349 DIGEST_BYTE_LENGTH_SHA512); 2350 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2351 2352 rte_memcpy(ut_params->digest, 2353 digest, 2354 DIGEST_BYTE_LENGTH_SHA512); 2355 2356 /* Generate Crypto op data structure */ 2357 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2358 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2359 TEST_ASSERT_NOT_NULL(ut_params->op, 2360 "Failed to allocate symmetric crypto operation struct"); 2361 2362 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2363 2364 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2365 2366 /* set crypto operation source mbuf */ 2367 sym_op->m_src = ut_params->ibuf; 2368 2369 sym_op->auth.digest.data = ut_params->digest; 2370 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2371 ut_params->ibuf, QUOTE_512_BYTES); 2372 2373 sym_op->auth.data.offset = 0; 2374 sym_op->auth.data.length = QUOTE_512_BYTES; 2375 2376 /* Copy IV at the end of the crypto operation */ 2377 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2378 iv, CIPHER_IV_LENGTH_AES_CBC); 2379 2380 sym_op->cipher.data.offset = 0; 2381 sym_op->cipher.data.length = QUOTE_512_BYTES; 2382 2383 /* Process crypto operation */ 2384 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2385 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2386 ut_params->op); 2387 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2388 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2389 ut_params->op, 1, 1, 0, 0); 2390 else 2391 TEST_ASSERT_NOT_NULL( 2392 process_crypto_request(ts_params->valid_devs[0], 2393 ut_params->op), 2394 "failed to process sym crypto op"); 2395 2396 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2397 "crypto op processing failed"); 2398 2399 ut_params->obuf = ut_params->op->sym->m_src; 2400 2401 /* Validate obuf */ 2402 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2403 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2404 catch_22_quote, 2405 QUOTE_512_BYTES, 2406 "Plaintext data not as expected"); 2407 2408 /* Validate obuf */ 2409 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2410 "Digest verification failed"); 2411 2412 return TEST_SUCCESS; 2413 } 2414 2415 /* ***** SNOW 3G Tests ***** */ 2416 static int 2417 create_wireless_algo_hash_session(uint8_t dev_id, 2418 const uint8_t *key, const uint8_t key_len, 2419 const uint8_t iv_len, const uint8_t auth_len, 2420 enum rte_crypto_auth_operation op, 2421 enum rte_crypto_auth_algorithm algo) 2422 { 2423 uint8_t hash_key[key_len]; 2424 int status; 2425 2426 struct crypto_testsuite_params *ts_params = &testsuite_params; 2427 struct crypto_unittest_params *ut_params = &unittest_params; 2428 2429 memcpy(hash_key, key, key_len); 2430 2431 debug_hexdump(stdout, "key:", key, key_len); 2432 2433 /* Setup Authentication Parameters */ 2434 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2435 ut_params->auth_xform.next = NULL; 2436 2437 ut_params->auth_xform.auth.op = op; 2438 ut_params->auth_xform.auth.algo = algo; 2439 ut_params->auth_xform.auth.key.length = key_len; 2440 ut_params->auth_xform.auth.key.data = hash_key; 2441 ut_params->auth_xform.auth.digest_length = auth_len; 2442 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2443 ut_params->auth_xform.auth.iv.length = iv_len; 2444 ut_params->sess = rte_cryptodev_sym_session_create( 2445 ts_params->session_mpool); 2446 2447 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2448 &ut_params->auth_xform, 2449 ts_params->session_priv_mpool); 2450 if (status == -ENOTSUP) 2451 return TEST_SKIPPED; 2452 2453 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2454 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2455 return 0; 2456 } 2457 2458 static int 2459 create_wireless_algo_cipher_session(uint8_t dev_id, 2460 enum rte_crypto_cipher_operation op, 2461 enum rte_crypto_cipher_algorithm algo, 2462 const uint8_t *key, const uint8_t key_len, 2463 uint8_t iv_len) 2464 { 2465 uint8_t cipher_key[key_len]; 2466 int status; 2467 struct crypto_testsuite_params *ts_params = &testsuite_params; 2468 struct crypto_unittest_params *ut_params = &unittest_params; 2469 2470 memcpy(cipher_key, key, key_len); 2471 2472 /* Setup Cipher Parameters */ 2473 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2474 ut_params->cipher_xform.next = NULL; 2475 2476 ut_params->cipher_xform.cipher.algo = algo; 2477 ut_params->cipher_xform.cipher.op = op; 2478 ut_params->cipher_xform.cipher.key.data = cipher_key; 2479 ut_params->cipher_xform.cipher.key.length = key_len; 2480 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2481 ut_params->cipher_xform.cipher.iv.length = iv_len; 2482 2483 debug_hexdump(stdout, "key:", key, key_len); 2484 2485 /* Create Crypto session */ 2486 ut_params->sess = rte_cryptodev_sym_session_create( 2487 ts_params->session_mpool); 2488 2489 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2490 &ut_params->cipher_xform, 2491 ts_params->session_priv_mpool); 2492 if (status == -ENOTSUP) 2493 return TEST_SKIPPED; 2494 2495 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2496 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2497 return 0; 2498 } 2499 2500 static int 2501 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2502 unsigned int cipher_len, 2503 unsigned int cipher_offset) 2504 { 2505 struct crypto_testsuite_params *ts_params = &testsuite_params; 2506 struct crypto_unittest_params *ut_params = &unittest_params; 2507 2508 /* Generate Crypto op data structure */ 2509 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2510 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2511 TEST_ASSERT_NOT_NULL(ut_params->op, 2512 "Failed to allocate pktmbuf offload"); 2513 2514 /* Set crypto operation data parameters */ 2515 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2516 2517 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2518 2519 /* set crypto operation source mbuf */ 2520 sym_op->m_src = ut_params->ibuf; 2521 2522 /* iv */ 2523 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2524 iv, iv_len); 2525 sym_op->cipher.data.length = cipher_len; 2526 sym_op->cipher.data.offset = cipher_offset; 2527 return 0; 2528 } 2529 2530 static int 2531 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2532 unsigned int cipher_len, 2533 unsigned int cipher_offset) 2534 { 2535 struct crypto_testsuite_params *ts_params = &testsuite_params; 2536 struct crypto_unittest_params *ut_params = &unittest_params; 2537 2538 /* Generate Crypto op data structure */ 2539 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2540 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2541 TEST_ASSERT_NOT_NULL(ut_params->op, 2542 "Failed to allocate pktmbuf offload"); 2543 2544 /* Set crypto operation data parameters */ 2545 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2546 2547 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2548 2549 /* set crypto operation source mbuf */ 2550 sym_op->m_src = ut_params->ibuf; 2551 sym_op->m_dst = ut_params->obuf; 2552 2553 /* iv */ 2554 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2555 iv, iv_len); 2556 sym_op->cipher.data.length = cipher_len; 2557 sym_op->cipher.data.offset = cipher_offset; 2558 return 0; 2559 } 2560 2561 static int 2562 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2563 enum rte_crypto_cipher_operation cipher_op, 2564 enum rte_crypto_auth_operation auth_op, 2565 enum rte_crypto_auth_algorithm auth_algo, 2566 enum rte_crypto_cipher_algorithm cipher_algo, 2567 const uint8_t *key, uint8_t key_len, 2568 uint8_t auth_iv_len, uint8_t auth_len, 2569 uint8_t cipher_iv_len) 2570 2571 { 2572 uint8_t cipher_auth_key[key_len]; 2573 int status; 2574 2575 struct crypto_testsuite_params *ts_params = &testsuite_params; 2576 struct crypto_unittest_params *ut_params = &unittest_params; 2577 2578 memcpy(cipher_auth_key, key, key_len); 2579 2580 /* Setup Authentication Parameters */ 2581 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2582 ut_params->auth_xform.next = NULL; 2583 2584 ut_params->auth_xform.auth.op = auth_op; 2585 ut_params->auth_xform.auth.algo = auth_algo; 2586 ut_params->auth_xform.auth.key.length = key_len; 2587 /* Hash key = cipher key */ 2588 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2589 ut_params->auth_xform.auth.digest_length = auth_len; 2590 /* Auth IV will be after cipher IV */ 2591 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2592 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2593 2594 /* Setup Cipher Parameters */ 2595 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2596 ut_params->cipher_xform.next = &ut_params->auth_xform; 2597 2598 ut_params->cipher_xform.cipher.algo = cipher_algo; 2599 ut_params->cipher_xform.cipher.op = cipher_op; 2600 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2601 ut_params->cipher_xform.cipher.key.length = key_len; 2602 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2603 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2604 2605 debug_hexdump(stdout, "key:", key, key_len); 2606 2607 /* Create Crypto session*/ 2608 ut_params->sess = rte_cryptodev_sym_session_create( 2609 ts_params->session_mpool); 2610 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2611 2612 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2613 &ut_params->cipher_xform, 2614 ts_params->session_priv_mpool); 2615 if (status == -ENOTSUP) 2616 return TEST_SKIPPED; 2617 2618 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2619 return 0; 2620 } 2621 2622 static int 2623 create_wireless_cipher_auth_session(uint8_t dev_id, 2624 enum rte_crypto_cipher_operation cipher_op, 2625 enum rte_crypto_auth_operation auth_op, 2626 enum rte_crypto_auth_algorithm auth_algo, 2627 enum rte_crypto_cipher_algorithm cipher_algo, 2628 const struct wireless_test_data *tdata) 2629 { 2630 const uint8_t key_len = tdata->key.len; 2631 uint8_t cipher_auth_key[key_len]; 2632 int status; 2633 2634 struct crypto_testsuite_params *ts_params = &testsuite_params; 2635 struct crypto_unittest_params *ut_params = &unittest_params; 2636 const uint8_t *key = tdata->key.data; 2637 const uint8_t auth_len = tdata->digest.len; 2638 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2639 uint8_t auth_iv_len = tdata->auth_iv.len; 2640 2641 memcpy(cipher_auth_key, key, key_len); 2642 2643 /* Setup Authentication Parameters */ 2644 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2645 ut_params->auth_xform.next = NULL; 2646 2647 ut_params->auth_xform.auth.op = auth_op; 2648 ut_params->auth_xform.auth.algo = auth_algo; 2649 ut_params->auth_xform.auth.key.length = key_len; 2650 /* Hash key = cipher key */ 2651 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2652 ut_params->auth_xform.auth.digest_length = auth_len; 2653 /* Auth IV will be after cipher IV */ 2654 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2655 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2656 2657 /* Setup Cipher Parameters */ 2658 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2659 ut_params->cipher_xform.next = &ut_params->auth_xform; 2660 2661 ut_params->cipher_xform.cipher.algo = cipher_algo; 2662 ut_params->cipher_xform.cipher.op = cipher_op; 2663 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2664 ut_params->cipher_xform.cipher.key.length = key_len; 2665 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2666 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2667 2668 2669 debug_hexdump(stdout, "key:", key, key_len); 2670 2671 /* Create Crypto session*/ 2672 ut_params->sess = rte_cryptodev_sym_session_create( 2673 ts_params->session_mpool); 2674 2675 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2676 &ut_params->cipher_xform, 2677 ts_params->session_priv_mpool); 2678 if (status == -ENOTSUP) 2679 return TEST_SKIPPED; 2680 2681 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2682 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2683 return 0; 2684 } 2685 2686 static int 2687 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2688 const struct wireless_test_data *tdata) 2689 { 2690 return create_wireless_cipher_auth_session(dev_id, 2691 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2692 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2693 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2694 } 2695 2696 static int 2697 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2698 enum rte_crypto_cipher_operation cipher_op, 2699 enum rte_crypto_auth_operation auth_op, 2700 enum rte_crypto_auth_algorithm auth_algo, 2701 enum rte_crypto_cipher_algorithm cipher_algo, 2702 const uint8_t *key, const uint8_t key_len, 2703 uint8_t auth_iv_len, uint8_t auth_len, 2704 uint8_t cipher_iv_len) 2705 { 2706 uint8_t auth_cipher_key[key_len]; 2707 int status; 2708 struct crypto_testsuite_params *ts_params = &testsuite_params; 2709 struct crypto_unittest_params *ut_params = &unittest_params; 2710 2711 memcpy(auth_cipher_key, key, key_len); 2712 2713 /* Setup Authentication Parameters */ 2714 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2715 ut_params->auth_xform.auth.op = auth_op; 2716 ut_params->auth_xform.next = &ut_params->cipher_xform; 2717 ut_params->auth_xform.auth.algo = auth_algo; 2718 ut_params->auth_xform.auth.key.length = key_len; 2719 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2720 ut_params->auth_xform.auth.digest_length = auth_len; 2721 /* Auth IV will be after cipher IV */ 2722 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2723 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2724 2725 /* Setup Cipher Parameters */ 2726 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2727 ut_params->cipher_xform.next = NULL; 2728 ut_params->cipher_xform.cipher.algo = cipher_algo; 2729 ut_params->cipher_xform.cipher.op = cipher_op; 2730 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2731 ut_params->cipher_xform.cipher.key.length = key_len; 2732 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2733 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2734 2735 debug_hexdump(stdout, "key:", key, key_len); 2736 2737 /* Create Crypto session*/ 2738 ut_params->sess = rte_cryptodev_sym_session_create( 2739 ts_params->session_mpool); 2740 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2741 2742 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2743 ut_params->auth_xform.next = NULL; 2744 ut_params->cipher_xform.next = &ut_params->auth_xform; 2745 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2746 &ut_params->cipher_xform, 2747 ts_params->session_priv_mpool); 2748 2749 } else 2750 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2751 &ut_params->auth_xform, 2752 ts_params->session_priv_mpool); 2753 2754 if (status == -ENOTSUP) 2755 return TEST_SKIPPED; 2756 2757 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2758 2759 return 0; 2760 } 2761 2762 static int 2763 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2764 unsigned int auth_tag_len, 2765 const uint8_t *iv, unsigned int iv_len, 2766 unsigned int data_pad_len, 2767 enum rte_crypto_auth_operation op, 2768 unsigned int auth_len, unsigned int auth_offset) 2769 { 2770 struct crypto_testsuite_params *ts_params = &testsuite_params; 2771 2772 struct crypto_unittest_params *ut_params = &unittest_params; 2773 2774 /* Generate Crypto op data structure */ 2775 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2776 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2777 TEST_ASSERT_NOT_NULL(ut_params->op, 2778 "Failed to allocate pktmbuf offload"); 2779 2780 /* Set crypto operation data parameters */ 2781 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2782 2783 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2784 2785 /* set crypto operation source mbuf */ 2786 sym_op->m_src = ut_params->ibuf; 2787 2788 /* iv */ 2789 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2790 iv, iv_len); 2791 /* digest */ 2792 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2793 ut_params->ibuf, auth_tag_len); 2794 2795 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2796 "no room to append auth tag"); 2797 ut_params->digest = sym_op->auth.digest.data; 2798 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2799 ut_params->ibuf, data_pad_len); 2800 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2801 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2802 else 2803 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2804 2805 debug_hexdump(stdout, "digest:", 2806 sym_op->auth.digest.data, 2807 auth_tag_len); 2808 2809 sym_op->auth.data.length = auth_len; 2810 sym_op->auth.data.offset = auth_offset; 2811 2812 return 0; 2813 } 2814 2815 static int 2816 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2817 enum rte_crypto_auth_operation op) 2818 { 2819 struct crypto_testsuite_params *ts_params = &testsuite_params; 2820 struct crypto_unittest_params *ut_params = &unittest_params; 2821 2822 const uint8_t *auth_tag = tdata->digest.data; 2823 const unsigned int auth_tag_len = tdata->digest.len; 2824 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2825 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2826 2827 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2828 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2829 const uint8_t *auth_iv = tdata->auth_iv.data; 2830 const uint8_t auth_iv_len = tdata->auth_iv.len; 2831 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2832 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2833 2834 /* Generate Crypto op data structure */ 2835 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2836 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2837 TEST_ASSERT_NOT_NULL(ut_params->op, 2838 "Failed to allocate pktmbuf offload"); 2839 /* Set crypto operation data parameters */ 2840 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2841 2842 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2843 2844 /* set crypto operation source mbuf */ 2845 sym_op->m_src = ut_params->ibuf; 2846 2847 /* digest */ 2848 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2849 ut_params->ibuf, auth_tag_len); 2850 2851 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2852 "no room to append auth tag"); 2853 ut_params->digest = sym_op->auth.digest.data; 2854 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2855 ut_params->ibuf, data_pad_len); 2856 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2857 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2858 else 2859 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2860 2861 debug_hexdump(stdout, "digest:", 2862 sym_op->auth.digest.data, 2863 auth_tag_len); 2864 2865 /* Copy cipher and auth IVs at the end of the crypto operation */ 2866 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2867 IV_OFFSET); 2868 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2869 iv_ptr += cipher_iv_len; 2870 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2871 2872 sym_op->cipher.data.length = cipher_len; 2873 sym_op->cipher.data.offset = 0; 2874 sym_op->auth.data.length = auth_len; 2875 sym_op->auth.data.offset = 0; 2876 2877 return 0; 2878 } 2879 2880 static int 2881 create_zuc_cipher_hash_generate_operation( 2882 const struct wireless_test_data *tdata) 2883 { 2884 return create_wireless_cipher_hash_operation(tdata, 2885 RTE_CRYPTO_AUTH_OP_GENERATE); 2886 } 2887 2888 static int 2889 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2890 const unsigned auth_tag_len, 2891 const uint8_t *auth_iv, uint8_t auth_iv_len, 2892 unsigned data_pad_len, 2893 enum rte_crypto_auth_operation op, 2894 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2895 const unsigned cipher_len, const unsigned cipher_offset, 2896 const unsigned auth_len, const unsigned auth_offset) 2897 { 2898 struct crypto_testsuite_params *ts_params = &testsuite_params; 2899 struct crypto_unittest_params *ut_params = &unittest_params; 2900 2901 enum rte_crypto_cipher_algorithm cipher_algo = 2902 ut_params->cipher_xform.cipher.algo; 2903 enum rte_crypto_auth_algorithm auth_algo = 2904 ut_params->auth_xform.auth.algo; 2905 2906 /* Generate Crypto op data structure */ 2907 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2908 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2909 TEST_ASSERT_NOT_NULL(ut_params->op, 2910 "Failed to allocate pktmbuf offload"); 2911 /* Set crypto operation data parameters */ 2912 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2913 2914 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2915 2916 /* set crypto operation source mbuf */ 2917 sym_op->m_src = ut_params->ibuf; 2918 2919 /* digest */ 2920 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2921 ut_params->ibuf, auth_tag_len); 2922 2923 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2924 "no room to append auth tag"); 2925 ut_params->digest = sym_op->auth.digest.data; 2926 2927 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2928 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2929 ut_params->ibuf, data_pad_len); 2930 } else { 2931 struct rte_mbuf *m = ut_params->ibuf; 2932 unsigned int offset = data_pad_len; 2933 2934 while (offset > m->data_len && m->next != NULL) { 2935 offset -= m->data_len; 2936 m = m->next; 2937 } 2938 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2939 m, offset); 2940 } 2941 2942 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2943 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2944 else 2945 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2946 2947 debug_hexdump(stdout, "digest:", 2948 sym_op->auth.digest.data, 2949 auth_tag_len); 2950 2951 /* Copy cipher and auth IVs at the end of the crypto operation */ 2952 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2953 IV_OFFSET); 2954 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2955 iv_ptr += cipher_iv_len; 2956 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2957 2958 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2959 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2960 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2961 sym_op->cipher.data.length = cipher_len; 2962 sym_op->cipher.data.offset = cipher_offset; 2963 } else { 2964 sym_op->cipher.data.length = cipher_len >> 3; 2965 sym_op->cipher.data.offset = cipher_offset >> 3; 2966 } 2967 2968 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2969 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2970 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2971 sym_op->auth.data.length = auth_len; 2972 sym_op->auth.data.offset = auth_offset; 2973 } else { 2974 sym_op->auth.data.length = auth_len >> 3; 2975 sym_op->auth.data.offset = auth_offset >> 3; 2976 } 2977 2978 return 0; 2979 } 2980 2981 static int 2982 create_wireless_algo_auth_cipher_operation( 2983 const uint8_t *auth_tag, unsigned int auth_tag_len, 2984 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2985 const uint8_t *auth_iv, uint8_t auth_iv_len, 2986 unsigned int data_pad_len, 2987 unsigned int cipher_len, unsigned int cipher_offset, 2988 unsigned int auth_len, unsigned int auth_offset, 2989 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2990 { 2991 struct crypto_testsuite_params *ts_params = &testsuite_params; 2992 struct crypto_unittest_params *ut_params = &unittest_params; 2993 2994 enum rte_crypto_cipher_algorithm cipher_algo = 2995 ut_params->cipher_xform.cipher.algo; 2996 enum rte_crypto_auth_algorithm auth_algo = 2997 ut_params->auth_xform.auth.algo; 2998 2999 /* Generate Crypto op data structure */ 3000 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3001 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3002 TEST_ASSERT_NOT_NULL(ut_params->op, 3003 "Failed to allocate pktmbuf offload"); 3004 3005 /* Set crypto operation data parameters */ 3006 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3007 3008 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3009 3010 /* set crypto operation mbufs */ 3011 sym_op->m_src = ut_params->ibuf; 3012 if (op_mode == OUT_OF_PLACE) 3013 sym_op->m_dst = ut_params->obuf; 3014 3015 /* digest */ 3016 if (!do_sgl) { 3017 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3018 (op_mode == IN_PLACE ? 3019 ut_params->ibuf : ut_params->obuf), 3020 uint8_t *, data_pad_len); 3021 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3022 (op_mode == IN_PLACE ? 3023 ut_params->ibuf : ut_params->obuf), 3024 data_pad_len); 3025 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3026 } else { 3027 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3028 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3029 sym_op->m_src : sym_op->m_dst); 3030 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3031 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3032 sgl_buf = sgl_buf->next; 3033 } 3034 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3035 uint8_t *, remaining_off); 3036 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3037 remaining_off); 3038 memset(sym_op->auth.digest.data, 0, remaining_off); 3039 while (sgl_buf->next != NULL) { 3040 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3041 0, rte_pktmbuf_data_len(sgl_buf)); 3042 sgl_buf = sgl_buf->next; 3043 } 3044 } 3045 3046 /* Copy digest for the verification */ 3047 if (verify) 3048 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3049 3050 /* Copy cipher and auth IVs at the end of the crypto operation */ 3051 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3052 ut_params->op, uint8_t *, IV_OFFSET); 3053 3054 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3055 iv_ptr += cipher_iv_len; 3056 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3057 3058 /* Only copy over the offset data needed from src to dst in OOP, 3059 * if the auth and cipher offsets are not aligned 3060 */ 3061 if (op_mode == OUT_OF_PLACE) { 3062 if (cipher_offset > auth_offset) 3063 rte_memcpy( 3064 rte_pktmbuf_mtod_offset( 3065 sym_op->m_dst, 3066 uint8_t *, auth_offset >> 3), 3067 rte_pktmbuf_mtod_offset( 3068 sym_op->m_src, 3069 uint8_t *, auth_offset >> 3), 3070 ((cipher_offset >> 3) - (auth_offset >> 3))); 3071 } 3072 3073 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3074 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3075 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3076 sym_op->cipher.data.length = cipher_len; 3077 sym_op->cipher.data.offset = cipher_offset; 3078 } else { 3079 sym_op->cipher.data.length = cipher_len >> 3; 3080 sym_op->cipher.data.offset = cipher_offset >> 3; 3081 } 3082 3083 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3084 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3085 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3086 sym_op->auth.data.length = auth_len; 3087 sym_op->auth.data.offset = auth_offset; 3088 } else { 3089 sym_op->auth.data.length = auth_len >> 3; 3090 sym_op->auth.data.offset = auth_offset >> 3; 3091 } 3092 3093 return 0; 3094 } 3095 3096 static int 3097 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3098 { 3099 struct crypto_testsuite_params *ts_params = &testsuite_params; 3100 struct crypto_unittest_params *ut_params = &unittest_params; 3101 3102 int retval; 3103 unsigned plaintext_pad_len; 3104 unsigned plaintext_len; 3105 uint8_t *plaintext; 3106 struct rte_cryptodev_info dev_info; 3107 3108 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3109 uint64_t feat_flags = dev_info.feature_flags; 3110 3111 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3112 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3113 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3114 return TEST_SKIPPED; 3115 } 3116 3117 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3118 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3119 printf("Device doesn't support RAW data-path APIs.\n"); 3120 return TEST_SKIPPED; 3121 } 3122 3123 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3124 return TEST_SKIPPED; 3125 3126 /* Verify the capabilities */ 3127 struct rte_cryptodev_sym_capability_idx cap_idx; 3128 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3129 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3130 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3131 &cap_idx) == NULL) 3132 return TEST_SKIPPED; 3133 3134 /* Create SNOW 3G session */ 3135 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3136 tdata->key.data, tdata->key.len, 3137 tdata->auth_iv.len, tdata->digest.len, 3138 RTE_CRYPTO_AUTH_OP_GENERATE, 3139 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3140 if (retval < 0) 3141 return retval; 3142 3143 /* alloc mbuf and set payload */ 3144 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3145 3146 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3147 rte_pktmbuf_tailroom(ut_params->ibuf)); 3148 3149 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3150 /* Append data which is padded to a multiple of */ 3151 /* the algorithms block size */ 3152 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3153 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3154 plaintext_pad_len); 3155 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3156 3157 /* Create SNOW 3G operation */ 3158 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3159 tdata->auth_iv.data, tdata->auth_iv.len, 3160 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3161 tdata->validAuthLenInBits.len, 3162 0); 3163 if (retval < 0) 3164 return retval; 3165 3166 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3167 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3168 ut_params->op, 0, 1, 1, 0); 3169 else 3170 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3171 ut_params->op); 3172 ut_params->obuf = ut_params->op->sym->m_src; 3173 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3174 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3175 + plaintext_pad_len; 3176 3177 /* Validate obuf */ 3178 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3179 ut_params->digest, 3180 tdata->digest.data, 3181 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3182 "SNOW 3G Generated auth tag not as expected"); 3183 3184 return 0; 3185 } 3186 3187 static int 3188 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3189 { 3190 struct crypto_testsuite_params *ts_params = &testsuite_params; 3191 struct crypto_unittest_params *ut_params = &unittest_params; 3192 3193 int retval; 3194 unsigned plaintext_pad_len; 3195 unsigned plaintext_len; 3196 uint8_t *plaintext; 3197 struct rte_cryptodev_info dev_info; 3198 3199 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3200 uint64_t feat_flags = dev_info.feature_flags; 3201 3202 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3203 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3204 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3205 return TEST_SKIPPED; 3206 } 3207 3208 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3209 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3210 printf("Device doesn't support RAW data-path APIs.\n"); 3211 return TEST_SKIPPED; 3212 } 3213 3214 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3215 return TEST_SKIPPED; 3216 3217 /* Verify the capabilities */ 3218 struct rte_cryptodev_sym_capability_idx cap_idx; 3219 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3220 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3221 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3222 &cap_idx) == NULL) 3223 return TEST_SKIPPED; 3224 3225 /* Create SNOW 3G session */ 3226 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3227 tdata->key.data, tdata->key.len, 3228 tdata->auth_iv.len, tdata->digest.len, 3229 RTE_CRYPTO_AUTH_OP_VERIFY, 3230 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3231 if (retval < 0) 3232 return retval; 3233 /* alloc mbuf and set payload */ 3234 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3235 3236 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3237 rte_pktmbuf_tailroom(ut_params->ibuf)); 3238 3239 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3240 /* Append data which is padded to a multiple of */ 3241 /* the algorithms block size */ 3242 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3243 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3244 plaintext_pad_len); 3245 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3246 3247 /* Create SNOW 3G operation */ 3248 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3249 tdata->digest.len, 3250 tdata->auth_iv.data, tdata->auth_iv.len, 3251 plaintext_pad_len, 3252 RTE_CRYPTO_AUTH_OP_VERIFY, 3253 tdata->validAuthLenInBits.len, 3254 0); 3255 if (retval < 0) 3256 return retval; 3257 3258 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3259 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3260 ut_params->op, 0, 1, 1, 0); 3261 else 3262 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3263 ut_params->op); 3264 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3265 ut_params->obuf = ut_params->op->sym->m_src; 3266 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3267 + plaintext_pad_len; 3268 3269 /* Validate obuf */ 3270 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3271 return 0; 3272 else 3273 return -1; 3274 3275 return 0; 3276 } 3277 3278 static int 3279 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3280 { 3281 struct crypto_testsuite_params *ts_params = &testsuite_params; 3282 struct crypto_unittest_params *ut_params = &unittest_params; 3283 3284 int retval; 3285 unsigned plaintext_pad_len; 3286 unsigned plaintext_len; 3287 uint8_t *plaintext; 3288 struct rte_cryptodev_info dev_info; 3289 3290 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3291 uint64_t feat_flags = dev_info.feature_flags; 3292 3293 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3294 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3295 printf("Device doesn't support RAW data-path APIs.\n"); 3296 return TEST_SKIPPED; 3297 } 3298 3299 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3300 return TEST_SKIPPED; 3301 3302 /* Verify the capabilities */ 3303 struct rte_cryptodev_sym_capability_idx cap_idx; 3304 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3305 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3306 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3307 &cap_idx) == NULL) 3308 return TEST_SKIPPED; 3309 3310 /* Create KASUMI session */ 3311 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3312 tdata->key.data, tdata->key.len, 3313 0, tdata->digest.len, 3314 RTE_CRYPTO_AUTH_OP_GENERATE, 3315 RTE_CRYPTO_AUTH_KASUMI_F9); 3316 if (retval < 0) 3317 return retval; 3318 3319 /* alloc mbuf and set payload */ 3320 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3321 3322 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3323 rte_pktmbuf_tailroom(ut_params->ibuf)); 3324 3325 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3326 /* Append data which is padded to a multiple of */ 3327 /* the algorithms block size */ 3328 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3329 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3330 plaintext_pad_len); 3331 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3332 3333 /* Create KASUMI operation */ 3334 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3335 NULL, 0, 3336 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3337 tdata->plaintext.len, 3338 0); 3339 if (retval < 0) 3340 return retval; 3341 3342 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3343 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3344 ut_params->op); 3345 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3346 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3347 ut_params->op, 0, 1, 1, 0); 3348 else 3349 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3350 ut_params->op); 3351 3352 ut_params->obuf = ut_params->op->sym->m_src; 3353 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3354 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3355 + plaintext_pad_len; 3356 3357 /* Validate obuf */ 3358 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3359 ut_params->digest, 3360 tdata->digest.data, 3361 DIGEST_BYTE_LENGTH_KASUMI_F9, 3362 "KASUMI Generated auth tag not as expected"); 3363 3364 return 0; 3365 } 3366 3367 static int 3368 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3369 { 3370 struct crypto_testsuite_params *ts_params = &testsuite_params; 3371 struct crypto_unittest_params *ut_params = &unittest_params; 3372 3373 int retval; 3374 unsigned plaintext_pad_len; 3375 unsigned plaintext_len; 3376 uint8_t *plaintext; 3377 struct rte_cryptodev_info dev_info; 3378 3379 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3380 uint64_t feat_flags = dev_info.feature_flags; 3381 3382 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3383 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3384 printf("Device doesn't support RAW data-path APIs.\n"); 3385 return TEST_SKIPPED; 3386 } 3387 3388 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3389 return TEST_SKIPPED; 3390 3391 /* Verify the capabilities */ 3392 struct rte_cryptodev_sym_capability_idx cap_idx; 3393 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3394 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3395 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3396 &cap_idx) == NULL) 3397 return TEST_SKIPPED; 3398 3399 /* Create KASUMI session */ 3400 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3401 tdata->key.data, tdata->key.len, 3402 0, tdata->digest.len, 3403 RTE_CRYPTO_AUTH_OP_VERIFY, 3404 RTE_CRYPTO_AUTH_KASUMI_F9); 3405 if (retval < 0) 3406 return retval; 3407 /* alloc mbuf and set payload */ 3408 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3409 3410 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3411 rte_pktmbuf_tailroom(ut_params->ibuf)); 3412 3413 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3414 /* Append data which is padded to a multiple */ 3415 /* of the algorithms block size */ 3416 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3417 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3418 plaintext_pad_len); 3419 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3420 3421 /* Create KASUMI operation */ 3422 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3423 tdata->digest.len, 3424 NULL, 0, 3425 plaintext_pad_len, 3426 RTE_CRYPTO_AUTH_OP_VERIFY, 3427 tdata->plaintext.len, 3428 0); 3429 if (retval < 0) 3430 return retval; 3431 3432 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3433 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3434 ut_params->op, 0, 1, 1, 0); 3435 else 3436 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3437 ut_params->op); 3438 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3439 ut_params->obuf = ut_params->op->sym->m_src; 3440 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3441 + plaintext_pad_len; 3442 3443 /* Validate obuf */ 3444 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3445 return 0; 3446 else 3447 return -1; 3448 3449 return 0; 3450 } 3451 3452 static int 3453 test_snow3g_hash_generate_test_case_1(void) 3454 { 3455 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3456 } 3457 3458 static int 3459 test_snow3g_hash_generate_test_case_2(void) 3460 { 3461 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3462 } 3463 3464 static int 3465 test_snow3g_hash_generate_test_case_3(void) 3466 { 3467 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3468 } 3469 3470 static int 3471 test_snow3g_hash_generate_test_case_4(void) 3472 { 3473 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3474 } 3475 3476 static int 3477 test_snow3g_hash_generate_test_case_5(void) 3478 { 3479 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3480 } 3481 3482 static int 3483 test_snow3g_hash_generate_test_case_6(void) 3484 { 3485 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3486 } 3487 3488 static int 3489 test_snow3g_hash_verify_test_case_1(void) 3490 { 3491 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3492 3493 } 3494 3495 static int 3496 test_snow3g_hash_verify_test_case_2(void) 3497 { 3498 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3499 } 3500 3501 static int 3502 test_snow3g_hash_verify_test_case_3(void) 3503 { 3504 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3505 } 3506 3507 static int 3508 test_snow3g_hash_verify_test_case_4(void) 3509 { 3510 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3511 } 3512 3513 static int 3514 test_snow3g_hash_verify_test_case_5(void) 3515 { 3516 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3517 } 3518 3519 static int 3520 test_snow3g_hash_verify_test_case_6(void) 3521 { 3522 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3523 } 3524 3525 static int 3526 test_kasumi_hash_generate_test_case_1(void) 3527 { 3528 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3529 } 3530 3531 static int 3532 test_kasumi_hash_generate_test_case_2(void) 3533 { 3534 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3535 } 3536 3537 static int 3538 test_kasumi_hash_generate_test_case_3(void) 3539 { 3540 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3541 } 3542 3543 static int 3544 test_kasumi_hash_generate_test_case_4(void) 3545 { 3546 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3547 } 3548 3549 static int 3550 test_kasumi_hash_generate_test_case_5(void) 3551 { 3552 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3553 } 3554 3555 static int 3556 test_kasumi_hash_generate_test_case_6(void) 3557 { 3558 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3559 } 3560 3561 static int 3562 test_kasumi_hash_verify_test_case_1(void) 3563 { 3564 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3565 } 3566 3567 static int 3568 test_kasumi_hash_verify_test_case_2(void) 3569 { 3570 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3571 } 3572 3573 static int 3574 test_kasumi_hash_verify_test_case_3(void) 3575 { 3576 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3577 } 3578 3579 static int 3580 test_kasumi_hash_verify_test_case_4(void) 3581 { 3582 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3583 } 3584 3585 static int 3586 test_kasumi_hash_verify_test_case_5(void) 3587 { 3588 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3589 } 3590 3591 static int 3592 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3593 { 3594 struct crypto_testsuite_params *ts_params = &testsuite_params; 3595 struct crypto_unittest_params *ut_params = &unittest_params; 3596 3597 int retval; 3598 uint8_t *plaintext, *ciphertext; 3599 unsigned plaintext_pad_len; 3600 unsigned plaintext_len; 3601 struct rte_cryptodev_info dev_info; 3602 3603 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3604 uint64_t feat_flags = dev_info.feature_flags; 3605 3606 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3607 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3608 printf("Device doesn't support RAW data-path APIs.\n"); 3609 return TEST_SKIPPED; 3610 } 3611 3612 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3613 return TEST_SKIPPED; 3614 3615 /* Verify the capabilities */ 3616 struct rte_cryptodev_sym_capability_idx cap_idx; 3617 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3618 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3619 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3620 &cap_idx) == NULL) 3621 return TEST_SKIPPED; 3622 3623 /* Create KASUMI session */ 3624 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3625 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3626 RTE_CRYPTO_CIPHER_KASUMI_F8, 3627 tdata->key.data, tdata->key.len, 3628 tdata->cipher_iv.len); 3629 if (retval < 0) 3630 return retval; 3631 3632 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3633 3634 /* Clear mbuf payload */ 3635 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3636 rte_pktmbuf_tailroom(ut_params->ibuf)); 3637 3638 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3639 /* Append data which is padded to a multiple */ 3640 /* of the algorithms block size */ 3641 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3642 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3643 plaintext_pad_len); 3644 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3645 3646 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3647 3648 /* Create KASUMI operation */ 3649 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3650 tdata->cipher_iv.len, 3651 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3652 tdata->validCipherOffsetInBits.len); 3653 if (retval < 0) 3654 return retval; 3655 3656 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3657 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3658 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3659 else 3660 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3661 ut_params->op); 3662 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3663 3664 ut_params->obuf = ut_params->op->sym->m_dst; 3665 if (ut_params->obuf) 3666 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3667 else 3668 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3669 3670 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3671 3672 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3673 (tdata->validCipherOffsetInBits.len >> 3); 3674 /* Validate obuf */ 3675 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3676 ciphertext, 3677 reference_ciphertext, 3678 tdata->validCipherLenInBits.len, 3679 "KASUMI Ciphertext data not as expected"); 3680 return 0; 3681 } 3682 3683 static int 3684 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3685 { 3686 struct crypto_testsuite_params *ts_params = &testsuite_params; 3687 struct crypto_unittest_params *ut_params = &unittest_params; 3688 3689 int retval; 3690 3691 unsigned int plaintext_pad_len; 3692 unsigned int plaintext_len; 3693 3694 uint8_t buffer[10000]; 3695 const uint8_t *ciphertext; 3696 3697 struct rte_cryptodev_info dev_info; 3698 3699 /* Verify the capabilities */ 3700 struct rte_cryptodev_sym_capability_idx cap_idx; 3701 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3702 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3703 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3704 &cap_idx) == NULL) 3705 return TEST_SKIPPED; 3706 3707 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3708 3709 uint64_t feat_flags = dev_info.feature_flags; 3710 3711 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3712 printf("Device doesn't support in-place scatter-gather. " 3713 "Test Skipped.\n"); 3714 return TEST_SKIPPED; 3715 } 3716 3717 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3718 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3719 printf("Device doesn't support RAW data-path APIs.\n"); 3720 return TEST_SKIPPED; 3721 } 3722 3723 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3724 return TEST_SKIPPED; 3725 3726 /* Create KASUMI session */ 3727 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3728 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3729 RTE_CRYPTO_CIPHER_KASUMI_F8, 3730 tdata->key.data, tdata->key.len, 3731 tdata->cipher_iv.len); 3732 if (retval < 0) 3733 return retval; 3734 3735 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3736 3737 3738 /* Append data which is padded to a multiple */ 3739 /* of the algorithms block size */ 3740 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3741 3742 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3743 plaintext_pad_len, 10, 0); 3744 3745 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3746 3747 /* Create KASUMI operation */ 3748 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3749 tdata->cipher_iv.len, 3750 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3751 tdata->validCipherOffsetInBits.len); 3752 if (retval < 0) 3753 return retval; 3754 3755 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3756 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3757 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3758 else 3759 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3760 ut_params->op); 3761 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3762 3763 ut_params->obuf = ut_params->op->sym->m_dst; 3764 3765 if (ut_params->obuf) 3766 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3767 plaintext_len, buffer); 3768 else 3769 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3770 tdata->validCipherOffsetInBits.len >> 3, 3771 plaintext_len, buffer); 3772 3773 /* Validate obuf */ 3774 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3775 3776 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3777 (tdata->validCipherOffsetInBits.len >> 3); 3778 /* Validate obuf */ 3779 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3780 ciphertext, 3781 reference_ciphertext, 3782 tdata->validCipherLenInBits.len, 3783 "KASUMI Ciphertext data not as expected"); 3784 return 0; 3785 } 3786 3787 static int 3788 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3789 { 3790 struct crypto_testsuite_params *ts_params = &testsuite_params; 3791 struct crypto_unittest_params *ut_params = &unittest_params; 3792 3793 int retval; 3794 uint8_t *plaintext, *ciphertext; 3795 unsigned plaintext_pad_len; 3796 unsigned plaintext_len; 3797 3798 /* Verify the capabilities */ 3799 struct rte_cryptodev_sym_capability_idx cap_idx; 3800 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3801 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3802 /* Data-path service does not support OOP */ 3803 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3804 &cap_idx) == NULL) 3805 return TEST_SKIPPED; 3806 3807 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3808 return TEST_SKIPPED; 3809 3810 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3811 return TEST_SKIPPED; 3812 3813 /* Create KASUMI session */ 3814 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3815 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3816 RTE_CRYPTO_CIPHER_KASUMI_F8, 3817 tdata->key.data, tdata->key.len, 3818 tdata->cipher_iv.len); 3819 if (retval < 0) 3820 return retval; 3821 3822 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3823 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3824 3825 /* Clear mbuf payload */ 3826 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3827 rte_pktmbuf_tailroom(ut_params->ibuf)); 3828 3829 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3830 /* Append data which is padded to a multiple */ 3831 /* of the algorithms block size */ 3832 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3833 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3834 plaintext_pad_len); 3835 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3836 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3837 3838 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3839 3840 /* Create KASUMI operation */ 3841 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3842 tdata->cipher_iv.len, 3843 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3844 tdata->validCipherOffsetInBits.len); 3845 if (retval < 0) 3846 return retval; 3847 3848 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3849 ut_params->op); 3850 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3851 3852 ut_params->obuf = ut_params->op->sym->m_dst; 3853 if (ut_params->obuf) 3854 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3855 else 3856 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3857 3858 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3859 3860 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3861 (tdata->validCipherOffsetInBits.len >> 3); 3862 /* Validate obuf */ 3863 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3864 ciphertext, 3865 reference_ciphertext, 3866 tdata->validCipherLenInBits.len, 3867 "KASUMI Ciphertext data not as expected"); 3868 return 0; 3869 } 3870 3871 static int 3872 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3873 { 3874 struct crypto_testsuite_params *ts_params = &testsuite_params; 3875 struct crypto_unittest_params *ut_params = &unittest_params; 3876 3877 int retval; 3878 unsigned int plaintext_pad_len; 3879 unsigned int plaintext_len; 3880 3881 const uint8_t *ciphertext; 3882 uint8_t buffer[2048]; 3883 3884 struct rte_cryptodev_info dev_info; 3885 3886 /* Verify the capabilities */ 3887 struct rte_cryptodev_sym_capability_idx cap_idx; 3888 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3889 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3890 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3891 &cap_idx) == NULL) 3892 return TEST_SKIPPED; 3893 3894 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3895 return TEST_SKIPPED; 3896 3897 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3898 return TEST_SKIPPED; 3899 3900 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3901 3902 uint64_t feat_flags = dev_info.feature_flags; 3903 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3904 printf("Device doesn't support out-of-place scatter-gather " 3905 "in both input and output mbufs. " 3906 "Test Skipped.\n"); 3907 return TEST_SKIPPED; 3908 } 3909 3910 /* Create KASUMI session */ 3911 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3912 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3913 RTE_CRYPTO_CIPHER_KASUMI_F8, 3914 tdata->key.data, tdata->key.len, 3915 tdata->cipher_iv.len); 3916 if (retval < 0) 3917 return retval; 3918 3919 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3920 /* Append data which is padded to a multiple */ 3921 /* of the algorithms block size */ 3922 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3923 3924 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3925 plaintext_pad_len, 10, 0); 3926 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3927 plaintext_pad_len, 3, 0); 3928 3929 /* Append data which is padded to a multiple */ 3930 /* of the algorithms block size */ 3931 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3932 3933 /* Create KASUMI operation */ 3934 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3935 tdata->cipher_iv.len, 3936 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3937 tdata->validCipherOffsetInBits.len); 3938 if (retval < 0) 3939 return retval; 3940 3941 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3942 ut_params->op); 3943 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3944 3945 ut_params->obuf = ut_params->op->sym->m_dst; 3946 if (ut_params->obuf) 3947 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3948 plaintext_pad_len, buffer); 3949 else 3950 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3951 tdata->validCipherOffsetInBits.len >> 3, 3952 plaintext_pad_len, buffer); 3953 3954 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3955 (tdata->validCipherOffsetInBits.len >> 3); 3956 /* Validate obuf */ 3957 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3958 ciphertext, 3959 reference_ciphertext, 3960 tdata->validCipherLenInBits.len, 3961 "KASUMI Ciphertext data not as expected"); 3962 return 0; 3963 } 3964 3965 3966 static int 3967 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3968 { 3969 struct crypto_testsuite_params *ts_params = &testsuite_params; 3970 struct crypto_unittest_params *ut_params = &unittest_params; 3971 3972 int retval; 3973 uint8_t *ciphertext, *plaintext; 3974 unsigned ciphertext_pad_len; 3975 unsigned ciphertext_len; 3976 3977 /* Verify the capabilities */ 3978 struct rte_cryptodev_sym_capability_idx cap_idx; 3979 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3980 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3981 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3982 &cap_idx) == NULL) 3983 return TEST_SKIPPED; 3984 3985 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3986 return TEST_SKIPPED; 3987 3988 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3989 return TEST_SKIPPED; 3990 3991 /* Create KASUMI session */ 3992 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3993 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3994 RTE_CRYPTO_CIPHER_KASUMI_F8, 3995 tdata->key.data, tdata->key.len, 3996 tdata->cipher_iv.len); 3997 if (retval < 0) 3998 return retval; 3999 4000 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4001 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4002 4003 /* Clear mbuf payload */ 4004 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4005 rte_pktmbuf_tailroom(ut_params->ibuf)); 4006 4007 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4008 /* Append data which is padded to a multiple */ 4009 /* of the algorithms block size */ 4010 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4011 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4012 ciphertext_pad_len); 4013 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4014 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4015 4016 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4017 4018 /* Create KASUMI operation */ 4019 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4020 tdata->cipher_iv.len, 4021 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4022 tdata->validCipherOffsetInBits.len); 4023 if (retval < 0) 4024 return retval; 4025 4026 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4027 ut_params->op); 4028 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4029 4030 ut_params->obuf = ut_params->op->sym->m_dst; 4031 if (ut_params->obuf) 4032 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4033 else 4034 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4035 4036 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4037 4038 const uint8_t *reference_plaintext = tdata->plaintext.data + 4039 (tdata->validCipherOffsetInBits.len >> 3); 4040 /* Validate obuf */ 4041 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4042 plaintext, 4043 reference_plaintext, 4044 tdata->validCipherLenInBits.len, 4045 "KASUMI Plaintext data not as expected"); 4046 return 0; 4047 } 4048 4049 static int 4050 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4051 { 4052 struct crypto_testsuite_params *ts_params = &testsuite_params; 4053 struct crypto_unittest_params *ut_params = &unittest_params; 4054 4055 int retval; 4056 uint8_t *ciphertext, *plaintext; 4057 unsigned ciphertext_pad_len; 4058 unsigned ciphertext_len; 4059 struct rte_cryptodev_info dev_info; 4060 4061 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4062 uint64_t feat_flags = dev_info.feature_flags; 4063 4064 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4065 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4066 printf("Device doesn't support RAW data-path APIs.\n"); 4067 return TEST_SKIPPED; 4068 } 4069 4070 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4071 return TEST_SKIPPED; 4072 4073 /* Verify the capabilities */ 4074 struct rte_cryptodev_sym_capability_idx cap_idx; 4075 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4076 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4077 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4078 &cap_idx) == NULL) 4079 return TEST_SKIPPED; 4080 4081 /* Create KASUMI session */ 4082 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4083 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4084 RTE_CRYPTO_CIPHER_KASUMI_F8, 4085 tdata->key.data, tdata->key.len, 4086 tdata->cipher_iv.len); 4087 if (retval < 0) 4088 return retval; 4089 4090 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4091 4092 /* Clear mbuf payload */ 4093 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4094 rte_pktmbuf_tailroom(ut_params->ibuf)); 4095 4096 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4097 /* Append data which is padded to a multiple */ 4098 /* of the algorithms block size */ 4099 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4100 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4101 ciphertext_pad_len); 4102 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4103 4104 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4105 4106 /* Create KASUMI operation */ 4107 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4108 tdata->cipher_iv.len, 4109 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4110 tdata->validCipherOffsetInBits.len); 4111 if (retval < 0) 4112 return retval; 4113 4114 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4115 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4116 ut_params->op, 1, 0, 1, 0); 4117 else 4118 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4119 ut_params->op); 4120 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4121 4122 ut_params->obuf = ut_params->op->sym->m_dst; 4123 if (ut_params->obuf) 4124 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4125 else 4126 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4127 4128 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4129 4130 const uint8_t *reference_plaintext = tdata->plaintext.data + 4131 (tdata->validCipherOffsetInBits.len >> 3); 4132 /* Validate obuf */ 4133 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4134 plaintext, 4135 reference_plaintext, 4136 tdata->validCipherLenInBits.len, 4137 "KASUMI Plaintext data not as expected"); 4138 return 0; 4139 } 4140 4141 static int 4142 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4143 { 4144 struct crypto_testsuite_params *ts_params = &testsuite_params; 4145 struct crypto_unittest_params *ut_params = &unittest_params; 4146 4147 int retval; 4148 uint8_t *plaintext, *ciphertext; 4149 unsigned plaintext_pad_len; 4150 unsigned plaintext_len; 4151 struct rte_cryptodev_info dev_info; 4152 4153 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4154 uint64_t feat_flags = dev_info.feature_flags; 4155 4156 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4157 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4158 printf("Device doesn't support RAW data-path APIs.\n"); 4159 return TEST_SKIPPED; 4160 } 4161 4162 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4163 return TEST_SKIPPED; 4164 4165 /* Verify the capabilities */ 4166 struct rte_cryptodev_sym_capability_idx cap_idx; 4167 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4168 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4169 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4170 &cap_idx) == NULL) 4171 return TEST_SKIPPED; 4172 4173 /* Create SNOW 3G session */ 4174 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4175 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4176 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4177 tdata->key.data, tdata->key.len, 4178 tdata->cipher_iv.len); 4179 if (retval < 0) 4180 return retval; 4181 4182 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4183 4184 /* Clear mbuf payload */ 4185 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4186 rte_pktmbuf_tailroom(ut_params->ibuf)); 4187 4188 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4189 /* Append data which is padded to a multiple of */ 4190 /* the algorithms block size */ 4191 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4192 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4193 plaintext_pad_len); 4194 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4195 4196 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4197 4198 /* Create SNOW 3G operation */ 4199 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4200 tdata->cipher_iv.len, 4201 tdata->validCipherLenInBits.len, 4202 0); 4203 if (retval < 0) 4204 return retval; 4205 4206 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4207 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4208 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4209 else 4210 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4211 ut_params->op); 4212 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4213 4214 ut_params->obuf = ut_params->op->sym->m_dst; 4215 if (ut_params->obuf) 4216 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4217 else 4218 ciphertext = plaintext; 4219 4220 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4221 4222 /* Validate obuf */ 4223 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4224 ciphertext, 4225 tdata->ciphertext.data, 4226 tdata->validDataLenInBits.len, 4227 "SNOW 3G Ciphertext data not as expected"); 4228 return 0; 4229 } 4230 4231 4232 static int 4233 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4234 { 4235 struct crypto_testsuite_params *ts_params = &testsuite_params; 4236 struct crypto_unittest_params *ut_params = &unittest_params; 4237 uint8_t *plaintext, *ciphertext; 4238 4239 int retval; 4240 unsigned plaintext_pad_len; 4241 unsigned plaintext_len; 4242 struct rte_cryptodev_info dev_info; 4243 4244 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4245 uint64_t feat_flags = dev_info.feature_flags; 4246 4247 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4248 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4249 printf("Device does not support RAW data-path APIs.\n"); 4250 return -ENOTSUP; 4251 } 4252 4253 /* Verify the capabilities */ 4254 struct rte_cryptodev_sym_capability_idx cap_idx; 4255 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4256 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4257 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4258 &cap_idx) == NULL) 4259 return TEST_SKIPPED; 4260 4261 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4262 return TEST_SKIPPED; 4263 4264 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4265 return TEST_SKIPPED; 4266 4267 /* Create SNOW 3G session */ 4268 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4269 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4270 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4271 tdata->key.data, tdata->key.len, 4272 tdata->cipher_iv.len); 4273 if (retval < 0) 4274 return retval; 4275 4276 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4277 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4278 4279 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4280 "Failed to allocate input buffer in mempool"); 4281 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4282 "Failed to allocate output buffer in mempool"); 4283 4284 /* Clear mbuf payload */ 4285 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4286 rte_pktmbuf_tailroom(ut_params->ibuf)); 4287 4288 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4289 /* Append data which is padded to a multiple of */ 4290 /* the algorithms block size */ 4291 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4292 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4293 plaintext_pad_len); 4294 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4295 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4296 4297 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4298 4299 /* Create SNOW 3G operation */ 4300 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4301 tdata->cipher_iv.len, 4302 tdata->validCipherLenInBits.len, 4303 0); 4304 if (retval < 0) 4305 return retval; 4306 4307 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4308 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4309 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4310 else 4311 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4312 ut_params->op); 4313 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4314 4315 ut_params->obuf = ut_params->op->sym->m_dst; 4316 if (ut_params->obuf) 4317 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4318 else 4319 ciphertext = plaintext; 4320 4321 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4322 4323 /* Validate obuf */ 4324 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4325 ciphertext, 4326 tdata->ciphertext.data, 4327 tdata->validDataLenInBits.len, 4328 "SNOW 3G Ciphertext data not as expected"); 4329 return 0; 4330 } 4331 4332 static int 4333 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4334 { 4335 struct crypto_testsuite_params *ts_params = &testsuite_params; 4336 struct crypto_unittest_params *ut_params = &unittest_params; 4337 4338 int retval; 4339 unsigned int plaintext_pad_len; 4340 unsigned int plaintext_len; 4341 uint8_t buffer[10000]; 4342 const uint8_t *ciphertext; 4343 4344 struct rte_cryptodev_info dev_info; 4345 4346 /* Verify the capabilities */ 4347 struct rte_cryptodev_sym_capability_idx cap_idx; 4348 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4349 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4350 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4351 &cap_idx) == NULL) 4352 return TEST_SKIPPED; 4353 4354 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4355 return TEST_SKIPPED; 4356 4357 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4358 return TEST_SKIPPED; 4359 4360 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4361 4362 uint64_t feat_flags = dev_info.feature_flags; 4363 4364 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4365 printf("Device doesn't support out-of-place scatter-gather " 4366 "in both input and output mbufs. " 4367 "Test Skipped.\n"); 4368 return TEST_SKIPPED; 4369 } 4370 4371 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4372 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4373 printf("Device does not support RAW data-path APIs.\n"); 4374 return -ENOTSUP; 4375 } 4376 4377 /* Create SNOW 3G session */ 4378 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4379 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4380 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4381 tdata->key.data, tdata->key.len, 4382 tdata->cipher_iv.len); 4383 if (retval < 0) 4384 return retval; 4385 4386 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4387 /* Append data which is padded to a multiple of */ 4388 /* the algorithms block size */ 4389 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4390 4391 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4392 plaintext_pad_len, 10, 0); 4393 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4394 plaintext_pad_len, 3, 0); 4395 4396 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4397 "Failed to allocate input buffer in mempool"); 4398 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4399 "Failed to allocate output buffer in mempool"); 4400 4401 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4402 4403 /* Create SNOW 3G operation */ 4404 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4405 tdata->cipher_iv.len, 4406 tdata->validCipherLenInBits.len, 4407 0); 4408 if (retval < 0) 4409 return retval; 4410 4411 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4412 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4413 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4414 else 4415 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4416 ut_params->op); 4417 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4418 4419 ut_params->obuf = ut_params->op->sym->m_dst; 4420 if (ut_params->obuf) 4421 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4422 plaintext_len, buffer); 4423 else 4424 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4425 plaintext_len, buffer); 4426 4427 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4428 4429 /* Validate obuf */ 4430 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4431 ciphertext, 4432 tdata->ciphertext.data, 4433 tdata->validDataLenInBits.len, 4434 "SNOW 3G Ciphertext data not as expected"); 4435 4436 return 0; 4437 } 4438 4439 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4440 static void 4441 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4442 { 4443 uint8_t curr_byte, prev_byte; 4444 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4445 uint8_t lower_byte_mask = (1 << offset) - 1; 4446 unsigned i; 4447 4448 prev_byte = buffer[0]; 4449 buffer[0] >>= offset; 4450 4451 for (i = 1; i < length_in_bytes; i++) { 4452 curr_byte = buffer[i]; 4453 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4454 (curr_byte >> offset); 4455 prev_byte = curr_byte; 4456 } 4457 } 4458 4459 static int 4460 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4461 { 4462 struct crypto_testsuite_params *ts_params = &testsuite_params; 4463 struct crypto_unittest_params *ut_params = &unittest_params; 4464 uint8_t *plaintext, *ciphertext; 4465 int retval; 4466 uint32_t plaintext_len; 4467 uint32_t plaintext_pad_len; 4468 uint8_t extra_offset = 4; 4469 uint8_t *expected_ciphertext_shifted; 4470 struct rte_cryptodev_info dev_info; 4471 4472 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4473 uint64_t feat_flags = dev_info.feature_flags; 4474 4475 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4476 ((tdata->validDataLenInBits.len % 8) != 0)) { 4477 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4478 return TEST_SKIPPED; 4479 } 4480 4481 /* Verify the capabilities */ 4482 struct rte_cryptodev_sym_capability_idx cap_idx; 4483 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4484 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4485 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4486 &cap_idx) == NULL) 4487 return TEST_SKIPPED; 4488 4489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4490 return TEST_SKIPPED; 4491 4492 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4493 return TEST_SKIPPED; 4494 4495 /* Create SNOW 3G session */ 4496 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4497 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4498 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4499 tdata->key.data, tdata->key.len, 4500 tdata->cipher_iv.len); 4501 if (retval < 0) 4502 return retval; 4503 4504 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4505 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4506 4507 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4508 "Failed to allocate input buffer in mempool"); 4509 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4510 "Failed to allocate output buffer in mempool"); 4511 4512 /* Clear mbuf payload */ 4513 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4514 rte_pktmbuf_tailroom(ut_params->ibuf)); 4515 4516 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4517 /* 4518 * Append data which is padded to a 4519 * multiple of the algorithms block size 4520 */ 4521 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4522 4523 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4524 plaintext_pad_len); 4525 4526 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4527 4528 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4529 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4530 4531 #ifdef RTE_APP_TEST_DEBUG 4532 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4533 #endif 4534 /* Create SNOW 3G operation */ 4535 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4536 tdata->cipher_iv.len, 4537 tdata->validCipherLenInBits.len, 4538 extra_offset); 4539 if (retval < 0) 4540 return retval; 4541 4542 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4543 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4544 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4545 else 4546 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4547 ut_params->op); 4548 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4549 4550 ut_params->obuf = ut_params->op->sym->m_dst; 4551 if (ut_params->obuf) 4552 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4553 else 4554 ciphertext = plaintext; 4555 4556 #ifdef RTE_APP_TEST_DEBUG 4557 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4558 #endif 4559 4560 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4561 4562 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4563 "failed to reserve memory for ciphertext shifted\n"); 4564 4565 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4566 ceil_byte_length(tdata->ciphertext.len)); 4567 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4568 extra_offset); 4569 /* Validate obuf */ 4570 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4571 ciphertext, 4572 expected_ciphertext_shifted, 4573 tdata->validDataLenInBits.len, 4574 extra_offset, 4575 "SNOW 3G Ciphertext data not as expected"); 4576 return 0; 4577 } 4578 4579 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4580 { 4581 struct crypto_testsuite_params *ts_params = &testsuite_params; 4582 struct crypto_unittest_params *ut_params = &unittest_params; 4583 4584 int retval; 4585 4586 uint8_t *plaintext, *ciphertext; 4587 unsigned ciphertext_pad_len; 4588 unsigned ciphertext_len; 4589 struct rte_cryptodev_info dev_info; 4590 4591 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4592 uint64_t feat_flags = dev_info.feature_flags; 4593 4594 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4595 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4596 printf("Device doesn't support RAW data-path APIs.\n"); 4597 return TEST_SKIPPED; 4598 } 4599 4600 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4601 return TEST_SKIPPED; 4602 4603 /* Verify the capabilities */ 4604 struct rte_cryptodev_sym_capability_idx cap_idx; 4605 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4606 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4607 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4608 &cap_idx) == NULL) 4609 return TEST_SKIPPED; 4610 4611 /* Create SNOW 3G session */ 4612 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4613 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4614 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4615 tdata->key.data, tdata->key.len, 4616 tdata->cipher_iv.len); 4617 if (retval < 0) 4618 return retval; 4619 4620 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4621 4622 /* Clear mbuf payload */ 4623 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4624 rte_pktmbuf_tailroom(ut_params->ibuf)); 4625 4626 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4627 /* Append data which is padded to a multiple of */ 4628 /* the algorithms block size */ 4629 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4630 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4631 ciphertext_pad_len); 4632 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4633 4634 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4635 4636 /* Create SNOW 3G operation */ 4637 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4638 tdata->cipher_iv.len, 4639 tdata->validCipherLenInBits.len, 4640 tdata->cipher.offset_bits); 4641 if (retval < 0) 4642 return retval; 4643 4644 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4645 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4646 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4647 else 4648 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4649 ut_params->op); 4650 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4651 ut_params->obuf = ut_params->op->sym->m_dst; 4652 if (ut_params->obuf) 4653 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4654 else 4655 plaintext = ciphertext; 4656 4657 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4658 4659 /* Validate obuf */ 4660 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4661 tdata->plaintext.data, 4662 tdata->validDataLenInBits.len, 4663 "SNOW 3G Plaintext data not as expected"); 4664 return 0; 4665 } 4666 4667 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4668 { 4669 struct crypto_testsuite_params *ts_params = &testsuite_params; 4670 struct crypto_unittest_params *ut_params = &unittest_params; 4671 4672 int retval; 4673 4674 uint8_t *plaintext, *ciphertext; 4675 unsigned ciphertext_pad_len; 4676 unsigned ciphertext_len; 4677 struct rte_cryptodev_info dev_info; 4678 4679 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4680 uint64_t feat_flags = dev_info.feature_flags; 4681 4682 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4683 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4684 printf("Device does not support RAW data-path APIs.\n"); 4685 return -ENOTSUP; 4686 } 4687 /* Verify the capabilities */ 4688 struct rte_cryptodev_sym_capability_idx cap_idx; 4689 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4690 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4691 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4692 &cap_idx) == NULL) 4693 return TEST_SKIPPED; 4694 4695 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4696 return TEST_SKIPPED; 4697 4698 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4699 return TEST_SKIPPED; 4700 4701 /* Create SNOW 3G session */ 4702 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4703 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4704 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4705 tdata->key.data, tdata->key.len, 4706 tdata->cipher_iv.len); 4707 if (retval < 0) 4708 return retval; 4709 4710 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4711 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4712 4713 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4714 "Failed to allocate input buffer"); 4715 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4716 "Failed to allocate output buffer"); 4717 4718 /* Clear mbuf payload */ 4719 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4720 rte_pktmbuf_tailroom(ut_params->ibuf)); 4721 4722 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4723 rte_pktmbuf_tailroom(ut_params->obuf)); 4724 4725 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4726 /* Append data which is padded to a multiple of */ 4727 /* the algorithms block size */ 4728 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4729 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4730 ciphertext_pad_len); 4731 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4732 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4733 4734 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4735 4736 /* Create SNOW 3G operation */ 4737 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4738 tdata->cipher_iv.len, 4739 tdata->validCipherLenInBits.len, 4740 0); 4741 if (retval < 0) 4742 return retval; 4743 4744 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4745 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4746 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4747 else 4748 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4749 ut_params->op); 4750 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4751 ut_params->obuf = ut_params->op->sym->m_dst; 4752 if (ut_params->obuf) 4753 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4754 else 4755 plaintext = ciphertext; 4756 4757 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4758 4759 /* Validate obuf */ 4760 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4761 tdata->plaintext.data, 4762 tdata->validDataLenInBits.len, 4763 "SNOW 3G Plaintext data not as expected"); 4764 return 0; 4765 } 4766 4767 static int 4768 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4769 { 4770 struct crypto_testsuite_params *ts_params = &testsuite_params; 4771 struct crypto_unittest_params *ut_params = &unittest_params; 4772 4773 int retval; 4774 4775 uint8_t *plaintext, *ciphertext; 4776 unsigned int plaintext_pad_len; 4777 unsigned int plaintext_len; 4778 4779 struct rte_cryptodev_info dev_info; 4780 struct rte_cryptodev_sym_capability_idx cap_idx; 4781 4782 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4783 uint64_t feat_flags = dev_info.feature_flags; 4784 4785 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4786 ((tdata->validAuthLenInBits.len % 8 != 0) || 4787 (tdata->validDataLenInBits.len % 8 != 0))) { 4788 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4789 return TEST_SKIPPED; 4790 } 4791 4792 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4793 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4794 printf("Device doesn't support RAW data-path APIs.\n"); 4795 return TEST_SKIPPED; 4796 } 4797 4798 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4799 return TEST_SKIPPED; 4800 4801 /* Check if device supports ZUC EEA3 */ 4802 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4803 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4804 4805 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4806 &cap_idx) == NULL) 4807 return TEST_SKIPPED; 4808 4809 /* Check if device supports ZUC EIA3 */ 4810 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4811 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4812 4813 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4814 &cap_idx) == NULL) 4815 return TEST_SKIPPED; 4816 4817 /* Create ZUC session */ 4818 retval = create_zuc_cipher_auth_encrypt_generate_session( 4819 ts_params->valid_devs[0], 4820 tdata); 4821 if (retval != 0) 4822 return retval; 4823 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4824 4825 /* clear mbuf payload */ 4826 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4827 rte_pktmbuf_tailroom(ut_params->ibuf)); 4828 4829 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4830 /* Append data which is padded to a multiple of */ 4831 /* the algorithms block size */ 4832 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4833 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4834 plaintext_pad_len); 4835 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4836 4837 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4838 4839 /* Create ZUC operation */ 4840 retval = create_zuc_cipher_hash_generate_operation(tdata); 4841 if (retval < 0) 4842 return retval; 4843 4844 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4845 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4846 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4847 else 4848 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4849 ut_params->op); 4850 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4851 ut_params->obuf = ut_params->op->sym->m_src; 4852 if (ut_params->obuf) 4853 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4854 else 4855 ciphertext = plaintext; 4856 4857 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4858 /* Validate obuf */ 4859 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4860 ciphertext, 4861 tdata->ciphertext.data, 4862 tdata->validDataLenInBits.len, 4863 "ZUC Ciphertext data not as expected"); 4864 4865 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4866 + plaintext_pad_len; 4867 4868 /* Validate obuf */ 4869 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4870 ut_params->digest, 4871 tdata->digest.data, 4872 4, 4873 "ZUC Generated auth tag not as expected"); 4874 return 0; 4875 } 4876 4877 static int 4878 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4879 { 4880 struct crypto_testsuite_params *ts_params = &testsuite_params; 4881 struct crypto_unittest_params *ut_params = &unittest_params; 4882 4883 int retval; 4884 4885 uint8_t *plaintext, *ciphertext; 4886 unsigned plaintext_pad_len; 4887 unsigned plaintext_len; 4888 struct rte_cryptodev_info dev_info; 4889 4890 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4891 uint64_t feat_flags = dev_info.feature_flags; 4892 4893 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4894 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4895 printf("Device doesn't support RAW data-path APIs.\n"); 4896 return TEST_SKIPPED; 4897 } 4898 4899 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4900 return TEST_SKIPPED; 4901 4902 /* Verify the capabilities */ 4903 struct rte_cryptodev_sym_capability_idx cap_idx; 4904 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4905 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4906 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4907 &cap_idx) == NULL) 4908 return TEST_SKIPPED; 4909 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4910 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4911 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4912 &cap_idx) == NULL) 4913 return TEST_SKIPPED; 4914 4915 /* Create SNOW 3G session */ 4916 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4917 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4918 RTE_CRYPTO_AUTH_OP_GENERATE, 4919 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4920 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4921 tdata->key.data, tdata->key.len, 4922 tdata->auth_iv.len, tdata->digest.len, 4923 tdata->cipher_iv.len); 4924 if (retval != 0) 4925 return retval; 4926 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4927 4928 /* clear mbuf payload */ 4929 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4930 rte_pktmbuf_tailroom(ut_params->ibuf)); 4931 4932 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4933 /* Append data which is padded to a multiple of */ 4934 /* the algorithms block size */ 4935 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4936 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4937 plaintext_pad_len); 4938 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4939 4940 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4941 4942 /* Create SNOW 3G operation */ 4943 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4944 tdata->digest.len, tdata->auth_iv.data, 4945 tdata->auth_iv.len, 4946 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4947 tdata->cipher_iv.data, tdata->cipher_iv.len, 4948 tdata->validCipherLenInBits.len, 4949 0, 4950 tdata->validAuthLenInBits.len, 4951 0 4952 ); 4953 if (retval < 0) 4954 return retval; 4955 4956 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4957 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4958 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4959 else 4960 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4961 ut_params->op); 4962 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4963 ut_params->obuf = ut_params->op->sym->m_src; 4964 if (ut_params->obuf) 4965 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4966 else 4967 ciphertext = plaintext; 4968 4969 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4970 /* Validate obuf */ 4971 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4972 ciphertext, 4973 tdata->ciphertext.data, 4974 tdata->validDataLenInBits.len, 4975 "SNOW 3G Ciphertext data not as expected"); 4976 4977 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4978 + plaintext_pad_len; 4979 4980 /* Validate obuf */ 4981 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4982 ut_params->digest, 4983 tdata->digest.data, 4984 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4985 "SNOW 3G Generated auth tag not as expected"); 4986 return 0; 4987 } 4988 4989 static int 4990 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4991 uint8_t op_mode, uint8_t verify) 4992 { 4993 struct crypto_testsuite_params *ts_params = &testsuite_params; 4994 struct crypto_unittest_params *ut_params = &unittest_params; 4995 4996 int retval; 4997 4998 uint8_t *plaintext = NULL, *ciphertext = NULL; 4999 unsigned int plaintext_pad_len; 5000 unsigned int plaintext_len; 5001 unsigned int ciphertext_pad_len; 5002 unsigned int ciphertext_len; 5003 5004 struct rte_cryptodev_info dev_info; 5005 5006 /* Verify the capabilities */ 5007 struct rte_cryptodev_sym_capability_idx cap_idx; 5008 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5009 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5010 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5011 &cap_idx) == NULL) 5012 return TEST_SKIPPED; 5013 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5014 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5015 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5016 &cap_idx) == NULL) 5017 return TEST_SKIPPED; 5018 5019 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5020 return TEST_SKIPPED; 5021 5022 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5023 5024 uint64_t feat_flags = dev_info.feature_flags; 5025 5026 if (op_mode == OUT_OF_PLACE) { 5027 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5028 printf("Device doesn't support digest encrypted.\n"); 5029 return TEST_SKIPPED; 5030 } 5031 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5032 return TEST_SKIPPED; 5033 } 5034 5035 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5036 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5037 printf("Device doesn't support RAW data-path APIs.\n"); 5038 return TEST_SKIPPED; 5039 } 5040 5041 /* Create SNOW 3G session */ 5042 retval = create_wireless_algo_auth_cipher_session( 5043 ts_params->valid_devs[0], 5044 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5045 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5046 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5047 : RTE_CRYPTO_AUTH_OP_GENERATE), 5048 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5049 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5050 tdata->key.data, tdata->key.len, 5051 tdata->auth_iv.len, tdata->digest.len, 5052 tdata->cipher_iv.len); 5053 if (retval != 0) 5054 return retval; 5055 5056 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5057 if (op_mode == OUT_OF_PLACE) 5058 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5059 5060 /* clear mbuf payload */ 5061 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5062 rte_pktmbuf_tailroom(ut_params->ibuf)); 5063 if (op_mode == OUT_OF_PLACE) 5064 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5065 rte_pktmbuf_tailroom(ut_params->obuf)); 5066 5067 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5068 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5069 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5070 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5071 5072 if (verify) { 5073 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5074 ciphertext_pad_len); 5075 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5076 if (op_mode == OUT_OF_PLACE) 5077 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5078 debug_hexdump(stdout, "ciphertext:", ciphertext, 5079 ciphertext_len); 5080 } else { 5081 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5082 plaintext_pad_len); 5083 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5084 if (op_mode == OUT_OF_PLACE) 5085 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5086 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5087 } 5088 5089 /* Create SNOW 3G operation */ 5090 retval = create_wireless_algo_auth_cipher_operation( 5091 tdata->digest.data, tdata->digest.len, 5092 tdata->cipher_iv.data, tdata->cipher_iv.len, 5093 tdata->auth_iv.data, tdata->auth_iv.len, 5094 (tdata->digest.offset_bytes == 0 ? 5095 (verify ? ciphertext_pad_len : plaintext_pad_len) 5096 : tdata->digest.offset_bytes), 5097 tdata->validCipherLenInBits.len, 5098 tdata->cipher.offset_bits, 5099 tdata->validAuthLenInBits.len, 5100 tdata->auth.offset_bits, 5101 op_mode, 0, verify); 5102 5103 if (retval < 0) 5104 return retval; 5105 5106 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5107 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5108 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5109 else 5110 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5111 ut_params->op); 5112 5113 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5114 5115 ut_params->obuf = (op_mode == IN_PLACE ? 5116 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5117 5118 if (verify) { 5119 if (ut_params->obuf) 5120 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5121 uint8_t *); 5122 else 5123 plaintext = ciphertext + 5124 (tdata->cipher.offset_bits >> 3); 5125 5126 debug_hexdump(stdout, "plaintext:", plaintext, 5127 (tdata->plaintext.len >> 3) - tdata->digest.len); 5128 debug_hexdump(stdout, "plaintext expected:", 5129 tdata->plaintext.data, 5130 (tdata->plaintext.len >> 3) - tdata->digest.len); 5131 } else { 5132 if (ut_params->obuf) 5133 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5134 uint8_t *); 5135 else 5136 ciphertext = plaintext; 5137 5138 debug_hexdump(stdout, "ciphertext:", ciphertext, 5139 ciphertext_len); 5140 debug_hexdump(stdout, "ciphertext expected:", 5141 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5142 5143 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5144 + (tdata->digest.offset_bytes == 0 ? 5145 plaintext_pad_len : tdata->digest.offset_bytes); 5146 5147 debug_hexdump(stdout, "digest:", ut_params->digest, 5148 tdata->digest.len); 5149 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5150 tdata->digest.len); 5151 } 5152 5153 /* Validate obuf */ 5154 if (verify) { 5155 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5156 plaintext, 5157 tdata->plaintext.data, 5158 (tdata->plaintext.len - tdata->cipher.offset_bits - 5159 (tdata->digest.len << 3)), 5160 tdata->cipher.offset_bits, 5161 "SNOW 3G Plaintext data not as expected"); 5162 } else { 5163 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5164 ciphertext, 5165 tdata->ciphertext.data, 5166 (tdata->validDataLenInBits.len - 5167 tdata->cipher.offset_bits), 5168 tdata->cipher.offset_bits, 5169 "SNOW 3G Ciphertext data not as expected"); 5170 5171 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5172 ut_params->digest, 5173 tdata->digest.data, 5174 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5175 "SNOW 3G Generated auth tag not as expected"); 5176 } 5177 return 0; 5178 } 5179 5180 static int 5181 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5182 uint8_t op_mode, uint8_t verify) 5183 { 5184 struct crypto_testsuite_params *ts_params = &testsuite_params; 5185 struct crypto_unittest_params *ut_params = &unittest_params; 5186 5187 int retval; 5188 5189 const uint8_t *plaintext = NULL; 5190 const uint8_t *ciphertext = NULL; 5191 const uint8_t *digest = NULL; 5192 unsigned int plaintext_pad_len; 5193 unsigned int plaintext_len; 5194 unsigned int ciphertext_pad_len; 5195 unsigned int ciphertext_len; 5196 uint8_t buffer[10000]; 5197 uint8_t digest_buffer[10000]; 5198 5199 struct rte_cryptodev_info dev_info; 5200 5201 /* Verify the capabilities */ 5202 struct rte_cryptodev_sym_capability_idx cap_idx; 5203 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5204 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5205 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5206 &cap_idx) == NULL) 5207 return TEST_SKIPPED; 5208 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5209 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5210 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5211 &cap_idx) == NULL) 5212 return TEST_SKIPPED; 5213 5214 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5215 return TEST_SKIPPED; 5216 5217 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5218 5219 uint64_t feat_flags = dev_info.feature_flags; 5220 5221 if (op_mode == IN_PLACE) { 5222 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5223 printf("Device doesn't support in-place scatter-gather " 5224 "in both input and output mbufs.\n"); 5225 return TEST_SKIPPED; 5226 } 5227 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5228 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5229 printf("Device doesn't support RAW data-path APIs.\n"); 5230 return TEST_SKIPPED; 5231 } 5232 } else { 5233 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5234 return TEST_SKIPPED; 5235 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5236 printf("Device doesn't support out-of-place scatter-gather " 5237 "in both input and output mbufs.\n"); 5238 return TEST_SKIPPED; 5239 } 5240 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5241 printf("Device doesn't support digest encrypted.\n"); 5242 return TEST_SKIPPED; 5243 } 5244 } 5245 5246 /* Create SNOW 3G session */ 5247 retval = create_wireless_algo_auth_cipher_session( 5248 ts_params->valid_devs[0], 5249 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5250 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5251 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5252 : RTE_CRYPTO_AUTH_OP_GENERATE), 5253 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5254 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5255 tdata->key.data, tdata->key.len, 5256 tdata->auth_iv.len, tdata->digest.len, 5257 tdata->cipher_iv.len); 5258 5259 if (retval != 0) 5260 return retval; 5261 5262 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5263 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5264 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5265 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5266 5267 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5268 plaintext_pad_len, 15, 0); 5269 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5270 "Failed to allocate input buffer in mempool"); 5271 5272 if (op_mode == OUT_OF_PLACE) { 5273 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5274 plaintext_pad_len, 15, 0); 5275 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5276 "Failed to allocate output buffer in mempool"); 5277 } 5278 5279 if (verify) { 5280 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5281 tdata->ciphertext.data); 5282 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5283 ciphertext_len, buffer); 5284 debug_hexdump(stdout, "ciphertext:", ciphertext, 5285 ciphertext_len); 5286 } else { 5287 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5288 tdata->plaintext.data); 5289 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5290 plaintext_len, buffer); 5291 debug_hexdump(stdout, "plaintext:", plaintext, 5292 plaintext_len); 5293 } 5294 memset(buffer, 0, sizeof(buffer)); 5295 5296 /* Create SNOW 3G operation */ 5297 retval = create_wireless_algo_auth_cipher_operation( 5298 tdata->digest.data, tdata->digest.len, 5299 tdata->cipher_iv.data, tdata->cipher_iv.len, 5300 tdata->auth_iv.data, tdata->auth_iv.len, 5301 (tdata->digest.offset_bytes == 0 ? 5302 (verify ? ciphertext_pad_len : plaintext_pad_len) 5303 : tdata->digest.offset_bytes), 5304 tdata->validCipherLenInBits.len, 5305 tdata->cipher.offset_bits, 5306 tdata->validAuthLenInBits.len, 5307 tdata->auth.offset_bits, 5308 op_mode, 1, verify); 5309 5310 if (retval < 0) 5311 return retval; 5312 5313 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5314 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5315 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5316 else 5317 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5318 ut_params->op); 5319 5320 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5321 5322 ut_params->obuf = (op_mode == IN_PLACE ? 5323 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5324 5325 if (verify) { 5326 if (ut_params->obuf) 5327 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5328 plaintext_len, buffer); 5329 else 5330 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5331 plaintext_len, buffer); 5332 5333 debug_hexdump(stdout, "plaintext:", plaintext, 5334 (tdata->plaintext.len >> 3) - tdata->digest.len); 5335 debug_hexdump(stdout, "plaintext expected:", 5336 tdata->plaintext.data, 5337 (tdata->plaintext.len >> 3) - tdata->digest.len); 5338 } else { 5339 if (ut_params->obuf) 5340 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5341 ciphertext_len, buffer); 5342 else 5343 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5344 ciphertext_len, buffer); 5345 5346 debug_hexdump(stdout, "ciphertext:", ciphertext, 5347 ciphertext_len); 5348 debug_hexdump(stdout, "ciphertext expected:", 5349 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5350 5351 if (ut_params->obuf) 5352 digest = rte_pktmbuf_read(ut_params->obuf, 5353 (tdata->digest.offset_bytes == 0 ? 5354 plaintext_pad_len : tdata->digest.offset_bytes), 5355 tdata->digest.len, digest_buffer); 5356 else 5357 digest = rte_pktmbuf_read(ut_params->ibuf, 5358 (tdata->digest.offset_bytes == 0 ? 5359 plaintext_pad_len : tdata->digest.offset_bytes), 5360 tdata->digest.len, digest_buffer); 5361 5362 debug_hexdump(stdout, "digest:", digest, 5363 tdata->digest.len); 5364 debug_hexdump(stdout, "digest expected:", 5365 tdata->digest.data, tdata->digest.len); 5366 } 5367 5368 /* Validate obuf */ 5369 if (verify) { 5370 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5371 plaintext, 5372 tdata->plaintext.data, 5373 (tdata->plaintext.len - tdata->cipher.offset_bits - 5374 (tdata->digest.len << 3)), 5375 tdata->cipher.offset_bits, 5376 "SNOW 3G Plaintext data not as expected"); 5377 } else { 5378 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5379 ciphertext, 5380 tdata->ciphertext.data, 5381 (tdata->validDataLenInBits.len - 5382 tdata->cipher.offset_bits), 5383 tdata->cipher.offset_bits, 5384 "SNOW 3G Ciphertext data not as expected"); 5385 5386 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5387 digest, 5388 tdata->digest.data, 5389 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5390 "SNOW 3G Generated auth tag not as expected"); 5391 } 5392 return 0; 5393 } 5394 5395 static int 5396 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5397 uint8_t op_mode, uint8_t verify) 5398 { 5399 struct crypto_testsuite_params *ts_params = &testsuite_params; 5400 struct crypto_unittest_params *ut_params = &unittest_params; 5401 5402 int retval; 5403 5404 uint8_t *plaintext = NULL, *ciphertext = NULL; 5405 unsigned int plaintext_pad_len; 5406 unsigned int plaintext_len; 5407 unsigned int ciphertext_pad_len; 5408 unsigned int ciphertext_len; 5409 5410 struct rte_cryptodev_info dev_info; 5411 5412 /* Verify the capabilities */ 5413 struct rte_cryptodev_sym_capability_idx cap_idx; 5414 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5415 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5416 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5417 &cap_idx) == NULL) 5418 return TEST_SKIPPED; 5419 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5420 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5421 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5422 &cap_idx) == NULL) 5423 return TEST_SKIPPED; 5424 5425 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5426 5427 uint64_t feat_flags = dev_info.feature_flags; 5428 5429 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5430 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5431 printf("Device doesn't support RAW data-path APIs.\n"); 5432 return TEST_SKIPPED; 5433 } 5434 5435 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5436 return TEST_SKIPPED; 5437 5438 if (op_mode == OUT_OF_PLACE) { 5439 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5440 return TEST_SKIPPED; 5441 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5442 printf("Device doesn't support digest encrypted.\n"); 5443 return TEST_SKIPPED; 5444 } 5445 } 5446 5447 /* Create KASUMI session */ 5448 retval = create_wireless_algo_auth_cipher_session( 5449 ts_params->valid_devs[0], 5450 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5451 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5452 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5453 : RTE_CRYPTO_AUTH_OP_GENERATE), 5454 RTE_CRYPTO_AUTH_KASUMI_F9, 5455 RTE_CRYPTO_CIPHER_KASUMI_F8, 5456 tdata->key.data, tdata->key.len, 5457 0, tdata->digest.len, 5458 tdata->cipher_iv.len); 5459 5460 if (retval != 0) 5461 return retval; 5462 5463 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5464 if (op_mode == OUT_OF_PLACE) 5465 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5466 5467 /* clear mbuf payload */ 5468 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5469 rte_pktmbuf_tailroom(ut_params->ibuf)); 5470 if (op_mode == OUT_OF_PLACE) 5471 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5472 rte_pktmbuf_tailroom(ut_params->obuf)); 5473 5474 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5475 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5476 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5477 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5478 5479 if (verify) { 5480 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5481 ciphertext_pad_len); 5482 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5483 if (op_mode == OUT_OF_PLACE) 5484 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5485 debug_hexdump(stdout, "ciphertext:", ciphertext, 5486 ciphertext_len); 5487 } else { 5488 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5489 plaintext_pad_len); 5490 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5491 if (op_mode == OUT_OF_PLACE) 5492 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5493 debug_hexdump(stdout, "plaintext:", plaintext, 5494 plaintext_len); 5495 } 5496 5497 /* Create KASUMI operation */ 5498 retval = create_wireless_algo_auth_cipher_operation( 5499 tdata->digest.data, tdata->digest.len, 5500 tdata->cipher_iv.data, tdata->cipher_iv.len, 5501 NULL, 0, 5502 (tdata->digest.offset_bytes == 0 ? 5503 (verify ? ciphertext_pad_len : plaintext_pad_len) 5504 : tdata->digest.offset_bytes), 5505 tdata->validCipherLenInBits.len, 5506 tdata->validCipherOffsetInBits.len, 5507 tdata->validAuthLenInBits.len, 5508 0, 5509 op_mode, 0, verify); 5510 5511 if (retval < 0) 5512 return retval; 5513 5514 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5515 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5516 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5517 else 5518 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5519 ut_params->op); 5520 5521 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5522 5523 ut_params->obuf = (op_mode == IN_PLACE ? 5524 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5525 5526 5527 if (verify) { 5528 if (ut_params->obuf) 5529 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5530 uint8_t *); 5531 else 5532 plaintext = ciphertext; 5533 5534 debug_hexdump(stdout, "plaintext:", plaintext, 5535 (tdata->plaintext.len >> 3) - tdata->digest.len); 5536 debug_hexdump(stdout, "plaintext expected:", 5537 tdata->plaintext.data, 5538 (tdata->plaintext.len >> 3) - tdata->digest.len); 5539 } else { 5540 if (ut_params->obuf) 5541 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5542 uint8_t *); 5543 else 5544 ciphertext = plaintext; 5545 5546 debug_hexdump(stdout, "ciphertext:", ciphertext, 5547 ciphertext_len); 5548 debug_hexdump(stdout, "ciphertext expected:", 5549 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5550 5551 ut_params->digest = rte_pktmbuf_mtod( 5552 ut_params->obuf, uint8_t *) + 5553 (tdata->digest.offset_bytes == 0 ? 5554 plaintext_pad_len : tdata->digest.offset_bytes); 5555 5556 debug_hexdump(stdout, "digest:", ut_params->digest, 5557 tdata->digest.len); 5558 debug_hexdump(stdout, "digest expected:", 5559 tdata->digest.data, tdata->digest.len); 5560 } 5561 5562 /* Validate obuf */ 5563 if (verify) { 5564 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5565 plaintext, 5566 tdata->plaintext.data, 5567 tdata->plaintext.len >> 3, 5568 "KASUMI Plaintext data not as expected"); 5569 } else { 5570 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5571 ciphertext, 5572 tdata->ciphertext.data, 5573 tdata->ciphertext.len >> 3, 5574 "KASUMI Ciphertext data not as expected"); 5575 5576 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5577 ut_params->digest, 5578 tdata->digest.data, 5579 DIGEST_BYTE_LENGTH_KASUMI_F9, 5580 "KASUMI Generated auth tag not as expected"); 5581 } 5582 return 0; 5583 } 5584 5585 static int 5586 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5587 uint8_t op_mode, uint8_t verify) 5588 { 5589 struct crypto_testsuite_params *ts_params = &testsuite_params; 5590 struct crypto_unittest_params *ut_params = &unittest_params; 5591 5592 int retval; 5593 5594 const uint8_t *plaintext = NULL; 5595 const uint8_t *ciphertext = NULL; 5596 const uint8_t *digest = NULL; 5597 unsigned int plaintext_pad_len; 5598 unsigned int plaintext_len; 5599 unsigned int ciphertext_pad_len; 5600 unsigned int ciphertext_len; 5601 uint8_t buffer[10000]; 5602 uint8_t digest_buffer[10000]; 5603 5604 struct rte_cryptodev_info dev_info; 5605 5606 /* Verify the capabilities */ 5607 struct rte_cryptodev_sym_capability_idx cap_idx; 5608 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5609 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5610 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5611 &cap_idx) == NULL) 5612 return TEST_SKIPPED; 5613 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5614 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5615 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5616 &cap_idx) == NULL) 5617 return TEST_SKIPPED; 5618 5619 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5620 return TEST_SKIPPED; 5621 5622 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5623 5624 uint64_t feat_flags = dev_info.feature_flags; 5625 5626 if (op_mode == IN_PLACE) { 5627 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5628 printf("Device doesn't support in-place scatter-gather " 5629 "in both input and output mbufs.\n"); 5630 return TEST_SKIPPED; 5631 } 5632 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5633 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5634 printf("Device doesn't support RAW data-path APIs.\n"); 5635 return TEST_SKIPPED; 5636 } 5637 } else { 5638 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5639 return TEST_SKIPPED; 5640 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5641 printf("Device doesn't support out-of-place scatter-gather " 5642 "in both input and output mbufs.\n"); 5643 return TEST_SKIPPED; 5644 } 5645 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5646 printf("Device doesn't support digest encrypted.\n"); 5647 return TEST_SKIPPED; 5648 } 5649 } 5650 5651 /* Create KASUMI session */ 5652 retval = create_wireless_algo_auth_cipher_session( 5653 ts_params->valid_devs[0], 5654 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5655 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5656 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5657 : RTE_CRYPTO_AUTH_OP_GENERATE), 5658 RTE_CRYPTO_AUTH_KASUMI_F9, 5659 RTE_CRYPTO_CIPHER_KASUMI_F8, 5660 tdata->key.data, tdata->key.len, 5661 0, tdata->digest.len, 5662 tdata->cipher_iv.len); 5663 5664 if (retval != 0) 5665 return retval; 5666 5667 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5668 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5669 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5670 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5671 5672 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5673 plaintext_pad_len, 15, 0); 5674 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5675 "Failed to allocate input buffer in mempool"); 5676 5677 if (op_mode == OUT_OF_PLACE) { 5678 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5679 plaintext_pad_len, 15, 0); 5680 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5681 "Failed to allocate output buffer in mempool"); 5682 } 5683 5684 if (verify) { 5685 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5686 tdata->ciphertext.data); 5687 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5688 ciphertext_len, buffer); 5689 debug_hexdump(stdout, "ciphertext:", ciphertext, 5690 ciphertext_len); 5691 } else { 5692 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5693 tdata->plaintext.data); 5694 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5695 plaintext_len, buffer); 5696 debug_hexdump(stdout, "plaintext:", plaintext, 5697 plaintext_len); 5698 } 5699 memset(buffer, 0, sizeof(buffer)); 5700 5701 /* Create KASUMI operation */ 5702 retval = create_wireless_algo_auth_cipher_operation( 5703 tdata->digest.data, tdata->digest.len, 5704 tdata->cipher_iv.data, tdata->cipher_iv.len, 5705 NULL, 0, 5706 (tdata->digest.offset_bytes == 0 ? 5707 (verify ? ciphertext_pad_len : plaintext_pad_len) 5708 : tdata->digest.offset_bytes), 5709 tdata->validCipherLenInBits.len, 5710 tdata->validCipherOffsetInBits.len, 5711 tdata->validAuthLenInBits.len, 5712 0, 5713 op_mode, 1, verify); 5714 5715 if (retval < 0) 5716 return retval; 5717 5718 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5719 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5720 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5721 else 5722 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5723 ut_params->op); 5724 5725 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5726 5727 ut_params->obuf = (op_mode == IN_PLACE ? 5728 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5729 5730 if (verify) { 5731 if (ut_params->obuf) 5732 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5733 plaintext_len, buffer); 5734 else 5735 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5736 plaintext_len, buffer); 5737 5738 debug_hexdump(stdout, "plaintext:", plaintext, 5739 (tdata->plaintext.len >> 3) - tdata->digest.len); 5740 debug_hexdump(stdout, "plaintext expected:", 5741 tdata->plaintext.data, 5742 (tdata->plaintext.len >> 3) - tdata->digest.len); 5743 } else { 5744 if (ut_params->obuf) 5745 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5746 ciphertext_len, buffer); 5747 else 5748 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5749 ciphertext_len, buffer); 5750 5751 debug_hexdump(stdout, "ciphertext:", ciphertext, 5752 ciphertext_len); 5753 debug_hexdump(stdout, "ciphertext expected:", 5754 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5755 5756 if (ut_params->obuf) 5757 digest = rte_pktmbuf_read(ut_params->obuf, 5758 (tdata->digest.offset_bytes == 0 ? 5759 plaintext_pad_len : tdata->digest.offset_bytes), 5760 tdata->digest.len, digest_buffer); 5761 else 5762 digest = rte_pktmbuf_read(ut_params->ibuf, 5763 (tdata->digest.offset_bytes == 0 ? 5764 plaintext_pad_len : tdata->digest.offset_bytes), 5765 tdata->digest.len, digest_buffer); 5766 5767 debug_hexdump(stdout, "digest:", digest, 5768 tdata->digest.len); 5769 debug_hexdump(stdout, "digest expected:", 5770 tdata->digest.data, tdata->digest.len); 5771 } 5772 5773 /* Validate obuf */ 5774 if (verify) { 5775 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5776 plaintext, 5777 tdata->plaintext.data, 5778 tdata->plaintext.len >> 3, 5779 "KASUMI Plaintext data not as expected"); 5780 } else { 5781 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5782 ciphertext, 5783 tdata->ciphertext.data, 5784 tdata->validDataLenInBits.len, 5785 "KASUMI Ciphertext data not as expected"); 5786 5787 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5788 digest, 5789 tdata->digest.data, 5790 DIGEST_BYTE_LENGTH_KASUMI_F9, 5791 "KASUMI Generated auth tag not as expected"); 5792 } 5793 return 0; 5794 } 5795 5796 static int 5797 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5798 { 5799 struct crypto_testsuite_params *ts_params = &testsuite_params; 5800 struct crypto_unittest_params *ut_params = &unittest_params; 5801 5802 int retval; 5803 5804 uint8_t *plaintext, *ciphertext; 5805 unsigned plaintext_pad_len; 5806 unsigned plaintext_len; 5807 struct rte_cryptodev_info dev_info; 5808 5809 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5810 uint64_t feat_flags = dev_info.feature_flags; 5811 5812 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5813 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5814 printf("Device doesn't support RAW data-path APIs.\n"); 5815 return TEST_SKIPPED; 5816 } 5817 5818 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5819 return TEST_SKIPPED; 5820 5821 /* Verify the capabilities */ 5822 struct rte_cryptodev_sym_capability_idx cap_idx; 5823 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5824 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5825 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5826 &cap_idx) == NULL) 5827 return TEST_SKIPPED; 5828 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5829 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5830 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5831 &cap_idx) == NULL) 5832 return TEST_SKIPPED; 5833 5834 /* Create KASUMI session */ 5835 retval = create_wireless_algo_cipher_auth_session( 5836 ts_params->valid_devs[0], 5837 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5838 RTE_CRYPTO_AUTH_OP_GENERATE, 5839 RTE_CRYPTO_AUTH_KASUMI_F9, 5840 RTE_CRYPTO_CIPHER_KASUMI_F8, 5841 tdata->key.data, tdata->key.len, 5842 0, tdata->digest.len, 5843 tdata->cipher_iv.len); 5844 if (retval != 0) 5845 return retval; 5846 5847 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5848 5849 /* clear mbuf payload */ 5850 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5851 rte_pktmbuf_tailroom(ut_params->ibuf)); 5852 5853 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5854 /* Append data which is padded to a multiple of */ 5855 /* the algorithms block size */ 5856 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5857 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5858 plaintext_pad_len); 5859 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5860 5861 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5862 5863 /* Create KASUMI operation */ 5864 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5865 tdata->digest.len, NULL, 0, 5866 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5867 tdata->cipher_iv.data, tdata->cipher_iv.len, 5868 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5869 tdata->validCipherOffsetInBits.len, 5870 tdata->validAuthLenInBits.len, 5871 0 5872 ); 5873 if (retval < 0) 5874 return retval; 5875 5876 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5877 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5878 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5879 else 5880 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5881 ut_params->op); 5882 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5883 5884 if (ut_params->op->sym->m_dst) 5885 ut_params->obuf = ut_params->op->sym->m_dst; 5886 else 5887 ut_params->obuf = ut_params->op->sym->m_src; 5888 5889 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5890 tdata->validCipherOffsetInBits.len >> 3); 5891 5892 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5893 + plaintext_pad_len; 5894 5895 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5896 (tdata->validCipherOffsetInBits.len >> 3); 5897 /* Validate obuf */ 5898 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5899 ciphertext, 5900 reference_ciphertext, 5901 tdata->validCipherLenInBits.len, 5902 "KASUMI Ciphertext data not as expected"); 5903 5904 /* Validate obuf */ 5905 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5906 ut_params->digest, 5907 tdata->digest.data, 5908 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5909 "KASUMI Generated auth tag not as expected"); 5910 return 0; 5911 } 5912 5913 static int 5914 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5915 const enum rte_crypto_cipher_algorithm cipher_algo, 5916 const uint16_t key_size, const uint16_t iv_size) 5917 { 5918 struct rte_cryptodev_sym_capability_idx cap_idx; 5919 const struct rte_cryptodev_symmetric_capability *cap; 5920 5921 /* Check if device supports the algorithm */ 5922 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5923 cap_idx.algo.cipher = cipher_algo; 5924 5925 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5926 &cap_idx); 5927 5928 if (cap == NULL) 5929 return -1; 5930 5931 /* Check if device supports key size and IV size */ 5932 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5933 iv_size) < 0) { 5934 return -1; 5935 } 5936 5937 return 0; 5938 } 5939 5940 static int 5941 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5942 const enum rte_crypto_auth_algorithm auth_algo, 5943 const uint16_t key_size, const uint16_t iv_size, 5944 const uint16_t tag_size) 5945 { 5946 struct rte_cryptodev_sym_capability_idx cap_idx; 5947 const struct rte_cryptodev_symmetric_capability *cap; 5948 5949 /* Check if device supports the algorithm */ 5950 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5951 cap_idx.algo.auth = auth_algo; 5952 5953 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5954 &cap_idx); 5955 5956 if (cap == NULL) 5957 return -1; 5958 5959 /* Check if device supports key size and IV size */ 5960 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5961 tag_size, iv_size) < 0) { 5962 return -1; 5963 } 5964 5965 return 0; 5966 } 5967 5968 static int 5969 test_zuc_encryption(const struct wireless_test_data *tdata) 5970 { 5971 struct crypto_testsuite_params *ts_params = &testsuite_params; 5972 struct crypto_unittest_params *ut_params = &unittest_params; 5973 5974 int retval; 5975 uint8_t *plaintext, *ciphertext; 5976 unsigned plaintext_pad_len; 5977 unsigned plaintext_len; 5978 struct rte_cryptodev_info dev_info; 5979 5980 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5981 uint64_t feat_flags = dev_info.feature_flags; 5982 5983 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5984 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5985 printf("Device doesn't support RAW data-path APIs.\n"); 5986 return TEST_SKIPPED; 5987 } 5988 5989 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5990 return TEST_SKIPPED; 5991 5992 /* Check if device supports ZUC EEA3 */ 5993 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5994 tdata->key.len, tdata->cipher_iv.len) < 0) 5995 return TEST_SKIPPED; 5996 5997 /* Create ZUC session */ 5998 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5999 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6000 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6001 tdata->key.data, tdata->key.len, 6002 tdata->cipher_iv.len); 6003 if (retval != 0) 6004 return retval; 6005 6006 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6007 6008 /* Clear mbuf payload */ 6009 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6010 rte_pktmbuf_tailroom(ut_params->ibuf)); 6011 6012 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6013 /* Append data which is padded to a multiple */ 6014 /* of the algorithms block size */ 6015 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6016 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6017 plaintext_pad_len); 6018 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6019 6020 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6021 6022 /* Create ZUC operation */ 6023 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6024 tdata->cipher_iv.len, 6025 tdata->plaintext.len, 6026 0); 6027 if (retval < 0) 6028 return retval; 6029 6030 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6031 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6032 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6033 else 6034 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6035 ut_params->op); 6036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6037 6038 ut_params->obuf = ut_params->op->sym->m_dst; 6039 if (ut_params->obuf) 6040 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6041 else 6042 ciphertext = plaintext; 6043 6044 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6045 6046 /* Validate obuf */ 6047 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6048 ciphertext, 6049 tdata->ciphertext.data, 6050 tdata->validCipherLenInBits.len, 6051 "ZUC Ciphertext data not as expected"); 6052 return 0; 6053 } 6054 6055 static int 6056 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6057 { 6058 struct crypto_testsuite_params *ts_params = &testsuite_params; 6059 struct crypto_unittest_params *ut_params = &unittest_params; 6060 6061 int retval; 6062 6063 unsigned int plaintext_pad_len; 6064 unsigned int plaintext_len; 6065 const uint8_t *ciphertext; 6066 uint8_t ciphertext_buffer[2048]; 6067 struct rte_cryptodev_info dev_info; 6068 6069 /* Check if device supports ZUC EEA3 */ 6070 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6071 tdata->key.len, tdata->cipher_iv.len) < 0) 6072 return TEST_SKIPPED; 6073 6074 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6075 return TEST_SKIPPED; 6076 6077 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6078 6079 uint64_t feat_flags = dev_info.feature_flags; 6080 6081 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6082 printf("Device doesn't support in-place scatter-gather. " 6083 "Test Skipped.\n"); 6084 return TEST_SKIPPED; 6085 } 6086 6087 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6088 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6089 printf("Device doesn't support RAW data-path APIs.\n"); 6090 return TEST_SKIPPED; 6091 } 6092 6093 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6094 6095 /* Append data which is padded to a multiple */ 6096 /* of the algorithms block size */ 6097 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6098 6099 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6100 plaintext_pad_len, 10, 0); 6101 6102 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6103 tdata->plaintext.data); 6104 6105 /* Create ZUC session */ 6106 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6107 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6108 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6109 tdata->key.data, tdata->key.len, 6110 tdata->cipher_iv.len); 6111 if (retval < 0) 6112 return retval; 6113 6114 /* Clear mbuf payload */ 6115 6116 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6117 6118 /* Create ZUC operation */ 6119 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6120 tdata->cipher_iv.len, tdata->plaintext.len, 6121 0); 6122 if (retval < 0) 6123 return retval; 6124 6125 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6126 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6127 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6128 else 6129 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6130 ut_params->op); 6131 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6132 6133 ut_params->obuf = ut_params->op->sym->m_dst; 6134 if (ut_params->obuf) 6135 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6136 0, plaintext_len, ciphertext_buffer); 6137 else 6138 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6139 0, plaintext_len, ciphertext_buffer); 6140 6141 /* Validate obuf */ 6142 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6143 6144 /* Validate obuf */ 6145 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6146 ciphertext, 6147 tdata->ciphertext.data, 6148 tdata->validCipherLenInBits.len, 6149 "ZUC Ciphertext data not as expected"); 6150 6151 return 0; 6152 } 6153 6154 static int 6155 test_zuc_authentication(const struct wireless_test_data *tdata) 6156 { 6157 struct crypto_testsuite_params *ts_params = &testsuite_params; 6158 struct crypto_unittest_params *ut_params = &unittest_params; 6159 6160 int retval; 6161 unsigned plaintext_pad_len; 6162 unsigned plaintext_len; 6163 uint8_t *plaintext; 6164 6165 struct rte_cryptodev_info dev_info; 6166 6167 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6168 uint64_t feat_flags = dev_info.feature_flags; 6169 6170 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6171 (tdata->validAuthLenInBits.len % 8 != 0)) { 6172 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6173 return TEST_SKIPPED; 6174 } 6175 6176 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6177 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6178 printf("Device doesn't support RAW data-path APIs.\n"); 6179 return TEST_SKIPPED; 6180 } 6181 6182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6183 return TEST_SKIPPED; 6184 6185 /* Check if device supports ZUC EIA3 */ 6186 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6187 tdata->key.len, tdata->auth_iv.len, 6188 tdata->digest.len) < 0) 6189 return TEST_SKIPPED; 6190 6191 /* Create ZUC session */ 6192 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6193 tdata->key.data, tdata->key.len, 6194 tdata->auth_iv.len, tdata->digest.len, 6195 RTE_CRYPTO_AUTH_OP_GENERATE, 6196 RTE_CRYPTO_AUTH_ZUC_EIA3); 6197 if (retval != 0) 6198 return retval; 6199 6200 /* alloc mbuf and set payload */ 6201 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6202 6203 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6204 rte_pktmbuf_tailroom(ut_params->ibuf)); 6205 6206 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6207 /* Append data which is padded to a multiple of */ 6208 /* the algorithms block size */ 6209 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6210 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6211 plaintext_pad_len); 6212 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6213 6214 /* Create ZUC operation */ 6215 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6216 tdata->auth_iv.data, tdata->auth_iv.len, 6217 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6218 tdata->validAuthLenInBits.len, 6219 0); 6220 if (retval < 0) 6221 return retval; 6222 6223 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6224 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6225 ut_params->op, 0, 1, 1, 0); 6226 else 6227 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6228 ut_params->op); 6229 ut_params->obuf = ut_params->op->sym->m_src; 6230 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6231 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6232 + plaintext_pad_len; 6233 6234 /* Validate obuf */ 6235 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6236 ut_params->digest, 6237 tdata->digest.data, 6238 tdata->digest.len, 6239 "ZUC Generated auth tag not as expected"); 6240 6241 return 0; 6242 } 6243 6244 static int 6245 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6246 uint8_t op_mode, uint8_t verify) 6247 { 6248 struct crypto_testsuite_params *ts_params = &testsuite_params; 6249 struct crypto_unittest_params *ut_params = &unittest_params; 6250 6251 int retval; 6252 6253 uint8_t *plaintext = NULL, *ciphertext = NULL; 6254 unsigned int plaintext_pad_len; 6255 unsigned int plaintext_len; 6256 unsigned int ciphertext_pad_len; 6257 unsigned int ciphertext_len; 6258 6259 struct rte_cryptodev_info dev_info; 6260 6261 /* Check if device supports ZUC EEA3 */ 6262 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6263 tdata->key.len, tdata->cipher_iv.len) < 0) 6264 return TEST_SKIPPED; 6265 6266 /* Check if device supports ZUC EIA3 */ 6267 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6268 tdata->key.len, tdata->auth_iv.len, 6269 tdata->digest.len) < 0) 6270 return TEST_SKIPPED; 6271 6272 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6273 6274 uint64_t feat_flags = dev_info.feature_flags; 6275 6276 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6277 printf("Device doesn't support digest encrypted.\n"); 6278 return TEST_SKIPPED; 6279 } 6280 if (op_mode == IN_PLACE) { 6281 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6282 printf("Device doesn't support in-place scatter-gather " 6283 "in both input and output mbufs.\n"); 6284 return TEST_SKIPPED; 6285 } 6286 6287 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6288 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6289 printf("Device doesn't support RAW data-path APIs.\n"); 6290 return TEST_SKIPPED; 6291 } 6292 } else { 6293 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6294 return TEST_SKIPPED; 6295 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6296 printf("Device doesn't support out-of-place scatter-gather " 6297 "in both input and output mbufs.\n"); 6298 return TEST_SKIPPED; 6299 } 6300 } 6301 6302 /* Create ZUC session */ 6303 retval = create_wireless_algo_auth_cipher_session( 6304 ts_params->valid_devs[0], 6305 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6306 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6307 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6308 : RTE_CRYPTO_AUTH_OP_GENERATE), 6309 RTE_CRYPTO_AUTH_ZUC_EIA3, 6310 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6311 tdata->key.data, tdata->key.len, 6312 tdata->auth_iv.len, tdata->digest.len, 6313 tdata->cipher_iv.len); 6314 6315 if (retval != 0) 6316 return retval; 6317 6318 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6319 if (op_mode == OUT_OF_PLACE) 6320 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6321 6322 /* clear mbuf payload */ 6323 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6324 rte_pktmbuf_tailroom(ut_params->ibuf)); 6325 if (op_mode == OUT_OF_PLACE) 6326 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6327 rte_pktmbuf_tailroom(ut_params->obuf)); 6328 6329 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6330 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6331 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6332 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6333 6334 if (verify) { 6335 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6336 ciphertext_pad_len); 6337 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6338 debug_hexdump(stdout, "ciphertext:", ciphertext, 6339 ciphertext_len); 6340 } else { 6341 /* make sure enough space to cover partial digest verify case */ 6342 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6343 ciphertext_pad_len); 6344 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6345 debug_hexdump(stdout, "plaintext:", plaintext, 6346 plaintext_len); 6347 } 6348 6349 if (op_mode == OUT_OF_PLACE) 6350 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6351 6352 /* Create ZUC operation */ 6353 retval = create_wireless_algo_auth_cipher_operation( 6354 tdata->digest.data, tdata->digest.len, 6355 tdata->cipher_iv.data, tdata->cipher_iv.len, 6356 tdata->auth_iv.data, tdata->auth_iv.len, 6357 (tdata->digest.offset_bytes == 0 ? 6358 (verify ? ciphertext_pad_len : plaintext_pad_len) 6359 : tdata->digest.offset_bytes), 6360 tdata->validCipherLenInBits.len, 6361 tdata->validCipherOffsetInBits.len, 6362 tdata->validAuthLenInBits.len, 6363 0, 6364 op_mode, 0, verify); 6365 6366 if (retval < 0) 6367 return retval; 6368 6369 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6370 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6371 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6372 else 6373 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6374 ut_params->op); 6375 6376 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6377 6378 ut_params->obuf = (op_mode == IN_PLACE ? 6379 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6380 6381 6382 if (verify) { 6383 if (ut_params->obuf) 6384 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6385 uint8_t *); 6386 else 6387 plaintext = ciphertext; 6388 6389 debug_hexdump(stdout, "plaintext:", plaintext, 6390 (tdata->plaintext.len >> 3) - tdata->digest.len); 6391 debug_hexdump(stdout, "plaintext expected:", 6392 tdata->plaintext.data, 6393 (tdata->plaintext.len >> 3) - tdata->digest.len); 6394 } else { 6395 if (ut_params->obuf) 6396 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6397 uint8_t *); 6398 else 6399 ciphertext = plaintext; 6400 6401 debug_hexdump(stdout, "ciphertext:", ciphertext, 6402 ciphertext_len); 6403 debug_hexdump(stdout, "ciphertext expected:", 6404 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6405 6406 ut_params->digest = rte_pktmbuf_mtod( 6407 ut_params->obuf, uint8_t *) + 6408 (tdata->digest.offset_bytes == 0 ? 6409 plaintext_pad_len : tdata->digest.offset_bytes); 6410 6411 debug_hexdump(stdout, "digest:", ut_params->digest, 6412 tdata->digest.len); 6413 debug_hexdump(stdout, "digest expected:", 6414 tdata->digest.data, tdata->digest.len); 6415 } 6416 6417 /* Validate obuf */ 6418 if (verify) { 6419 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6420 plaintext, 6421 tdata->plaintext.data, 6422 tdata->plaintext.len >> 3, 6423 "ZUC Plaintext data not as expected"); 6424 } else { 6425 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6426 ciphertext, 6427 tdata->ciphertext.data, 6428 tdata->ciphertext.len >> 3, 6429 "ZUC Ciphertext data not as expected"); 6430 6431 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6432 ut_params->digest, 6433 tdata->digest.data, 6434 DIGEST_BYTE_LENGTH_KASUMI_F9, 6435 "ZUC Generated auth tag not as expected"); 6436 } 6437 return 0; 6438 } 6439 6440 static int 6441 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6442 uint8_t op_mode, uint8_t verify) 6443 { 6444 struct crypto_testsuite_params *ts_params = &testsuite_params; 6445 struct crypto_unittest_params *ut_params = &unittest_params; 6446 6447 int retval; 6448 6449 const uint8_t *plaintext = NULL; 6450 const uint8_t *ciphertext = NULL; 6451 const uint8_t *digest = NULL; 6452 unsigned int plaintext_pad_len; 6453 unsigned int plaintext_len; 6454 unsigned int ciphertext_pad_len; 6455 unsigned int ciphertext_len; 6456 uint8_t buffer[10000]; 6457 uint8_t digest_buffer[10000]; 6458 6459 struct rte_cryptodev_info dev_info; 6460 6461 /* Check if device supports ZUC EEA3 */ 6462 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6463 tdata->key.len, tdata->cipher_iv.len) < 0) 6464 return TEST_SKIPPED; 6465 6466 /* Check if device supports ZUC EIA3 */ 6467 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6468 tdata->key.len, tdata->auth_iv.len, 6469 tdata->digest.len) < 0) 6470 return TEST_SKIPPED; 6471 6472 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6473 6474 uint64_t feat_flags = dev_info.feature_flags; 6475 6476 if (op_mode == IN_PLACE) { 6477 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6478 printf("Device doesn't support in-place scatter-gather " 6479 "in both input and output mbufs.\n"); 6480 return TEST_SKIPPED; 6481 } 6482 6483 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6484 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6485 printf("Device doesn't support RAW data-path APIs.\n"); 6486 return TEST_SKIPPED; 6487 } 6488 } else { 6489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6490 return TEST_SKIPPED; 6491 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6492 printf("Device doesn't support out-of-place scatter-gather " 6493 "in both input and output mbufs.\n"); 6494 return TEST_SKIPPED; 6495 } 6496 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6497 printf("Device doesn't support digest encrypted.\n"); 6498 return TEST_SKIPPED; 6499 } 6500 } 6501 6502 /* Create ZUC session */ 6503 retval = create_wireless_algo_auth_cipher_session( 6504 ts_params->valid_devs[0], 6505 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6506 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6507 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6508 : RTE_CRYPTO_AUTH_OP_GENERATE), 6509 RTE_CRYPTO_AUTH_ZUC_EIA3, 6510 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6511 tdata->key.data, tdata->key.len, 6512 tdata->auth_iv.len, tdata->digest.len, 6513 tdata->cipher_iv.len); 6514 6515 if (retval != 0) 6516 return retval; 6517 6518 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6519 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6520 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6521 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6522 6523 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6524 plaintext_pad_len, 15, 0); 6525 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6526 "Failed to allocate input buffer in mempool"); 6527 6528 if (op_mode == OUT_OF_PLACE) { 6529 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6530 plaintext_pad_len, 15, 0); 6531 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6532 "Failed to allocate output buffer in mempool"); 6533 } 6534 6535 if (verify) { 6536 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6537 tdata->ciphertext.data); 6538 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6539 ciphertext_len, buffer); 6540 debug_hexdump(stdout, "ciphertext:", ciphertext, 6541 ciphertext_len); 6542 } else { 6543 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6544 tdata->plaintext.data); 6545 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6546 plaintext_len, buffer); 6547 debug_hexdump(stdout, "plaintext:", plaintext, 6548 plaintext_len); 6549 } 6550 memset(buffer, 0, sizeof(buffer)); 6551 6552 /* Create ZUC operation */ 6553 retval = create_wireless_algo_auth_cipher_operation( 6554 tdata->digest.data, tdata->digest.len, 6555 tdata->cipher_iv.data, tdata->cipher_iv.len, 6556 NULL, 0, 6557 (tdata->digest.offset_bytes == 0 ? 6558 (verify ? ciphertext_pad_len : plaintext_pad_len) 6559 : tdata->digest.offset_bytes), 6560 tdata->validCipherLenInBits.len, 6561 tdata->validCipherOffsetInBits.len, 6562 tdata->validAuthLenInBits.len, 6563 0, 6564 op_mode, 1, verify); 6565 6566 if (retval < 0) 6567 return retval; 6568 6569 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6570 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6571 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6572 else 6573 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6574 ut_params->op); 6575 6576 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6577 6578 ut_params->obuf = (op_mode == IN_PLACE ? 6579 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6580 6581 if (verify) { 6582 if (ut_params->obuf) 6583 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6584 plaintext_len, buffer); 6585 else 6586 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6587 plaintext_len, buffer); 6588 6589 debug_hexdump(stdout, "plaintext:", plaintext, 6590 (tdata->plaintext.len >> 3) - tdata->digest.len); 6591 debug_hexdump(stdout, "plaintext expected:", 6592 tdata->plaintext.data, 6593 (tdata->plaintext.len >> 3) - tdata->digest.len); 6594 } else { 6595 if (ut_params->obuf) 6596 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6597 ciphertext_len, buffer); 6598 else 6599 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6600 ciphertext_len, buffer); 6601 6602 debug_hexdump(stdout, "ciphertext:", ciphertext, 6603 ciphertext_len); 6604 debug_hexdump(stdout, "ciphertext expected:", 6605 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6606 6607 if (ut_params->obuf) 6608 digest = rte_pktmbuf_read(ut_params->obuf, 6609 (tdata->digest.offset_bytes == 0 ? 6610 plaintext_pad_len : tdata->digest.offset_bytes), 6611 tdata->digest.len, digest_buffer); 6612 else 6613 digest = rte_pktmbuf_read(ut_params->ibuf, 6614 (tdata->digest.offset_bytes == 0 ? 6615 plaintext_pad_len : tdata->digest.offset_bytes), 6616 tdata->digest.len, digest_buffer); 6617 6618 debug_hexdump(stdout, "digest:", digest, 6619 tdata->digest.len); 6620 debug_hexdump(stdout, "digest expected:", 6621 tdata->digest.data, tdata->digest.len); 6622 } 6623 6624 /* Validate obuf */ 6625 if (verify) { 6626 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6627 plaintext, 6628 tdata->plaintext.data, 6629 tdata->plaintext.len >> 3, 6630 "ZUC Plaintext data not as expected"); 6631 } else { 6632 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6633 ciphertext, 6634 tdata->ciphertext.data, 6635 tdata->validDataLenInBits.len, 6636 "ZUC Ciphertext data not as expected"); 6637 6638 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6639 digest, 6640 tdata->digest.data, 6641 DIGEST_BYTE_LENGTH_KASUMI_F9, 6642 "ZUC Generated auth tag not as expected"); 6643 } 6644 return 0; 6645 } 6646 6647 static int 6648 test_kasumi_encryption_test_case_1(void) 6649 { 6650 return test_kasumi_encryption(&kasumi_test_case_1); 6651 } 6652 6653 static int 6654 test_kasumi_encryption_test_case_1_sgl(void) 6655 { 6656 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6657 } 6658 6659 static int 6660 test_kasumi_encryption_test_case_1_oop(void) 6661 { 6662 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6663 } 6664 6665 static int 6666 test_kasumi_encryption_test_case_1_oop_sgl(void) 6667 { 6668 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6669 } 6670 6671 static int 6672 test_kasumi_encryption_test_case_2(void) 6673 { 6674 return test_kasumi_encryption(&kasumi_test_case_2); 6675 } 6676 6677 static int 6678 test_kasumi_encryption_test_case_3(void) 6679 { 6680 return test_kasumi_encryption(&kasumi_test_case_3); 6681 } 6682 6683 static int 6684 test_kasumi_encryption_test_case_4(void) 6685 { 6686 return test_kasumi_encryption(&kasumi_test_case_4); 6687 } 6688 6689 static int 6690 test_kasumi_encryption_test_case_5(void) 6691 { 6692 return test_kasumi_encryption(&kasumi_test_case_5); 6693 } 6694 6695 static int 6696 test_kasumi_decryption_test_case_1(void) 6697 { 6698 return test_kasumi_decryption(&kasumi_test_case_1); 6699 } 6700 6701 static int 6702 test_kasumi_decryption_test_case_1_oop(void) 6703 { 6704 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6705 } 6706 6707 static int 6708 test_kasumi_decryption_test_case_2(void) 6709 { 6710 return test_kasumi_decryption(&kasumi_test_case_2); 6711 } 6712 6713 static int 6714 test_kasumi_decryption_test_case_3(void) 6715 { 6716 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6717 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6718 return TEST_SKIPPED; 6719 return test_kasumi_decryption(&kasumi_test_case_3); 6720 } 6721 6722 static int 6723 test_kasumi_decryption_test_case_4(void) 6724 { 6725 return test_kasumi_decryption(&kasumi_test_case_4); 6726 } 6727 6728 static int 6729 test_kasumi_decryption_test_case_5(void) 6730 { 6731 return test_kasumi_decryption(&kasumi_test_case_5); 6732 } 6733 static int 6734 test_snow3g_encryption_test_case_1(void) 6735 { 6736 return test_snow3g_encryption(&snow3g_test_case_1); 6737 } 6738 6739 static int 6740 test_snow3g_encryption_test_case_1_oop(void) 6741 { 6742 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6743 } 6744 6745 static int 6746 test_snow3g_encryption_test_case_1_oop_sgl(void) 6747 { 6748 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6749 } 6750 6751 6752 static int 6753 test_snow3g_encryption_test_case_1_offset_oop(void) 6754 { 6755 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6756 } 6757 6758 static int 6759 test_snow3g_encryption_test_case_2(void) 6760 { 6761 return test_snow3g_encryption(&snow3g_test_case_2); 6762 } 6763 6764 static int 6765 test_snow3g_encryption_test_case_3(void) 6766 { 6767 return test_snow3g_encryption(&snow3g_test_case_3); 6768 } 6769 6770 static int 6771 test_snow3g_encryption_test_case_4(void) 6772 { 6773 return test_snow3g_encryption(&snow3g_test_case_4); 6774 } 6775 6776 static int 6777 test_snow3g_encryption_test_case_5(void) 6778 { 6779 return test_snow3g_encryption(&snow3g_test_case_5); 6780 } 6781 6782 static int 6783 test_snow3g_decryption_test_case_1(void) 6784 { 6785 return test_snow3g_decryption(&snow3g_test_case_1); 6786 } 6787 6788 static int 6789 test_snow3g_decryption_test_case_1_oop(void) 6790 { 6791 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6792 } 6793 6794 static int 6795 test_snow3g_decryption_test_case_2(void) 6796 { 6797 return test_snow3g_decryption(&snow3g_test_case_2); 6798 } 6799 6800 static int 6801 test_snow3g_decryption_test_case_3(void) 6802 { 6803 return test_snow3g_decryption(&snow3g_test_case_3); 6804 } 6805 6806 static int 6807 test_snow3g_decryption_test_case_4(void) 6808 { 6809 return test_snow3g_decryption(&snow3g_test_case_4); 6810 } 6811 6812 static int 6813 test_snow3g_decryption_test_case_5(void) 6814 { 6815 return test_snow3g_decryption(&snow3g_test_case_5); 6816 } 6817 6818 /* 6819 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6820 * Pattern digest from snow3g_test_data must be allocated as 6821 * 4 last bytes in plaintext. 6822 */ 6823 static void 6824 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6825 struct snow3g_hash_test_data *output) 6826 { 6827 if ((pattern != NULL) && (output != NULL)) { 6828 output->key.len = pattern->key.len; 6829 6830 memcpy(output->key.data, 6831 pattern->key.data, pattern->key.len); 6832 6833 output->auth_iv.len = pattern->auth_iv.len; 6834 6835 memcpy(output->auth_iv.data, 6836 pattern->auth_iv.data, pattern->auth_iv.len); 6837 6838 output->plaintext.len = pattern->plaintext.len; 6839 6840 memcpy(output->plaintext.data, 6841 pattern->plaintext.data, pattern->plaintext.len >> 3); 6842 6843 output->digest.len = pattern->digest.len; 6844 6845 memcpy(output->digest.data, 6846 &pattern->plaintext.data[pattern->digest.offset_bytes], 6847 pattern->digest.len); 6848 6849 output->validAuthLenInBits.len = 6850 pattern->validAuthLenInBits.len; 6851 } 6852 } 6853 6854 /* 6855 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6856 */ 6857 static int 6858 test_snow3g_decryption_with_digest_test_case_1(void) 6859 { 6860 struct snow3g_hash_test_data snow3g_hash_data; 6861 struct rte_cryptodev_info dev_info; 6862 struct crypto_testsuite_params *ts_params = &testsuite_params; 6863 6864 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6865 uint64_t feat_flags = dev_info.feature_flags; 6866 6867 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6868 printf("Device doesn't support encrypted digest operations.\n"); 6869 return TEST_SKIPPED; 6870 } 6871 6872 /* 6873 * Function prepare data for hash verification test case. 6874 * Digest is allocated in 4 last bytes in plaintext, pattern. 6875 */ 6876 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6877 6878 return test_snow3g_decryption(&snow3g_test_case_7) & 6879 test_snow3g_authentication_verify(&snow3g_hash_data); 6880 } 6881 6882 static int 6883 test_snow3g_cipher_auth_test_case_1(void) 6884 { 6885 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6886 } 6887 6888 static int 6889 test_snow3g_auth_cipher_test_case_1(void) 6890 { 6891 return test_snow3g_auth_cipher( 6892 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6893 } 6894 6895 static int 6896 test_snow3g_auth_cipher_test_case_2(void) 6897 { 6898 return test_snow3g_auth_cipher( 6899 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6900 } 6901 6902 static int 6903 test_snow3g_auth_cipher_test_case_2_oop(void) 6904 { 6905 return test_snow3g_auth_cipher( 6906 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6907 } 6908 6909 static int 6910 test_snow3g_auth_cipher_part_digest_enc(void) 6911 { 6912 return test_snow3g_auth_cipher( 6913 &snow3g_auth_cipher_partial_digest_encryption, 6914 IN_PLACE, 0); 6915 } 6916 6917 static int 6918 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6919 { 6920 return test_snow3g_auth_cipher( 6921 &snow3g_auth_cipher_partial_digest_encryption, 6922 OUT_OF_PLACE, 0); 6923 } 6924 6925 static int 6926 test_snow3g_auth_cipher_test_case_3_sgl(void) 6927 { 6928 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6929 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6930 return TEST_SKIPPED; 6931 return test_snow3g_auth_cipher_sgl( 6932 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6933 } 6934 6935 static int 6936 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6937 { 6938 return test_snow3g_auth_cipher_sgl( 6939 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6940 } 6941 6942 static int 6943 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6944 { 6945 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6946 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6947 return TEST_SKIPPED; 6948 return test_snow3g_auth_cipher_sgl( 6949 &snow3g_auth_cipher_partial_digest_encryption, 6950 IN_PLACE, 0); 6951 } 6952 6953 static int 6954 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6955 { 6956 return test_snow3g_auth_cipher_sgl( 6957 &snow3g_auth_cipher_partial_digest_encryption, 6958 OUT_OF_PLACE, 0); 6959 } 6960 6961 static int 6962 test_snow3g_auth_cipher_verify_test_case_1(void) 6963 { 6964 return test_snow3g_auth_cipher( 6965 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6966 } 6967 6968 static int 6969 test_snow3g_auth_cipher_verify_test_case_2(void) 6970 { 6971 return test_snow3g_auth_cipher( 6972 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6973 } 6974 6975 static int 6976 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6977 { 6978 return test_snow3g_auth_cipher( 6979 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6980 } 6981 6982 static int 6983 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6984 { 6985 return test_snow3g_auth_cipher( 6986 &snow3g_auth_cipher_partial_digest_encryption, 6987 IN_PLACE, 1); 6988 } 6989 6990 static int 6991 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6992 { 6993 return test_snow3g_auth_cipher( 6994 &snow3g_auth_cipher_partial_digest_encryption, 6995 OUT_OF_PLACE, 1); 6996 } 6997 6998 static int 6999 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7000 { 7001 return test_snow3g_auth_cipher_sgl( 7002 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7003 } 7004 7005 static int 7006 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7007 { 7008 return test_snow3g_auth_cipher_sgl( 7009 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7010 } 7011 7012 static int 7013 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7014 { 7015 return test_snow3g_auth_cipher_sgl( 7016 &snow3g_auth_cipher_partial_digest_encryption, 7017 IN_PLACE, 1); 7018 } 7019 7020 static int 7021 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7022 { 7023 return test_snow3g_auth_cipher_sgl( 7024 &snow3g_auth_cipher_partial_digest_encryption, 7025 OUT_OF_PLACE, 1); 7026 } 7027 7028 static int 7029 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7030 { 7031 return test_snow3g_auth_cipher( 7032 &snow3g_test_case_7, IN_PLACE, 0); 7033 } 7034 7035 static int 7036 test_kasumi_auth_cipher_test_case_1(void) 7037 { 7038 return test_kasumi_auth_cipher( 7039 &kasumi_test_case_3, IN_PLACE, 0); 7040 } 7041 7042 static int 7043 test_kasumi_auth_cipher_test_case_2(void) 7044 { 7045 return test_kasumi_auth_cipher( 7046 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7047 } 7048 7049 static int 7050 test_kasumi_auth_cipher_test_case_2_oop(void) 7051 { 7052 return test_kasumi_auth_cipher( 7053 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7054 } 7055 7056 static int 7057 test_kasumi_auth_cipher_test_case_2_sgl(void) 7058 { 7059 return test_kasumi_auth_cipher_sgl( 7060 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7061 } 7062 7063 static int 7064 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7065 { 7066 return test_kasumi_auth_cipher_sgl( 7067 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7068 } 7069 7070 static int 7071 test_kasumi_auth_cipher_verify_test_case_1(void) 7072 { 7073 return test_kasumi_auth_cipher( 7074 &kasumi_test_case_3, IN_PLACE, 1); 7075 } 7076 7077 static int 7078 test_kasumi_auth_cipher_verify_test_case_2(void) 7079 { 7080 return test_kasumi_auth_cipher( 7081 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7082 } 7083 7084 static int 7085 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7086 { 7087 return test_kasumi_auth_cipher( 7088 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7089 } 7090 7091 static int 7092 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7093 { 7094 return test_kasumi_auth_cipher_sgl( 7095 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7096 } 7097 7098 static int 7099 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7100 { 7101 return test_kasumi_auth_cipher_sgl( 7102 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7103 } 7104 7105 static int 7106 test_kasumi_cipher_auth_test_case_1(void) 7107 { 7108 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7109 } 7110 7111 static int 7112 test_zuc_encryption_test_case_1(void) 7113 { 7114 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7115 } 7116 7117 static int 7118 test_zuc_encryption_test_case_2(void) 7119 { 7120 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7121 } 7122 7123 static int 7124 test_zuc_encryption_test_case_3(void) 7125 { 7126 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7127 } 7128 7129 static int 7130 test_zuc_encryption_test_case_4(void) 7131 { 7132 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7133 } 7134 7135 static int 7136 test_zuc_encryption_test_case_5(void) 7137 { 7138 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7139 } 7140 7141 static int 7142 test_zuc_encryption_test_case_6_sgl(void) 7143 { 7144 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7145 } 7146 7147 static int 7148 test_zuc_hash_generate_test_case_1(void) 7149 { 7150 return test_zuc_authentication(&zuc_test_case_auth_1b); 7151 } 7152 7153 static int 7154 test_zuc_hash_generate_test_case_2(void) 7155 { 7156 return test_zuc_authentication(&zuc_test_case_auth_90b); 7157 } 7158 7159 static int 7160 test_zuc_hash_generate_test_case_3(void) 7161 { 7162 return test_zuc_authentication(&zuc_test_case_auth_577b); 7163 } 7164 7165 static int 7166 test_zuc_hash_generate_test_case_4(void) 7167 { 7168 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7169 } 7170 7171 static int 7172 test_zuc_hash_generate_test_case_5(void) 7173 { 7174 return test_zuc_authentication(&zuc_test_auth_5670b); 7175 } 7176 7177 static int 7178 test_zuc_hash_generate_test_case_6(void) 7179 { 7180 return test_zuc_authentication(&zuc_test_case_auth_128b); 7181 } 7182 7183 static int 7184 test_zuc_hash_generate_test_case_7(void) 7185 { 7186 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7187 } 7188 7189 static int 7190 test_zuc_hash_generate_test_case_8(void) 7191 { 7192 return test_zuc_authentication(&zuc_test_case_auth_584b); 7193 } 7194 7195 static int 7196 test_zuc_hash_generate_test_case_9(void) 7197 { 7198 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b); 7199 } 7200 7201 static int 7202 test_zuc_hash_generate_test_case_10(void) 7203 { 7204 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b); 7205 } 7206 7207 static int 7208 test_zuc_hash_generate_test_case_11(void) 7209 { 7210 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b); 7211 } 7212 7213 static int 7214 test_zuc_cipher_auth_test_case_1(void) 7215 { 7216 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7217 } 7218 7219 static int 7220 test_zuc_cipher_auth_test_case_2(void) 7221 { 7222 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7223 } 7224 7225 static int 7226 test_zuc_auth_cipher_test_case_1(void) 7227 { 7228 return test_zuc_auth_cipher( 7229 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7230 } 7231 7232 static int 7233 test_zuc_auth_cipher_test_case_1_oop(void) 7234 { 7235 return test_zuc_auth_cipher( 7236 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7237 } 7238 7239 static int 7240 test_zuc_auth_cipher_test_case_1_sgl(void) 7241 { 7242 return test_zuc_auth_cipher_sgl( 7243 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7244 } 7245 7246 static int 7247 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7248 { 7249 return test_zuc_auth_cipher_sgl( 7250 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7251 } 7252 7253 static int 7254 test_zuc_auth_cipher_verify_test_case_1(void) 7255 { 7256 return test_zuc_auth_cipher( 7257 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7258 } 7259 7260 static int 7261 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7262 { 7263 return test_zuc_auth_cipher( 7264 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7265 } 7266 7267 static int 7268 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7269 { 7270 return test_zuc_auth_cipher_sgl( 7271 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7272 } 7273 7274 static int 7275 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7276 { 7277 return test_zuc_auth_cipher_sgl( 7278 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7279 } 7280 7281 static int 7282 test_zuc256_encryption_test_case_1(void) 7283 { 7284 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7285 } 7286 7287 static int 7288 test_zuc256_encryption_test_case_2(void) 7289 { 7290 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7291 } 7292 7293 static int 7294 test_zuc256_authentication_test_case_1(void) 7295 { 7296 return test_zuc_authentication(&zuc256_test_case_auth_1); 7297 } 7298 7299 static int 7300 test_zuc256_authentication_test_case_2(void) 7301 { 7302 return test_zuc_authentication(&zuc256_test_case_auth_2); 7303 } 7304 7305 static int 7306 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7307 { 7308 uint8_t dev_id = testsuite_params.valid_devs[0]; 7309 7310 struct rte_cryptodev_sym_capability_idx cap_idx; 7311 7312 /* Check if device supports particular cipher algorithm */ 7313 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7314 cap_idx.algo.cipher = tdata->cipher_algo; 7315 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7316 return TEST_SKIPPED; 7317 7318 /* Check if device supports particular hash algorithm */ 7319 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7320 cap_idx.algo.auth = tdata->auth_algo; 7321 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7322 return TEST_SKIPPED; 7323 7324 return 0; 7325 } 7326 7327 static int 7328 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7329 uint8_t op_mode, uint8_t verify) 7330 { 7331 struct crypto_testsuite_params *ts_params = &testsuite_params; 7332 struct crypto_unittest_params *ut_params = &unittest_params; 7333 7334 int retval; 7335 7336 uint8_t *plaintext = NULL, *ciphertext = NULL; 7337 unsigned int plaintext_pad_len; 7338 unsigned int plaintext_len; 7339 unsigned int ciphertext_pad_len; 7340 unsigned int ciphertext_len; 7341 7342 struct rte_cryptodev_info dev_info; 7343 struct rte_crypto_op *op; 7344 7345 /* Check if device supports particular algorithms separately */ 7346 if (test_mixed_check_if_unsupported(tdata)) 7347 return TEST_SKIPPED; 7348 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7349 return TEST_SKIPPED; 7350 7351 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7352 7353 uint64_t feat_flags = dev_info.feature_flags; 7354 7355 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7356 printf("Device doesn't support digest encrypted.\n"); 7357 return TEST_SKIPPED; 7358 } 7359 7360 /* Create the session */ 7361 if (verify) 7362 retval = create_wireless_algo_cipher_auth_session( 7363 ts_params->valid_devs[0], 7364 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7365 RTE_CRYPTO_AUTH_OP_VERIFY, 7366 tdata->auth_algo, 7367 tdata->cipher_algo, 7368 tdata->auth_key.data, tdata->auth_key.len, 7369 tdata->auth_iv.len, tdata->digest_enc.len, 7370 tdata->cipher_iv.len); 7371 else 7372 retval = create_wireless_algo_auth_cipher_session( 7373 ts_params->valid_devs[0], 7374 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7375 RTE_CRYPTO_AUTH_OP_GENERATE, 7376 tdata->auth_algo, 7377 tdata->cipher_algo, 7378 tdata->auth_key.data, tdata->auth_key.len, 7379 tdata->auth_iv.len, tdata->digest_enc.len, 7380 tdata->cipher_iv.len); 7381 if (retval != 0) 7382 return retval; 7383 7384 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7385 if (op_mode == OUT_OF_PLACE) 7386 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7387 7388 /* clear mbuf payload */ 7389 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7390 rte_pktmbuf_tailroom(ut_params->ibuf)); 7391 if (op_mode == OUT_OF_PLACE) { 7392 7393 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7394 rte_pktmbuf_tailroom(ut_params->obuf)); 7395 } 7396 7397 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7398 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7399 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7400 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7401 7402 if (verify) { 7403 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7404 ciphertext_pad_len); 7405 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7406 debug_hexdump(stdout, "ciphertext:", ciphertext, 7407 ciphertext_len); 7408 } else { 7409 /* make sure enough space to cover partial digest verify case */ 7410 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7411 ciphertext_pad_len); 7412 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7413 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7414 } 7415 7416 if (op_mode == OUT_OF_PLACE) 7417 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7418 7419 /* Create the operation */ 7420 retval = create_wireless_algo_auth_cipher_operation( 7421 tdata->digest_enc.data, tdata->digest_enc.len, 7422 tdata->cipher_iv.data, tdata->cipher_iv.len, 7423 tdata->auth_iv.data, tdata->auth_iv.len, 7424 (tdata->digest_enc.offset == 0 ? 7425 plaintext_pad_len 7426 : tdata->digest_enc.offset), 7427 tdata->validCipherLen.len_bits, 7428 tdata->cipher.offset_bits, 7429 tdata->validAuthLen.len_bits, 7430 tdata->auth.offset_bits, 7431 op_mode, 0, verify); 7432 7433 if (retval < 0) 7434 return retval; 7435 7436 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7437 7438 /* Check if the op failed because the device doesn't */ 7439 /* support this particular combination of algorithms */ 7440 if (op == NULL && ut_params->op->status == 7441 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7442 printf("Device doesn't support this mixed combination. " 7443 "Test Skipped.\n"); 7444 return TEST_SKIPPED; 7445 } 7446 ut_params->op = op; 7447 7448 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7449 7450 ut_params->obuf = (op_mode == IN_PLACE ? 7451 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7452 7453 if (verify) { 7454 if (ut_params->obuf) 7455 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7456 uint8_t *); 7457 else 7458 plaintext = ciphertext + 7459 (tdata->cipher.offset_bits >> 3); 7460 7461 debug_hexdump(stdout, "plaintext:", plaintext, 7462 tdata->plaintext.len_bits >> 3); 7463 debug_hexdump(stdout, "plaintext expected:", 7464 tdata->plaintext.data, 7465 tdata->plaintext.len_bits >> 3); 7466 } else { 7467 if (ut_params->obuf) 7468 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7469 uint8_t *); 7470 else 7471 ciphertext = plaintext; 7472 7473 debug_hexdump(stdout, "ciphertext:", ciphertext, 7474 ciphertext_len); 7475 debug_hexdump(stdout, "ciphertext expected:", 7476 tdata->ciphertext.data, 7477 tdata->ciphertext.len_bits >> 3); 7478 7479 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7480 + (tdata->digest_enc.offset == 0 ? 7481 plaintext_pad_len : tdata->digest_enc.offset); 7482 7483 debug_hexdump(stdout, "digest:", ut_params->digest, 7484 tdata->digest_enc.len); 7485 debug_hexdump(stdout, "digest expected:", 7486 tdata->digest_enc.data, 7487 tdata->digest_enc.len); 7488 } 7489 7490 if (!verify) { 7491 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7492 ut_params->digest, 7493 tdata->digest_enc.data, 7494 tdata->digest_enc.len, 7495 "Generated auth tag not as expected"); 7496 } 7497 7498 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7499 if (verify) { 7500 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7501 plaintext, 7502 tdata->plaintext.data, 7503 tdata->plaintext.len_bits >> 3, 7504 "Plaintext data not as expected"); 7505 } else { 7506 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7507 ciphertext, 7508 tdata->ciphertext.data, 7509 tdata->validDataLen.len_bits, 7510 "Ciphertext data not as expected"); 7511 } 7512 } 7513 7514 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7515 "crypto op processing failed"); 7516 7517 return 0; 7518 } 7519 7520 static int 7521 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7522 uint8_t op_mode, uint8_t verify) 7523 { 7524 struct crypto_testsuite_params *ts_params = &testsuite_params; 7525 struct crypto_unittest_params *ut_params = &unittest_params; 7526 7527 int retval; 7528 7529 const uint8_t *plaintext = NULL; 7530 const uint8_t *ciphertext = NULL; 7531 const uint8_t *digest = NULL; 7532 unsigned int plaintext_pad_len; 7533 unsigned int plaintext_len; 7534 unsigned int ciphertext_pad_len; 7535 unsigned int ciphertext_len; 7536 uint8_t buffer[10000]; 7537 uint8_t digest_buffer[10000]; 7538 7539 struct rte_cryptodev_info dev_info; 7540 struct rte_crypto_op *op; 7541 7542 /* Check if device supports particular algorithms */ 7543 if (test_mixed_check_if_unsupported(tdata)) 7544 return TEST_SKIPPED; 7545 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7546 return TEST_SKIPPED; 7547 7548 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7549 7550 uint64_t feat_flags = dev_info.feature_flags; 7551 7552 if (op_mode == IN_PLACE) { 7553 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7554 printf("Device doesn't support in-place scatter-gather " 7555 "in both input and output mbufs.\n"); 7556 return TEST_SKIPPED; 7557 } 7558 } else { 7559 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7560 printf("Device doesn't support out-of-place scatter-gather " 7561 "in both input and output mbufs.\n"); 7562 return TEST_SKIPPED; 7563 } 7564 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7565 printf("Device doesn't support digest encrypted.\n"); 7566 return TEST_SKIPPED; 7567 } 7568 } 7569 7570 /* Create the session */ 7571 if (verify) 7572 retval = create_wireless_algo_cipher_auth_session( 7573 ts_params->valid_devs[0], 7574 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7575 RTE_CRYPTO_AUTH_OP_VERIFY, 7576 tdata->auth_algo, 7577 tdata->cipher_algo, 7578 tdata->auth_key.data, tdata->auth_key.len, 7579 tdata->auth_iv.len, tdata->digest_enc.len, 7580 tdata->cipher_iv.len); 7581 else 7582 retval = create_wireless_algo_auth_cipher_session( 7583 ts_params->valid_devs[0], 7584 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7585 RTE_CRYPTO_AUTH_OP_GENERATE, 7586 tdata->auth_algo, 7587 tdata->cipher_algo, 7588 tdata->auth_key.data, tdata->auth_key.len, 7589 tdata->auth_iv.len, tdata->digest_enc.len, 7590 tdata->cipher_iv.len); 7591 if (retval != 0) 7592 return retval; 7593 7594 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7595 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7596 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7597 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7598 7599 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7600 ciphertext_pad_len, 15, 0); 7601 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7602 "Failed to allocate input buffer in mempool"); 7603 7604 if (op_mode == OUT_OF_PLACE) { 7605 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7606 plaintext_pad_len, 15, 0); 7607 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7608 "Failed to allocate output buffer in mempool"); 7609 } 7610 7611 if (verify) { 7612 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7613 tdata->ciphertext.data); 7614 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7615 ciphertext_len, buffer); 7616 debug_hexdump(stdout, "ciphertext:", ciphertext, 7617 ciphertext_len); 7618 } else { 7619 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7620 tdata->plaintext.data); 7621 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7622 plaintext_len, buffer); 7623 debug_hexdump(stdout, "plaintext:", plaintext, 7624 plaintext_len); 7625 } 7626 memset(buffer, 0, sizeof(buffer)); 7627 7628 /* Create the operation */ 7629 retval = create_wireless_algo_auth_cipher_operation( 7630 tdata->digest_enc.data, tdata->digest_enc.len, 7631 tdata->cipher_iv.data, tdata->cipher_iv.len, 7632 tdata->auth_iv.data, tdata->auth_iv.len, 7633 (tdata->digest_enc.offset == 0 ? 7634 plaintext_pad_len 7635 : tdata->digest_enc.offset), 7636 tdata->validCipherLen.len_bits, 7637 tdata->cipher.offset_bits, 7638 tdata->validAuthLen.len_bits, 7639 tdata->auth.offset_bits, 7640 op_mode, 1, verify); 7641 7642 if (retval < 0) 7643 return retval; 7644 7645 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7646 7647 /* Check if the op failed because the device doesn't */ 7648 /* support this particular combination of algorithms */ 7649 if (op == NULL && ut_params->op->status == 7650 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7651 printf("Device doesn't support this mixed combination. " 7652 "Test Skipped.\n"); 7653 return TEST_SKIPPED; 7654 } 7655 ut_params->op = op; 7656 7657 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7658 7659 ut_params->obuf = (op_mode == IN_PLACE ? 7660 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7661 7662 if (verify) { 7663 if (ut_params->obuf) 7664 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7665 plaintext_len, buffer); 7666 else 7667 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7668 plaintext_len, buffer); 7669 7670 debug_hexdump(stdout, "plaintext:", plaintext, 7671 (tdata->plaintext.len_bits >> 3) - 7672 tdata->digest_enc.len); 7673 debug_hexdump(stdout, "plaintext expected:", 7674 tdata->plaintext.data, 7675 (tdata->plaintext.len_bits >> 3) - 7676 tdata->digest_enc.len); 7677 } else { 7678 if (ut_params->obuf) 7679 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7680 ciphertext_len, buffer); 7681 else 7682 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7683 ciphertext_len, buffer); 7684 7685 debug_hexdump(stdout, "ciphertext:", ciphertext, 7686 ciphertext_len); 7687 debug_hexdump(stdout, "ciphertext expected:", 7688 tdata->ciphertext.data, 7689 tdata->ciphertext.len_bits >> 3); 7690 7691 if (ut_params->obuf) 7692 digest = rte_pktmbuf_read(ut_params->obuf, 7693 (tdata->digest_enc.offset == 0 ? 7694 plaintext_pad_len : 7695 tdata->digest_enc.offset), 7696 tdata->digest_enc.len, digest_buffer); 7697 else 7698 digest = rte_pktmbuf_read(ut_params->ibuf, 7699 (tdata->digest_enc.offset == 0 ? 7700 plaintext_pad_len : 7701 tdata->digest_enc.offset), 7702 tdata->digest_enc.len, digest_buffer); 7703 7704 debug_hexdump(stdout, "digest:", digest, 7705 tdata->digest_enc.len); 7706 debug_hexdump(stdout, "digest expected:", 7707 tdata->digest_enc.data, tdata->digest_enc.len); 7708 } 7709 7710 if (!verify) { 7711 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7712 digest, 7713 tdata->digest_enc.data, 7714 tdata->digest_enc.len, 7715 "Generated auth tag not as expected"); 7716 } 7717 7718 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7719 if (verify) { 7720 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7721 plaintext, 7722 tdata->plaintext.data, 7723 tdata->plaintext.len_bits >> 3, 7724 "Plaintext data not as expected"); 7725 } else { 7726 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7727 ciphertext, 7728 tdata->ciphertext.data, 7729 tdata->validDataLen.len_bits, 7730 "Ciphertext data not as expected"); 7731 } 7732 } 7733 7734 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7735 "crypto op processing failed"); 7736 7737 return 0; 7738 } 7739 7740 /** AUTH AES CMAC + CIPHER AES CTR */ 7741 7742 static int 7743 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7744 { 7745 return test_mixed_auth_cipher( 7746 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7747 } 7748 7749 static int 7750 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7751 { 7752 return test_mixed_auth_cipher( 7753 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7754 } 7755 7756 static int 7757 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7758 { 7759 return test_mixed_auth_cipher_sgl( 7760 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7761 } 7762 7763 static int 7764 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7765 { 7766 return test_mixed_auth_cipher_sgl( 7767 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7768 } 7769 7770 static int 7771 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7772 { 7773 return test_mixed_auth_cipher( 7774 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7775 } 7776 7777 static int 7778 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7779 { 7780 return test_mixed_auth_cipher( 7781 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7782 } 7783 7784 static int 7785 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7786 { 7787 return test_mixed_auth_cipher_sgl( 7788 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7789 } 7790 7791 static int 7792 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7793 { 7794 return test_mixed_auth_cipher_sgl( 7795 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7796 } 7797 7798 /** MIXED AUTH + CIPHER */ 7799 7800 static int 7801 test_auth_zuc_cipher_snow_test_case_1(void) 7802 { 7803 return test_mixed_auth_cipher( 7804 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7805 } 7806 7807 static int 7808 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7809 { 7810 return test_mixed_auth_cipher( 7811 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7812 } 7813 7814 static int 7815 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7816 { 7817 return test_mixed_auth_cipher( 7818 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7819 } 7820 7821 static int 7822 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7823 { 7824 return test_mixed_auth_cipher( 7825 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7826 } 7827 7828 static int 7829 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7830 { 7831 return test_mixed_auth_cipher( 7832 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7833 } 7834 7835 static int 7836 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7837 { 7838 return test_mixed_auth_cipher( 7839 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7840 } 7841 7842 static int 7843 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7844 { 7845 return test_mixed_auth_cipher( 7846 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7847 } 7848 7849 static int 7850 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7851 { 7852 return test_mixed_auth_cipher( 7853 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7854 } 7855 7856 static int 7857 test_auth_snow_cipher_zuc_test_case_1(void) 7858 { 7859 return test_mixed_auth_cipher( 7860 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7861 } 7862 7863 static int 7864 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7865 { 7866 return test_mixed_auth_cipher( 7867 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7868 } 7869 7870 static int 7871 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7872 { 7873 return test_mixed_auth_cipher( 7874 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7875 } 7876 7877 static int 7878 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7879 { 7880 return test_mixed_auth_cipher( 7881 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7882 } 7883 7884 static int 7885 test_auth_null_cipher_snow_test_case_1(void) 7886 { 7887 return test_mixed_auth_cipher( 7888 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7889 } 7890 7891 static int 7892 test_verify_auth_null_cipher_snow_test_case_1(void) 7893 { 7894 return test_mixed_auth_cipher( 7895 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7896 } 7897 7898 static int 7899 test_auth_null_cipher_zuc_test_case_1(void) 7900 { 7901 return test_mixed_auth_cipher( 7902 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7903 } 7904 7905 static int 7906 test_verify_auth_null_cipher_zuc_test_case_1(void) 7907 { 7908 return test_mixed_auth_cipher( 7909 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7910 } 7911 7912 static int 7913 test_auth_snow_cipher_null_test_case_1(void) 7914 { 7915 return test_mixed_auth_cipher( 7916 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7917 } 7918 7919 static int 7920 test_verify_auth_snow_cipher_null_test_case_1(void) 7921 { 7922 return test_mixed_auth_cipher( 7923 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7924 } 7925 7926 static int 7927 test_auth_zuc_cipher_null_test_case_1(void) 7928 { 7929 return test_mixed_auth_cipher( 7930 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7931 } 7932 7933 static int 7934 test_verify_auth_zuc_cipher_null_test_case_1(void) 7935 { 7936 return test_mixed_auth_cipher( 7937 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7938 } 7939 7940 static int 7941 test_auth_null_cipher_aes_ctr_test_case_1(void) 7942 { 7943 return test_mixed_auth_cipher( 7944 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7945 } 7946 7947 static int 7948 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7949 { 7950 return test_mixed_auth_cipher( 7951 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7952 } 7953 7954 static int 7955 test_auth_aes_cmac_cipher_null_test_case_1(void) 7956 { 7957 return test_mixed_auth_cipher( 7958 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7959 } 7960 7961 static int 7962 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7963 { 7964 return test_mixed_auth_cipher( 7965 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7966 } 7967 7968 /* ***** AEAD algorithm Tests ***** */ 7969 7970 static int 7971 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7972 enum rte_crypto_aead_operation op, 7973 const uint8_t *key, const uint8_t key_len, 7974 const uint16_t aad_len, const uint8_t auth_len, 7975 uint8_t iv_len) 7976 { 7977 uint8_t aead_key[key_len]; 7978 int status; 7979 7980 struct crypto_testsuite_params *ts_params = &testsuite_params; 7981 struct crypto_unittest_params *ut_params = &unittest_params; 7982 7983 memcpy(aead_key, key, key_len); 7984 7985 /* Setup AEAD Parameters */ 7986 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7987 ut_params->aead_xform.next = NULL; 7988 ut_params->aead_xform.aead.algo = algo; 7989 ut_params->aead_xform.aead.op = op; 7990 ut_params->aead_xform.aead.key.data = aead_key; 7991 ut_params->aead_xform.aead.key.length = key_len; 7992 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7993 ut_params->aead_xform.aead.iv.length = iv_len; 7994 ut_params->aead_xform.aead.digest_length = auth_len; 7995 ut_params->aead_xform.aead.aad_length = aad_len; 7996 7997 debug_hexdump(stdout, "key:", key, key_len); 7998 7999 /* Create Crypto session*/ 8000 ut_params->sess = rte_cryptodev_sym_session_create( 8001 ts_params->session_mpool); 8002 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8003 8004 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 8005 &ut_params->aead_xform, 8006 ts_params->session_priv_mpool); 8007 8008 return status; 8009 } 8010 8011 static int 8012 create_aead_xform(struct rte_crypto_op *op, 8013 enum rte_crypto_aead_algorithm algo, 8014 enum rte_crypto_aead_operation aead_op, 8015 uint8_t *key, const uint8_t key_len, 8016 const uint8_t aad_len, const uint8_t auth_len, 8017 uint8_t iv_len) 8018 { 8019 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8020 "failed to allocate space for crypto transform"); 8021 8022 struct rte_crypto_sym_op *sym_op = op->sym; 8023 8024 /* Setup AEAD Parameters */ 8025 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8026 sym_op->xform->next = NULL; 8027 sym_op->xform->aead.algo = algo; 8028 sym_op->xform->aead.op = aead_op; 8029 sym_op->xform->aead.key.data = key; 8030 sym_op->xform->aead.key.length = key_len; 8031 sym_op->xform->aead.iv.offset = IV_OFFSET; 8032 sym_op->xform->aead.iv.length = iv_len; 8033 sym_op->xform->aead.digest_length = auth_len; 8034 sym_op->xform->aead.aad_length = aad_len; 8035 8036 debug_hexdump(stdout, "key:", key, key_len); 8037 8038 return 0; 8039 } 8040 8041 static int 8042 create_aead_operation(enum rte_crypto_aead_operation op, 8043 const struct aead_test_data *tdata) 8044 { 8045 struct crypto_testsuite_params *ts_params = &testsuite_params; 8046 struct crypto_unittest_params *ut_params = &unittest_params; 8047 8048 uint8_t *plaintext, *ciphertext; 8049 unsigned int aad_pad_len, plaintext_pad_len; 8050 8051 /* Generate Crypto op data structure */ 8052 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8053 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8054 TEST_ASSERT_NOT_NULL(ut_params->op, 8055 "Failed to allocate symmetric crypto operation struct"); 8056 8057 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8058 8059 /* Append aad data */ 8060 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8061 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8062 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8063 aad_pad_len); 8064 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8065 "no room to append aad"); 8066 8067 sym_op->aead.aad.phys_addr = 8068 rte_pktmbuf_iova(ut_params->ibuf); 8069 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8070 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8071 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8072 tdata->aad.len); 8073 8074 /* Append IV at the end of the crypto operation*/ 8075 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8076 uint8_t *, IV_OFFSET); 8077 8078 /* Copy IV 1 byte after the IV pointer, according to the API */ 8079 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8080 debug_hexdump(stdout, "iv:", iv_ptr, 8081 tdata->iv.len); 8082 } else { 8083 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8084 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8085 aad_pad_len); 8086 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8087 "no room to append aad"); 8088 8089 sym_op->aead.aad.phys_addr = 8090 rte_pktmbuf_iova(ut_params->ibuf); 8091 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8092 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8093 tdata->aad.len); 8094 8095 /* Append IV at the end of the crypto operation*/ 8096 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8097 uint8_t *, IV_OFFSET); 8098 8099 if (tdata->iv.len == 0) { 8100 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8101 debug_hexdump(stdout, "iv:", iv_ptr, 8102 AES_GCM_J0_LENGTH); 8103 } else { 8104 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8105 debug_hexdump(stdout, "iv:", iv_ptr, 8106 tdata->iv.len); 8107 } 8108 } 8109 8110 /* Append plaintext/ciphertext */ 8111 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8112 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8113 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8114 plaintext_pad_len); 8115 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8116 8117 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8118 debug_hexdump(stdout, "plaintext:", plaintext, 8119 tdata->plaintext.len); 8120 8121 if (ut_params->obuf) { 8122 ciphertext = (uint8_t *)rte_pktmbuf_append( 8123 ut_params->obuf, 8124 plaintext_pad_len + aad_pad_len); 8125 TEST_ASSERT_NOT_NULL(ciphertext, 8126 "no room to append ciphertext"); 8127 8128 memset(ciphertext + aad_pad_len, 0, 8129 tdata->ciphertext.len); 8130 } 8131 } else { 8132 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8133 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8134 plaintext_pad_len); 8135 TEST_ASSERT_NOT_NULL(ciphertext, 8136 "no room to append ciphertext"); 8137 8138 memcpy(ciphertext, tdata->ciphertext.data, 8139 tdata->ciphertext.len); 8140 debug_hexdump(stdout, "ciphertext:", ciphertext, 8141 tdata->ciphertext.len); 8142 8143 if (ut_params->obuf) { 8144 plaintext = (uint8_t *)rte_pktmbuf_append( 8145 ut_params->obuf, 8146 plaintext_pad_len + aad_pad_len); 8147 TEST_ASSERT_NOT_NULL(plaintext, 8148 "no room to append plaintext"); 8149 8150 memset(plaintext + aad_pad_len, 0, 8151 tdata->plaintext.len); 8152 } 8153 } 8154 8155 /* Append digest data */ 8156 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8157 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8158 ut_params->obuf ? ut_params->obuf : 8159 ut_params->ibuf, 8160 tdata->auth_tag.len); 8161 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8162 "no room to append digest"); 8163 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8164 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8165 ut_params->obuf ? ut_params->obuf : 8166 ut_params->ibuf, 8167 plaintext_pad_len + 8168 aad_pad_len); 8169 } else { 8170 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8171 ut_params->ibuf, tdata->auth_tag.len); 8172 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8173 "no room to append digest"); 8174 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8175 ut_params->ibuf, 8176 plaintext_pad_len + aad_pad_len); 8177 8178 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8179 tdata->auth_tag.len); 8180 debug_hexdump(stdout, "digest:", 8181 sym_op->aead.digest.data, 8182 tdata->auth_tag.len); 8183 } 8184 8185 sym_op->aead.data.length = tdata->plaintext.len; 8186 sym_op->aead.data.offset = aad_pad_len; 8187 8188 return 0; 8189 } 8190 8191 static int 8192 test_authenticated_encryption(const struct aead_test_data *tdata) 8193 { 8194 struct crypto_testsuite_params *ts_params = &testsuite_params; 8195 struct crypto_unittest_params *ut_params = &unittest_params; 8196 8197 int retval; 8198 uint8_t *ciphertext, *auth_tag; 8199 uint16_t plaintext_pad_len; 8200 uint32_t i; 8201 struct rte_cryptodev_info dev_info; 8202 8203 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8204 uint64_t feat_flags = dev_info.feature_flags; 8205 8206 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8207 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8208 printf("Device doesn't support RAW data-path APIs.\n"); 8209 return TEST_SKIPPED; 8210 } 8211 8212 /* Verify the capabilities */ 8213 struct rte_cryptodev_sym_capability_idx cap_idx; 8214 const struct rte_cryptodev_symmetric_capability *capability; 8215 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8216 cap_idx.algo.aead = tdata->algo; 8217 capability = rte_cryptodev_sym_capability_get( 8218 ts_params->valid_devs[0], &cap_idx); 8219 if (capability == NULL) 8220 return TEST_SKIPPED; 8221 if (rte_cryptodev_sym_capability_check_aead( 8222 capability, tdata->key.len, tdata->auth_tag.len, 8223 tdata->aad.len, tdata->iv.len)) 8224 return TEST_SKIPPED; 8225 8226 /* Create AEAD session */ 8227 retval = create_aead_session(ts_params->valid_devs[0], 8228 tdata->algo, 8229 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8230 tdata->key.data, tdata->key.len, 8231 tdata->aad.len, tdata->auth_tag.len, 8232 tdata->iv.len); 8233 if (retval < 0) 8234 return retval; 8235 8236 if (tdata->aad.len > MBUF_SIZE) { 8237 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8238 /* Populate full size of add data */ 8239 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8240 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8241 } else 8242 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8243 8244 /* clear mbuf payload */ 8245 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8246 rte_pktmbuf_tailroom(ut_params->ibuf)); 8247 8248 /* Create AEAD operation */ 8249 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8250 if (retval < 0) 8251 return retval; 8252 8253 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8254 8255 ut_params->op->sym->m_src = ut_params->ibuf; 8256 8257 /* Process crypto operation */ 8258 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8259 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8260 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8261 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8262 ut_params->op, 0, 0, 0, 0); 8263 else 8264 TEST_ASSERT_NOT_NULL( 8265 process_crypto_request(ts_params->valid_devs[0], 8266 ut_params->op), "failed to process sym crypto op"); 8267 8268 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8269 "crypto op processing failed"); 8270 8271 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8272 8273 if (ut_params->op->sym->m_dst) { 8274 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8275 uint8_t *); 8276 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8277 uint8_t *, plaintext_pad_len); 8278 } else { 8279 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8280 uint8_t *, 8281 ut_params->op->sym->cipher.data.offset); 8282 auth_tag = ciphertext + plaintext_pad_len; 8283 } 8284 8285 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8286 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8287 8288 /* Validate obuf */ 8289 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8290 ciphertext, 8291 tdata->ciphertext.data, 8292 tdata->ciphertext.len, 8293 "Ciphertext data not as expected"); 8294 8295 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8296 auth_tag, 8297 tdata->auth_tag.data, 8298 tdata->auth_tag.len, 8299 "Generated auth tag not as expected"); 8300 8301 return 0; 8302 8303 } 8304 8305 #ifdef RTE_LIB_SECURITY 8306 static int 8307 security_proto_supported(enum rte_security_session_action_type action, 8308 enum rte_security_session_protocol proto) 8309 { 8310 struct crypto_testsuite_params *ts_params = &testsuite_params; 8311 8312 const struct rte_security_capability *capabilities; 8313 const struct rte_security_capability *capability; 8314 uint16_t i = 0; 8315 8316 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8317 rte_cryptodev_get_sec_ctx( 8318 ts_params->valid_devs[0]); 8319 8320 8321 capabilities = rte_security_capabilities_get(ctx); 8322 8323 if (capabilities == NULL) 8324 return -ENOTSUP; 8325 8326 while ((capability = &capabilities[i++])->action != 8327 RTE_SECURITY_ACTION_TYPE_NONE) { 8328 if (capability->action == action && 8329 capability->protocol == proto) 8330 return 0; 8331 } 8332 8333 return -ENOTSUP; 8334 } 8335 8336 /* Basic algorithm run function for async inplace mode. 8337 * Creates a session from input parameters and runs one operation 8338 * on input_vec. Checks the output of the crypto operation against 8339 * output_vec. 8340 */ 8341 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8342 enum rte_crypto_auth_operation opa, 8343 const uint8_t *input_vec, unsigned int input_vec_len, 8344 const uint8_t *output_vec, 8345 unsigned int output_vec_len, 8346 enum rte_crypto_cipher_algorithm cipher_alg, 8347 const uint8_t *cipher_key, uint32_t cipher_key_len, 8348 enum rte_crypto_auth_algorithm auth_alg, 8349 const uint8_t *auth_key, uint32_t auth_key_len, 8350 uint8_t bearer, enum rte_security_pdcp_domain domain, 8351 uint8_t packet_direction, uint8_t sn_size, 8352 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8353 { 8354 struct crypto_testsuite_params *ts_params = &testsuite_params; 8355 struct crypto_unittest_params *ut_params = &unittest_params; 8356 uint8_t *plaintext; 8357 int ret = TEST_SUCCESS; 8358 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8359 rte_cryptodev_get_sec_ctx( 8360 ts_params->valid_devs[0]); 8361 8362 /* Verify the capabilities */ 8363 struct rte_security_capability_idx sec_cap_idx; 8364 8365 sec_cap_idx.action = ut_params->type; 8366 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8367 sec_cap_idx.pdcp.domain = domain; 8368 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8369 return TEST_SKIPPED; 8370 8371 /* Generate test mbuf data */ 8372 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8373 8374 /* clear mbuf payload */ 8375 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8376 rte_pktmbuf_tailroom(ut_params->ibuf)); 8377 8378 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8379 input_vec_len); 8380 memcpy(plaintext, input_vec, input_vec_len); 8381 8382 /* Out of place support */ 8383 if (oop) { 8384 /* 8385 * For out-op-place we need to alloc another mbuf 8386 */ 8387 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8388 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8389 } 8390 8391 /* Setup Cipher Parameters */ 8392 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8393 ut_params->cipher_xform.cipher.algo = cipher_alg; 8394 ut_params->cipher_xform.cipher.op = opc; 8395 ut_params->cipher_xform.cipher.key.data = cipher_key; 8396 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8397 ut_params->cipher_xform.cipher.iv.length = 8398 packet_direction ? 4 : 0; 8399 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8400 8401 /* Setup HMAC Parameters if ICV header is required */ 8402 if (auth_alg != 0) { 8403 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8404 ut_params->auth_xform.next = NULL; 8405 ut_params->auth_xform.auth.algo = auth_alg; 8406 ut_params->auth_xform.auth.op = opa; 8407 ut_params->auth_xform.auth.key.data = auth_key; 8408 ut_params->auth_xform.auth.key.length = auth_key_len; 8409 8410 ut_params->cipher_xform.next = &ut_params->auth_xform; 8411 } else { 8412 ut_params->cipher_xform.next = NULL; 8413 } 8414 8415 struct rte_security_session_conf sess_conf = { 8416 .action_type = ut_params->type, 8417 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8418 {.pdcp = { 8419 .bearer = bearer, 8420 .domain = domain, 8421 .pkt_dir = packet_direction, 8422 .sn_size = sn_size, 8423 .hfn = packet_direction ? 0 : hfn, 8424 /** 8425 * hfn can be set as pdcp_test_hfn[i] 8426 * if hfn_ovrd is not set. Here, PDCP 8427 * packet direction is just used to 8428 * run half of the cases with session 8429 * HFN and other half with per packet 8430 * HFN. 8431 */ 8432 .hfn_threshold = hfn_threshold, 8433 .hfn_ovrd = packet_direction ? 1 : 0, 8434 .sdap_enabled = sdap, 8435 } }, 8436 .crypto_xform = &ut_params->cipher_xform 8437 }; 8438 8439 /* Create security session */ 8440 ut_params->sec_session = rte_security_session_create(ctx, 8441 &sess_conf, ts_params->session_mpool, 8442 ts_params->session_priv_mpool); 8443 8444 if (!ut_params->sec_session) { 8445 printf("TestCase %s()-%d line %d failed %s: ", 8446 __func__, i, __LINE__, "Failed to allocate session"); 8447 ret = TEST_FAILED; 8448 goto on_err; 8449 } 8450 8451 /* Generate crypto op data structure */ 8452 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8453 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8454 if (!ut_params->op) { 8455 printf("TestCase %s()-%d line %d failed %s: ", 8456 __func__, i, __LINE__, 8457 "Failed to allocate symmetric crypto operation struct"); 8458 ret = TEST_FAILED; 8459 goto on_err; 8460 } 8461 8462 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8463 uint32_t *, IV_OFFSET); 8464 *per_pkt_hfn = packet_direction ? hfn : 0; 8465 8466 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8467 8468 /* set crypto operation source mbuf */ 8469 ut_params->op->sym->m_src = ut_params->ibuf; 8470 if (oop) 8471 ut_params->op->sym->m_dst = ut_params->obuf; 8472 8473 /* Process crypto operation */ 8474 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8475 == NULL) { 8476 printf("TestCase %s()-%d line %d failed %s: ", 8477 __func__, i, __LINE__, 8478 "failed to process sym crypto op"); 8479 ret = TEST_FAILED; 8480 goto on_err; 8481 } 8482 8483 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8484 printf("TestCase %s()-%d line %d failed %s: ", 8485 __func__, i, __LINE__, "crypto op processing failed"); 8486 ret = TEST_FAILED; 8487 goto on_err; 8488 } 8489 8490 /* Validate obuf */ 8491 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8492 uint8_t *); 8493 if (oop) { 8494 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8495 uint8_t *); 8496 } 8497 8498 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8499 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8500 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8501 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8502 ret = TEST_FAILED; 8503 goto on_err; 8504 } 8505 8506 on_err: 8507 rte_crypto_op_free(ut_params->op); 8508 ut_params->op = NULL; 8509 8510 if (ut_params->sec_session) 8511 rte_security_session_destroy(ctx, ut_params->sec_session); 8512 ut_params->sec_session = NULL; 8513 8514 rte_pktmbuf_free(ut_params->ibuf); 8515 ut_params->ibuf = NULL; 8516 if (oop) { 8517 rte_pktmbuf_free(ut_params->obuf); 8518 ut_params->obuf = NULL; 8519 } 8520 8521 return ret; 8522 } 8523 8524 static int 8525 test_pdcp_proto_SGL(int i, int oop, 8526 enum rte_crypto_cipher_operation opc, 8527 enum rte_crypto_auth_operation opa, 8528 uint8_t *input_vec, 8529 unsigned int input_vec_len, 8530 uint8_t *output_vec, 8531 unsigned int output_vec_len, 8532 uint32_t fragsz, 8533 uint32_t fragsz_oop) 8534 { 8535 struct crypto_testsuite_params *ts_params = &testsuite_params; 8536 struct crypto_unittest_params *ut_params = &unittest_params; 8537 uint8_t *plaintext; 8538 struct rte_mbuf *buf, *buf_oop = NULL; 8539 int ret = TEST_SUCCESS; 8540 int to_trn = 0; 8541 int to_trn_tbl[16]; 8542 int segs = 1; 8543 unsigned int trn_data = 0; 8544 struct rte_cryptodev_info dev_info; 8545 uint64_t feat_flags; 8546 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8547 rte_cryptodev_get_sec_ctx( 8548 ts_params->valid_devs[0]); 8549 struct rte_mbuf *temp_mbuf; 8550 8551 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8552 feat_flags = dev_info.feature_flags; 8553 8554 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8555 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8556 printf("Device does not support RAW data-path APIs.\n"); 8557 return -ENOTSUP; 8558 } 8559 /* Verify the capabilities */ 8560 struct rte_security_capability_idx sec_cap_idx; 8561 8562 sec_cap_idx.action = ut_params->type; 8563 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8564 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8565 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8566 return TEST_SKIPPED; 8567 8568 if (fragsz > input_vec_len) 8569 fragsz = input_vec_len; 8570 8571 uint16_t plaintext_len = fragsz; 8572 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8573 8574 if (fragsz_oop > output_vec_len) 8575 frag_size_oop = output_vec_len; 8576 8577 int ecx = 0; 8578 if (input_vec_len % fragsz != 0) { 8579 if (input_vec_len / fragsz + 1 > 16) 8580 return 1; 8581 } else if (input_vec_len / fragsz > 16) 8582 return 1; 8583 8584 /* Out of place support */ 8585 if (oop) { 8586 /* 8587 * For out-op-place we need to alloc another mbuf 8588 */ 8589 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8590 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8591 buf_oop = ut_params->obuf; 8592 } 8593 8594 /* Generate test mbuf data */ 8595 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8596 8597 /* clear mbuf payload */ 8598 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8599 rte_pktmbuf_tailroom(ut_params->ibuf)); 8600 8601 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8602 plaintext_len); 8603 memcpy(plaintext, input_vec, plaintext_len); 8604 trn_data += plaintext_len; 8605 8606 buf = ut_params->ibuf; 8607 8608 /* 8609 * Loop until no more fragments 8610 */ 8611 8612 while (trn_data < input_vec_len) { 8613 ++segs; 8614 to_trn = (input_vec_len - trn_data < fragsz) ? 8615 (input_vec_len - trn_data) : fragsz; 8616 8617 to_trn_tbl[ecx++] = to_trn; 8618 8619 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8620 buf = buf->next; 8621 8622 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8623 rte_pktmbuf_tailroom(buf)); 8624 8625 /* OOP */ 8626 if (oop && !fragsz_oop) { 8627 buf_oop->next = 8628 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8629 buf_oop = buf_oop->next; 8630 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8631 0, rte_pktmbuf_tailroom(buf_oop)); 8632 rte_pktmbuf_append(buf_oop, to_trn); 8633 } 8634 8635 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8636 to_trn); 8637 8638 memcpy(plaintext, input_vec + trn_data, to_trn); 8639 trn_data += to_trn; 8640 } 8641 8642 ut_params->ibuf->nb_segs = segs; 8643 8644 segs = 1; 8645 if (fragsz_oop && oop) { 8646 to_trn = 0; 8647 ecx = 0; 8648 8649 trn_data = frag_size_oop; 8650 while (trn_data < output_vec_len) { 8651 ++segs; 8652 to_trn = 8653 (output_vec_len - trn_data < 8654 frag_size_oop) ? 8655 (output_vec_len - trn_data) : 8656 frag_size_oop; 8657 8658 to_trn_tbl[ecx++] = to_trn; 8659 8660 buf_oop->next = 8661 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8662 buf_oop = buf_oop->next; 8663 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8664 0, rte_pktmbuf_tailroom(buf_oop)); 8665 rte_pktmbuf_append(buf_oop, to_trn); 8666 8667 trn_data += to_trn; 8668 } 8669 ut_params->obuf->nb_segs = segs; 8670 } 8671 8672 /* Setup Cipher Parameters */ 8673 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8674 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8675 ut_params->cipher_xform.cipher.op = opc; 8676 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8677 ut_params->cipher_xform.cipher.key.length = 8678 pdcp_test_params[i].cipher_key_len; 8679 ut_params->cipher_xform.cipher.iv.length = 0; 8680 8681 /* Setup HMAC Parameters if ICV header is required */ 8682 if (pdcp_test_params[i].auth_alg != 0) { 8683 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8684 ut_params->auth_xform.next = NULL; 8685 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8686 ut_params->auth_xform.auth.op = opa; 8687 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8688 ut_params->auth_xform.auth.key.length = 8689 pdcp_test_params[i].auth_key_len; 8690 8691 ut_params->cipher_xform.next = &ut_params->auth_xform; 8692 } else { 8693 ut_params->cipher_xform.next = NULL; 8694 } 8695 8696 struct rte_security_session_conf sess_conf = { 8697 .action_type = ut_params->type, 8698 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8699 {.pdcp = { 8700 .bearer = pdcp_test_bearer[i], 8701 .domain = pdcp_test_params[i].domain, 8702 .pkt_dir = pdcp_test_packet_direction[i], 8703 .sn_size = pdcp_test_data_sn_size[i], 8704 .hfn = pdcp_test_hfn[i], 8705 .hfn_threshold = pdcp_test_hfn_threshold[i], 8706 .hfn_ovrd = 0, 8707 } }, 8708 .crypto_xform = &ut_params->cipher_xform 8709 }; 8710 8711 /* Create security session */ 8712 ut_params->sec_session = rte_security_session_create(ctx, 8713 &sess_conf, ts_params->session_mpool, 8714 ts_params->session_priv_mpool); 8715 8716 if (!ut_params->sec_session) { 8717 printf("TestCase %s()-%d line %d failed %s: ", 8718 __func__, i, __LINE__, "Failed to allocate session"); 8719 ret = TEST_FAILED; 8720 goto on_err; 8721 } 8722 8723 /* Generate crypto op data structure */ 8724 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8725 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8726 if (!ut_params->op) { 8727 printf("TestCase %s()-%d line %d failed %s: ", 8728 __func__, i, __LINE__, 8729 "Failed to allocate symmetric crypto operation struct"); 8730 ret = TEST_FAILED; 8731 goto on_err; 8732 } 8733 8734 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8735 8736 /* set crypto operation source mbuf */ 8737 ut_params->op->sym->m_src = ut_params->ibuf; 8738 if (oop) 8739 ut_params->op->sym->m_dst = ut_params->obuf; 8740 8741 /* Process crypto operation */ 8742 temp_mbuf = ut_params->op->sym->m_src; 8743 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8744 /* filling lengths */ 8745 while (temp_mbuf) { 8746 ut_params->op->sym->cipher.data.length 8747 += temp_mbuf->pkt_len; 8748 ut_params->op->sym->auth.data.length 8749 += temp_mbuf->pkt_len; 8750 temp_mbuf = temp_mbuf->next; 8751 } 8752 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8753 ut_params->op, 1, 1, 0, 0); 8754 } else { 8755 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 8756 ut_params->op); 8757 } 8758 if (ut_params->op == NULL) { 8759 printf("TestCase %s()-%d line %d failed %s: ", 8760 __func__, i, __LINE__, 8761 "failed to process sym crypto op"); 8762 ret = TEST_FAILED; 8763 goto on_err; 8764 } 8765 8766 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8767 printf("TestCase %s()-%d line %d failed %s: ", 8768 __func__, i, __LINE__, "crypto op processing failed"); 8769 ret = TEST_FAILED; 8770 goto on_err; 8771 } 8772 8773 /* Validate obuf */ 8774 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8775 uint8_t *); 8776 if (oop) { 8777 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8778 uint8_t *); 8779 } 8780 if (fragsz_oop) 8781 fragsz = frag_size_oop; 8782 if (memcmp(ciphertext, output_vec, fragsz)) { 8783 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8784 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8785 rte_hexdump(stdout, "reference", output_vec, fragsz); 8786 ret = TEST_FAILED; 8787 goto on_err; 8788 } 8789 8790 buf = ut_params->op->sym->m_src->next; 8791 if (oop) 8792 buf = ut_params->op->sym->m_dst->next; 8793 8794 unsigned int off = fragsz; 8795 8796 ecx = 0; 8797 while (buf) { 8798 ciphertext = rte_pktmbuf_mtod(buf, 8799 uint8_t *); 8800 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8801 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8802 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8803 rte_hexdump(stdout, "reference", output_vec + off, 8804 to_trn_tbl[ecx]); 8805 ret = TEST_FAILED; 8806 goto on_err; 8807 } 8808 off += to_trn_tbl[ecx++]; 8809 buf = buf->next; 8810 } 8811 on_err: 8812 rte_crypto_op_free(ut_params->op); 8813 ut_params->op = NULL; 8814 8815 if (ut_params->sec_session) 8816 rte_security_session_destroy(ctx, ut_params->sec_session); 8817 ut_params->sec_session = NULL; 8818 8819 rte_pktmbuf_free(ut_params->ibuf); 8820 ut_params->ibuf = NULL; 8821 if (oop) { 8822 rte_pktmbuf_free(ut_params->obuf); 8823 ut_params->obuf = NULL; 8824 } 8825 8826 return ret; 8827 } 8828 8829 int 8830 test_pdcp_proto_cplane_encap(int i) 8831 { 8832 return test_pdcp_proto( 8833 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8834 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8835 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8836 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8837 pdcp_test_params[i].cipher_key_len, 8838 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8839 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8840 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8841 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8842 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8843 } 8844 8845 int 8846 test_pdcp_proto_uplane_encap(int i) 8847 { 8848 return test_pdcp_proto( 8849 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8850 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8851 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8852 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8853 pdcp_test_params[i].cipher_key_len, 8854 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8855 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8856 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8857 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8858 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8859 } 8860 8861 int 8862 test_pdcp_proto_uplane_encap_with_int(int i) 8863 { 8864 return test_pdcp_proto( 8865 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8866 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8867 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8868 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8869 pdcp_test_params[i].cipher_key_len, 8870 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8871 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8872 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8873 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8874 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8875 } 8876 8877 int 8878 test_pdcp_proto_cplane_decap(int i) 8879 { 8880 return test_pdcp_proto( 8881 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8882 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8883 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8884 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8885 pdcp_test_params[i].cipher_key_len, 8886 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8887 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8888 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8889 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8890 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8891 } 8892 8893 int 8894 test_pdcp_proto_uplane_decap(int i) 8895 { 8896 return test_pdcp_proto( 8897 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8898 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8899 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8900 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8901 pdcp_test_params[i].cipher_key_len, 8902 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8903 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8904 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8905 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8906 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8907 } 8908 8909 int 8910 test_pdcp_proto_uplane_decap_with_int(int i) 8911 { 8912 return test_pdcp_proto( 8913 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8914 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8915 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8916 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8917 pdcp_test_params[i].cipher_key_len, 8918 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8919 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8920 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8921 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8922 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8923 } 8924 8925 static int 8926 test_PDCP_PROTO_SGL_in_place_32B(void) 8927 { 8928 /* i can be used for running any PDCP case 8929 * In this case it is uplane 12-bit AES-SNOW DL encap 8930 */ 8931 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8932 return test_pdcp_proto_SGL(i, IN_PLACE, 8933 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8934 RTE_CRYPTO_AUTH_OP_GENERATE, 8935 pdcp_test_data_in[i], 8936 pdcp_test_data_in_len[i], 8937 pdcp_test_data_out[i], 8938 pdcp_test_data_in_len[i]+4, 8939 32, 0); 8940 } 8941 static int 8942 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8943 { 8944 /* i can be used for running any PDCP case 8945 * In this case it is uplane 18-bit NULL-NULL DL encap 8946 */ 8947 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8948 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8949 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8950 RTE_CRYPTO_AUTH_OP_GENERATE, 8951 pdcp_test_data_in[i], 8952 pdcp_test_data_in_len[i], 8953 pdcp_test_data_out[i], 8954 pdcp_test_data_in_len[i]+4, 8955 32, 128); 8956 } 8957 static int 8958 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8959 { 8960 /* i can be used for running any PDCP case 8961 * In this case it is uplane 18-bit AES DL encap 8962 */ 8963 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8964 + DOWNLINK; 8965 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8966 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8967 RTE_CRYPTO_AUTH_OP_GENERATE, 8968 pdcp_test_data_in[i], 8969 pdcp_test_data_in_len[i], 8970 pdcp_test_data_out[i], 8971 pdcp_test_data_in_len[i], 8972 32, 40); 8973 } 8974 static int 8975 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8976 { 8977 /* i can be used for running any PDCP case 8978 * In this case it is cplane 12-bit AES-ZUC DL encap 8979 */ 8980 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8981 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8982 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8983 RTE_CRYPTO_AUTH_OP_GENERATE, 8984 pdcp_test_data_in[i], 8985 pdcp_test_data_in_len[i], 8986 pdcp_test_data_out[i], 8987 pdcp_test_data_in_len[i]+4, 8988 128, 32); 8989 } 8990 8991 static int 8992 test_PDCP_SDAP_PROTO_encap_all(void) 8993 { 8994 int i = 0, size = 0; 8995 int err, all_err = TEST_SUCCESS; 8996 const struct pdcp_sdap_test *cur_test; 8997 8998 size = RTE_DIM(list_pdcp_sdap_tests); 8999 9000 for (i = 0; i < size; i++) { 9001 cur_test = &list_pdcp_sdap_tests[i]; 9002 err = test_pdcp_proto( 9003 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9004 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9005 cur_test->in_len, cur_test->data_out, 9006 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9007 cur_test->param.cipher_alg, cur_test->cipher_key, 9008 cur_test->param.cipher_key_len, 9009 cur_test->param.auth_alg, 9010 cur_test->auth_key, cur_test->param.auth_key_len, 9011 cur_test->bearer, cur_test->param.domain, 9012 cur_test->packet_direction, cur_test->sn_size, 9013 cur_test->hfn, 9014 cur_test->hfn_threshold, SDAP_ENABLED); 9015 if (err) { 9016 printf("\t%d) %s: Encapsulation failed\n", 9017 cur_test->test_idx, 9018 cur_test->param.name); 9019 err = TEST_FAILED; 9020 } else { 9021 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9022 cur_test->param.name); 9023 err = TEST_SUCCESS; 9024 } 9025 all_err += err; 9026 } 9027 9028 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9029 9030 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9031 } 9032 9033 static int 9034 test_PDCP_PROTO_short_mac(void) 9035 { 9036 int i = 0, size = 0; 9037 int err, all_err = TEST_SUCCESS; 9038 const struct pdcp_short_mac_test *cur_test; 9039 9040 size = RTE_DIM(list_pdcp_smac_tests); 9041 9042 for (i = 0; i < size; i++) { 9043 cur_test = &list_pdcp_smac_tests[i]; 9044 err = test_pdcp_proto( 9045 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9046 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9047 cur_test->in_len, cur_test->data_out, 9048 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9049 RTE_CRYPTO_CIPHER_NULL, NULL, 9050 0, cur_test->param.auth_alg, 9051 cur_test->auth_key, cur_test->param.auth_key_len, 9052 0, cur_test->param.domain, 0, 0, 9053 0, 0, 0); 9054 if (err) { 9055 printf("\t%d) %s: Short MAC test failed\n", 9056 cur_test->test_idx, 9057 cur_test->param.name); 9058 err = TEST_FAILED; 9059 } else { 9060 printf("\t%d) %s: Short MAC test PASS\n", 9061 cur_test->test_idx, 9062 cur_test->param.name); 9063 rte_hexdump(stdout, "MAC I", 9064 cur_test->data_out + cur_test->in_len + 2, 9065 2); 9066 err = TEST_SUCCESS; 9067 } 9068 all_err += err; 9069 } 9070 9071 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9072 9073 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9074 9075 } 9076 9077 static int 9078 test_PDCP_SDAP_PROTO_decap_all(void) 9079 { 9080 int i = 0, size = 0; 9081 int err, all_err = TEST_SUCCESS; 9082 const struct pdcp_sdap_test *cur_test; 9083 9084 size = RTE_DIM(list_pdcp_sdap_tests); 9085 9086 for (i = 0; i < size; i++) { 9087 cur_test = &list_pdcp_sdap_tests[i]; 9088 err = test_pdcp_proto( 9089 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9090 RTE_CRYPTO_AUTH_OP_VERIFY, 9091 cur_test->data_out, 9092 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9093 cur_test->data_in, cur_test->in_len, 9094 cur_test->param.cipher_alg, 9095 cur_test->cipher_key, cur_test->param.cipher_key_len, 9096 cur_test->param.auth_alg, cur_test->auth_key, 9097 cur_test->param.auth_key_len, cur_test->bearer, 9098 cur_test->param.domain, cur_test->packet_direction, 9099 cur_test->sn_size, cur_test->hfn, 9100 cur_test->hfn_threshold, SDAP_ENABLED); 9101 if (err) { 9102 printf("\t%d) %s: Decapsulation failed\n", 9103 cur_test->test_idx, 9104 cur_test->param.name); 9105 err = TEST_FAILED; 9106 } else { 9107 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9108 cur_test->param.name); 9109 err = TEST_SUCCESS; 9110 } 9111 all_err += err; 9112 } 9113 9114 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9115 9116 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9117 } 9118 9119 static int 9120 test_ipsec_proto_process(const struct ipsec_test_data td[], 9121 struct ipsec_test_data res_d[], 9122 int nb_td, 9123 bool silent, 9124 const struct ipsec_test_flags *flags) 9125 { 9126 struct crypto_testsuite_params *ts_params = &testsuite_params; 9127 struct crypto_unittest_params *ut_params = &unittest_params; 9128 struct rte_security_capability_idx sec_cap_idx; 9129 const struct rte_security_capability *sec_cap; 9130 struct rte_security_ipsec_xform ipsec_xform; 9131 uint8_t dev_id = ts_params->valid_devs[0]; 9132 enum rte_security_ipsec_sa_direction dir; 9133 struct ipsec_test_data *res_d_tmp = NULL; 9134 uint32_t src = RTE_IPV4(192, 168, 1, 0); 9135 uint32_t dst = RTE_IPV4(192, 168, 1, 1); 9136 int salt_len, i, ret = TEST_SUCCESS; 9137 struct rte_security_ctx *ctx; 9138 uint8_t *input_text; 9139 uint32_t verify; 9140 9141 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9142 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9143 9144 /* Use first test data to create session */ 9145 9146 /* Copy IPsec xform */ 9147 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9148 9149 dir = ipsec_xform.direction; 9150 verify = flags->tunnel_hdr_verify; 9151 9152 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9153 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9154 src += 1; 9155 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9156 dst += 1; 9157 } 9158 9159 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src)); 9160 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst)); 9161 9162 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9163 9164 sec_cap_idx.action = ut_params->type; 9165 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9166 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9167 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9168 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9169 9170 if (flags->udp_encap) 9171 ipsec_xform.options.udp_encap = 1; 9172 9173 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9174 if (sec_cap == NULL) 9175 return TEST_SKIPPED; 9176 9177 /* Copy cipher session parameters */ 9178 if (td[0].aead) { 9179 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9180 sizeof(ut_params->aead_xform)); 9181 ut_params->aead_xform.aead.key.data = td[0].key.data; 9182 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9183 9184 /* Verify crypto capabilities */ 9185 if (test_ipsec_crypto_caps_aead_verify( 9186 sec_cap, 9187 &ut_params->aead_xform) != 0) { 9188 if (!silent) 9189 RTE_LOG(INFO, USER1, 9190 "Crypto capabilities not supported\n"); 9191 return TEST_SKIPPED; 9192 } 9193 } else { 9194 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 9195 sizeof(ut_params->cipher_xform)); 9196 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9197 sizeof(ut_params->auth_xform)); 9198 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 9199 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9200 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9201 9202 /* Verify crypto capabilities */ 9203 9204 if (test_ipsec_crypto_caps_cipher_verify( 9205 sec_cap, 9206 &ut_params->cipher_xform) != 0) { 9207 if (!silent) 9208 RTE_LOG(INFO, USER1, 9209 "Cipher crypto capabilities not supported\n"); 9210 return TEST_SKIPPED; 9211 } 9212 9213 if (test_ipsec_crypto_caps_auth_verify( 9214 sec_cap, 9215 &ut_params->auth_xform) != 0) { 9216 if (!silent) 9217 RTE_LOG(INFO, USER1, 9218 "Auth crypto capabilities not supported\n"); 9219 return TEST_SKIPPED; 9220 } 9221 } 9222 9223 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9224 return TEST_SKIPPED; 9225 9226 struct rte_security_session_conf sess_conf = { 9227 .action_type = ut_params->type, 9228 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9229 }; 9230 9231 if (td[0].aead) { 9232 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9233 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9234 sess_conf.ipsec = ipsec_xform; 9235 sess_conf.crypto_xform = &ut_params->aead_xform; 9236 } else { 9237 sess_conf.ipsec = ipsec_xform; 9238 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 9239 sess_conf.crypto_xform = &ut_params->cipher_xform; 9240 ut_params->cipher_xform.next = &ut_params->auth_xform; 9241 } else { 9242 sess_conf.crypto_xform = &ut_params->auth_xform; 9243 ut_params->auth_xform.next = &ut_params->cipher_xform; 9244 } 9245 } 9246 9247 /* Create security session */ 9248 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9249 ts_params->session_mpool, 9250 ts_params->session_priv_mpool); 9251 9252 if (ut_params->sec_session == NULL) 9253 return TEST_SKIPPED; 9254 9255 for (i = 0; i < nb_td; i++) { 9256 /* Setup source mbuf payload */ 9257 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9258 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9259 rte_pktmbuf_tailroom(ut_params->ibuf)); 9260 9261 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9262 td[i].input_text.len); 9263 9264 memcpy(input_text, td[i].input_text.data, 9265 td[i].input_text.len); 9266 9267 /* Generate crypto op data structure */ 9268 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9269 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9270 if (!ut_params->op) { 9271 printf("TestCase %s line %d: %s\n", 9272 __func__, __LINE__, 9273 "failed to allocate crypto op"); 9274 ret = TEST_FAILED; 9275 goto crypto_op_free; 9276 } 9277 9278 /* Attach session to operation */ 9279 rte_security_attach_session(ut_params->op, 9280 ut_params->sec_session); 9281 9282 /* Set crypto operation mbufs */ 9283 ut_params->op->sym->m_src = ut_params->ibuf; 9284 ut_params->op->sym->m_dst = NULL; 9285 9286 /* Copy IV in crypto operation when IV generation is disabled */ 9287 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9288 ipsec_xform.options.iv_gen_disable == 1) { 9289 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9290 uint8_t *, 9291 IV_OFFSET); 9292 int len; 9293 9294 if (td[i].aead) 9295 len = td[i].xform.aead.aead.iv.length; 9296 else 9297 len = td[i].xform.chain.cipher.cipher.iv.length; 9298 9299 memcpy(iv, td[i].iv.data, len); 9300 } 9301 9302 /* Process crypto operation */ 9303 process_crypto_request(dev_id, ut_params->op); 9304 9305 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1); 9306 if (ret != TEST_SUCCESS) 9307 goto crypto_op_free; 9308 9309 if (res_d != NULL) 9310 res_d_tmp = &res_d[i]; 9311 9312 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9313 res_d_tmp, silent, flags); 9314 if (ret != TEST_SUCCESS) 9315 goto crypto_op_free; 9316 9317 rte_crypto_op_free(ut_params->op); 9318 ut_params->op = NULL; 9319 9320 rte_pktmbuf_free(ut_params->ibuf); 9321 ut_params->ibuf = NULL; 9322 } 9323 9324 crypto_op_free: 9325 rte_crypto_op_free(ut_params->op); 9326 ut_params->op = NULL; 9327 9328 rte_pktmbuf_free(ut_params->ibuf); 9329 ut_params->ibuf = NULL; 9330 9331 if (ut_params->sec_session) 9332 rte_security_session_destroy(ctx, ut_params->sec_session); 9333 ut_params->sec_session = NULL; 9334 9335 return ret; 9336 } 9337 9338 static int 9339 test_ipsec_proto_known_vec(const void *test_data) 9340 { 9341 struct ipsec_test_data td_outb; 9342 struct ipsec_test_flags flags; 9343 9344 memset(&flags, 0, sizeof(flags)); 9345 9346 memcpy(&td_outb, test_data, sizeof(td_outb)); 9347 9348 /* Disable IV gen to be able to test with known vectors */ 9349 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9350 9351 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9352 } 9353 9354 static int 9355 test_ipsec_proto_known_vec_inb(const void *test_data) 9356 { 9357 const struct ipsec_test_data *td = test_data; 9358 struct ipsec_test_flags flags; 9359 struct ipsec_test_data td_inb; 9360 9361 memset(&flags, 0, sizeof(flags)); 9362 9363 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 9364 test_ipsec_td_in_from_out(td, &td_inb); 9365 else 9366 memcpy(&td_inb, td, sizeof(td_inb)); 9367 9368 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9369 } 9370 9371 static int 9372 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9373 { 9374 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9375 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9376 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9377 int ret; 9378 9379 if (flags->iv_gen || 9380 flags->sa_expiry_pkts_soft || 9381 flags->sa_expiry_pkts_hard) 9382 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9383 9384 for (i = 0; i < RTE_DIM(aead_list); i++) { 9385 test_ipsec_td_prepare(&aead_list[i], 9386 NULL, 9387 flags, 9388 td_outb, 9389 nb_pkts); 9390 9391 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9392 flags); 9393 if (ret == TEST_SKIPPED) 9394 continue; 9395 9396 if (ret == TEST_FAILED) 9397 return TEST_FAILED; 9398 9399 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9400 9401 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9402 flags); 9403 if (ret == TEST_SKIPPED) 9404 continue; 9405 9406 if (ret == TEST_FAILED) 9407 return TEST_FAILED; 9408 9409 if (flags->display_alg) 9410 test_ipsec_display_alg(&aead_list[i], NULL); 9411 9412 pass_cnt++; 9413 } 9414 9415 if (pass_cnt > 0) 9416 return TEST_SUCCESS; 9417 else 9418 return TEST_SKIPPED; 9419 } 9420 9421 static int 9422 test_ipsec_proto_display_list(const void *data __rte_unused) 9423 { 9424 struct ipsec_test_flags flags; 9425 9426 memset(&flags, 0, sizeof(flags)); 9427 9428 flags.display_alg = true; 9429 9430 return test_ipsec_proto_all(&flags); 9431 } 9432 9433 static int 9434 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9435 { 9436 struct ipsec_test_flags flags; 9437 9438 memset(&flags, 0, sizeof(flags)); 9439 9440 flags.iv_gen = true; 9441 9442 return test_ipsec_proto_all(&flags); 9443 } 9444 9445 static int 9446 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9447 { 9448 struct ipsec_test_flags flags; 9449 9450 memset(&flags, 0, sizeof(flags)); 9451 9452 flags.sa_expiry_pkts_soft = true; 9453 9454 return test_ipsec_proto_all(&flags); 9455 } 9456 9457 static int 9458 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9459 { 9460 struct ipsec_test_flags flags; 9461 9462 memset(&flags, 0, sizeof(flags)); 9463 9464 flags.sa_expiry_pkts_hard = true; 9465 9466 return test_ipsec_proto_all(&flags); 9467 } 9468 9469 static int 9470 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9471 { 9472 struct ipsec_test_flags flags; 9473 9474 memset(&flags, 0, sizeof(flags)); 9475 9476 flags.icv_corrupt = true; 9477 9478 return test_ipsec_proto_all(&flags); 9479 } 9480 9481 static int 9482 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9483 { 9484 struct ipsec_test_flags flags; 9485 9486 memset(&flags, 0, sizeof(flags)); 9487 9488 flags.udp_encap = true; 9489 9490 return test_ipsec_proto_all(&flags); 9491 } 9492 9493 static int 9494 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9495 { 9496 struct ipsec_test_flags flags; 9497 9498 memset(&flags, 0, sizeof(flags)); 9499 9500 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9501 9502 return test_ipsec_proto_all(&flags); 9503 } 9504 9505 static int 9506 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9507 { 9508 struct ipsec_test_flags flags; 9509 9510 memset(&flags, 0, sizeof(flags)); 9511 9512 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9513 9514 return test_ipsec_proto_all(&flags); 9515 } 9516 9517 static int 9518 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9519 { 9520 struct ipsec_test_flags flags; 9521 9522 memset(&flags, 0, sizeof(flags)); 9523 9524 flags.udp_encap = true; 9525 flags.udp_ports_verify = true; 9526 9527 return test_ipsec_proto_all(&flags); 9528 } 9529 9530 static int 9531 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9532 { 9533 struct ipsec_test_flags flags; 9534 9535 memset(&flags, 0, sizeof(flags)); 9536 9537 flags.ip_csum = true; 9538 9539 return test_ipsec_proto_all(&flags); 9540 } 9541 9542 static int 9543 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9544 { 9545 struct ipsec_test_flags flags; 9546 9547 memset(&flags, 0, sizeof(flags)); 9548 9549 flags.l4_csum = true; 9550 9551 return test_ipsec_proto_all(&flags); 9552 } 9553 9554 static int 9555 test_PDCP_PROTO_all(void) 9556 { 9557 struct crypto_testsuite_params *ts_params = &testsuite_params; 9558 struct crypto_unittest_params *ut_params = &unittest_params; 9559 struct rte_cryptodev_info dev_info; 9560 int status; 9561 9562 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9563 uint64_t feat_flags = dev_info.feature_flags; 9564 9565 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 9566 return TEST_SKIPPED; 9567 9568 /* Set action type */ 9569 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9570 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9571 gbl_action_type; 9572 9573 if (security_proto_supported(ut_params->type, 9574 RTE_SECURITY_PROTOCOL_PDCP) < 0) 9575 return TEST_SKIPPED; 9576 9577 status = test_PDCP_PROTO_cplane_encap_all(); 9578 status += test_PDCP_PROTO_cplane_decap_all(); 9579 status += test_PDCP_PROTO_uplane_encap_all(); 9580 status += test_PDCP_PROTO_uplane_decap_all(); 9581 status += test_PDCP_PROTO_SGL_in_place_32B(); 9582 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 9583 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 9584 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 9585 status += test_PDCP_SDAP_PROTO_encap_all(); 9586 status += test_PDCP_SDAP_PROTO_decap_all(); 9587 status += test_PDCP_PROTO_short_mac(); 9588 9589 if (status) 9590 return TEST_FAILED; 9591 else 9592 return TEST_SUCCESS; 9593 } 9594 9595 static int 9596 test_docsis_proto_uplink(const void *data) 9597 { 9598 const struct docsis_test_data *d_td = data; 9599 struct crypto_testsuite_params *ts_params = &testsuite_params; 9600 struct crypto_unittest_params *ut_params = &unittest_params; 9601 uint8_t *plaintext = NULL; 9602 uint8_t *ciphertext = NULL; 9603 uint8_t *iv_ptr; 9604 int32_t cipher_len, crc_len; 9605 uint32_t crc_data_len; 9606 int ret = TEST_SUCCESS; 9607 9608 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9609 rte_cryptodev_get_sec_ctx( 9610 ts_params->valid_devs[0]); 9611 9612 /* Verify the capabilities */ 9613 struct rte_security_capability_idx sec_cap_idx; 9614 const struct rte_security_capability *sec_cap; 9615 const struct rte_cryptodev_capabilities *crypto_cap; 9616 const struct rte_cryptodev_symmetric_capability *sym_cap; 9617 int j = 0; 9618 9619 /* Set action type */ 9620 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9621 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9622 gbl_action_type; 9623 9624 if (security_proto_supported(ut_params->type, 9625 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9626 return TEST_SKIPPED; 9627 9628 sec_cap_idx.action = ut_params->type; 9629 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9630 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 9631 9632 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9633 if (sec_cap == NULL) 9634 return TEST_SKIPPED; 9635 9636 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9637 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9638 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9639 crypto_cap->sym.xform_type == 9640 RTE_CRYPTO_SYM_XFORM_CIPHER && 9641 crypto_cap->sym.cipher.algo == 9642 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9643 sym_cap = &crypto_cap->sym; 9644 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9645 d_td->key.len, 9646 d_td->iv.len) == 0) 9647 break; 9648 } 9649 } 9650 9651 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9652 return TEST_SKIPPED; 9653 9654 /* Setup source mbuf payload */ 9655 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9656 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9657 rte_pktmbuf_tailroom(ut_params->ibuf)); 9658 9659 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9660 d_td->ciphertext.len); 9661 9662 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 9663 9664 /* Setup cipher session parameters */ 9665 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9666 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9667 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 9668 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9669 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9670 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9671 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9672 ut_params->cipher_xform.next = NULL; 9673 9674 /* Setup DOCSIS session parameters */ 9675 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 9676 9677 struct rte_security_session_conf sess_conf = { 9678 .action_type = ut_params->type, 9679 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9680 .docsis = ut_params->docsis_xform, 9681 .crypto_xform = &ut_params->cipher_xform, 9682 }; 9683 9684 /* Create security session */ 9685 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9686 ts_params->session_mpool, 9687 ts_params->session_priv_mpool); 9688 9689 if (!ut_params->sec_session) { 9690 printf("Test function %s line %u: failed to allocate session\n", 9691 __func__, __LINE__); 9692 ret = TEST_FAILED; 9693 goto on_err; 9694 } 9695 9696 /* Generate crypto op data structure */ 9697 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9698 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9699 if (!ut_params->op) { 9700 printf("Test function %s line %u: failed to allocate symmetric " 9701 "crypto operation\n", __func__, __LINE__); 9702 ret = TEST_FAILED; 9703 goto on_err; 9704 } 9705 9706 /* Setup CRC operation parameters */ 9707 crc_len = d_td->ciphertext.no_crc == false ? 9708 (d_td->ciphertext.len - 9709 d_td->ciphertext.crc_offset - 9710 RTE_ETHER_CRC_LEN) : 9711 0; 9712 crc_len = crc_len > 0 ? crc_len : 0; 9713 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 9714 ut_params->op->sym->auth.data.length = crc_len; 9715 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 9716 9717 /* Setup cipher operation parameters */ 9718 cipher_len = d_td->ciphertext.no_cipher == false ? 9719 (d_td->ciphertext.len - 9720 d_td->ciphertext.cipher_offset) : 9721 0; 9722 cipher_len = cipher_len > 0 ? cipher_len : 0; 9723 ut_params->op->sym->cipher.data.length = cipher_len; 9724 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 9725 9726 /* Setup cipher IV */ 9727 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9728 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9729 9730 /* Attach session to operation */ 9731 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9732 9733 /* Set crypto operation mbufs */ 9734 ut_params->op->sym->m_src = ut_params->ibuf; 9735 ut_params->op->sym->m_dst = NULL; 9736 9737 /* Process crypto operation */ 9738 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9739 NULL) { 9740 printf("Test function %s line %u: failed to process security " 9741 "crypto op\n", __func__, __LINE__); 9742 ret = TEST_FAILED; 9743 goto on_err; 9744 } 9745 9746 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9747 printf("Test function %s line %u: failed to process crypto op\n", 9748 __func__, __LINE__); 9749 ret = TEST_FAILED; 9750 goto on_err; 9751 } 9752 9753 /* Validate plaintext */ 9754 plaintext = ciphertext; 9755 9756 if (memcmp(plaintext, d_td->plaintext.data, 9757 d_td->plaintext.len - crc_data_len)) { 9758 printf("Test function %s line %u: plaintext not as expected\n", 9759 __func__, __LINE__); 9760 rte_hexdump(stdout, "expected", d_td->plaintext.data, 9761 d_td->plaintext.len); 9762 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 9763 ret = TEST_FAILED; 9764 goto on_err; 9765 } 9766 9767 on_err: 9768 rte_crypto_op_free(ut_params->op); 9769 ut_params->op = NULL; 9770 9771 if (ut_params->sec_session) 9772 rte_security_session_destroy(ctx, ut_params->sec_session); 9773 ut_params->sec_session = NULL; 9774 9775 rte_pktmbuf_free(ut_params->ibuf); 9776 ut_params->ibuf = NULL; 9777 9778 return ret; 9779 } 9780 9781 static int 9782 test_docsis_proto_downlink(const void *data) 9783 { 9784 const struct docsis_test_data *d_td = data; 9785 struct crypto_testsuite_params *ts_params = &testsuite_params; 9786 struct crypto_unittest_params *ut_params = &unittest_params; 9787 uint8_t *plaintext = NULL; 9788 uint8_t *ciphertext = NULL; 9789 uint8_t *iv_ptr; 9790 int32_t cipher_len, crc_len; 9791 int ret = TEST_SUCCESS; 9792 9793 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9794 rte_cryptodev_get_sec_ctx( 9795 ts_params->valid_devs[0]); 9796 9797 /* Verify the capabilities */ 9798 struct rte_security_capability_idx sec_cap_idx; 9799 const struct rte_security_capability *sec_cap; 9800 const struct rte_cryptodev_capabilities *crypto_cap; 9801 const struct rte_cryptodev_symmetric_capability *sym_cap; 9802 int j = 0; 9803 9804 /* Set action type */ 9805 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9806 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9807 gbl_action_type; 9808 9809 if (security_proto_supported(ut_params->type, 9810 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9811 return TEST_SKIPPED; 9812 9813 sec_cap_idx.action = ut_params->type; 9814 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9815 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9816 9817 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9818 if (sec_cap == NULL) 9819 return TEST_SKIPPED; 9820 9821 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9822 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9823 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9824 crypto_cap->sym.xform_type == 9825 RTE_CRYPTO_SYM_XFORM_CIPHER && 9826 crypto_cap->sym.cipher.algo == 9827 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9828 sym_cap = &crypto_cap->sym; 9829 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9830 d_td->key.len, 9831 d_td->iv.len) == 0) 9832 break; 9833 } 9834 } 9835 9836 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9837 return TEST_SKIPPED; 9838 9839 /* Setup source mbuf payload */ 9840 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9841 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9842 rte_pktmbuf_tailroom(ut_params->ibuf)); 9843 9844 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9845 d_td->plaintext.len); 9846 9847 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 9848 9849 /* Setup cipher session parameters */ 9850 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9851 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9852 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9853 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9854 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9855 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9856 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9857 ut_params->cipher_xform.next = NULL; 9858 9859 /* Setup DOCSIS session parameters */ 9860 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9861 9862 struct rte_security_session_conf sess_conf = { 9863 .action_type = ut_params->type, 9864 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9865 .docsis = ut_params->docsis_xform, 9866 .crypto_xform = &ut_params->cipher_xform, 9867 }; 9868 9869 /* Create security session */ 9870 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9871 ts_params->session_mpool, 9872 ts_params->session_priv_mpool); 9873 9874 if (!ut_params->sec_session) { 9875 printf("Test function %s line %u: failed to allocate session\n", 9876 __func__, __LINE__); 9877 ret = TEST_FAILED; 9878 goto on_err; 9879 } 9880 9881 /* Generate crypto op data structure */ 9882 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9883 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9884 if (!ut_params->op) { 9885 printf("Test function %s line %u: failed to allocate symmetric " 9886 "crypto operation\n", __func__, __LINE__); 9887 ret = TEST_FAILED; 9888 goto on_err; 9889 } 9890 9891 /* Setup CRC operation parameters */ 9892 crc_len = d_td->plaintext.no_crc == false ? 9893 (d_td->plaintext.len - 9894 d_td->plaintext.crc_offset - 9895 RTE_ETHER_CRC_LEN) : 9896 0; 9897 crc_len = crc_len > 0 ? crc_len : 0; 9898 ut_params->op->sym->auth.data.length = crc_len; 9899 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 9900 9901 /* Setup cipher operation parameters */ 9902 cipher_len = d_td->plaintext.no_cipher == false ? 9903 (d_td->plaintext.len - 9904 d_td->plaintext.cipher_offset) : 9905 0; 9906 cipher_len = cipher_len > 0 ? cipher_len : 0; 9907 ut_params->op->sym->cipher.data.length = cipher_len; 9908 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 9909 9910 /* Setup cipher IV */ 9911 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9912 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9913 9914 /* Attach session to operation */ 9915 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9916 9917 /* Set crypto operation mbufs */ 9918 ut_params->op->sym->m_src = ut_params->ibuf; 9919 ut_params->op->sym->m_dst = NULL; 9920 9921 /* Process crypto operation */ 9922 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9923 NULL) { 9924 printf("Test function %s line %u: failed to process crypto op\n", 9925 __func__, __LINE__); 9926 ret = TEST_FAILED; 9927 goto on_err; 9928 } 9929 9930 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9931 printf("Test function %s line %u: crypto op processing failed\n", 9932 __func__, __LINE__); 9933 ret = TEST_FAILED; 9934 goto on_err; 9935 } 9936 9937 /* Validate ciphertext */ 9938 ciphertext = plaintext; 9939 9940 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 9941 printf("Test function %s line %u: plaintext not as expected\n", 9942 __func__, __LINE__); 9943 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 9944 d_td->ciphertext.len); 9945 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 9946 ret = TEST_FAILED; 9947 goto on_err; 9948 } 9949 9950 on_err: 9951 rte_crypto_op_free(ut_params->op); 9952 ut_params->op = NULL; 9953 9954 if (ut_params->sec_session) 9955 rte_security_session_destroy(ctx, ut_params->sec_session); 9956 ut_params->sec_session = NULL; 9957 9958 rte_pktmbuf_free(ut_params->ibuf); 9959 ut_params->ibuf = NULL; 9960 9961 return ret; 9962 } 9963 #endif 9964 9965 static int 9966 test_AES_GCM_authenticated_encryption_test_case_1(void) 9967 { 9968 return test_authenticated_encryption(&gcm_test_case_1); 9969 } 9970 9971 static int 9972 test_AES_GCM_authenticated_encryption_test_case_2(void) 9973 { 9974 return test_authenticated_encryption(&gcm_test_case_2); 9975 } 9976 9977 static int 9978 test_AES_GCM_authenticated_encryption_test_case_3(void) 9979 { 9980 return test_authenticated_encryption(&gcm_test_case_3); 9981 } 9982 9983 static int 9984 test_AES_GCM_authenticated_encryption_test_case_4(void) 9985 { 9986 return test_authenticated_encryption(&gcm_test_case_4); 9987 } 9988 9989 static int 9990 test_AES_GCM_authenticated_encryption_test_case_5(void) 9991 { 9992 return test_authenticated_encryption(&gcm_test_case_5); 9993 } 9994 9995 static int 9996 test_AES_GCM_authenticated_encryption_test_case_6(void) 9997 { 9998 return test_authenticated_encryption(&gcm_test_case_6); 9999 } 10000 10001 static int 10002 test_AES_GCM_authenticated_encryption_test_case_7(void) 10003 { 10004 return test_authenticated_encryption(&gcm_test_case_7); 10005 } 10006 10007 static int 10008 test_AES_GCM_authenticated_encryption_test_case_8(void) 10009 { 10010 return test_authenticated_encryption(&gcm_test_case_8); 10011 } 10012 10013 static int 10014 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 10015 { 10016 return test_authenticated_encryption(&gcm_J0_test_case_1); 10017 } 10018 10019 static int 10020 test_AES_GCM_auth_encryption_test_case_192_1(void) 10021 { 10022 return test_authenticated_encryption(&gcm_test_case_192_1); 10023 } 10024 10025 static int 10026 test_AES_GCM_auth_encryption_test_case_192_2(void) 10027 { 10028 return test_authenticated_encryption(&gcm_test_case_192_2); 10029 } 10030 10031 static int 10032 test_AES_GCM_auth_encryption_test_case_192_3(void) 10033 { 10034 return test_authenticated_encryption(&gcm_test_case_192_3); 10035 } 10036 10037 static int 10038 test_AES_GCM_auth_encryption_test_case_192_4(void) 10039 { 10040 return test_authenticated_encryption(&gcm_test_case_192_4); 10041 } 10042 10043 static int 10044 test_AES_GCM_auth_encryption_test_case_192_5(void) 10045 { 10046 return test_authenticated_encryption(&gcm_test_case_192_5); 10047 } 10048 10049 static int 10050 test_AES_GCM_auth_encryption_test_case_192_6(void) 10051 { 10052 return test_authenticated_encryption(&gcm_test_case_192_6); 10053 } 10054 10055 static int 10056 test_AES_GCM_auth_encryption_test_case_192_7(void) 10057 { 10058 return test_authenticated_encryption(&gcm_test_case_192_7); 10059 } 10060 10061 static int 10062 test_AES_GCM_auth_encryption_test_case_256_1(void) 10063 { 10064 return test_authenticated_encryption(&gcm_test_case_256_1); 10065 } 10066 10067 static int 10068 test_AES_GCM_auth_encryption_test_case_256_2(void) 10069 { 10070 return test_authenticated_encryption(&gcm_test_case_256_2); 10071 } 10072 10073 static int 10074 test_AES_GCM_auth_encryption_test_case_256_3(void) 10075 { 10076 return test_authenticated_encryption(&gcm_test_case_256_3); 10077 } 10078 10079 static int 10080 test_AES_GCM_auth_encryption_test_case_256_4(void) 10081 { 10082 return test_authenticated_encryption(&gcm_test_case_256_4); 10083 } 10084 10085 static int 10086 test_AES_GCM_auth_encryption_test_case_256_5(void) 10087 { 10088 return test_authenticated_encryption(&gcm_test_case_256_5); 10089 } 10090 10091 static int 10092 test_AES_GCM_auth_encryption_test_case_256_6(void) 10093 { 10094 return test_authenticated_encryption(&gcm_test_case_256_6); 10095 } 10096 10097 static int 10098 test_AES_GCM_auth_encryption_test_case_256_7(void) 10099 { 10100 return test_authenticated_encryption(&gcm_test_case_256_7); 10101 } 10102 10103 static int 10104 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10105 { 10106 return test_authenticated_encryption(&gcm_test_case_aad_1); 10107 } 10108 10109 static int 10110 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10111 { 10112 return test_authenticated_encryption(&gcm_test_case_aad_2); 10113 } 10114 10115 static int 10116 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10117 { 10118 struct aead_test_data tdata; 10119 int res; 10120 10121 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10122 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10123 tdata.iv.data[0] += 1; 10124 res = test_authenticated_encryption(&tdata); 10125 if (res == TEST_SKIPPED) 10126 return res; 10127 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10128 return TEST_SUCCESS; 10129 } 10130 10131 static int 10132 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10133 { 10134 struct aead_test_data tdata; 10135 int res; 10136 10137 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10138 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10139 tdata.plaintext.data[0] += 1; 10140 res = test_authenticated_encryption(&tdata); 10141 if (res == TEST_SKIPPED) 10142 return res; 10143 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10144 return TEST_SUCCESS; 10145 } 10146 10147 static int 10148 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10149 { 10150 struct aead_test_data tdata; 10151 int res; 10152 10153 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10154 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10155 tdata.ciphertext.data[0] += 1; 10156 res = test_authenticated_encryption(&tdata); 10157 if (res == TEST_SKIPPED) 10158 return res; 10159 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10160 return TEST_SUCCESS; 10161 } 10162 10163 static int 10164 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10165 { 10166 struct aead_test_data tdata; 10167 int res; 10168 10169 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10170 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10171 tdata.aad.len += 1; 10172 res = test_authenticated_encryption(&tdata); 10173 if (res == TEST_SKIPPED) 10174 return res; 10175 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10176 return TEST_SUCCESS; 10177 } 10178 10179 static int 10180 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10181 { 10182 struct aead_test_data tdata; 10183 uint8_t aad[gcm_test_case_7.aad.len]; 10184 int res; 10185 10186 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10187 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10188 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10189 aad[0] += 1; 10190 tdata.aad.data = aad; 10191 res = test_authenticated_encryption(&tdata); 10192 if (res == TEST_SKIPPED) 10193 return res; 10194 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10195 return TEST_SUCCESS; 10196 } 10197 10198 static int 10199 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10200 { 10201 struct aead_test_data tdata; 10202 int res; 10203 10204 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10205 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10206 tdata.auth_tag.data[0] += 1; 10207 res = test_authenticated_encryption(&tdata); 10208 if (res == TEST_SKIPPED) 10209 return res; 10210 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10211 return TEST_SUCCESS; 10212 } 10213 10214 static int 10215 test_authenticated_decryption(const struct aead_test_data *tdata) 10216 { 10217 struct crypto_testsuite_params *ts_params = &testsuite_params; 10218 struct crypto_unittest_params *ut_params = &unittest_params; 10219 10220 int retval; 10221 uint8_t *plaintext; 10222 uint32_t i; 10223 struct rte_cryptodev_info dev_info; 10224 10225 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10226 uint64_t feat_flags = dev_info.feature_flags; 10227 10228 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10229 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10230 printf("Device doesn't support RAW data-path APIs.\n"); 10231 return TEST_SKIPPED; 10232 } 10233 10234 /* Verify the capabilities */ 10235 struct rte_cryptodev_sym_capability_idx cap_idx; 10236 const struct rte_cryptodev_symmetric_capability *capability; 10237 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10238 cap_idx.algo.aead = tdata->algo; 10239 capability = rte_cryptodev_sym_capability_get( 10240 ts_params->valid_devs[0], &cap_idx); 10241 if (capability == NULL) 10242 return TEST_SKIPPED; 10243 if (rte_cryptodev_sym_capability_check_aead( 10244 capability, tdata->key.len, tdata->auth_tag.len, 10245 tdata->aad.len, tdata->iv.len)) 10246 return TEST_SKIPPED; 10247 10248 /* Create AEAD session */ 10249 retval = create_aead_session(ts_params->valid_devs[0], 10250 tdata->algo, 10251 RTE_CRYPTO_AEAD_OP_DECRYPT, 10252 tdata->key.data, tdata->key.len, 10253 tdata->aad.len, tdata->auth_tag.len, 10254 tdata->iv.len); 10255 if (retval < 0) 10256 return retval; 10257 10258 /* alloc mbuf and set payload */ 10259 if (tdata->aad.len > MBUF_SIZE) { 10260 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10261 /* Populate full size of add data */ 10262 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10263 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10264 } else 10265 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10266 10267 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10268 rte_pktmbuf_tailroom(ut_params->ibuf)); 10269 10270 /* Create AEAD operation */ 10271 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10272 if (retval < 0) 10273 return retval; 10274 10275 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10276 10277 ut_params->op->sym->m_src = ut_params->ibuf; 10278 10279 /* Process crypto operation */ 10280 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10281 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10282 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10283 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10284 ut_params->op, 0, 0, 0, 0); 10285 else 10286 TEST_ASSERT_NOT_NULL( 10287 process_crypto_request(ts_params->valid_devs[0], 10288 ut_params->op), "failed to process sym crypto op"); 10289 10290 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10291 "crypto op processing failed"); 10292 10293 if (ut_params->op->sym->m_dst) 10294 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10295 uint8_t *); 10296 else 10297 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10298 uint8_t *, 10299 ut_params->op->sym->cipher.data.offset); 10300 10301 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10302 10303 /* Validate obuf */ 10304 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10305 plaintext, 10306 tdata->plaintext.data, 10307 tdata->plaintext.len, 10308 "Plaintext data not as expected"); 10309 10310 TEST_ASSERT_EQUAL(ut_params->op->status, 10311 RTE_CRYPTO_OP_STATUS_SUCCESS, 10312 "Authentication failed"); 10313 10314 return 0; 10315 } 10316 10317 static int 10318 test_AES_GCM_authenticated_decryption_test_case_1(void) 10319 { 10320 return test_authenticated_decryption(&gcm_test_case_1); 10321 } 10322 10323 static int 10324 test_AES_GCM_authenticated_decryption_test_case_2(void) 10325 { 10326 return test_authenticated_decryption(&gcm_test_case_2); 10327 } 10328 10329 static int 10330 test_AES_GCM_authenticated_decryption_test_case_3(void) 10331 { 10332 return test_authenticated_decryption(&gcm_test_case_3); 10333 } 10334 10335 static int 10336 test_AES_GCM_authenticated_decryption_test_case_4(void) 10337 { 10338 return test_authenticated_decryption(&gcm_test_case_4); 10339 } 10340 10341 static int 10342 test_AES_GCM_authenticated_decryption_test_case_5(void) 10343 { 10344 return test_authenticated_decryption(&gcm_test_case_5); 10345 } 10346 10347 static int 10348 test_AES_GCM_authenticated_decryption_test_case_6(void) 10349 { 10350 return test_authenticated_decryption(&gcm_test_case_6); 10351 } 10352 10353 static int 10354 test_AES_GCM_authenticated_decryption_test_case_7(void) 10355 { 10356 return test_authenticated_decryption(&gcm_test_case_7); 10357 } 10358 10359 static int 10360 test_AES_GCM_authenticated_decryption_test_case_8(void) 10361 { 10362 return test_authenticated_decryption(&gcm_test_case_8); 10363 } 10364 10365 static int 10366 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 10367 { 10368 return test_authenticated_decryption(&gcm_J0_test_case_1); 10369 } 10370 10371 static int 10372 test_AES_GCM_auth_decryption_test_case_192_1(void) 10373 { 10374 return test_authenticated_decryption(&gcm_test_case_192_1); 10375 } 10376 10377 static int 10378 test_AES_GCM_auth_decryption_test_case_192_2(void) 10379 { 10380 return test_authenticated_decryption(&gcm_test_case_192_2); 10381 } 10382 10383 static int 10384 test_AES_GCM_auth_decryption_test_case_192_3(void) 10385 { 10386 return test_authenticated_decryption(&gcm_test_case_192_3); 10387 } 10388 10389 static int 10390 test_AES_GCM_auth_decryption_test_case_192_4(void) 10391 { 10392 return test_authenticated_decryption(&gcm_test_case_192_4); 10393 } 10394 10395 static int 10396 test_AES_GCM_auth_decryption_test_case_192_5(void) 10397 { 10398 return test_authenticated_decryption(&gcm_test_case_192_5); 10399 } 10400 10401 static int 10402 test_AES_GCM_auth_decryption_test_case_192_6(void) 10403 { 10404 return test_authenticated_decryption(&gcm_test_case_192_6); 10405 } 10406 10407 static int 10408 test_AES_GCM_auth_decryption_test_case_192_7(void) 10409 { 10410 return test_authenticated_decryption(&gcm_test_case_192_7); 10411 } 10412 10413 static int 10414 test_AES_GCM_auth_decryption_test_case_256_1(void) 10415 { 10416 return test_authenticated_decryption(&gcm_test_case_256_1); 10417 } 10418 10419 static int 10420 test_AES_GCM_auth_decryption_test_case_256_2(void) 10421 { 10422 return test_authenticated_decryption(&gcm_test_case_256_2); 10423 } 10424 10425 static int 10426 test_AES_GCM_auth_decryption_test_case_256_3(void) 10427 { 10428 return test_authenticated_decryption(&gcm_test_case_256_3); 10429 } 10430 10431 static int 10432 test_AES_GCM_auth_decryption_test_case_256_4(void) 10433 { 10434 return test_authenticated_decryption(&gcm_test_case_256_4); 10435 } 10436 10437 static int 10438 test_AES_GCM_auth_decryption_test_case_256_5(void) 10439 { 10440 return test_authenticated_decryption(&gcm_test_case_256_5); 10441 } 10442 10443 static int 10444 test_AES_GCM_auth_decryption_test_case_256_6(void) 10445 { 10446 return test_authenticated_decryption(&gcm_test_case_256_6); 10447 } 10448 10449 static int 10450 test_AES_GCM_auth_decryption_test_case_256_7(void) 10451 { 10452 return test_authenticated_decryption(&gcm_test_case_256_7); 10453 } 10454 10455 static int 10456 test_AES_GCM_auth_decryption_test_case_aad_1(void) 10457 { 10458 return test_authenticated_decryption(&gcm_test_case_aad_1); 10459 } 10460 10461 static int 10462 test_AES_GCM_auth_decryption_test_case_aad_2(void) 10463 { 10464 return test_authenticated_decryption(&gcm_test_case_aad_2); 10465 } 10466 10467 static int 10468 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 10469 { 10470 struct aead_test_data tdata; 10471 int res; 10472 10473 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10474 tdata.iv.data[0] += 1; 10475 res = test_authenticated_decryption(&tdata); 10476 if (res == TEST_SKIPPED) 10477 return res; 10478 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10479 return TEST_SUCCESS; 10480 } 10481 10482 static int 10483 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 10484 { 10485 struct aead_test_data tdata; 10486 int res; 10487 10488 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10489 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10490 tdata.plaintext.data[0] += 1; 10491 res = test_authenticated_decryption(&tdata); 10492 if (res == TEST_SKIPPED) 10493 return res; 10494 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10495 return TEST_SUCCESS; 10496 } 10497 10498 static int 10499 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 10500 { 10501 struct aead_test_data tdata; 10502 int res; 10503 10504 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10505 tdata.ciphertext.data[0] += 1; 10506 res = test_authenticated_decryption(&tdata); 10507 if (res == TEST_SKIPPED) 10508 return res; 10509 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10510 return TEST_SUCCESS; 10511 } 10512 10513 static int 10514 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 10515 { 10516 struct aead_test_data tdata; 10517 int res; 10518 10519 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10520 tdata.aad.len += 1; 10521 res = test_authenticated_decryption(&tdata); 10522 if (res == TEST_SKIPPED) 10523 return res; 10524 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10525 return TEST_SUCCESS; 10526 } 10527 10528 static int 10529 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 10530 { 10531 struct aead_test_data tdata; 10532 uint8_t aad[gcm_test_case_7.aad.len]; 10533 int res; 10534 10535 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10536 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10537 aad[0] += 1; 10538 tdata.aad.data = aad; 10539 res = test_authenticated_decryption(&tdata); 10540 if (res == TEST_SKIPPED) 10541 return res; 10542 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10543 return TEST_SUCCESS; 10544 } 10545 10546 static int 10547 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 10548 { 10549 struct aead_test_data tdata; 10550 int res; 10551 10552 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10553 tdata.auth_tag.data[0] += 1; 10554 res = test_authenticated_decryption(&tdata); 10555 if (res == TEST_SKIPPED) 10556 return res; 10557 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 10558 return TEST_SUCCESS; 10559 } 10560 10561 static int 10562 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 10563 { 10564 struct crypto_testsuite_params *ts_params = &testsuite_params; 10565 struct crypto_unittest_params *ut_params = &unittest_params; 10566 10567 int retval; 10568 uint8_t *ciphertext, *auth_tag; 10569 uint16_t plaintext_pad_len; 10570 struct rte_cryptodev_info dev_info; 10571 10572 /* Verify the capabilities */ 10573 struct rte_cryptodev_sym_capability_idx cap_idx; 10574 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10575 cap_idx.algo.aead = tdata->algo; 10576 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10577 &cap_idx) == NULL) 10578 return TEST_SKIPPED; 10579 10580 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10581 uint64_t feat_flags = dev_info.feature_flags; 10582 10583 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10584 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 10585 return TEST_SKIPPED; 10586 10587 /* not supported with CPU crypto */ 10588 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10589 return TEST_SKIPPED; 10590 10591 /* Create AEAD session */ 10592 retval = create_aead_session(ts_params->valid_devs[0], 10593 tdata->algo, 10594 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10595 tdata->key.data, tdata->key.len, 10596 tdata->aad.len, tdata->auth_tag.len, 10597 tdata->iv.len); 10598 if (retval < 0) 10599 return retval; 10600 10601 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10602 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10603 10604 /* clear mbuf payload */ 10605 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10606 rte_pktmbuf_tailroom(ut_params->ibuf)); 10607 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10608 rte_pktmbuf_tailroom(ut_params->obuf)); 10609 10610 /* Create AEAD operation */ 10611 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10612 if (retval < 0) 10613 return retval; 10614 10615 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10616 10617 ut_params->op->sym->m_src = ut_params->ibuf; 10618 ut_params->op->sym->m_dst = ut_params->obuf; 10619 10620 /* Process crypto operation */ 10621 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10622 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10623 ut_params->op, 0, 0, 0, 0); 10624 else 10625 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10626 ut_params->op), "failed to process sym crypto op"); 10627 10628 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10629 "crypto op processing failed"); 10630 10631 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10632 10633 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10634 ut_params->op->sym->cipher.data.offset); 10635 auth_tag = ciphertext + plaintext_pad_len; 10636 10637 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10638 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10639 10640 /* Validate obuf */ 10641 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10642 ciphertext, 10643 tdata->ciphertext.data, 10644 tdata->ciphertext.len, 10645 "Ciphertext data not as expected"); 10646 10647 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10648 auth_tag, 10649 tdata->auth_tag.data, 10650 tdata->auth_tag.len, 10651 "Generated auth tag not as expected"); 10652 10653 return 0; 10654 10655 } 10656 10657 static int 10658 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 10659 { 10660 return test_authenticated_encryption_oop(&gcm_test_case_5); 10661 } 10662 10663 static int 10664 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 10665 { 10666 struct crypto_testsuite_params *ts_params = &testsuite_params; 10667 struct crypto_unittest_params *ut_params = &unittest_params; 10668 10669 int retval; 10670 uint8_t *plaintext; 10671 struct rte_cryptodev_info dev_info; 10672 10673 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10674 uint64_t feat_flags = dev_info.feature_flags; 10675 10676 /* Verify the capabilities */ 10677 struct rte_cryptodev_sym_capability_idx cap_idx; 10678 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10679 cap_idx.algo.aead = tdata->algo; 10680 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10681 &cap_idx) == NULL) 10682 return TEST_SKIPPED; 10683 10684 /* not supported with CPU crypto and raw data-path APIs*/ 10685 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 10686 global_api_test_type == CRYPTODEV_RAW_API_TEST) 10687 return TEST_SKIPPED; 10688 10689 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10690 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10691 printf("Device does not support RAW data-path APIs.\n"); 10692 return TEST_SKIPPED; 10693 } 10694 10695 /* Create AEAD session */ 10696 retval = create_aead_session(ts_params->valid_devs[0], 10697 tdata->algo, 10698 RTE_CRYPTO_AEAD_OP_DECRYPT, 10699 tdata->key.data, tdata->key.len, 10700 tdata->aad.len, tdata->auth_tag.len, 10701 tdata->iv.len); 10702 if (retval < 0) 10703 return retval; 10704 10705 /* alloc mbuf and set payload */ 10706 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10707 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10708 10709 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10710 rte_pktmbuf_tailroom(ut_params->ibuf)); 10711 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10712 rte_pktmbuf_tailroom(ut_params->obuf)); 10713 10714 /* Create AEAD operation */ 10715 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10716 if (retval < 0) 10717 return retval; 10718 10719 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10720 10721 ut_params->op->sym->m_src = ut_params->ibuf; 10722 ut_params->op->sym->m_dst = ut_params->obuf; 10723 10724 /* Process crypto operation */ 10725 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10726 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10727 ut_params->op, 0, 0, 0, 0); 10728 else 10729 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10730 ut_params->op), "failed to process sym crypto op"); 10731 10732 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10733 "crypto op processing failed"); 10734 10735 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10736 ut_params->op->sym->cipher.data.offset); 10737 10738 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10739 10740 /* Validate obuf */ 10741 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10742 plaintext, 10743 tdata->plaintext.data, 10744 tdata->plaintext.len, 10745 "Plaintext data not as expected"); 10746 10747 TEST_ASSERT_EQUAL(ut_params->op->status, 10748 RTE_CRYPTO_OP_STATUS_SUCCESS, 10749 "Authentication failed"); 10750 return 0; 10751 } 10752 10753 static int 10754 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 10755 { 10756 return test_authenticated_decryption_oop(&gcm_test_case_5); 10757 } 10758 10759 static int 10760 test_authenticated_encryption_sessionless( 10761 const struct aead_test_data *tdata) 10762 { 10763 struct crypto_testsuite_params *ts_params = &testsuite_params; 10764 struct crypto_unittest_params *ut_params = &unittest_params; 10765 10766 int retval; 10767 uint8_t *ciphertext, *auth_tag; 10768 uint16_t plaintext_pad_len; 10769 uint8_t key[tdata->key.len + 1]; 10770 struct rte_cryptodev_info dev_info; 10771 10772 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10773 uint64_t feat_flags = dev_info.feature_flags; 10774 10775 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10776 printf("Device doesn't support Sessionless ops.\n"); 10777 return TEST_SKIPPED; 10778 } 10779 10780 /* not supported with CPU crypto */ 10781 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10782 return TEST_SKIPPED; 10783 10784 /* Verify the capabilities */ 10785 struct rte_cryptodev_sym_capability_idx cap_idx; 10786 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10787 cap_idx.algo.aead = tdata->algo; 10788 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10789 &cap_idx) == NULL) 10790 return TEST_SKIPPED; 10791 10792 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10793 10794 /* clear mbuf payload */ 10795 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10796 rte_pktmbuf_tailroom(ut_params->ibuf)); 10797 10798 /* Create AEAD operation */ 10799 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10800 if (retval < 0) 10801 return retval; 10802 10803 /* Create GCM xform */ 10804 memcpy(key, tdata->key.data, tdata->key.len); 10805 retval = create_aead_xform(ut_params->op, 10806 tdata->algo, 10807 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10808 key, tdata->key.len, 10809 tdata->aad.len, tdata->auth_tag.len, 10810 tdata->iv.len); 10811 if (retval < 0) 10812 return retval; 10813 10814 ut_params->op->sym->m_src = ut_params->ibuf; 10815 10816 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10817 RTE_CRYPTO_OP_SESSIONLESS, 10818 "crypto op session type not sessionless"); 10819 10820 /* Process crypto operation */ 10821 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10822 ut_params->op), "failed to process sym crypto op"); 10823 10824 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10825 10826 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10827 "crypto op status not success"); 10828 10829 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10830 10831 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10832 ut_params->op->sym->cipher.data.offset); 10833 auth_tag = ciphertext + plaintext_pad_len; 10834 10835 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10836 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10837 10838 /* Validate obuf */ 10839 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10840 ciphertext, 10841 tdata->ciphertext.data, 10842 tdata->ciphertext.len, 10843 "Ciphertext data not as expected"); 10844 10845 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10846 auth_tag, 10847 tdata->auth_tag.data, 10848 tdata->auth_tag.len, 10849 "Generated auth tag not as expected"); 10850 10851 return 0; 10852 10853 } 10854 10855 static int 10856 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 10857 { 10858 return test_authenticated_encryption_sessionless( 10859 &gcm_test_case_5); 10860 } 10861 10862 static int 10863 test_authenticated_decryption_sessionless( 10864 const struct aead_test_data *tdata) 10865 { 10866 struct crypto_testsuite_params *ts_params = &testsuite_params; 10867 struct crypto_unittest_params *ut_params = &unittest_params; 10868 10869 int retval; 10870 uint8_t *plaintext; 10871 uint8_t key[tdata->key.len + 1]; 10872 struct rte_cryptodev_info dev_info; 10873 10874 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10875 uint64_t feat_flags = dev_info.feature_flags; 10876 10877 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10878 printf("Device doesn't support Sessionless ops.\n"); 10879 return TEST_SKIPPED; 10880 } 10881 10882 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10883 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10884 printf("Device doesn't support RAW data-path APIs.\n"); 10885 return TEST_SKIPPED; 10886 } 10887 10888 /* not supported with CPU crypto */ 10889 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10890 return TEST_SKIPPED; 10891 10892 /* Verify the capabilities */ 10893 struct rte_cryptodev_sym_capability_idx cap_idx; 10894 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10895 cap_idx.algo.aead = tdata->algo; 10896 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10897 &cap_idx) == NULL) 10898 return TEST_SKIPPED; 10899 10900 /* alloc mbuf and set payload */ 10901 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10902 10903 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10904 rte_pktmbuf_tailroom(ut_params->ibuf)); 10905 10906 /* Create AEAD operation */ 10907 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10908 if (retval < 0) 10909 return retval; 10910 10911 /* Create AEAD xform */ 10912 memcpy(key, tdata->key.data, tdata->key.len); 10913 retval = create_aead_xform(ut_params->op, 10914 tdata->algo, 10915 RTE_CRYPTO_AEAD_OP_DECRYPT, 10916 key, tdata->key.len, 10917 tdata->aad.len, tdata->auth_tag.len, 10918 tdata->iv.len); 10919 if (retval < 0) 10920 return retval; 10921 10922 ut_params->op->sym->m_src = ut_params->ibuf; 10923 10924 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10925 RTE_CRYPTO_OP_SESSIONLESS, 10926 "crypto op session type not sessionless"); 10927 10928 /* Process crypto operation */ 10929 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10930 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10931 ut_params->op, 0, 0, 0, 0); 10932 else 10933 TEST_ASSERT_NOT_NULL(process_crypto_request( 10934 ts_params->valid_devs[0], ut_params->op), 10935 "failed to process sym crypto op"); 10936 10937 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10938 10939 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10940 "crypto op status not success"); 10941 10942 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10943 ut_params->op->sym->cipher.data.offset); 10944 10945 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10946 10947 /* Validate obuf */ 10948 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10949 plaintext, 10950 tdata->plaintext.data, 10951 tdata->plaintext.len, 10952 "Plaintext data not as expected"); 10953 10954 TEST_ASSERT_EQUAL(ut_params->op->status, 10955 RTE_CRYPTO_OP_STATUS_SUCCESS, 10956 "Authentication failed"); 10957 return 0; 10958 } 10959 10960 static int 10961 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 10962 { 10963 return test_authenticated_decryption_sessionless( 10964 &gcm_test_case_5); 10965 } 10966 10967 static int 10968 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 10969 { 10970 return test_authenticated_encryption(&ccm_test_case_128_1); 10971 } 10972 10973 static int 10974 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 10975 { 10976 return test_authenticated_encryption(&ccm_test_case_128_2); 10977 } 10978 10979 static int 10980 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 10981 { 10982 return test_authenticated_encryption(&ccm_test_case_128_3); 10983 } 10984 10985 static int 10986 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 10987 { 10988 return test_authenticated_decryption(&ccm_test_case_128_1); 10989 } 10990 10991 static int 10992 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 10993 { 10994 return test_authenticated_decryption(&ccm_test_case_128_2); 10995 } 10996 10997 static int 10998 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 10999 { 11000 return test_authenticated_decryption(&ccm_test_case_128_3); 11001 } 11002 11003 static int 11004 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 11005 { 11006 return test_authenticated_encryption(&ccm_test_case_192_1); 11007 } 11008 11009 static int 11010 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 11011 { 11012 return test_authenticated_encryption(&ccm_test_case_192_2); 11013 } 11014 11015 static int 11016 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 11017 { 11018 return test_authenticated_encryption(&ccm_test_case_192_3); 11019 } 11020 11021 static int 11022 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 11023 { 11024 return test_authenticated_decryption(&ccm_test_case_192_1); 11025 } 11026 11027 static int 11028 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 11029 { 11030 return test_authenticated_decryption(&ccm_test_case_192_2); 11031 } 11032 11033 static int 11034 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 11035 { 11036 return test_authenticated_decryption(&ccm_test_case_192_3); 11037 } 11038 11039 static int 11040 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11041 { 11042 return test_authenticated_encryption(&ccm_test_case_256_1); 11043 } 11044 11045 static int 11046 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11047 { 11048 return test_authenticated_encryption(&ccm_test_case_256_2); 11049 } 11050 11051 static int 11052 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11053 { 11054 return test_authenticated_encryption(&ccm_test_case_256_3); 11055 } 11056 11057 static int 11058 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11059 { 11060 return test_authenticated_decryption(&ccm_test_case_256_1); 11061 } 11062 11063 static int 11064 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11065 { 11066 return test_authenticated_decryption(&ccm_test_case_256_2); 11067 } 11068 11069 static int 11070 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11071 { 11072 return test_authenticated_decryption(&ccm_test_case_256_3); 11073 } 11074 11075 static int 11076 test_stats(void) 11077 { 11078 struct crypto_testsuite_params *ts_params = &testsuite_params; 11079 struct rte_cryptodev_stats stats; 11080 11081 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11082 return TEST_SKIPPED; 11083 11084 /* Verify the capabilities */ 11085 struct rte_cryptodev_sym_capability_idx cap_idx; 11086 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11087 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11088 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11089 &cap_idx) == NULL) 11090 return TEST_SKIPPED; 11091 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11092 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11093 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11094 &cap_idx) == NULL) 11095 return TEST_SKIPPED; 11096 11097 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11098 == -ENOTSUP) 11099 return TEST_SKIPPED; 11100 11101 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11102 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11103 &stats) == -ENODEV), 11104 "rte_cryptodev_stats_get invalid dev failed"); 11105 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11106 "rte_cryptodev_stats_get invalid Param failed"); 11107 11108 /* Test expected values */ 11109 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11110 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11111 &stats), 11112 "rte_cryptodev_stats_get failed"); 11113 TEST_ASSERT((stats.enqueued_count == 1), 11114 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11115 TEST_ASSERT((stats.dequeued_count == 1), 11116 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11117 TEST_ASSERT((stats.enqueue_err_count == 0), 11118 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11119 TEST_ASSERT((stats.dequeue_err_count == 0), 11120 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11121 11122 /* invalid device but should ignore and not reset device stats*/ 11123 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11124 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11125 &stats), 11126 "rte_cryptodev_stats_get failed"); 11127 TEST_ASSERT((stats.enqueued_count == 1), 11128 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11129 11130 /* check that a valid reset clears stats */ 11131 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11132 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11133 &stats), 11134 "rte_cryptodev_stats_get failed"); 11135 TEST_ASSERT((stats.enqueued_count == 0), 11136 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11137 TEST_ASSERT((stats.dequeued_count == 0), 11138 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11139 11140 return TEST_SUCCESS; 11141 } 11142 11143 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11144 struct crypto_unittest_params *ut_params, 11145 enum rte_crypto_auth_operation op, 11146 const struct HMAC_MD5_vector *test_case) 11147 { 11148 uint8_t key[64]; 11149 int status; 11150 11151 memcpy(key, test_case->key.data, test_case->key.len); 11152 11153 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11154 ut_params->auth_xform.next = NULL; 11155 ut_params->auth_xform.auth.op = op; 11156 11157 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11158 11159 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11160 ut_params->auth_xform.auth.key.length = test_case->key.len; 11161 ut_params->auth_xform.auth.key.data = key; 11162 11163 ut_params->sess = rte_cryptodev_sym_session_create( 11164 ts_params->session_mpool); 11165 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11166 if (ut_params->sess == NULL) 11167 return TEST_FAILED; 11168 11169 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11170 ut_params->sess, &ut_params->auth_xform, 11171 ts_params->session_priv_mpool); 11172 if (status == -ENOTSUP) 11173 return TEST_SKIPPED; 11174 11175 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11176 11177 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11178 rte_pktmbuf_tailroom(ut_params->ibuf)); 11179 11180 return 0; 11181 } 11182 11183 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11184 const struct HMAC_MD5_vector *test_case, 11185 uint8_t **plaintext) 11186 { 11187 uint16_t plaintext_pad_len; 11188 11189 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11190 11191 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11192 16); 11193 11194 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11195 plaintext_pad_len); 11196 memcpy(*plaintext, test_case->plaintext.data, 11197 test_case->plaintext.len); 11198 11199 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11200 ut_params->ibuf, MD5_DIGEST_LEN); 11201 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11202 "no room to append digest"); 11203 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11204 ut_params->ibuf, plaintext_pad_len); 11205 11206 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11207 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11208 test_case->auth_tag.len); 11209 } 11210 11211 sym_op->auth.data.offset = 0; 11212 sym_op->auth.data.length = test_case->plaintext.len; 11213 11214 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11215 ut_params->op->sym->m_src = ut_params->ibuf; 11216 11217 return 0; 11218 } 11219 11220 static int 11221 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11222 { 11223 uint16_t plaintext_pad_len; 11224 uint8_t *plaintext, *auth_tag; 11225 11226 struct crypto_testsuite_params *ts_params = &testsuite_params; 11227 struct crypto_unittest_params *ut_params = &unittest_params; 11228 struct rte_cryptodev_info dev_info; 11229 11230 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11231 uint64_t feat_flags = dev_info.feature_flags; 11232 11233 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11234 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11235 printf("Device doesn't support RAW data-path APIs.\n"); 11236 return TEST_SKIPPED; 11237 } 11238 11239 /* Verify the capabilities */ 11240 struct rte_cryptodev_sym_capability_idx cap_idx; 11241 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11242 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11243 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11244 &cap_idx) == NULL) 11245 return TEST_SKIPPED; 11246 11247 if (MD5_HMAC_create_session(ts_params, ut_params, 11248 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11249 return TEST_FAILED; 11250 11251 /* Generate Crypto op data structure */ 11252 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11253 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11254 TEST_ASSERT_NOT_NULL(ut_params->op, 11255 "Failed to allocate symmetric crypto operation struct"); 11256 11257 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11258 16); 11259 11260 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11261 return TEST_FAILED; 11262 11263 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11264 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11265 ut_params->op); 11266 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11267 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11268 ut_params->op, 0, 1, 0, 0); 11269 else 11270 TEST_ASSERT_NOT_NULL( 11271 process_crypto_request(ts_params->valid_devs[0], 11272 ut_params->op), 11273 "failed to process sym crypto op"); 11274 11275 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11276 "crypto op processing failed"); 11277 11278 if (ut_params->op->sym->m_dst) { 11279 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11280 uint8_t *, plaintext_pad_len); 11281 } else { 11282 auth_tag = plaintext + plaintext_pad_len; 11283 } 11284 11285 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11286 auth_tag, 11287 test_case->auth_tag.data, 11288 test_case->auth_tag.len, 11289 "HMAC_MD5 generated tag not as expected"); 11290 11291 return TEST_SUCCESS; 11292 } 11293 11294 static int 11295 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11296 { 11297 uint8_t *plaintext; 11298 11299 struct crypto_testsuite_params *ts_params = &testsuite_params; 11300 struct crypto_unittest_params *ut_params = &unittest_params; 11301 struct rte_cryptodev_info dev_info; 11302 11303 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11304 uint64_t feat_flags = dev_info.feature_flags; 11305 11306 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11307 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11308 printf("Device doesn't support RAW data-path APIs.\n"); 11309 return TEST_SKIPPED; 11310 } 11311 11312 /* Verify the capabilities */ 11313 struct rte_cryptodev_sym_capability_idx cap_idx; 11314 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11315 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11316 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11317 &cap_idx) == NULL) 11318 return TEST_SKIPPED; 11319 11320 if (MD5_HMAC_create_session(ts_params, ut_params, 11321 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11322 return TEST_FAILED; 11323 } 11324 11325 /* Generate Crypto op data structure */ 11326 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11327 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11328 TEST_ASSERT_NOT_NULL(ut_params->op, 11329 "Failed to allocate symmetric crypto operation struct"); 11330 11331 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11332 return TEST_FAILED; 11333 11334 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11335 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11336 ut_params->op); 11337 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11338 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11339 ut_params->op, 0, 1, 0, 0); 11340 else 11341 TEST_ASSERT_NOT_NULL( 11342 process_crypto_request(ts_params->valid_devs[0], 11343 ut_params->op), 11344 "failed to process sym crypto op"); 11345 11346 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11347 "HMAC_MD5 crypto op processing failed"); 11348 11349 return TEST_SUCCESS; 11350 } 11351 11352 static int 11353 test_MD5_HMAC_generate_case_1(void) 11354 { 11355 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 11356 } 11357 11358 static int 11359 test_MD5_HMAC_verify_case_1(void) 11360 { 11361 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 11362 } 11363 11364 static int 11365 test_MD5_HMAC_generate_case_2(void) 11366 { 11367 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 11368 } 11369 11370 static int 11371 test_MD5_HMAC_verify_case_2(void) 11372 { 11373 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 11374 } 11375 11376 static int 11377 test_multi_session(void) 11378 { 11379 struct crypto_testsuite_params *ts_params = &testsuite_params; 11380 struct crypto_unittest_params *ut_params = &unittest_params; 11381 11382 struct rte_cryptodev_info dev_info; 11383 struct rte_cryptodev_sym_session **sessions; 11384 11385 uint16_t i; 11386 int status; 11387 11388 /* Verify the capabilities */ 11389 struct rte_cryptodev_sym_capability_idx cap_idx; 11390 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11391 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11392 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11393 &cap_idx) == NULL) 11394 return TEST_SKIPPED; 11395 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11396 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11397 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11398 &cap_idx) == NULL) 11399 return TEST_SKIPPED; 11400 11401 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 11402 aes_cbc_key, hmac_sha512_key); 11403 11404 11405 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11406 11407 sessions = rte_malloc(NULL, 11408 sizeof(struct rte_cryptodev_sym_session *) * 11409 (MAX_NB_SESSIONS + 1), 0); 11410 11411 /* Create multiple crypto sessions*/ 11412 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11413 11414 sessions[i] = rte_cryptodev_sym_session_create( 11415 ts_params->session_mpool); 11416 TEST_ASSERT_NOT_NULL(sessions[i], 11417 "Session creation failed at session number %u", 11418 i); 11419 11420 status = rte_cryptodev_sym_session_init( 11421 ts_params->valid_devs[0], 11422 sessions[i], &ut_params->auth_xform, 11423 ts_params->session_priv_mpool); 11424 if (status == -ENOTSUP) 11425 return TEST_SKIPPED; 11426 11427 /* Attempt to send a request on each session */ 11428 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 11429 sessions[i], 11430 ut_params, 11431 ts_params, 11432 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 11433 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 11434 aes_cbc_iv), 11435 "Failed to perform decrypt on request number %u.", i); 11436 /* free crypto operation structure */ 11437 if (ut_params->op) 11438 rte_crypto_op_free(ut_params->op); 11439 11440 /* 11441 * free mbuf - both obuf and ibuf are usually the same, 11442 * so check if they point at the same address is necessary, 11443 * to avoid freeing the mbuf twice. 11444 */ 11445 if (ut_params->obuf) { 11446 rte_pktmbuf_free(ut_params->obuf); 11447 if (ut_params->ibuf == ut_params->obuf) 11448 ut_params->ibuf = 0; 11449 ut_params->obuf = 0; 11450 } 11451 if (ut_params->ibuf) { 11452 rte_pktmbuf_free(ut_params->ibuf); 11453 ut_params->ibuf = 0; 11454 } 11455 } 11456 11457 sessions[i] = NULL; 11458 /* Next session create should fail */ 11459 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11460 sessions[i], &ut_params->auth_xform, 11461 ts_params->session_priv_mpool); 11462 TEST_ASSERT_NULL(sessions[i], 11463 "Session creation succeeded unexpectedly!"); 11464 11465 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11466 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11467 sessions[i]); 11468 rte_cryptodev_sym_session_free(sessions[i]); 11469 } 11470 11471 rte_free(sessions); 11472 11473 return TEST_SUCCESS; 11474 } 11475 11476 struct multi_session_params { 11477 struct crypto_unittest_params ut_params; 11478 uint8_t *cipher_key; 11479 uint8_t *hmac_key; 11480 const uint8_t *cipher; 11481 const uint8_t *digest; 11482 uint8_t *iv; 11483 }; 11484 11485 #define MB_SESSION_NUMBER 3 11486 11487 static int 11488 test_multi_session_random_usage(void) 11489 { 11490 struct crypto_testsuite_params *ts_params = &testsuite_params; 11491 struct rte_cryptodev_info dev_info; 11492 struct rte_cryptodev_sym_session **sessions; 11493 uint32_t i, j; 11494 struct multi_session_params ut_paramz[] = { 11495 11496 { 11497 .cipher_key = ms_aes_cbc_key0, 11498 .hmac_key = ms_hmac_key0, 11499 .cipher = ms_aes_cbc_cipher0, 11500 .digest = ms_hmac_digest0, 11501 .iv = ms_aes_cbc_iv0 11502 }, 11503 { 11504 .cipher_key = ms_aes_cbc_key1, 11505 .hmac_key = ms_hmac_key1, 11506 .cipher = ms_aes_cbc_cipher1, 11507 .digest = ms_hmac_digest1, 11508 .iv = ms_aes_cbc_iv1 11509 }, 11510 { 11511 .cipher_key = ms_aes_cbc_key2, 11512 .hmac_key = ms_hmac_key2, 11513 .cipher = ms_aes_cbc_cipher2, 11514 .digest = ms_hmac_digest2, 11515 .iv = ms_aes_cbc_iv2 11516 }, 11517 11518 }; 11519 int status; 11520 11521 /* Verify the capabilities */ 11522 struct rte_cryptodev_sym_capability_idx cap_idx; 11523 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11524 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11525 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11526 &cap_idx) == NULL) 11527 return TEST_SKIPPED; 11528 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11529 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11530 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11531 &cap_idx) == NULL) 11532 return TEST_SKIPPED; 11533 11534 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11535 11536 sessions = rte_malloc(NULL, 11537 (sizeof(struct rte_cryptodev_sym_session *) 11538 * MAX_NB_SESSIONS) + 1, 0); 11539 11540 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11541 sessions[i] = rte_cryptodev_sym_session_create( 11542 ts_params->session_mpool); 11543 TEST_ASSERT_NOT_NULL(sessions[i], 11544 "Session creation failed at session number %u", 11545 i); 11546 11547 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 11548 sizeof(struct crypto_unittest_params)); 11549 11550 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 11551 &ut_paramz[i].ut_params, 11552 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 11553 11554 /* Create multiple crypto sessions*/ 11555 status = rte_cryptodev_sym_session_init( 11556 ts_params->valid_devs[0], 11557 sessions[i], 11558 &ut_paramz[i].ut_params.auth_xform, 11559 ts_params->session_priv_mpool); 11560 11561 if (status == -ENOTSUP) 11562 return TEST_SKIPPED; 11563 11564 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11565 } 11566 11567 srand(time(NULL)); 11568 for (i = 0; i < 40000; i++) { 11569 11570 j = rand() % MB_SESSION_NUMBER; 11571 11572 TEST_ASSERT_SUCCESS( 11573 test_AES_CBC_HMAC_SHA512_decrypt_perform( 11574 sessions[j], 11575 &ut_paramz[j].ut_params, 11576 ts_params, ut_paramz[j].cipher, 11577 ut_paramz[j].digest, 11578 ut_paramz[j].iv), 11579 "Failed to perform decrypt on request number %u.", i); 11580 11581 if (ut_paramz[j].ut_params.op) 11582 rte_crypto_op_free(ut_paramz[j].ut_params.op); 11583 11584 /* 11585 * free mbuf - both obuf and ibuf are usually the same, 11586 * so check if they point at the same address is necessary, 11587 * to avoid freeing the mbuf twice. 11588 */ 11589 if (ut_paramz[j].ut_params.obuf) { 11590 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 11591 if (ut_paramz[j].ut_params.ibuf 11592 == ut_paramz[j].ut_params.obuf) 11593 ut_paramz[j].ut_params.ibuf = 0; 11594 ut_paramz[j].ut_params.obuf = 0; 11595 } 11596 if (ut_paramz[j].ut_params.ibuf) { 11597 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 11598 ut_paramz[j].ut_params.ibuf = 0; 11599 } 11600 } 11601 11602 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11603 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11604 sessions[i]); 11605 rte_cryptodev_sym_session_free(sessions[i]); 11606 } 11607 11608 rte_free(sessions); 11609 11610 return TEST_SUCCESS; 11611 } 11612 11613 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 11614 0xab, 0xab, 0xab, 0xab, 11615 0xab, 0xab, 0xab, 0xab, 11616 0xab, 0xab, 0xab, 0xab}; 11617 11618 static int 11619 test_null_invalid_operation(void) 11620 { 11621 struct crypto_testsuite_params *ts_params = &testsuite_params; 11622 struct crypto_unittest_params *ut_params = &unittest_params; 11623 int ret; 11624 11625 /* This test is for NULL PMD only */ 11626 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11627 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11628 return TEST_SKIPPED; 11629 11630 /* Setup Cipher Parameters */ 11631 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11632 ut_params->cipher_xform.next = NULL; 11633 11634 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 11635 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11636 11637 ut_params->sess = rte_cryptodev_sym_session_create( 11638 ts_params->session_mpool); 11639 11640 /* Create Crypto session*/ 11641 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11642 ut_params->sess, &ut_params->cipher_xform, 11643 ts_params->session_priv_mpool); 11644 TEST_ASSERT(ret < 0, 11645 "Session creation succeeded unexpectedly"); 11646 11647 11648 /* Setup HMAC Parameters */ 11649 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11650 ut_params->auth_xform.next = NULL; 11651 11652 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 11653 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11654 11655 ut_params->sess = rte_cryptodev_sym_session_create( 11656 ts_params->session_mpool); 11657 11658 /* Create Crypto session*/ 11659 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11660 ut_params->sess, &ut_params->auth_xform, 11661 ts_params->session_priv_mpool); 11662 TEST_ASSERT(ret < 0, 11663 "Session creation succeeded unexpectedly"); 11664 11665 return TEST_SUCCESS; 11666 } 11667 11668 11669 #define NULL_BURST_LENGTH (32) 11670 11671 static int 11672 test_null_burst_operation(void) 11673 { 11674 struct crypto_testsuite_params *ts_params = &testsuite_params; 11675 struct crypto_unittest_params *ut_params = &unittest_params; 11676 int status; 11677 11678 unsigned i, burst_len = NULL_BURST_LENGTH; 11679 11680 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 11681 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 11682 11683 /* This test is for NULL PMD only */ 11684 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11685 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11686 return TEST_SKIPPED; 11687 11688 /* Setup Cipher Parameters */ 11689 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11690 ut_params->cipher_xform.next = &ut_params->auth_xform; 11691 11692 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 11693 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11694 11695 /* Setup HMAC Parameters */ 11696 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11697 ut_params->auth_xform.next = NULL; 11698 11699 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 11700 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11701 11702 ut_params->sess = rte_cryptodev_sym_session_create( 11703 ts_params->session_mpool); 11704 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11705 11706 /* Create Crypto session*/ 11707 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11708 ut_params->sess, &ut_params->cipher_xform, 11709 ts_params->session_priv_mpool); 11710 11711 if (status == -ENOTSUP) 11712 return TEST_SKIPPED; 11713 11714 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 11715 11716 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 11717 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 11718 burst_len, "failed to generate burst of crypto ops"); 11719 11720 /* Generate an operation for each mbuf in burst */ 11721 for (i = 0; i < burst_len; i++) { 11722 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11723 11724 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 11725 11726 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 11727 sizeof(unsigned)); 11728 *data = i; 11729 11730 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 11731 11732 burst[i]->sym->m_src = m; 11733 } 11734 11735 /* Process crypto operation */ 11736 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 11737 0, burst, burst_len), 11738 burst_len, 11739 "Error enqueuing burst"); 11740 11741 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 11742 0, burst_dequeued, burst_len), 11743 burst_len, 11744 "Error dequeuing burst"); 11745 11746 11747 for (i = 0; i < burst_len; i++) { 11748 TEST_ASSERT_EQUAL( 11749 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 11750 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 11751 uint32_t *), 11752 "data not as expected"); 11753 11754 rte_pktmbuf_free(burst[i]->sym->m_src); 11755 rte_crypto_op_free(burst[i]); 11756 } 11757 11758 return TEST_SUCCESS; 11759 } 11760 11761 static uint16_t 11762 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11763 uint16_t nb_ops, void *user_param) 11764 { 11765 RTE_SET_USED(dev_id); 11766 RTE_SET_USED(qp_id); 11767 RTE_SET_USED(ops); 11768 RTE_SET_USED(user_param); 11769 11770 printf("crypto enqueue callback called\n"); 11771 return nb_ops; 11772 } 11773 11774 static uint16_t 11775 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11776 uint16_t nb_ops, void *user_param) 11777 { 11778 RTE_SET_USED(dev_id); 11779 RTE_SET_USED(qp_id); 11780 RTE_SET_USED(ops); 11781 RTE_SET_USED(user_param); 11782 11783 printf("crypto dequeue callback called\n"); 11784 return nb_ops; 11785 } 11786 11787 /* 11788 * Thread using enqueue/dequeue callback with RCU. 11789 */ 11790 static int 11791 test_enqdeq_callback_thread(void *arg) 11792 { 11793 RTE_SET_USED(arg); 11794 /* DP thread calls rte_cryptodev_enqueue_burst()/ 11795 * rte_cryptodev_dequeue_burst() and invokes callback. 11796 */ 11797 test_null_burst_operation(); 11798 return 0; 11799 } 11800 11801 static int 11802 test_enq_callback_setup(void) 11803 { 11804 struct crypto_testsuite_params *ts_params = &testsuite_params; 11805 struct rte_cryptodev_info dev_info; 11806 struct rte_cryptodev_qp_conf qp_conf = { 11807 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11808 }; 11809 11810 struct rte_cryptodev_cb *cb; 11811 uint16_t qp_id = 0; 11812 11813 /* Stop the device in case it's started so it can be configured */ 11814 rte_cryptodev_stop(ts_params->valid_devs[0]); 11815 11816 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11817 11818 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11819 &ts_params->conf), 11820 "Failed to configure cryptodev %u", 11821 ts_params->valid_devs[0]); 11822 11823 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11824 qp_conf.mp_session = ts_params->session_mpool; 11825 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11826 11827 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11828 ts_params->valid_devs[0], qp_id, &qp_conf, 11829 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11830 "Failed test for " 11831 "rte_cryptodev_queue_pair_setup: num_inflights " 11832 "%u on qp %u on cryptodev %u", 11833 qp_conf.nb_descriptors, qp_id, 11834 ts_params->valid_devs[0]); 11835 11836 /* Test with invalid crypto device */ 11837 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 11838 qp_id, test_enq_callback, NULL); 11839 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11840 "cryptodev %u did not fail", 11841 qp_id, RTE_CRYPTO_MAX_DEVS); 11842 11843 /* Test with invalid queue pair */ 11844 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11845 dev_info.max_nb_queue_pairs + 1, 11846 test_enq_callback, NULL); 11847 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11848 "cryptodev %u did not fail", 11849 dev_info.max_nb_queue_pairs + 1, 11850 ts_params->valid_devs[0]); 11851 11852 /* Test with NULL callback */ 11853 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11854 qp_id, NULL, NULL); 11855 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11856 "cryptodev %u did not fail", 11857 qp_id, ts_params->valid_devs[0]); 11858 11859 /* Test with valid configuration */ 11860 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11861 qp_id, test_enq_callback, NULL); 11862 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11863 "qp %u on cryptodev %u", 11864 qp_id, ts_params->valid_devs[0]); 11865 11866 rte_cryptodev_start(ts_params->valid_devs[0]); 11867 11868 /* Launch a thread */ 11869 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11870 rte_get_next_lcore(-1, 1, 0)); 11871 11872 /* Wait until reader exited. */ 11873 rte_eal_mp_wait_lcore(); 11874 11875 /* Test with invalid crypto device */ 11876 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11877 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11878 "Expected call to fail as crypto device is invalid"); 11879 11880 /* Test with invalid queue pair */ 11881 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11882 ts_params->valid_devs[0], 11883 dev_info.max_nb_queue_pairs + 1, cb), 11884 "Expected call to fail as queue pair is invalid"); 11885 11886 /* Test with NULL callback */ 11887 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11888 ts_params->valid_devs[0], qp_id, NULL), 11889 "Expected call to fail as callback is NULL"); 11890 11891 /* Test with valid configuration */ 11892 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 11893 ts_params->valid_devs[0], qp_id, cb), 11894 "Failed test to remove callback on " 11895 "qp %u on cryptodev %u", 11896 qp_id, ts_params->valid_devs[0]); 11897 11898 return TEST_SUCCESS; 11899 } 11900 11901 static int 11902 test_deq_callback_setup(void) 11903 { 11904 struct crypto_testsuite_params *ts_params = &testsuite_params; 11905 struct rte_cryptodev_info dev_info; 11906 struct rte_cryptodev_qp_conf qp_conf = { 11907 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11908 }; 11909 11910 struct rte_cryptodev_cb *cb; 11911 uint16_t qp_id = 0; 11912 11913 /* Stop the device in case it's started so it can be configured */ 11914 rte_cryptodev_stop(ts_params->valid_devs[0]); 11915 11916 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11917 11918 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11919 &ts_params->conf), 11920 "Failed to configure cryptodev %u", 11921 ts_params->valid_devs[0]); 11922 11923 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11924 qp_conf.mp_session = ts_params->session_mpool; 11925 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11926 11927 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11928 ts_params->valid_devs[0], qp_id, &qp_conf, 11929 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11930 "Failed test for " 11931 "rte_cryptodev_queue_pair_setup: num_inflights " 11932 "%u on qp %u on cryptodev %u", 11933 qp_conf.nb_descriptors, qp_id, 11934 ts_params->valid_devs[0]); 11935 11936 /* Test with invalid crypto device */ 11937 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 11938 qp_id, test_deq_callback, NULL); 11939 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11940 "cryptodev %u did not fail", 11941 qp_id, RTE_CRYPTO_MAX_DEVS); 11942 11943 /* Test with invalid queue pair */ 11944 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11945 dev_info.max_nb_queue_pairs + 1, 11946 test_deq_callback, NULL); 11947 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11948 "cryptodev %u did not fail", 11949 dev_info.max_nb_queue_pairs + 1, 11950 ts_params->valid_devs[0]); 11951 11952 /* Test with NULL callback */ 11953 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11954 qp_id, NULL, NULL); 11955 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11956 "cryptodev %u did not fail", 11957 qp_id, ts_params->valid_devs[0]); 11958 11959 /* Test with valid configuration */ 11960 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11961 qp_id, test_deq_callback, NULL); 11962 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11963 "qp %u on cryptodev %u", 11964 qp_id, ts_params->valid_devs[0]); 11965 11966 rte_cryptodev_start(ts_params->valid_devs[0]); 11967 11968 /* Launch a thread */ 11969 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11970 rte_get_next_lcore(-1, 1, 0)); 11971 11972 /* Wait until reader exited. */ 11973 rte_eal_mp_wait_lcore(); 11974 11975 /* Test with invalid crypto device */ 11976 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11977 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11978 "Expected call to fail as crypto device is invalid"); 11979 11980 /* Test with invalid queue pair */ 11981 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11982 ts_params->valid_devs[0], 11983 dev_info.max_nb_queue_pairs + 1, cb), 11984 "Expected call to fail as queue pair is invalid"); 11985 11986 /* Test with NULL callback */ 11987 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11988 ts_params->valid_devs[0], qp_id, NULL), 11989 "Expected call to fail as callback is NULL"); 11990 11991 /* Test with valid configuration */ 11992 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 11993 ts_params->valid_devs[0], qp_id, cb), 11994 "Failed test to remove callback on " 11995 "qp %u on cryptodev %u", 11996 qp_id, ts_params->valid_devs[0]); 11997 11998 return TEST_SUCCESS; 11999 } 12000 12001 static void 12002 generate_gmac_large_plaintext(uint8_t *data) 12003 { 12004 uint16_t i; 12005 12006 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 12007 memcpy(&data[i], &data[0], 32); 12008 } 12009 12010 static int 12011 create_gmac_operation(enum rte_crypto_auth_operation op, 12012 const struct gmac_test_data *tdata) 12013 { 12014 struct crypto_testsuite_params *ts_params = &testsuite_params; 12015 struct crypto_unittest_params *ut_params = &unittest_params; 12016 struct rte_crypto_sym_op *sym_op; 12017 12018 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12019 12020 /* Generate Crypto op data structure */ 12021 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12022 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12023 TEST_ASSERT_NOT_NULL(ut_params->op, 12024 "Failed to allocate symmetric crypto operation struct"); 12025 12026 sym_op = ut_params->op->sym; 12027 12028 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12029 ut_params->ibuf, tdata->gmac_tag.len); 12030 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12031 "no room to append digest"); 12032 12033 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12034 ut_params->ibuf, plaintext_pad_len); 12035 12036 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12037 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12038 tdata->gmac_tag.len); 12039 debug_hexdump(stdout, "digest:", 12040 sym_op->auth.digest.data, 12041 tdata->gmac_tag.len); 12042 } 12043 12044 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12045 uint8_t *, IV_OFFSET); 12046 12047 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12048 12049 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12050 12051 sym_op->cipher.data.length = 0; 12052 sym_op->cipher.data.offset = 0; 12053 12054 sym_op->auth.data.offset = 0; 12055 sym_op->auth.data.length = tdata->plaintext.len; 12056 12057 return 0; 12058 } 12059 12060 static int 12061 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12062 const struct gmac_test_data *tdata, 12063 void *digest_mem, uint64_t digest_phys) 12064 { 12065 struct crypto_testsuite_params *ts_params = &testsuite_params; 12066 struct crypto_unittest_params *ut_params = &unittest_params; 12067 struct rte_crypto_sym_op *sym_op; 12068 12069 /* Generate Crypto op data structure */ 12070 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12071 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12072 TEST_ASSERT_NOT_NULL(ut_params->op, 12073 "Failed to allocate symmetric crypto operation struct"); 12074 12075 sym_op = ut_params->op->sym; 12076 12077 sym_op->auth.digest.data = digest_mem; 12078 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12079 "no room to append digest"); 12080 12081 sym_op->auth.digest.phys_addr = digest_phys; 12082 12083 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12084 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12085 tdata->gmac_tag.len); 12086 debug_hexdump(stdout, "digest:", 12087 sym_op->auth.digest.data, 12088 tdata->gmac_tag.len); 12089 } 12090 12091 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12092 uint8_t *, IV_OFFSET); 12093 12094 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12095 12096 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12097 12098 sym_op->cipher.data.length = 0; 12099 sym_op->cipher.data.offset = 0; 12100 12101 sym_op->auth.data.offset = 0; 12102 sym_op->auth.data.length = tdata->plaintext.len; 12103 12104 return 0; 12105 } 12106 12107 static int create_gmac_session(uint8_t dev_id, 12108 const struct gmac_test_data *tdata, 12109 enum rte_crypto_auth_operation auth_op) 12110 { 12111 uint8_t auth_key[tdata->key.len]; 12112 int status; 12113 12114 struct crypto_testsuite_params *ts_params = &testsuite_params; 12115 struct crypto_unittest_params *ut_params = &unittest_params; 12116 12117 memcpy(auth_key, tdata->key.data, tdata->key.len); 12118 12119 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12120 ut_params->auth_xform.next = NULL; 12121 12122 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12123 ut_params->auth_xform.auth.op = auth_op; 12124 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12125 ut_params->auth_xform.auth.key.length = tdata->key.len; 12126 ut_params->auth_xform.auth.key.data = auth_key; 12127 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12128 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12129 12130 12131 ut_params->sess = rte_cryptodev_sym_session_create( 12132 ts_params->session_mpool); 12133 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12134 12135 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12136 &ut_params->auth_xform, 12137 ts_params->session_priv_mpool); 12138 12139 return status; 12140 } 12141 12142 static int 12143 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12144 { 12145 struct crypto_testsuite_params *ts_params = &testsuite_params; 12146 struct crypto_unittest_params *ut_params = &unittest_params; 12147 struct rte_cryptodev_info dev_info; 12148 12149 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12150 uint64_t feat_flags = dev_info.feature_flags; 12151 12152 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12153 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12154 printf("Device doesn't support RAW data-path APIs.\n"); 12155 return TEST_SKIPPED; 12156 } 12157 12158 int retval; 12159 12160 uint8_t *auth_tag, *plaintext; 12161 uint16_t plaintext_pad_len; 12162 12163 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12164 "No GMAC length in the source data"); 12165 12166 /* Verify the capabilities */ 12167 struct rte_cryptodev_sym_capability_idx cap_idx; 12168 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12169 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12170 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12171 &cap_idx) == NULL) 12172 return TEST_SKIPPED; 12173 12174 retval = create_gmac_session(ts_params->valid_devs[0], 12175 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12176 12177 if (retval == -ENOTSUP) 12178 return TEST_SKIPPED; 12179 if (retval < 0) 12180 return retval; 12181 12182 if (tdata->plaintext.len > MBUF_SIZE) 12183 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12184 else 12185 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12186 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12187 "Failed to allocate input buffer in mempool"); 12188 12189 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12190 rte_pktmbuf_tailroom(ut_params->ibuf)); 12191 12192 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12193 /* 12194 * Runtime generate the large plain text instead of use hard code 12195 * plain text vector. It is done to avoid create huge source file 12196 * with the test vector. 12197 */ 12198 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12199 generate_gmac_large_plaintext(tdata->plaintext.data); 12200 12201 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12202 plaintext_pad_len); 12203 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12204 12205 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12206 debug_hexdump(stdout, "plaintext:", plaintext, 12207 tdata->plaintext.len); 12208 12209 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12210 tdata); 12211 12212 if (retval < 0) 12213 return retval; 12214 12215 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12216 12217 ut_params->op->sym->m_src = ut_params->ibuf; 12218 12219 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12220 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12221 ut_params->op); 12222 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12223 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12224 ut_params->op, 0, 1, 0, 0); 12225 else 12226 TEST_ASSERT_NOT_NULL( 12227 process_crypto_request(ts_params->valid_devs[0], 12228 ut_params->op), "failed to process sym crypto op"); 12229 12230 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12231 "crypto op processing failed"); 12232 12233 if (ut_params->op->sym->m_dst) { 12234 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12235 uint8_t *, plaintext_pad_len); 12236 } else { 12237 auth_tag = plaintext + plaintext_pad_len; 12238 } 12239 12240 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12241 12242 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12243 auth_tag, 12244 tdata->gmac_tag.data, 12245 tdata->gmac_tag.len, 12246 "GMAC Generated auth tag not as expected"); 12247 12248 return 0; 12249 } 12250 12251 static int 12252 test_AES_GMAC_authentication_test_case_1(void) 12253 { 12254 return test_AES_GMAC_authentication(&gmac_test_case_1); 12255 } 12256 12257 static int 12258 test_AES_GMAC_authentication_test_case_2(void) 12259 { 12260 return test_AES_GMAC_authentication(&gmac_test_case_2); 12261 } 12262 12263 static int 12264 test_AES_GMAC_authentication_test_case_3(void) 12265 { 12266 return test_AES_GMAC_authentication(&gmac_test_case_3); 12267 } 12268 12269 static int 12270 test_AES_GMAC_authentication_test_case_4(void) 12271 { 12272 return test_AES_GMAC_authentication(&gmac_test_case_4); 12273 } 12274 12275 static int 12276 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12277 { 12278 struct crypto_testsuite_params *ts_params = &testsuite_params; 12279 struct crypto_unittest_params *ut_params = &unittest_params; 12280 int retval; 12281 uint32_t plaintext_pad_len; 12282 uint8_t *plaintext; 12283 struct rte_cryptodev_info dev_info; 12284 12285 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12286 uint64_t feat_flags = dev_info.feature_flags; 12287 12288 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12289 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12290 printf("Device doesn't support RAW data-path APIs.\n"); 12291 return TEST_SKIPPED; 12292 } 12293 12294 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12295 "No GMAC length in the source data"); 12296 12297 /* Verify the capabilities */ 12298 struct rte_cryptodev_sym_capability_idx cap_idx; 12299 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12300 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12301 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12302 &cap_idx) == NULL) 12303 return TEST_SKIPPED; 12304 12305 retval = create_gmac_session(ts_params->valid_devs[0], 12306 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12307 12308 if (retval == -ENOTSUP) 12309 return TEST_SKIPPED; 12310 if (retval < 0) 12311 return retval; 12312 12313 if (tdata->plaintext.len > MBUF_SIZE) 12314 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12315 else 12316 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12317 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12318 "Failed to allocate input buffer in mempool"); 12319 12320 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12321 rte_pktmbuf_tailroom(ut_params->ibuf)); 12322 12323 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12324 12325 /* 12326 * Runtime generate the large plain text instead of use hard code 12327 * plain text vector. It is done to avoid create huge source file 12328 * with the test vector. 12329 */ 12330 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12331 generate_gmac_large_plaintext(tdata->plaintext.data); 12332 12333 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12334 plaintext_pad_len); 12335 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12336 12337 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12338 debug_hexdump(stdout, "plaintext:", plaintext, 12339 tdata->plaintext.len); 12340 12341 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 12342 tdata); 12343 12344 if (retval < 0) 12345 return retval; 12346 12347 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12348 12349 ut_params->op->sym->m_src = ut_params->ibuf; 12350 12351 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12352 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12353 ut_params->op); 12354 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12355 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12356 ut_params->op, 0, 1, 0, 0); 12357 else 12358 TEST_ASSERT_NOT_NULL( 12359 process_crypto_request(ts_params->valid_devs[0], 12360 ut_params->op), "failed to process sym crypto op"); 12361 12362 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12363 "crypto op processing failed"); 12364 12365 return 0; 12366 12367 } 12368 12369 static int 12370 test_AES_GMAC_authentication_verify_test_case_1(void) 12371 { 12372 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 12373 } 12374 12375 static int 12376 test_AES_GMAC_authentication_verify_test_case_2(void) 12377 { 12378 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 12379 } 12380 12381 static int 12382 test_AES_GMAC_authentication_verify_test_case_3(void) 12383 { 12384 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 12385 } 12386 12387 static int 12388 test_AES_GMAC_authentication_verify_test_case_4(void) 12389 { 12390 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 12391 } 12392 12393 static int 12394 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 12395 uint32_t fragsz) 12396 { 12397 struct crypto_testsuite_params *ts_params = &testsuite_params; 12398 struct crypto_unittest_params *ut_params = &unittest_params; 12399 struct rte_cryptodev_info dev_info; 12400 uint64_t feature_flags; 12401 unsigned int trn_data = 0; 12402 void *digest_mem = NULL; 12403 uint32_t segs = 1; 12404 unsigned int to_trn = 0; 12405 struct rte_mbuf *buf = NULL; 12406 uint8_t *auth_tag, *plaintext; 12407 int retval; 12408 12409 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12410 "No GMAC length in the source data"); 12411 12412 /* Verify the capabilities */ 12413 struct rte_cryptodev_sym_capability_idx cap_idx; 12414 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12415 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12416 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12417 &cap_idx) == NULL) 12418 return TEST_SKIPPED; 12419 12420 /* Check for any input SGL support */ 12421 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12422 feature_flags = dev_info.feature_flags; 12423 12424 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 12425 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 12426 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 12427 return TEST_SKIPPED; 12428 12429 if (fragsz > tdata->plaintext.len) 12430 fragsz = tdata->plaintext.len; 12431 12432 uint16_t plaintext_len = fragsz; 12433 12434 retval = create_gmac_session(ts_params->valid_devs[0], 12435 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12436 12437 if (retval == -ENOTSUP) 12438 return TEST_SKIPPED; 12439 if (retval < 0) 12440 return retval; 12441 12442 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12443 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12444 "Failed to allocate input buffer in mempool"); 12445 12446 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12447 rte_pktmbuf_tailroom(ut_params->ibuf)); 12448 12449 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12450 plaintext_len); 12451 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12452 12453 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12454 12455 trn_data += plaintext_len; 12456 12457 buf = ut_params->ibuf; 12458 12459 /* 12460 * Loop until no more fragments 12461 */ 12462 12463 while (trn_data < tdata->plaintext.len) { 12464 ++segs; 12465 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12466 (tdata->plaintext.len - trn_data) : fragsz; 12467 12468 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12469 buf = buf->next; 12470 12471 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12472 rte_pktmbuf_tailroom(buf)); 12473 12474 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12475 to_trn); 12476 12477 memcpy(plaintext, tdata->plaintext.data + trn_data, 12478 to_trn); 12479 trn_data += to_trn; 12480 if (trn_data == tdata->plaintext.len) 12481 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12482 tdata->gmac_tag.len); 12483 } 12484 ut_params->ibuf->nb_segs = segs; 12485 12486 /* 12487 * Place digest at the end of the last buffer 12488 */ 12489 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12490 12491 if (!digest_mem) { 12492 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12493 + tdata->gmac_tag.len); 12494 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12495 tdata->plaintext.len); 12496 } 12497 12498 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 12499 tdata, digest_mem, digest_phys); 12500 12501 if (retval < 0) 12502 return retval; 12503 12504 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12505 12506 ut_params->op->sym->m_src = ut_params->ibuf; 12507 12508 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12509 return TEST_SKIPPED; 12510 12511 TEST_ASSERT_NOT_NULL( 12512 process_crypto_request(ts_params->valid_devs[0], 12513 ut_params->op), "failed to process sym crypto op"); 12514 12515 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12516 "crypto op processing failed"); 12517 12518 auth_tag = digest_mem; 12519 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12520 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12521 auth_tag, 12522 tdata->gmac_tag.data, 12523 tdata->gmac_tag.len, 12524 "GMAC Generated auth tag not as expected"); 12525 12526 return 0; 12527 } 12528 12529 /* Segment size not multiple of block size (16B) */ 12530 static int 12531 test_AES_GMAC_authentication_SGL_40B(void) 12532 { 12533 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 12534 } 12535 12536 static int 12537 test_AES_GMAC_authentication_SGL_80B(void) 12538 { 12539 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 12540 } 12541 12542 static int 12543 test_AES_GMAC_authentication_SGL_2048B(void) 12544 { 12545 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 12546 } 12547 12548 /* Segment size not multiple of block size (16B) */ 12549 static int 12550 test_AES_GMAC_authentication_SGL_2047B(void) 12551 { 12552 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 12553 } 12554 12555 struct test_crypto_vector { 12556 enum rte_crypto_cipher_algorithm crypto_algo; 12557 unsigned int cipher_offset; 12558 unsigned int cipher_len; 12559 12560 struct { 12561 uint8_t data[64]; 12562 unsigned int len; 12563 } cipher_key; 12564 12565 struct { 12566 uint8_t data[64]; 12567 unsigned int len; 12568 } iv; 12569 12570 struct { 12571 const uint8_t *data; 12572 unsigned int len; 12573 } plaintext; 12574 12575 struct { 12576 const uint8_t *data; 12577 unsigned int len; 12578 } ciphertext; 12579 12580 enum rte_crypto_auth_algorithm auth_algo; 12581 unsigned int auth_offset; 12582 12583 struct { 12584 uint8_t data[128]; 12585 unsigned int len; 12586 } auth_key; 12587 12588 struct { 12589 const uint8_t *data; 12590 unsigned int len; 12591 } aad; 12592 12593 struct { 12594 uint8_t data[128]; 12595 unsigned int len; 12596 } digest; 12597 }; 12598 12599 static const struct test_crypto_vector 12600 hmac_sha1_test_crypto_vector = { 12601 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12602 .plaintext = { 12603 .data = plaintext_hash, 12604 .len = 512 12605 }, 12606 .auth_key = { 12607 .data = { 12608 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12609 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12610 0xDE, 0xF4, 0xDE, 0xAD 12611 }, 12612 .len = 20 12613 }, 12614 .digest = { 12615 .data = { 12616 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 12617 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 12618 0x3F, 0x91, 0x64, 0x59 12619 }, 12620 .len = 20 12621 } 12622 }; 12623 12624 static const struct test_crypto_vector 12625 aes128_gmac_test_vector = { 12626 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 12627 .plaintext = { 12628 .data = plaintext_hash, 12629 .len = 512 12630 }, 12631 .iv = { 12632 .data = { 12633 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12634 0x08, 0x09, 0x0A, 0x0B 12635 }, 12636 .len = 12 12637 }, 12638 .auth_key = { 12639 .data = { 12640 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12641 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 12642 }, 12643 .len = 16 12644 }, 12645 .digest = { 12646 .data = { 12647 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 12648 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 12649 }, 12650 .len = 16 12651 } 12652 }; 12653 12654 static const struct test_crypto_vector 12655 aes128cbc_hmac_sha1_test_vector = { 12656 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12657 .cipher_offset = 0, 12658 .cipher_len = 512, 12659 .cipher_key = { 12660 .data = { 12661 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12662 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12663 }, 12664 .len = 16 12665 }, 12666 .iv = { 12667 .data = { 12668 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12669 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12670 }, 12671 .len = 16 12672 }, 12673 .plaintext = { 12674 .data = plaintext_hash, 12675 .len = 512 12676 }, 12677 .ciphertext = { 12678 .data = ciphertext512_aes128cbc, 12679 .len = 512 12680 }, 12681 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12682 .auth_offset = 0, 12683 .auth_key = { 12684 .data = { 12685 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12686 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12687 0xDE, 0xF4, 0xDE, 0xAD 12688 }, 12689 .len = 20 12690 }, 12691 .digest = { 12692 .data = { 12693 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 12694 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12695 0x18, 0x8C, 0x1D, 0x32 12696 }, 12697 .len = 20 12698 } 12699 }; 12700 12701 static const struct test_crypto_vector 12702 aes128cbc_hmac_sha1_aad_test_vector = { 12703 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12704 .cipher_offset = 8, 12705 .cipher_len = 496, 12706 .cipher_key = { 12707 .data = { 12708 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12709 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12710 }, 12711 .len = 16 12712 }, 12713 .iv = { 12714 .data = { 12715 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12716 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12717 }, 12718 .len = 16 12719 }, 12720 .plaintext = { 12721 .data = plaintext_hash, 12722 .len = 512 12723 }, 12724 .ciphertext = { 12725 .data = ciphertext512_aes128cbc_aad, 12726 .len = 512 12727 }, 12728 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12729 .auth_offset = 0, 12730 .auth_key = { 12731 .data = { 12732 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12733 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12734 0xDE, 0xF4, 0xDE, 0xAD 12735 }, 12736 .len = 20 12737 }, 12738 .digest = { 12739 .data = { 12740 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 12741 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 12742 0x62, 0x0F, 0xFB, 0x10 12743 }, 12744 .len = 20 12745 } 12746 }; 12747 12748 static void 12749 data_corruption(uint8_t *data) 12750 { 12751 data[0] += 1; 12752 } 12753 12754 static void 12755 tag_corruption(uint8_t *data, unsigned int tag_offset) 12756 { 12757 data[tag_offset] += 1; 12758 } 12759 12760 static int 12761 create_auth_session(struct crypto_unittest_params *ut_params, 12762 uint8_t dev_id, 12763 const struct test_crypto_vector *reference, 12764 enum rte_crypto_auth_operation auth_op) 12765 { 12766 struct crypto_testsuite_params *ts_params = &testsuite_params; 12767 uint8_t auth_key[reference->auth_key.len + 1]; 12768 int status; 12769 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.next = NULL; 12776 ut_params->auth_xform.auth.algo = reference->auth_algo; 12777 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12778 ut_params->auth_xform.auth.key.data = auth_key; 12779 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12780 12781 /* Create Crypto session*/ 12782 ut_params->sess = rte_cryptodev_sym_session_create( 12783 ts_params->session_mpool); 12784 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12785 12786 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12787 &ut_params->auth_xform, 12788 ts_params->session_priv_mpool); 12789 12790 return status; 12791 } 12792 12793 static int 12794 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 12795 uint8_t dev_id, 12796 const struct test_crypto_vector *reference, 12797 enum rte_crypto_auth_operation auth_op, 12798 enum rte_crypto_cipher_operation cipher_op) 12799 { 12800 struct crypto_testsuite_params *ts_params = &testsuite_params; 12801 uint8_t cipher_key[reference->cipher_key.len + 1]; 12802 uint8_t auth_key[reference->auth_key.len + 1]; 12803 int status; 12804 12805 memcpy(cipher_key, reference->cipher_key.data, 12806 reference->cipher_key.len); 12807 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12808 12809 /* Setup Authentication Parameters */ 12810 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12811 ut_params->auth_xform.auth.op = auth_op; 12812 ut_params->auth_xform.auth.algo = reference->auth_algo; 12813 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12814 ut_params->auth_xform.auth.key.data = auth_key; 12815 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12816 12817 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 12818 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12819 ut_params->auth_xform.auth.iv.length = reference->iv.len; 12820 } else { 12821 ut_params->auth_xform.next = &ut_params->cipher_xform; 12822 12823 /* Setup Cipher Parameters */ 12824 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12825 ut_params->cipher_xform.next = NULL; 12826 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12827 ut_params->cipher_xform.cipher.op = cipher_op; 12828 ut_params->cipher_xform.cipher.key.data = cipher_key; 12829 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12830 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12831 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12832 } 12833 12834 /* Create Crypto session*/ 12835 ut_params->sess = rte_cryptodev_sym_session_create( 12836 ts_params->session_mpool); 12837 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12838 12839 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12840 &ut_params->auth_xform, 12841 ts_params->session_priv_mpool); 12842 12843 return status; 12844 } 12845 12846 static int 12847 create_auth_operation(struct crypto_testsuite_params *ts_params, 12848 struct crypto_unittest_params *ut_params, 12849 const struct test_crypto_vector *reference, 12850 unsigned int auth_generate) 12851 { 12852 /* Generate Crypto op data structure */ 12853 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12854 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12855 TEST_ASSERT_NOT_NULL(ut_params->op, 12856 "Failed to allocate pktmbuf offload"); 12857 12858 /* Set crypto operation data parameters */ 12859 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12860 12861 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12862 12863 /* set crypto operation source mbuf */ 12864 sym_op->m_src = ut_params->ibuf; 12865 12866 /* digest */ 12867 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12868 ut_params->ibuf, reference->digest.len); 12869 12870 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12871 "no room to append auth tag"); 12872 12873 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12874 ut_params->ibuf, reference->plaintext.len); 12875 12876 if (auth_generate) 12877 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12878 else 12879 memcpy(sym_op->auth.digest.data, 12880 reference->digest.data, 12881 reference->digest.len); 12882 12883 debug_hexdump(stdout, "digest:", 12884 sym_op->auth.digest.data, 12885 reference->digest.len); 12886 12887 sym_op->auth.data.length = reference->plaintext.len; 12888 sym_op->auth.data.offset = 0; 12889 12890 return 0; 12891 } 12892 12893 static int 12894 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 12895 struct crypto_unittest_params *ut_params, 12896 const struct test_crypto_vector *reference, 12897 unsigned int auth_generate) 12898 { 12899 /* Generate Crypto op data structure */ 12900 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12901 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12902 TEST_ASSERT_NOT_NULL(ut_params->op, 12903 "Failed to allocate pktmbuf offload"); 12904 12905 /* Set crypto operation data parameters */ 12906 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12907 12908 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12909 12910 /* set crypto operation source mbuf */ 12911 sym_op->m_src = ut_params->ibuf; 12912 12913 /* digest */ 12914 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12915 ut_params->ibuf, reference->digest.len); 12916 12917 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12918 "no room to append auth tag"); 12919 12920 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12921 ut_params->ibuf, reference->ciphertext.len); 12922 12923 if (auth_generate) 12924 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12925 else 12926 memcpy(sym_op->auth.digest.data, 12927 reference->digest.data, 12928 reference->digest.len); 12929 12930 debug_hexdump(stdout, "digest:", 12931 sym_op->auth.digest.data, 12932 reference->digest.len); 12933 12934 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12935 reference->iv.data, reference->iv.len); 12936 12937 sym_op->cipher.data.length = 0; 12938 sym_op->cipher.data.offset = 0; 12939 12940 sym_op->auth.data.length = reference->plaintext.len; 12941 sym_op->auth.data.offset = 0; 12942 12943 return 0; 12944 } 12945 12946 static int 12947 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 12948 struct crypto_unittest_params *ut_params, 12949 const struct test_crypto_vector *reference, 12950 unsigned int auth_generate) 12951 { 12952 /* Generate Crypto op data structure */ 12953 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12954 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12955 TEST_ASSERT_NOT_NULL(ut_params->op, 12956 "Failed to allocate pktmbuf offload"); 12957 12958 /* Set crypto operation data parameters */ 12959 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12960 12961 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12962 12963 /* set crypto operation source mbuf */ 12964 sym_op->m_src = ut_params->ibuf; 12965 12966 /* digest */ 12967 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12968 ut_params->ibuf, reference->digest.len); 12969 12970 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12971 "no room to append auth tag"); 12972 12973 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12974 ut_params->ibuf, reference->ciphertext.len); 12975 12976 if (auth_generate) 12977 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12978 else 12979 memcpy(sym_op->auth.digest.data, 12980 reference->digest.data, 12981 reference->digest.len); 12982 12983 debug_hexdump(stdout, "digest:", 12984 sym_op->auth.digest.data, 12985 reference->digest.len); 12986 12987 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12988 reference->iv.data, reference->iv.len); 12989 12990 sym_op->cipher.data.length = reference->cipher_len; 12991 sym_op->cipher.data.offset = reference->cipher_offset; 12992 12993 sym_op->auth.data.length = reference->plaintext.len; 12994 sym_op->auth.data.offset = reference->auth_offset; 12995 12996 return 0; 12997 } 12998 12999 static int 13000 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13001 struct crypto_unittest_params *ut_params, 13002 const struct test_crypto_vector *reference) 13003 { 13004 return create_auth_operation(ts_params, ut_params, reference, 0); 13005 } 13006 13007 static int 13008 create_auth_verify_GMAC_operation( 13009 struct crypto_testsuite_params *ts_params, 13010 struct crypto_unittest_params *ut_params, 13011 const struct test_crypto_vector *reference) 13012 { 13013 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 13014 } 13015 13016 static int 13017 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13018 struct crypto_unittest_params *ut_params, 13019 const struct test_crypto_vector *reference) 13020 { 13021 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 13022 } 13023 13024 static int 13025 test_authentication_verify_fail_when_data_corruption( 13026 struct crypto_testsuite_params *ts_params, 13027 struct crypto_unittest_params *ut_params, 13028 const struct test_crypto_vector *reference, 13029 unsigned int data_corrupted) 13030 { 13031 int retval; 13032 13033 uint8_t *plaintext; 13034 struct rte_cryptodev_info dev_info; 13035 13036 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13037 uint64_t feat_flags = dev_info.feature_flags; 13038 13039 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13040 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13041 printf("Device doesn't support RAW data-path APIs.\n"); 13042 return TEST_SKIPPED; 13043 } 13044 13045 /* Verify the capabilities */ 13046 struct rte_cryptodev_sym_capability_idx cap_idx; 13047 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13048 cap_idx.algo.auth = reference->auth_algo; 13049 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13050 &cap_idx) == NULL) 13051 return TEST_SKIPPED; 13052 13053 13054 /* Create session */ 13055 retval = create_auth_session(ut_params, 13056 ts_params->valid_devs[0], 13057 reference, 13058 RTE_CRYPTO_AUTH_OP_VERIFY); 13059 13060 if (retval == -ENOTSUP) 13061 return TEST_SKIPPED; 13062 if (retval < 0) 13063 return retval; 13064 13065 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13066 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13067 "Failed to allocate input buffer in mempool"); 13068 13069 /* clear mbuf payload */ 13070 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13071 rte_pktmbuf_tailroom(ut_params->ibuf)); 13072 13073 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13074 reference->plaintext.len); 13075 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13076 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13077 13078 debug_hexdump(stdout, "plaintext:", plaintext, 13079 reference->plaintext.len); 13080 13081 /* Create operation */ 13082 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13083 13084 if (retval < 0) 13085 return retval; 13086 13087 if (data_corrupted) 13088 data_corruption(plaintext); 13089 else 13090 tag_corruption(plaintext, reference->plaintext.len); 13091 13092 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13093 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13094 ut_params->op); 13095 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13096 RTE_CRYPTO_OP_STATUS_SUCCESS, 13097 "authentication not failed"); 13098 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13099 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13100 ut_params->op, 0, 1, 0, 0); 13101 else { 13102 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13103 ut_params->op); 13104 } 13105 if (ut_params->op == NULL) 13106 return 0; 13107 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13108 return 0; 13109 13110 return -1; 13111 } 13112 13113 static int 13114 test_authentication_verify_GMAC_fail_when_corruption( 13115 struct crypto_testsuite_params *ts_params, 13116 struct crypto_unittest_params *ut_params, 13117 const struct test_crypto_vector *reference, 13118 unsigned int data_corrupted) 13119 { 13120 int retval; 13121 uint8_t *plaintext; 13122 struct rte_cryptodev_info dev_info; 13123 13124 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13125 uint64_t feat_flags = dev_info.feature_flags; 13126 13127 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13128 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13129 printf("Device doesn't support RAW data-path APIs.\n"); 13130 return TEST_SKIPPED; 13131 } 13132 13133 /* Verify the capabilities */ 13134 struct rte_cryptodev_sym_capability_idx cap_idx; 13135 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13136 cap_idx.algo.auth = reference->auth_algo; 13137 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13138 &cap_idx) == NULL) 13139 return TEST_SKIPPED; 13140 13141 /* Create session */ 13142 retval = create_auth_cipher_session(ut_params, 13143 ts_params->valid_devs[0], 13144 reference, 13145 RTE_CRYPTO_AUTH_OP_VERIFY, 13146 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13147 if (retval < 0) 13148 return retval; 13149 13150 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13151 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13152 "Failed to allocate input buffer in mempool"); 13153 13154 /* clear mbuf payload */ 13155 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13156 rte_pktmbuf_tailroom(ut_params->ibuf)); 13157 13158 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13159 reference->plaintext.len); 13160 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13161 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13162 13163 debug_hexdump(stdout, "plaintext:", plaintext, 13164 reference->plaintext.len); 13165 13166 /* Create operation */ 13167 retval = create_auth_verify_GMAC_operation(ts_params, 13168 ut_params, 13169 reference); 13170 13171 if (retval < 0) 13172 return retval; 13173 13174 if (data_corrupted) 13175 data_corruption(plaintext); 13176 else 13177 tag_corruption(plaintext, reference->aad.len); 13178 13179 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13180 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13181 ut_params->op); 13182 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13183 RTE_CRYPTO_OP_STATUS_SUCCESS, 13184 "authentication not failed"); 13185 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13186 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13187 ut_params->op, 0, 1, 0, 0); 13188 else { 13189 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13190 ut_params->op); 13191 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13192 } 13193 13194 return 0; 13195 } 13196 13197 static int 13198 test_authenticated_decryption_fail_when_corruption( 13199 struct crypto_testsuite_params *ts_params, 13200 struct crypto_unittest_params *ut_params, 13201 const struct test_crypto_vector *reference, 13202 unsigned int data_corrupted) 13203 { 13204 int retval; 13205 13206 uint8_t *ciphertext; 13207 struct rte_cryptodev_info dev_info; 13208 13209 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13210 uint64_t feat_flags = dev_info.feature_flags; 13211 13212 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13213 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13214 printf("Device doesn't support RAW data-path APIs.\n"); 13215 return TEST_SKIPPED; 13216 } 13217 13218 /* Verify the capabilities */ 13219 struct rte_cryptodev_sym_capability_idx cap_idx; 13220 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13221 cap_idx.algo.auth = reference->auth_algo; 13222 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13223 &cap_idx) == NULL) 13224 return TEST_SKIPPED; 13225 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13226 cap_idx.algo.cipher = reference->crypto_algo; 13227 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13228 &cap_idx) == NULL) 13229 return TEST_SKIPPED; 13230 13231 /* Create session */ 13232 retval = create_auth_cipher_session(ut_params, 13233 ts_params->valid_devs[0], 13234 reference, 13235 RTE_CRYPTO_AUTH_OP_VERIFY, 13236 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13237 13238 if (retval == -ENOTSUP) 13239 return TEST_SKIPPED; 13240 if (retval < 0) 13241 return retval; 13242 13243 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13244 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13245 "Failed to allocate input buffer in mempool"); 13246 13247 /* clear mbuf payload */ 13248 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13249 rte_pktmbuf_tailroom(ut_params->ibuf)); 13250 13251 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13252 reference->ciphertext.len); 13253 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13254 memcpy(ciphertext, reference->ciphertext.data, 13255 reference->ciphertext.len); 13256 13257 /* Create operation */ 13258 retval = create_cipher_auth_verify_operation(ts_params, 13259 ut_params, 13260 reference); 13261 13262 if (retval < 0) 13263 return retval; 13264 13265 if (data_corrupted) 13266 data_corruption(ciphertext); 13267 else 13268 tag_corruption(ciphertext, reference->ciphertext.len); 13269 13270 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13271 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13272 ut_params->op); 13273 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13274 RTE_CRYPTO_OP_STATUS_SUCCESS, 13275 "authentication not failed"); 13276 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13277 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13278 ut_params->op, 1, 1, 0, 0); 13279 else { 13280 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13281 ut_params->op); 13282 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13283 } 13284 13285 return 0; 13286 } 13287 13288 static int 13289 test_authenticated_encrypt_with_esn( 13290 struct crypto_testsuite_params *ts_params, 13291 struct crypto_unittest_params *ut_params, 13292 const struct test_crypto_vector *reference) 13293 { 13294 int retval; 13295 13296 uint8_t *authciphertext, *plaintext, *auth_tag; 13297 uint16_t plaintext_pad_len; 13298 uint8_t cipher_key[reference->cipher_key.len + 1]; 13299 uint8_t auth_key[reference->auth_key.len + 1]; 13300 struct rte_cryptodev_info dev_info; 13301 int status; 13302 13303 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13304 uint64_t feat_flags = dev_info.feature_flags; 13305 13306 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13307 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13308 printf("Device doesn't support RAW data-path APIs.\n"); 13309 return TEST_SKIPPED; 13310 } 13311 13312 /* Verify the capabilities */ 13313 struct rte_cryptodev_sym_capability_idx cap_idx; 13314 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13315 cap_idx.algo.auth = reference->auth_algo; 13316 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13317 &cap_idx) == NULL) 13318 return TEST_SKIPPED; 13319 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13320 cap_idx.algo.cipher = reference->crypto_algo; 13321 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13322 &cap_idx) == NULL) 13323 return TEST_SKIPPED; 13324 13325 /* Create session */ 13326 memcpy(cipher_key, reference->cipher_key.data, 13327 reference->cipher_key.len); 13328 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13329 13330 /* Setup Cipher Parameters */ 13331 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13332 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13333 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13334 ut_params->cipher_xform.cipher.key.data = cipher_key; 13335 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13336 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13337 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13338 13339 ut_params->cipher_xform.next = &ut_params->auth_xform; 13340 13341 /* Setup Authentication Parameters */ 13342 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13343 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13344 ut_params->auth_xform.auth.algo = reference->auth_algo; 13345 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13346 ut_params->auth_xform.auth.key.data = auth_key; 13347 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13348 ut_params->auth_xform.next = NULL; 13349 13350 /* Create Crypto session*/ 13351 ut_params->sess = rte_cryptodev_sym_session_create( 13352 ts_params->session_mpool); 13353 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13354 13355 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13356 ut_params->sess, 13357 &ut_params->cipher_xform, 13358 ts_params->session_priv_mpool); 13359 13360 if (status == -ENOTSUP) 13361 return TEST_SKIPPED; 13362 13363 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 13364 13365 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13366 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13367 "Failed to allocate input buffer in mempool"); 13368 13369 /* clear mbuf payload */ 13370 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13371 rte_pktmbuf_tailroom(ut_params->ibuf)); 13372 13373 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13374 reference->plaintext.len); 13375 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13376 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13377 13378 /* Create operation */ 13379 retval = create_cipher_auth_operation(ts_params, 13380 ut_params, 13381 reference, 0); 13382 13383 if (retval < 0) 13384 return retval; 13385 13386 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13387 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13388 ut_params->op); 13389 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13390 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13391 ut_params->op, 1, 1, 0, 0); 13392 else 13393 ut_params->op = process_crypto_request( 13394 ts_params->valid_devs[0], ut_params->op); 13395 13396 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 13397 13398 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13399 "crypto op processing failed"); 13400 13401 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 13402 13403 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13404 ut_params->op->sym->auth.data.offset); 13405 auth_tag = authciphertext + plaintext_pad_len; 13406 debug_hexdump(stdout, "ciphertext:", authciphertext, 13407 reference->ciphertext.len); 13408 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 13409 13410 /* Validate obuf */ 13411 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13412 authciphertext, 13413 reference->ciphertext.data, 13414 reference->ciphertext.len, 13415 "Ciphertext data not as expected"); 13416 13417 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13418 auth_tag, 13419 reference->digest.data, 13420 reference->digest.len, 13421 "Generated digest not as expected"); 13422 13423 return TEST_SUCCESS; 13424 13425 } 13426 13427 static int 13428 test_authenticated_decrypt_with_esn( 13429 struct crypto_testsuite_params *ts_params, 13430 struct crypto_unittest_params *ut_params, 13431 const struct test_crypto_vector *reference) 13432 { 13433 int retval; 13434 13435 uint8_t *ciphertext; 13436 uint8_t cipher_key[reference->cipher_key.len + 1]; 13437 uint8_t auth_key[reference->auth_key.len + 1]; 13438 struct rte_cryptodev_info dev_info; 13439 13440 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13441 uint64_t feat_flags = dev_info.feature_flags; 13442 13443 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13444 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13445 printf("Device doesn't support RAW data-path APIs.\n"); 13446 return TEST_SKIPPED; 13447 } 13448 13449 /* Verify the capabilities */ 13450 struct rte_cryptodev_sym_capability_idx cap_idx; 13451 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13452 cap_idx.algo.auth = reference->auth_algo; 13453 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13454 &cap_idx) == NULL) 13455 return TEST_SKIPPED; 13456 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13457 cap_idx.algo.cipher = reference->crypto_algo; 13458 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13459 &cap_idx) == NULL) 13460 return TEST_SKIPPED; 13461 13462 /* Create session */ 13463 memcpy(cipher_key, reference->cipher_key.data, 13464 reference->cipher_key.len); 13465 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13466 13467 /* Setup Authentication Parameters */ 13468 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13469 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 13470 ut_params->auth_xform.auth.algo = reference->auth_algo; 13471 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13472 ut_params->auth_xform.auth.key.data = auth_key; 13473 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13474 ut_params->auth_xform.next = &ut_params->cipher_xform; 13475 13476 /* Setup Cipher Parameters */ 13477 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13478 ut_params->cipher_xform.next = NULL; 13479 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13480 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 13481 ut_params->cipher_xform.cipher.key.data = cipher_key; 13482 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13483 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13484 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13485 13486 /* Create Crypto session*/ 13487 ut_params->sess = rte_cryptodev_sym_session_create( 13488 ts_params->session_mpool); 13489 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13490 13491 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13492 ut_params->sess, 13493 &ut_params->auth_xform, 13494 ts_params->session_priv_mpool); 13495 13496 if (retval == -ENOTSUP) 13497 return TEST_SKIPPED; 13498 13499 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 13500 13501 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13502 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13503 "Failed to allocate input buffer in mempool"); 13504 13505 /* clear mbuf payload */ 13506 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13507 rte_pktmbuf_tailroom(ut_params->ibuf)); 13508 13509 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13510 reference->ciphertext.len); 13511 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13512 memcpy(ciphertext, reference->ciphertext.data, 13513 reference->ciphertext.len); 13514 13515 /* Create operation */ 13516 retval = create_cipher_auth_verify_operation(ts_params, 13517 ut_params, 13518 reference); 13519 13520 if (retval < 0) 13521 return retval; 13522 13523 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13524 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13525 ut_params->op); 13526 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13527 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13528 ut_params->op, 1, 1, 0, 0); 13529 else 13530 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13531 ut_params->op); 13532 13533 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13534 TEST_ASSERT_EQUAL(ut_params->op->status, 13535 RTE_CRYPTO_OP_STATUS_SUCCESS, 13536 "crypto op processing passed"); 13537 13538 ut_params->obuf = ut_params->op->sym->m_src; 13539 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 13540 13541 return 0; 13542 } 13543 13544 static int 13545 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 13546 const struct aead_test_data *tdata, 13547 void *digest_mem, uint64_t digest_phys) 13548 { 13549 struct crypto_testsuite_params *ts_params = &testsuite_params; 13550 struct crypto_unittest_params *ut_params = &unittest_params; 13551 13552 const unsigned int auth_tag_len = tdata->auth_tag.len; 13553 const unsigned int iv_len = tdata->iv.len; 13554 unsigned int aad_len = tdata->aad.len; 13555 unsigned int aad_len_pad = 0; 13556 13557 /* Generate Crypto op data structure */ 13558 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13559 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13560 TEST_ASSERT_NOT_NULL(ut_params->op, 13561 "Failed to allocate symmetric crypto operation struct"); 13562 13563 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13564 13565 sym_op->aead.digest.data = digest_mem; 13566 13567 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 13568 "no room to append digest"); 13569 13570 sym_op->aead.digest.phys_addr = digest_phys; 13571 13572 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 13573 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 13574 auth_tag_len); 13575 debug_hexdump(stdout, "digest:", 13576 sym_op->aead.digest.data, 13577 auth_tag_len); 13578 } 13579 13580 /* Append aad data */ 13581 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 13582 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13583 uint8_t *, IV_OFFSET); 13584 13585 /* Copy IV 1 byte after the IV pointer, according to the API */ 13586 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 13587 13588 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 13589 13590 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13591 ut_params->ibuf, aad_len); 13592 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13593 "no room to prepend aad"); 13594 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13595 ut_params->ibuf); 13596 13597 memset(sym_op->aead.aad.data, 0, aad_len); 13598 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 13599 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13600 13601 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13602 debug_hexdump(stdout, "aad:", 13603 sym_op->aead.aad.data, aad_len); 13604 } else { 13605 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13606 uint8_t *, IV_OFFSET); 13607 13608 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 13609 13610 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 13611 13612 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13613 ut_params->ibuf, aad_len_pad); 13614 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13615 "no room to prepend aad"); 13616 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13617 ut_params->ibuf); 13618 13619 memset(sym_op->aead.aad.data, 0, aad_len); 13620 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13621 13622 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13623 debug_hexdump(stdout, "aad:", 13624 sym_op->aead.aad.data, aad_len); 13625 } 13626 13627 sym_op->aead.data.length = tdata->plaintext.len; 13628 sym_op->aead.data.offset = aad_len_pad; 13629 13630 return 0; 13631 } 13632 13633 #define SGL_MAX_NO 16 13634 13635 static int 13636 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 13637 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 13638 { 13639 struct crypto_testsuite_params *ts_params = &testsuite_params; 13640 struct crypto_unittest_params *ut_params = &unittest_params; 13641 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 13642 int retval; 13643 int to_trn = 0; 13644 int to_trn_tbl[SGL_MAX_NO]; 13645 int segs = 1; 13646 unsigned int trn_data = 0; 13647 uint8_t *plaintext, *ciphertext, *auth_tag; 13648 struct rte_cryptodev_info dev_info; 13649 13650 /* Verify the capabilities */ 13651 struct rte_cryptodev_sym_capability_idx cap_idx; 13652 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13653 cap_idx.algo.aead = tdata->algo; 13654 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13655 &cap_idx) == NULL) 13656 return TEST_SKIPPED; 13657 13658 /* OOP not supported with CPU crypto */ 13659 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13660 return TEST_SKIPPED; 13661 13662 /* Detailed check for the particular SGL support flag */ 13663 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13664 if (!oop) { 13665 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13666 if (sgl_in && (!(dev_info.feature_flags & 13667 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 13668 return TEST_SKIPPED; 13669 13670 uint64_t feat_flags = dev_info.feature_flags; 13671 13672 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13673 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13674 printf("Device doesn't support RAW data-path APIs.\n"); 13675 return TEST_SKIPPED; 13676 } 13677 } else { 13678 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13679 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 13680 tdata->plaintext.len; 13681 /* Raw data path API does not support OOP */ 13682 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13683 return TEST_SKIPPED; 13684 if (sgl_in && !sgl_out) { 13685 if (!(dev_info.feature_flags & 13686 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 13687 return TEST_SKIPPED; 13688 } else if (!sgl_in && sgl_out) { 13689 if (!(dev_info.feature_flags & 13690 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 13691 return TEST_SKIPPED; 13692 } else if (sgl_in && sgl_out) { 13693 if (!(dev_info.feature_flags & 13694 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 13695 return TEST_SKIPPED; 13696 } 13697 } 13698 13699 if (fragsz > tdata->plaintext.len) 13700 fragsz = tdata->plaintext.len; 13701 13702 uint16_t plaintext_len = fragsz; 13703 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 13704 13705 if (fragsz_oop > tdata->plaintext.len) 13706 frag_size_oop = tdata->plaintext.len; 13707 13708 int ecx = 0; 13709 void *digest_mem = NULL; 13710 13711 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 13712 13713 if (tdata->plaintext.len % fragsz != 0) { 13714 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 13715 return 1; 13716 } else { 13717 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 13718 return 1; 13719 } 13720 13721 /* 13722 * For out-op-place we need to alloc another mbuf 13723 */ 13724 if (oop) { 13725 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13726 rte_pktmbuf_append(ut_params->obuf, 13727 frag_size_oop + prepend_len); 13728 buf_oop = ut_params->obuf; 13729 } 13730 13731 /* Create AEAD session */ 13732 retval = create_aead_session(ts_params->valid_devs[0], 13733 tdata->algo, 13734 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13735 tdata->key.data, tdata->key.len, 13736 tdata->aad.len, tdata->auth_tag.len, 13737 tdata->iv.len); 13738 if (retval < 0) 13739 return retval; 13740 13741 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13742 13743 /* clear mbuf payload */ 13744 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13745 rte_pktmbuf_tailroom(ut_params->ibuf)); 13746 13747 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13748 plaintext_len); 13749 13750 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13751 13752 trn_data += plaintext_len; 13753 13754 buf = ut_params->ibuf; 13755 13756 /* 13757 * Loop until no more fragments 13758 */ 13759 13760 while (trn_data < tdata->plaintext.len) { 13761 ++segs; 13762 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13763 (tdata->plaintext.len - trn_data) : fragsz; 13764 13765 to_trn_tbl[ecx++] = to_trn; 13766 13767 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13768 buf = buf->next; 13769 13770 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13771 rte_pktmbuf_tailroom(buf)); 13772 13773 /* OOP */ 13774 if (oop && !fragsz_oop) { 13775 buf_last_oop = buf_oop->next = 13776 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13777 buf_oop = buf_oop->next; 13778 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13779 0, rte_pktmbuf_tailroom(buf_oop)); 13780 rte_pktmbuf_append(buf_oop, to_trn); 13781 } 13782 13783 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13784 to_trn); 13785 13786 memcpy(plaintext, tdata->plaintext.data + trn_data, 13787 to_trn); 13788 trn_data += to_trn; 13789 if (trn_data == tdata->plaintext.len) { 13790 if (oop) { 13791 if (!fragsz_oop) 13792 digest_mem = rte_pktmbuf_append(buf_oop, 13793 tdata->auth_tag.len); 13794 } else 13795 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13796 tdata->auth_tag.len); 13797 } 13798 } 13799 13800 uint64_t digest_phys = 0; 13801 13802 ut_params->ibuf->nb_segs = segs; 13803 13804 segs = 1; 13805 if (fragsz_oop && oop) { 13806 to_trn = 0; 13807 ecx = 0; 13808 13809 if (frag_size_oop == tdata->plaintext.len) { 13810 digest_mem = rte_pktmbuf_append(ut_params->obuf, 13811 tdata->auth_tag.len); 13812 13813 digest_phys = rte_pktmbuf_iova_offset( 13814 ut_params->obuf, 13815 tdata->plaintext.len + prepend_len); 13816 } 13817 13818 trn_data = frag_size_oop; 13819 while (trn_data < tdata->plaintext.len) { 13820 ++segs; 13821 to_trn = 13822 (tdata->plaintext.len - trn_data < 13823 frag_size_oop) ? 13824 (tdata->plaintext.len - trn_data) : 13825 frag_size_oop; 13826 13827 to_trn_tbl[ecx++] = to_trn; 13828 13829 buf_last_oop = buf_oop->next = 13830 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13831 buf_oop = buf_oop->next; 13832 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13833 0, rte_pktmbuf_tailroom(buf_oop)); 13834 rte_pktmbuf_append(buf_oop, to_trn); 13835 13836 trn_data += to_trn; 13837 13838 if (trn_data == tdata->plaintext.len) { 13839 digest_mem = rte_pktmbuf_append(buf_oop, 13840 tdata->auth_tag.len); 13841 } 13842 } 13843 13844 ut_params->obuf->nb_segs = segs; 13845 } 13846 13847 /* 13848 * Place digest at the end of the last buffer 13849 */ 13850 if (!digest_phys) 13851 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13852 if (oop && buf_last_oop) 13853 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 13854 13855 if (!digest_mem && !oop) { 13856 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13857 + tdata->auth_tag.len); 13858 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13859 tdata->plaintext.len); 13860 } 13861 13862 /* Create AEAD operation */ 13863 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 13864 tdata, digest_mem, digest_phys); 13865 13866 if (retval < 0) 13867 return retval; 13868 13869 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13870 13871 ut_params->op->sym->m_src = ut_params->ibuf; 13872 if (oop) 13873 ut_params->op->sym->m_dst = ut_params->obuf; 13874 13875 /* Process crypto operation */ 13876 if (oop == IN_PLACE && 13877 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13878 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 13879 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13880 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13881 ut_params->op, 0, 0, 0, 0); 13882 else 13883 TEST_ASSERT_NOT_NULL( 13884 process_crypto_request(ts_params->valid_devs[0], 13885 ut_params->op), "failed to process sym crypto op"); 13886 13887 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13888 "crypto op processing failed"); 13889 13890 13891 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 13892 uint8_t *, prepend_len); 13893 if (oop) { 13894 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13895 uint8_t *, prepend_len); 13896 } 13897 13898 if (fragsz_oop) 13899 fragsz = fragsz_oop; 13900 13901 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13902 ciphertext, 13903 tdata->ciphertext.data, 13904 fragsz, 13905 "Ciphertext data not as expected"); 13906 13907 buf = ut_params->op->sym->m_src->next; 13908 if (oop) 13909 buf = ut_params->op->sym->m_dst->next; 13910 13911 unsigned int off = fragsz; 13912 13913 ecx = 0; 13914 while (buf) { 13915 ciphertext = rte_pktmbuf_mtod(buf, 13916 uint8_t *); 13917 13918 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13919 ciphertext, 13920 tdata->ciphertext.data + off, 13921 to_trn_tbl[ecx], 13922 "Ciphertext data not as expected"); 13923 13924 off += to_trn_tbl[ecx++]; 13925 buf = buf->next; 13926 } 13927 13928 auth_tag = digest_mem; 13929 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13930 auth_tag, 13931 tdata->auth_tag.data, 13932 tdata->auth_tag.len, 13933 "Generated auth tag not as expected"); 13934 13935 return 0; 13936 } 13937 13938 static int 13939 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 13940 { 13941 return test_authenticated_encryption_SGL( 13942 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 13943 } 13944 13945 static int 13946 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 13947 { 13948 return test_authenticated_encryption_SGL( 13949 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 13950 } 13951 13952 static int 13953 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 13954 { 13955 return test_authenticated_encryption_SGL( 13956 &gcm_test_case_8, OUT_OF_PLACE, 400, 13957 gcm_test_case_8.plaintext.len); 13958 } 13959 13960 static int 13961 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 13962 { 13963 /* This test is not for OPENSSL PMD */ 13964 if (gbl_driver_id == rte_cryptodev_driver_id_get( 13965 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 13966 return TEST_SKIPPED; 13967 13968 return test_authenticated_encryption_SGL( 13969 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 13970 } 13971 13972 static int 13973 test_authentication_verify_fail_when_data_corrupted( 13974 struct crypto_testsuite_params *ts_params, 13975 struct crypto_unittest_params *ut_params, 13976 const struct test_crypto_vector *reference) 13977 { 13978 return test_authentication_verify_fail_when_data_corruption( 13979 ts_params, ut_params, reference, 1); 13980 } 13981 13982 static int 13983 test_authentication_verify_fail_when_tag_corrupted( 13984 struct crypto_testsuite_params *ts_params, 13985 struct crypto_unittest_params *ut_params, 13986 const struct test_crypto_vector *reference) 13987 { 13988 return test_authentication_verify_fail_when_data_corruption( 13989 ts_params, ut_params, reference, 0); 13990 } 13991 13992 static int 13993 test_authentication_verify_GMAC_fail_when_data_corrupted( 13994 struct crypto_testsuite_params *ts_params, 13995 struct crypto_unittest_params *ut_params, 13996 const struct test_crypto_vector *reference) 13997 { 13998 return test_authentication_verify_GMAC_fail_when_corruption( 13999 ts_params, ut_params, reference, 1); 14000 } 14001 14002 static int 14003 test_authentication_verify_GMAC_fail_when_tag_corrupted( 14004 struct crypto_testsuite_params *ts_params, 14005 struct crypto_unittest_params *ut_params, 14006 const struct test_crypto_vector *reference) 14007 { 14008 return test_authentication_verify_GMAC_fail_when_corruption( 14009 ts_params, ut_params, reference, 0); 14010 } 14011 14012 static int 14013 test_authenticated_decryption_fail_when_data_corrupted( 14014 struct crypto_testsuite_params *ts_params, 14015 struct crypto_unittest_params *ut_params, 14016 const struct test_crypto_vector *reference) 14017 { 14018 return test_authenticated_decryption_fail_when_corruption( 14019 ts_params, ut_params, reference, 1); 14020 } 14021 14022 static int 14023 test_authenticated_decryption_fail_when_tag_corrupted( 14024 struct crypto_testsuite_params *ts_params, 14025 struct crypto_unittest_params *ut_params, 14026 const struct test_crypto_vector *reference) 14027 { 14028 return test_authenticated_decryption_fail_when_corruption( 14029 ts_params, ut_params, reference, 0); 14030 } 14031 14032 static int 14033 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 14034 { 14035 return test_authentication_verify_fail_when_data_corrupted( 14036 &testsuite_params, &unittest_params, 14037 &hmac_sha1_test_crypto_vector); 14038 } 14039 14040 static int 14041 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14042 { 14043 return test_authentication_verify_fail_when_tag_corrupted( 14044 &testsuite_params, &unittest_params, 14045 &hmac_sha1_test_crypto_vector); 14046 } 14047 14048 static int 14049 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14050 { 14051 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14052 &testsuite_params, &unittest_params, 14053 &aes128_gmac_test_vector); 14054 } 14055 14056 static int 14057 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14058 { 14059 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14060 &testsuite_params, &unittest_params, 14061 &aes128_gmac_test_vector); 14062 } 14063 14064 static int 14065 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14066 { 14067 return test_authenticated_decryption_fail_when_data_corrupted( 14068 &testsuite_params, 14069 &unittest_params, 14070 &aes128cbc_hmac_sha1_test_vector); 14071 } 14072 14073 static int 14074 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14075 { 14076 return test_authenticated_decryption_fail_when_tag_corrupted( 14077 &testsuite_params, 14078 &unittest_params, 14079 &aes128cbc_hmac_sha1_test_vector); 14080 } 14081 14082 static int 14083 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14084 { 14085 return test_authenticated_encrypt_with_esn( 14086 &testsuite_params, 14087 &unittest_params, 14088 &aes128cbc_hmac_sha1_aad_test_vector); 14089 } 14090 14091 static int 14092 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14093 { 14094 return test_authenticated_decrypt_with_esn( 14095 &testsuite_params, 14096 &unittest_params, 14097 &aes128cbc_hmac_sha1_aad_test_vector); 14098 } 14099 14100 static int 14101 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14102 { 14103 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14104 } 14105 14106 static int 14107 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14108 { 14109 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14110 } 14111 14112 static int 14113 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14114 { 14115 return test_authenticated_encryption_SGL( 14116 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14117 chacha20_poly1305_case_2.plaintext.len); 14118 } 14119 14120 #ifdef RTE_CRYPTO_SCHEDULER 14121 14122 /* global AESNI worker IDs for the scheduler test */ 14123 uint8_t aesni_ids[2]; 14124 14125 static int 14126 scheduler_testsuite_setup(void) 14127 { 14128 uint32_t i = 0; 14129 int32_t nb_devs, ret; 14130 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14131 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14132 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14133 uint16_t worker_core_count = 0; 14134 uint16_t socket_id = 0; 14135 14136 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14137 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14138 14139 /* Identify the Worker Cores 14140 * Use 2 worker cores for the device args 14141 */ 14142 RTE_LCORE_FOREACH_WORKER(i) { 14143 if (worker_core_count > 1) 14144 break; 14145 snprintf(vdev_args, sizeof(vdev_args), 14146 "%s%d", temp_str, i); 14147 strcpy(temp_str, vdev_args); 14148 strlcat(temp_str, ";", sizeof(temp_str)); 14149 worker_core_count++; 14150 socket_id = rte_lcore_to_socket_id(i); 14151 } 14152 if (worker_core_count != 2) { 14153 RTE_LOG(ERR, USER1, 14154 "Cryptodev scheduler test require at least " 14155 "two worker cores to run. " 14156 "Please use the correct coremask.\n"); 14157 return TEST_FAILED; 14158 } 14159 strcpy(temp_str, vdev_args); 14160 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14161 temp_str, socket_id); 14162 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14163 nb_devs = rte_cryptodev_device_count_by_driver( 14164 rte_cryptodev_driver_id_get( 14165 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14166 if (nb_devs < 1) { 14167 ret = rte_vdev_init( 14168 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14169 vdev_args); 14170 TEST_ASSERT(ret == 0, 14171 "Failed to create instance %u of pmd : %s", 14172 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14173 } 14174 } 14175 return testsuite_setup(); 14176 } 14177 14178 static int 14179 test_scheduler_attach_worker_op(void) 14180 { 14181 struct crypto_testsuite_params *ts_params = &testsuite_params; 14182 uint8_t sched_id = ts_params->valid_devs[0]; 14183 uint32_t i, nb_devs_attached = 0; 14184 int ret; 14185 char vdev_name[32]; 14186 unsigned int count = rte_cryptodev_count(); 14187 14188 /* create 2 AESNI_MB vdevs on top of existing devices */ 14189 for (i = count; i < count + 2; i++) { 14190 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14191 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14192 i); 14193 ret = rte_vdev_init(vdev_name, NULL); 14194 14195 TEST_ASSERT(ret == 0, 14196 "Failed to create instance %u of" 14197 " pmd : %s", 14198 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14199 14200 if (ret < 0) { 14201 RTE_LOG(ERR, USER1, 14202 "Failed to create 2 AESNI MB PMDs.\n"); 14203 return TEST_SKIPPED; 14204 } 14205 } 14206 14207 /* attach 2 AESNI_MB cdevs */ 14208 for (i = count; i < count + 2; i++) { 14209 struct rte_cryptodev_info info; 14210 unsigned int session_size; 14211 14212 rte_cryptodev_info_get(i, &info); 14213 if (info.driver_id != rte_cryptodev_driver_id_get( 14214 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14215 continue; 14216 14217 session_size = rte_cryptodev_sym_get_private_session_size(i); 14218 /* 14219 * Create the session mempool again, since now there are new devices 14220 * to use the mempool. 14221 */ 14222 if (ts_params->session_mpool) { 14223 rte_mempool_free(ts_params->session_mpool); 14224 ts_params->session_mpool = NULL; 14225 } 14226 if (ts_params->session_priv_mpool) { 14227 rte_mempool_free(ts_params->session_priv_mpool); 14228 ts_params->session_priv_mpool = NULL; 14229 } 14230 14231 if (info.sym.max_nb_sessions != 0 && 14232 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14233 RTE_LOG(ERR, USER1, 14234 "Device does not support " 14235 "at least %u sessions\n", 14236 MAX_NB_SESSIONS); 14237 return TEST_FAILED; 14238 } 14239 /* 14240 * Create mempool with maximum number of sessions, 14241 * to include the session headers 14242 */ 14243 if (ts_params->session_mpool == NULL) { 14244 ts_params->session_mpool = 14245 rte_cryptodev_sym_session_pool_create( 14246 "test_sess_mp", 14247 MAX_NB_SESSIONS, 0, 0, 0, 14248 SOCKET_ID_ANY); 14249 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14250 "session mempool allocation failed"); 14251 } 14252 14253 /* 14254 * Create mempool with maximum number of sessions, 14255 * to include device specific session private data 14256 */ 14257 if (ts_params->session_priv_mpool == NULL) { 14258 ts_params->session_priv_mpool = rte_mempool_create( 14259 "test_sess_mp_priv", 14260 MAX_NB_SESSIONS, 14261 session_size, 14262 0, 0, NULL, NULL, NULL, 14263 NULL, SOCKET_ID_ANY, 14264 0); 14265 14266 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14267 "session mempool allocation failed"); 14268 } 14269 14270 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14271 ts_params->qp_conf.mp_session_private = 14272 ts_params->session_priv_mpool; 14273 14274 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14275 (uint8_t)i); 14276 14277 TEST_ASSERT(ret == 0, 14278 "Failed to attach device %u of pmd : %s", i, 14279 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14280 14281 aesni_ids[nb_devs_attached] = (uint8_t)i; 14282 14283 nb_devs_attached++; 14284 } 14285 14286 return 0; 14287 } 14288 14289 static int 14290 test_scheduler_detach_worker_op(void) 14291 { 14292 struct crypto_testsuite_params *ts_params = &testsuite_params; 14293 uint8_t sched_id = ts_params->valid_devs[0]; 14294 uint32_t i; 14295 int ret; 14296 14297 for (i = 0; i < 2; i++) { 14298 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14299 aesni_ids[i]); 14300 TEST_ASSERT(ret == 0, 14301 "Failed to detach device %u", aesni_ids[i]); 14302 } 14303 14304 return 0; 14305 } 14306 14307 static int 14308 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14309 { 14310 struct crypto_testsuite_params *ts_params = &testsuite_params; 14311 uint8_t sched_id = ts_params->valid_devs[0]; 14312 /* set mode */ 14313 return rte_cryptodev_scheduler_mode_set(sched_id, 14314 scheduler_mode); 14315 } 14316 14317 static int 14318 test_scheduler_mode_roundrobin_op(void) 14319 { 14320 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14321 0, "Failed to set roundrobin mode"); 14322 return 0; 14323 14324 } 14325 14326 static int 14327 test_scheduler_mode_multicore_op(void) 14328 { 14329 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14330 0, "Failed to set multicore mode"); 14331 14332 return 0; 14333 } 14334 14335 static int 14336 test_scheduler_mode_failover_op(void) 14337 { 14338 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 14339 0, "Failed to set failover mode"); 14340 14341 return 0; 14342 } 14343 14344 static int 14345 test_scheduler_mode_pkt_size_distr_op(void) 14346 { 14347 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 14348 0, "Failed to set pktsize mode"); 14349 14350 return 0; 14351 } 14352 14353 static int 14354 scheduler_multicore_testsuite_setup(void) 14355 { 14356 if (test_scheduler_attach_worker_op() < 0) 14357 return TEST_SKIPPED; 14358 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 14359 return TEST_SKIPPED; 14360 return 0; 14361 } 14362 14363 static int 14364 scheduler_roundrobin_testsuite_setup(void) 14365 { 14366 if (test_scheduler_attach_worker_op() < 0) 14367 return TEST_SKIPPED; 14368 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 14369 return TEST_SKIPPED; 14370 return 0; 14371 } 14372 14373 static int 14374 scheduler_failover_testsuite_setup(void) 14375 { 14376 if (test_scheduler_attach_worker_op() < 0) 14377 return TEST_SKIPPED; 14378 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 14379 return TEST_SKIPPED; 14380 return 0; 14381 } 14382 14383 static int 14384 scheduler_pkt_size_distr_testsuite_setup(void) 14385 { 14386 if (test_scheduler_attach_worker_op() < 0) 14387 return TEST_SKIPPED; 14388 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 14389 return TEST_SKIPPED; 14390 return 0; 14391 } 14392 14393 static void 14394 scheduler_mode_testsuite_teardown(void) 14395 { 14396 test_scheduler_detach_worker_op(); 14397 } 14398 14399 #endif /* RTE_CRYPTO_SCHEDULER */ 14400 14401 static struct unit_test_suite end_testsuite = { 14402 .suite_name = NULL, 14403 .setup = NULL, 14404 .teardown = NULL, 14405 .unit_test_suites = NULL 14406 }; 14407 14408 #ifdef RTE_LIB_SECURITY 14409 static struct unit_test_suite ipsec_proto_testsuite = { 14410 .suite_name = "IPsec Proto Unit Test Suite", 14411 .setup = ipsec_proto_testsuite_setup, 14412 .unit_test_cases = { 14413 TEST_CASE_NAMED_WITH_DATA( 14414 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14415 ut_setup_security, ut_teardown, 14416 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 14417 TEST_CASE_NAMED_WITH_DATA( 14418 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14419 ut_setup_security, ut_teardown, 14420 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 14421 TEST_CASE_NAMED_WITH_DATA( 14422 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14423 ut_setup_security, ut_teardown, 14424 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 14425 TEST_CASE_NAMED_WITH_DATA( 14426 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 14427 ut_setup_security, ut_teardown, 14428 test_ipsec_proto_known_vec, 14429 &pkt_aes_128_cbc_hmac_sha256), 14430 TEST_CASE_NAMED_WITH_DATA( 14431 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14432 ut_setup_security, ut_teardown, 14433 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 14434 TEST_CASE_NAMED_WITH_DATA( 14435 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14436 ut_setup_security, ut_teardown, 14437 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 14438 TEST_CASE_NAMED_WITH_DATA( 14439 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14440 ut_setup_security, ut_teardown, 14441 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 14442 TEST_CASE_NAMED_WITH_DATA( 14443 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 14444 ut_setup_security, ut_teardown, 14445 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 14446 TEST_CASE_NAMED_WITH_DATA( 14447 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 14448 ut_setup_security, ut_teardown, 14449 test_ipsec_proto_known_vec_inb, 14450 &pkt_aes_128_cbc_hmac_sha256), 14451 TEST_CASE_NAMED_ST( 14452 "Combined test alg list", 14453 ut_setup_security, ut_teardown, 14454 test_ipsec_proto_display_list), 14455 TEST_CASE_NAMED_ST( 14456 "IV generation", 14457 ut_setup_security, ut_teardown, 14458 test_ipsec_proto_iv_gen), 14459 TEST_CASE_NAMED_ST( 14460 "UDP encapsulation", 14461 ut_setup_security, ut_teardown, 14462 test_ipsec_proto_udp_encap), 14463 TEST_CASE_NAMED_ST( 14464 "UDP encapsulation ports verification test", 14465 ut_setup_security, ut_teardown, 14466 test_ipsec_proto_udp_ports_verify), 14467 TEST_CASE_NAMED_ST( 14468 "SA expiry packets soft", 14469 ut_setup_security, ut_teardown, 14470 test_ipsec_proto_sa_exp_pkts_soft), 14471 TEST_CASE_NAMED_ST( 14472 "SA expiry packets hard", 14473 ut_setup_security, ut_teardown, 14474 test_ipsec_proto_sa_exp_pkts_hard), 14475 TEST_CASE_NAMED_ST( 14476 "Negative test: ICV corruption", 14477 ut_setup_security, ut_teardown, 14478 test_ipsec_proto_err_icv_corrupt), 14479 TEST_CASE_NAMED_ST( 14480 "Tunnel dst addr verification", 14481 ut_setup_security, ut_teardown, 14482 test_ipsec_proto_tunnel_dst_addr_verify), 14483 TEST_CASE_NAMED_ST( 14484 "Tunnel src and dst addr verification", 14485 ut_setup_security, ut_teardown, 14486 test_ipsec_proto_tunnel_src_dst_addr_verify), 14487 TEST_CASE_NAMED_ST( 14488 "Inner IP checksum", 14489 ut_setup_security, ut_teardown, 14490 test_ipsec_proto_inner_ip_csum), 14491 TEST_CASE_NAMED_ST( 14492 "Inner L4 checksum", 14493 ut_setup_security, ut_teardown, 14494 test_ipsec_proto_inner_l4_csum), 14495 TEST_CASES_END() /**< NULL terminate unit test array */ 14496 } 14497 }; 14498 14499 static struct unit_test_suite pdcp_proto_testsuite = { 14500 .suite_name = "PDCP Proto Unit Test Suite", 14501 .setup = pdcp_proto_testsuite_setup, 14502 .unit_test_cases = { 14503 TEST_CASE_ST(ut_setup_security, ut_teardown, 14504 test_PDCP_PROTO_all), 14505 TEST_CASES_END() /**< NULL terminate unit test array */ 14506 } 14507 }; 14508 14509 #define ADD_UPLINK_TESTCASE(data) \ 14510 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 14511 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 14512 14513 #define ADD_DOWNLINK_TESTCASE(data) \ 14514 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 14515 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 14516 14517 static struct unit_test_suite docsis_proto_testsuite = { 14518 .suite_name = "DOCSIS Proto Unit Test Suite", 14519 .setup = docsis_proto_testsuite_setup, 14520 .unit_test_cases = { 14521 /* Uplink */ 14522 ADD_UPLINK_TESTCASE(docsis_test_case_1) 14523 ADD_UPLINK_TESTCASE(docsis_test_case_2) 14524 ADD_UPLINK_TESTCASE(docsis_test_case_3) 14525 ADD_UPLINK_TESTCASE(docsis_test_case_4) 14526 ADD_UPLINK_TESTCASE(docsis_test_case_5) 14527 ADD_UPLINK_TESTCASE(docsis_test_case_6) 14528 ADD_UPLINK_TESTCASE(docsis_test_case_7) 14529 ADD_UPLINK_TESTCASE(docsis_test_case_8) 14530 ADD_UPLINK_TESTCASE(docsis_test_case_9) 14531 ADD_UPLINK_TESTCASE(docsis_test_case_10) 14532 ADD_UPLINK_TESTCASE(docsis_test_case_11) 14533 ADD_UPLINK_TESTCASE(docsis_test_case_12) 14534 ADD_UPLINK_TESTCASE(docsis_test_case_13) 14535 ADD_UPLINK_TESTCASE(docsis_test_case_14) 14536 ADD_UPLINK_TESTCASE(docsis_test_case_15) 14537 ADD_UPLINK_TESTCASE(docsis_test_case_16) 14538 ADD_UPLINK_TESTCASE(docsis_test_case_17) 14539 ADD_UPLINK_TESTCASE(docsis_test_case_18) 14540 ADD_UPLINK_TESTCASE(docsis_test_case_19) 14541 ADD_UPLINK_TESTCASE(docsis_test_case_20) 14542 ADD_UPLINK_TESTCASE(docsis_test_case_21) 14543 ADD_UPLINK_TESTCASE(docsis_test_case_22) 14544 ADD_UPLINK_TESTCASE(docsis_test_case_23) 14545 ADD_UPLINK_TESTCASE(docsis_test_case_24) 14546 ADD_UPLINK_TESTCASE(docsis_test_case_25) 14547 ADD_UPLINK_TESTCASE(docsis_test_case_26) 14548 /* Downlink */ 14549 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 14550 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 14551 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 14552 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 14553 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 14554 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 14555 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 14556 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 14557 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 14558 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 14559 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 14560 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 14561 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 14562 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 14563 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 14564 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 14565 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 14566 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 14567 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 14568 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 14569 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 14570 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 14571 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 14572 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 14573 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 14574 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 14575 TEST_CASES_END() /**< NULL terminate unit test array */ 14576 } 14577 }; 14578 #endif 14579 14580 static struct unit_test_suite cryptodev_gen_testsuite = { 14581 .suite_name = "Crypto General Unit Test Suite", 14582 .setup = crypto_gen_testsuite_setup, 14583 .unit_test_cases = { 14584 TEST_CASE_ST(ut_setup, ut_teardown, 14585 test_device_configure_invalid_dev_id), 14586 TEST_CASE_ST(ut_setup, ut_teardown, 14587 test_queue_pair_descriptor_setup), 14588 TEST_CASE_ST(ut_setup, ut_teardown, 14589 test_device_configure_invalid_queue_pair_ids), 14590 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 14591 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 14592 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 14593 TEST_CASES_END() /**< NULL terminate unit test array */ 14594 } 14595 }; 14596 14597 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 14598 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 14599 .setup = negative_hmac_sha1_testsuite_setup, 14600 .unit_test_cases = { 14601 /** Negative tests */ 14602 TEST_CASE_ST(ut_setup, ut_teardown, 14603 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14604 TEST_CASE_ST(ut_setup, ut_teardown, 14605 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14606 TEST_CASE_ST(ut_setup, ut_teardown, 14607 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14608 TEST_CASE_ST(ut_setup, ut_teardown, 14609 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14610 14611 TEST_CASES_END() /**< NULL terminate unit test array */ 14612 } 14613 }; 14614 14615 static struct unit_test_suite cryptodev_multi_session_testsuite = { 14616 .suite_name = "Multi Session Unit Test Suite", 14617 .setup = multi_session_testsuite_setup, 14618 .unit_test_cases = { 14619 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 14620 TEST_CASE_ST(ut_setup, ut_teardown, 14621 test_multi_session_random_usage), 14622 14623 TEST_CASES_END() /**< NULL terminate unit test array */ 14624 } 14625 }; 14626 14627 static struct unit_test_suite cryptodev_null_testsuite = { 14628 .suite_name = "NULL Test Suite", 14629 .setup = null_testsuite_setup, 14630 .unit_test_cases = { 14631 TEST_CASE_ST(ut_setup, ut_teardown, 14632 test_null_invalid_operation), 14633 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 14634 TEST_CASES_END() 14635 } 14636 }; 14637 14638 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 14639 .suite_name = "AES CCM Authenticated Test Suite", 14640 .setup = aes_ccm_auth_testsuite_setup, 14641 .unit_test_cases = { 14642 /** AES CCM Authenticated Encryption 128 bits key*/ 14643 TEST_CASE_ST(ut_setup, ut_teardown, 14644 test_AES_CCM_authenticated_encryption_test_case_128_1), 14645 TEST_CASE_ST(ut_setup, ut_teardown, 14646 test_AES_CCM_authenticated_encryption_test_case_128_2), 14647 TEST_CASE_ST(ut_setup, ut_teardown, 14648 test_AES_CCM_authenticated_encryption_test_case_128_3), 14649 14650 /** AES CCM Authenticated Decryption 128 bits key*/ 14651 TEST_CASE_ST(ut_setup, ut_teardown, 14652 test_AES_CCM_authenticated_decryption_test_case_128_1), 14653 TEST_CASE_ST(ut_setup, ut_teardown, 14654 test_AES_CCM_authenticated_decryption_test_case_128_2), 14655 TEST_CASE_ST(ut_setup, ut_teardown, 14656 test_AES_CCM_authenticated_decryption_test_case_128_3), 14657 14658 /** AES CCM Authenticated Encryption 192 bits key */ 14659 TEST_CASE_ST(ut_setup, ut_teardown, 14660 test_AES_CCM_authenticated_encryption_test_case_192_1), 14661 TEST_CASE_ST(ut_setup, ut_teardown, 14662 test_AES_CCM_authenticated_encryption_test_case_192_2), 14663 TEST_CASE_ST(ut_setup, ut_teardown, 14664 test_AES_CCM_authenticated_encryption_test_case_192_3), 14665 14666 /** AES CCM Authenticated Decryption 192 bits key*/ 14667 TEST_CASE_ST(ut_setup, ut_teardown, 14668 test_AES_CCM_authenticated_decryption_test_case_192_1), 14669 TEST_CASE_ST(ut_setup, ut_teardown, 14670 test_AES_CCM_authenticated_decryption_test_case_192_2), 14671 TEST_CASE_ST(ut_setup, ut_teardown, 14672 test_AES_CCM_authenticated_decryption_test_case_192_3), 14673 14674 /** AES CCM Authenticated Encryption 256 bits key */ 14675 TEST_CASE_ST(ut_setup, ut_teardown, 14676 test_AES_CCM_authenticated_encryption_test_case_256_1), 14677 TEST_CASE_ST(ut_setup, ut_teardown, 14678 test_AES_CCM_authenticated_encryption_test_case_256_2), 14679 TEST_CASE_ST(ut_setup, ut_teardown, 14680 test_AES_CCM_authenticated_encryption_test_case_256_3), 14681 14682 /** AES CCM Authenticated Decryption 256 bits key*/ 14683 TEST_CASE_ST(ut_setup, ut_teardown, 14684 test_AES_CCM_authenticated_decryption_test_case_256_1), 14685 TEST_CASE_ST(ut_setup, ut_teardown, 14686 test_AES_CCM_authenticated_decryption_test_case_256_2), 14687 TEST_CASE_ST(ut_setup, ut_teardown, 14688 test_AES_CCM_authenticated_decryption_test_case_256_3), 14689 TEST_CASES_END() 14690 } 14691 }; 14692 14693 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 14694 .suite_name = "AES GCM Authenticated Test Suite", 14695 .setup = aes_gcm_auth_testsuite_setup, 14696 .unit_test_cases = { 14697 /** AES GCM Authenticated Encryption */ 14698 TEST_CASE_ST(ut_setup, ut_teardown, 14699 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 14700 TEST_CASE_ST(ut_setup, ut_teardown, 14701 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 14702 TEST_CASE_ST(ut_setup, ut_teardown, 14703 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 14704 TEST_CASE_ST(ut_setup, ut_teardown, 14705 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 14706 TEST_CASE_ST(ut_setup, ut_teardown, 14707 test_AES_GCM_authenticated_encryption_test_case_1), 14708 TEST_CASE_ST(ut_setup, ut_teardown, 14709 test_AES_GCM_authenticated_encryption_test_case_2), 14710 TEST_CASE_ST(ut_setup, ut_teardown, 14711 test_AES_GCM_authenticated_encryption_test_case_3), 14712 TEST_CASE_ST(ut_setup, ut_teardown, 14713 test_AES_GCM_authenticated_encryption_test_case_4), 14714 TEST_CASE_ST(ut_setup, ut_teardown, 14715 test_AES_GCM_authenticated_encryption_test_case_5), 14716 TEST_CASE_ST(ut_setup, ut_teardown, 14717 test_AES_GCM_authenticated_encryption_test_case_6), 14718 TEST_CASE_ST(ut_setup, ut_teardown, 14719 test_AES_GCM_authenticated_encryption_test_case_7), 14720 TEST_CASE_ST(ut_setup, ut_teardown, 14721 test_AES_GCM_authenticated_encryption_test_case_8), 14722 TEST_CASE_ST(ut_setup, ut_teardown, 14723 test_AES_GCM_J0_authenticated_encryption_test_case_1), 14724 14725 /** AES GCM Authenticated Decryption */ 14726 TEST_CASE_ST(ut_setup, ut_teardown, 14727 test_AES_GCM_authenticated_decryption_test_case_1), 14728 TEST_CASE_ST(ut_setup, ut_teardown, 14729 test_AES_GCM_authenticated_decryption_test_case_2), 14730 TEST_CASE_ST(ut_setup, ut_teardown, 14731 test_AES_GCM_authenticated_decryption_test_case_3), 14732 TEST_CASE_ST(ut_setup, ut_teardown, 14733 test_AES_GCM_authenticated_decryption_test_case_4), 14734 TEST_CASE_ST(ut_setup, ut_teardown, 14735 test_AES_GCM_authenticated_decryption_test_case_5), 14736 TEST_CASE_ST(ut_setup, ut_teardown, 14737 test_AES_GCM_authenticated_decryption_test_case_6), 14738 TEST_CASE_ST(ut_setup, ut_teardown, 14739 test_AES_GCM_authenticated_decryption_test_case_7), 14740 TEST_CASE_ST(ut_setup, ut_teardown, 14741 test_AES_GCM_authenticated_decryption_test_case_8), 14742 TEST_CASE_ST(ut_setup, ut_teardown, 14743 test_AES_GCM_J0_authenticated_decryption_test_case_1), 14744 14745 /** AES GCM Authenticated Encryption 192 bits key */ 14746 TEST_CASE_ST(ut_setup, ut_teardown, 14747 test_AES_GCM_auth_encryption_test_case_192_1), 14748 TEST_CASE_ST(ut_setup, ut_teardown, 14749 test_AES_GCM_auth_encryption_test_case_192_2), 14750 TEST_CASE_ST(ut_setup, ut_teardown, 14751 test_AES_GCM_auth_encryption_test_case_192_3), 14752 TEST_CASE_ST(ut_setup, ut_teardown, 14753 test_AES_GCM_auth_encryption_test_case_192_4), 14754 TEST_CASE_ST(ut_setup, ut_teardown, 14755 test_AES_GCM_auth_encryption_test_case_192_5), 14756 TEST_CASE_ST(ut_setup, ut_teardown, 14757 test_AES_GCM_auth_encryption_test_case_192_6), 14758 TEST_CASE_ST(ut_setup, ut_teardown, 14759 test_AES_GCM_auth_encryption_test_case_192_7), 14760 14761 /** AES GCM Authenticated Decryption 192 bits key */ 14762 TEST_CASE_ST(ut_setup, ut_teardown, 14763 test_AES_GCM_auth_decryption_test_case_192_1), 14764 TEST_CASE_ST(ut_setup, ut_teardown, 14765 test_AES_GCM_auth_decryption_test_case_192_2), 14766 TEST_CASE_ST(ut_setup, ut_teardown, 14767 test_AES_GCM_auth_decryption_test_case_192_3), 14768 TEST_CASE_ST(ut_setup, ut_teardown, 14769 test_AES_GCM_auth_decryption_test_case_192_4), 14770 TEST_CASE_ST(ut_setup, ut_teardown, 14771 test_AES_GCM_auth_decryption_test_case_192_5), 14772 TEST_CASE_ST(ut_setup, ut_teardown, 14773 test_AES_GCM_auth_decryption_test_case_192_6), 14774 TEST_CASE_ST(ut_setup, ut_teardown, 14775 test_AES_GCM_auth_decryption_test_case_192_7), 14776 14777 /** AES GCM Authenticated Encryption 256 bits key */ 14778 TEST_CASE_ST(ut_setup, ut_teardown, 14779 test_AES_GCM_auth_encryption_test_case_256_1), 14780 TEST_CASE_ST(ut_setup, ut_teardown, 14781 test_AES_GCM_auth_encryption_test_case_256_2), 14782 TEST_CASE_ST(ut_setup, ut_teardown, 14783 test_AES_GCM_auth_encryption_test_case_256_3), 14784 TEST_CASE_ST(ut_setup, ut_teardown, 14785 test_AES_GCM_auth_encryption_test_case_256_4), 14786 TEST_CASE_ST(ut_setup, ut_teardown, 14787 test_AES_GCM_auth_encryption_test_case_256_5), 14788 TEST_CASE_ST(ut_setup, ut_teardown, 14789 test_AES_GCM_auth_encryption_test_case_256_6), 14790 TEST_CASE_ST(ut_setup, ut_teardown, 14791 test_AES_GCM_auth_encryption_test_case_256_7), 14792 14793 /** AES GCM Authenticated Decryption 256 bits key */ 14794 TEST_CASE_ST(ut_setup, ut_teardown, 14795 test_AES_GCM_auth_decryption_test_case_256_1), 14796 TEST_CASE_ST(ut_setup, ut_teardown, 14797 test_AES_GCM_auth_decryption_test_case_256_2), 14798 TEST_CASE_ST(ut_setup, ut_teardown, 14799 test_AES_GCM_auth_decryption_test_case_256_3), 14800 TEST_CASE_ST(ut_setup, ut_teardown, 14801 test_AES_GCM_auth_decryption_test_case_256_4), 14802 TEST_CASE_ST(ut_setup, ut_teardown, 14803 test_AES_GCM_auth_decryption_test_case_256_5), 14804 TEST_CASE_ST(ut_setup, ut_teardown, 14805 test_AES_GCM_auth_decryption_test_case_256_6), 14806 TEST_CASE_ST(ut_setup, ut_teardown, 14807 test_AES_GCM_auth_decryption_test_case_256_7), 14808 14809 /** AES GCM Authenticated Encryption big aad size */ 14810 TEST_CASE_ST(ut_setup, ut_teardown, 14811 test_AES_GCM_auth_encryption_test_case_aad_1), 14812 TEST_CASE_ST(ut_setup, ut_teardown, 14813 test_AES_GCM_auth_encryption_test_case_aad_2), 14814 14815 /** AES GCM Authenticated Decryption big aad size */ 14816 TEST_CASE_ST(ut_setup, ut_teardown, 14817 test_AES_GCM_auth_decryption_test_case_aad_1), 14818 TEST_CASE_ST(ut_setup, ut_teardown, 14819 test_AES_GCM_auth_decryption_test_case_aad_2), 14820 14821 /** Out of place tests */ 14822 TEST_CASE_ST(ut_setup, ut_teardown, 14823 test_AES_GCM_authenticated_encryption_oop_test_case_1), 14824 TEST_CASE_ST(ut_setup, ut_teardown, 14825 test_AES_GCM_authenticated_decryption_oop_test_case_1), 14826 14827 /** Session-less tests */ 14828 TEST_CASE_ST(ut_setup, ut_teardown, 14829 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 14830 TEST_CASE_ST(ut_setup, ut_teardown, 14831 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 14832 14833 TEST_CASES_END() 14834 } 14835 }; 14836 14837 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 14838 .suite_name = "AES GMAC Authentication Test Suite", 14839 .setup = aes_gmac_auth_testsuite_setup, 14840 .unit_test_cases = { 14841 TEST_CASE_ST(ut_setup, ut_teardown, 14842 test_AES_GMAC_authentication_test_case_1), 14843 TEST_CASE_ST(ut_setup, ut_teardown, 14844 test_AES_GMAC_authentication_verify_test_case_1), 14845 TEST_CASE_ST(ut_setup, ut_teardown, 14846 test_AES_GMAC_authentication_test_case_2), 14847 TEST_CASE_ST(ut_setup, ut_teardown, 14848 test_AES_GMAC_authentication_verify_test_case_2), 14849 TEST_CASE_ST(ut_setup, ut_teardown, 14850 test_AES_GMAC_authentication_test_case_3), 14851 TEST_CASE_ST(ut_setup, ut_teardown, 14852 test_AES_GMAC_authentication_verify_test_case_3), 14853 TEST_CASE_ST(ut_setup, ut_teardown, 14854 test_AES_GMAC_authentication_test_case_4), 14855 TEST_CASE_ST(ut_setup, ut_teardown, 14856 test_AES_GMAC_authentication_verify_test_case_4), 14857 TEST_CASE_ST(ut_setup, ut_teardown, 14858 test_AES_GMAC_authentication_SGL_40B), 14859 TEST_CASE_ST(ut_setup, ut_teardown, 14860 test_AES_GMAC_authentication_SGL_80B), 14861 TEST_CASE_ST(ut_setup, ut_teardown, 14862 test_AES_GMAC_authentication_SGL_2048B), 14863 TEST_CASE_ST(ut_setup, ut_teardown, 14864 test_AES_GMAC_authentication_SGL_2047B), 14865 14866 TEST_CASES_END() 14867 } 14868 }; 14869 14870 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 14871 .suite_name = "Chacha20-Poly1305 Test Suite", 14872 .setup = chacha20_poly1305_testsuite_setup, 14873 .unit_test_cases = { 14874 TEST_CASE_ST(ut_setup, ut_teardown, 14875 test_chacha20_poly1305_encrypt_test_case_rfc8439), 14876 TEST_CASE_ST(ut_setup, ut_teardown, 14877 test_chacha20_poly1305_decrypt_test_case_rfc8439), 14878 TEST_CASE_ST(ut_setup, ut_teardown, 14879 test_chacha20_poly1305_encrypt_SGL_out_of_place), 14880 TEST_CASES_END() 14881 } 14882 }; 14883 14884 static struct unit_test_suite cryptodev_snow3g_testsuite = { 14885 .suite_name = "SNOW 3G Test Suite", 14886 .setup = snow3g_testsuite_setup, 14887 .unit_test_cases = { 14888 /** SNOW 3G encrypt only (UEA2) */ 14889 TEST_CASE_ST(ut_setup, ut_teardown, 14890 test_snow3g_encryption_test_case_1), 14891 TEST_CASE_ST(ut_setup, ut_teardown, 14892 test_snow3g_encryption_test_case_2), 14893 TEST_CASE_ST(ut_setup, ut_teardown, 14894 test_snow3g_encryption_test_case_3), 14895 TEST_CASE_ST(ut_setup, ut_teardown, 14896 test_snow3g_encryption_test_case_4), 14897 TEST_CASE_ST(ut_setup, ut_teardown, 14898 test_snow3g_encryption_test_case_5), 14899 14900 TEST_CASE_ST(ut_setup, ut_teardown, 14901 test_snow3g_encryption_test_case_1_oop), 14902 TEST_CASE_ST(ut_setup, ut_teardown, 14903 test_snow3g_encryption_test_case_1_oop_sgl), 14904 TEST_CASE_ST(ut_setup, ut_teardown, 14905 test_snow3g_encryption_test_case_1_offset_oop), 14906 TEST_CASE_ST(ut_setup, ut_teardown, 14907 test_snow3g_decryption_test_case_1_oop), 14908 14909 /** SNOW 3G generate auth, then encrypt (UEA2) */ 14910 TEST_CASE_ST(ut_setup, ut_teardown, 14911 test_snow3g_auth_cipher_test_case_1), 14912 TEST_CASE_ST(ut_setup, ut_teardown, 14913 test_snow3g_auth_cipher_test_case_2), 14914 TEST_CASE_ST(ut_setup, ut_teardown, 14915 test_snow3g_auth_cipher_test_case_2_oop), 14916 TEST_CASE_ST(ut_setup, ut_teardown, 14917 test_snow3g_auth_cipher_part_digest_enc), 14918 TEST_CASE_ST(ut_setup, ut_teardown, 14919 test_snow3g_auth_cipher_part_digest_enc_oop), 14920 TEST_CASE_ST(ut_setup, ut_teardown, 14921 test_snow3g_auth_cipher_test_case_3_sgl), 14922 TEST_CASE_ST(ut_setup, ut_teardown, 14923 test_snow3g_auth_cipher_test_case_3_oop_sgl), 14924 TEST_CASE_ST(ut_setup, ut_teardown, 14925 test_snow3g_auth_cipher_part_digest_enc_sgl), 14926 TEST_CASE_ST(ut_setup, ut_teardown, 14927 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 14928 14929 /** SNOW 3G decrypt (UEA2), then verify auth */ 14930 TEST_CASE_ST(ut_setup, ut_teardown, 14931 test_snow3g_auth_cipher_verify_test_case_1), 14932 TEST_CASE_ST(ut_setup, ut_teardown, 14933 test_snow3g_auth_cipher_verify_test_case_2), 14934 TEST_CASE_ST(ut_setup, ut_teardown, 14935 test_snow3g_auth_cipher_verify_test_case_2_oop), 14936 TEST_CASE_ST(ut_setup, ut_teardown, 14937 test_snow3g_auth_cipher_verify_part_digest_enc), 14938 TEST_CASE_ST(ut_setup, ut_teardown, 14939 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 14940 TEST_CASE_ST(ut_setup, ut_teardown, 14941 test_snow3g_auth_cipher_verify_test_case_3_sgl), 14942 TEST_CASE_ST(ut_setup, ut_teardown, 14943 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 14944 TEST_CASE_ST(ut_setup, ut_teardown, 14945 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 14946 TEST_CASE_ST(ut_setup, ut_teardown, 14947 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 14948 14949 /** SNOW 3G decrypt only (UEA2) */ 14950 TEST_CASE_ST(ut_setup, ut_teardown, 14951 test_snow3g_decryption_test_case_1), 14952 TEST_CASE_ST(ut_setup, ut_teardown, 14953 test_snow3g_decryption_test_case_2), 14954 TEST_CASE_ST(ut_setup, ut_teardown, 14955 test_snow3g_decryption_test_case_3), 14956 TEST_CASE_ST(ut_setup, ut_teardown, 14957 test_snow3g_decryption_test_case_4), 14958 TEST_CASE_ST(ut_setup, ut_teardown, 14959 test_snow3g_decryption_test_case_5), 14960 TEST_CASE_ST(ut_setup, ut_teardown, 14961 test_snow3g_decryption_with_digest_test_case_1), 14962 TEST_CASE_ST(ut_setup, ut_teardown, 14963 test_snow3g_hash_generate_test_case_1), 14964 TEST_CASE_ST(ut_setup, ut_teardown, 14965 test_snow3g_hash_generate_test_case_2), 14966 TEST_CASE_ST(ut_setup, ut_teardown, 14967 test_snow3g_hash_generate_test_case_3), 14968 14969 /* Tests with buffers which length is not byte-aligned */ 14970 TEST_CASE_ST(ut_setup, ut_teardown, 14971 test_snow3g_hash_generate_test_case_4), 14972 TEST_CASE_ST(ut_setup, ut_teardown, 14973 test_snow3g_hash_generate_test_case_5), 14974 TEST_CASE_ST(ut_setup, ut_teardown, 14975 test_snow3g_hash_generate_test_case_6), 14976 TEST_CASE_ST(ut_setup, ut_teardown, 14977 test_snow3g_hash_verify_test_case_1), 14978 TEST_CASE_ST(ut_setup, ut_teardown, 14979 test_snow3g_hash_verify_test_case_2), 14980 TEST_CASE_ST(ut_setup, ut_teardown, 14981 test_snow3g_hash_verify_test_case_3), 14982 14983 /* Tests with buffers which length is not byte-aligned */ 14984 TEST_CASE_ST(ut_setup, ut_teardown, 14985 test_snow3g_hash_verify_test_case_4), 14986 TEST_CASE_ST(ut_setup, ut_teardown, 14987 test_snow3g_hash_verify_test_case_5), 14988 TEST_CASE_ST(ut_setup, ut_teardown, 14989 test_snow3g_hash_verify_test_case_6), 14990 TEST_CASE_ST(ut_setup, ut_teardown, 14991 test_snow3g_cipher_auth_test_case_1), 14992 TEST_CASE_ST(ut_setup, ut_teardown, 14993 test_snow3g_auth_cipher_with_digest_test_case_1), 14994 TEST_CASES_END() 14995 } 14996 }; 14997 14998 static struct unit_test_suite cryptodev_zuc_testsuite = { 14999 .suite_name = "ZUC Test Suite", 15000 .setup = zuc_testsuite_setup, 15001 .unit_test_cases = { 15002 /** ZUC encrypt only (EEA3) */ 15003 TEST_CASE_ST(ut_setup, ut_teardown, 15004 test_zuc_encryption_test_case_1), 15005 TEST_CASE_ST(ut_setup, ut_teardown, 15006 test_zuc_encryption_test_case_2), 15007 TEST_CASE_ST(ut_setup, ut_teardown, 15008 test_zuc_encryption_test_case_3), 15009 TEST_CASE_ST(ut_setup, ut_teardown, 15010 test_zuc_encryption_test_case_4), 15011 TEST_CASE_ST(ut_setup, ut_teardown, 15012 test_zuc_encryption_test_case_5), 15013 TEST_CASE_ST(ut_setup, ut_teardown, 15014 test_zuc_encryption_test_case_6_sgl), 15015 15016 /** ZUC authenticate (EIA3) */ 15017 TEST_CASE_ST(ut_setup, ut_teardown, 15018 test_zuc_hash_generate_test_case_1), 15019 TEST_CASE_ST(ut_setup, ut_teardown, 15020 test_zuc_hash_generate_test_case_2), 15021 TEST_CASE_ST(ut_setup, ut_teardown, 15022 test_zuc_hash_generate_test_case_3), 15023 TEST_CASE_ST(ut_setup, ut_teardown, 15024 test_zuc_hash_generate_test_case_4), 15025 TEST_CASE_ST(ut_setup, ut_teardown, 15026 test_zuc_hash_generate_test_case_5), 15027 TEST_CASE_ST(ut_setup, ut_teardown, 15028 test_zuc_hash_generate_test_case_6), 15029 TEST_CASE_ST(ut_setup, ut_teardown, 15030 test_zuc_hash_generate_test_case_7), 15031 TEST_CASE_ST(ut_setup, ut_teardown, 15032 test_zuc_hash_generate_test_case_8), 15033 TEST_CASE_ST(ut_setup, ut_teardown, 15034 test_zuc_hash_generate_test_case_9), 15035 TEST_CASE_ST(ut_setup, ut_teardown, 15036 test_zuc_hash_generate_test_case_10), 15037 TEST_CASE_ST(ut_setup, ut_teardown, 15038 test_zuc_hash_generate_test_case_11), 15039 15040 15041 /** ZUC alg-chain (EEA3/EIA3) */ 15042 TEST_CASE_ST(ut_setup, ut_teardown, 15043 test_zuc_cipher_auth_test_case_1), 15044 TEST_CASE_ST(ut_setup, ut_teardown, 15045 test_zuc_cipher_auth_test_case_2), 15046 15047 /** ZUC generate auth, then encrypt (EEA3) */ 15048 TEST_CASE_ST(ut_setup, ut_teardown, 15049 test_zuc_auth_cipher_test_case_1), 15050 TEST_CASE_ST(ut_setup, ut_teardown, 15051 test_zuc_auth_cipher_test_case_1_oop), 15052 TEST_CASE_ST(ut_setup, ut_teardown, 15053 test_zuc_auth_cipher_test_case_1_sgl), 15054 TEST_CASE_ST(ut_setup, ut_teardown, 15055 test_zuc_auth_cipher_test_case_1_oop_sgl), 15056 15057 /** ZUC decrypt (EEA3), then verify auth */ 15058 TEST_CASE_ST(ut_setup, ut_teardown, 15059 test_zuc_auth_cipher_verify_test_case_1), 15060 TEST_CASE_ST(ut_setup, ut_teardown, 15061 test_zuc_auth_cipher_verify_test_case_1_oop), 15062 TEST_CASE_ST(ut_setup, ut_teardown, 15063 test_zuc_auth_cipher_verify_test_case_1_sgl), 15064 TEST_CASE_ST(ut_setup, ut_teardown, 15065 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 15066 15067 /** ZUC-256 encrypt only **/ 15068 TEST_CASE_ST(ut_setup, ut_teardown, 15069 test_zuc256_encryption_test_case_1), 15070 TEST_CASE_ST(ut_setup, ut_teardown, 15071 test_zuc256_encryption_test_case_2), 15072 15073 /** ZUC-256 authentication only **/ 15074 TEST_CASE_ST(ut_setup, ut_teardown, 15075 test_zuc256_authentication_test_case_1), 15076 TEST_CASE_ST(ut_setup, ut_teardown, 15077 test_zuc256_authentication_test_case_2), 15078 15079 TEST_CASES_END() 15080 } 15081 }; 15082 15083 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15084 .suite_name = "HMAC_MD5 Authentication Test Suite", 15085 .setup = hmac_md5_auth_testsuite_setup, 15086 .unit_test_cases = { 15087 TEST_CASE_ST(ut_setup, ut_teardown, 15088 test_MD5_HMAC_generate_case_1), 15089 TEST_CASE_ST(ut_setup, ut_teardown, 15090 test_MD5_HMAC_verify_case_1), 15091 TEST_CASE_ST(ut_setup, ut_teardown, 15092 test_MD5_HMAC_generate_case_2), 15093 TEST_CASE_ST(ut_setup, ut_teardown, 15094 test_MD5_HMAC_verify_case_2), 15095 TEST_CASES_END() 15096 } 15097 }; 15098 15099 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15100 .suite_name = "Kasumi Test Suite", 15101 .setup = kasumi_testsuite_setup, 15102 .unit_test_cases = { 15103 /** KASUMI hash only (UIA1) */ 15104 TEST_CASE_ST(ut_setup, ut_teardown, 15105 test_kasumi_hash_generate_test_case_1), 15106 TEST_CASE_ST(ut_setup, ut_teardown, 15107 test_kasumi_hash_generate_test_case_2), 15108 TEST_CASE_ST(ut_setup, ut_teardown, 15109 test_kasumi_hash_generate_test_case_3), 15110 TEST_CASE_ST(ut_setup, ut_teardown, 15111 test_kasumi_hash_generate_test_case_4), 15112 TEST_CASE_ST(ut_setup, ut_teardown, 15113 test_kasumi_hash_generate_test_case_5), 15114 TEST_CASE_ST(ut_setup, ut_teardown, 15115 test_kasumi_hash_generate_test_case_6), 15116 15117 TEST_CASE_ST(ut_setup, ut_teardown, 15118 test_kasumi_hash_verify_test_case_1), 15119 TEST_CASE_ST(ut_setup, ut_teardown, 15120 test_kasumi_hash_verify_test_case_2), 15121 TEST_CASE_ST(ut_setup, ut_teardown, 15122 test_kasumi_hash_verify_test_case_3), 15123 TEST_CASE_ST(ut_setup, ut_teardown, 15124 test_kasumi_hash_verify_test_case_4), 15125 TEST_CASE_ST(ut_setup, ut_teardown, 15126 test_kasumi_hash_verify_test_case_5), 15127 15128 /** KASUMI encrypt only (UEA1) */ 15129 TEST_CASE_ST(ut_setup, ut_teardown, 15130 test_kasumi_encryption_test_case_1), 15131 TEST_CASE_ST(ut_setup, ut_teardown, 15132 test_kasumi_encryption_test_case_1_sgl), 15133 TEST_CASE_ST(ut_setup, ut_teardown, 15134 test_kasumi_encryption_test_case_1_oop), 15135 TEST_CASE_ST(ut_setup, ut_teardown, 15136 test_kasumi_encryption_test_case_1_oop_sgl), 15137 TEST_CASE_ST(ut_setup, ut_teardown, 15138 test_kasumi_encryption_test_case_2), 15139 TEST_CASE_ST(ut_setup, ut_teardown, 15140 test_kasumi_encryption_test_case_3), 15141 TEST_CASE_ST(ut_setup, ut_teardown, 15142 test_kasumi_encryption_test_case_4), 15143 TEST_CASE_ST(ut_setup, ut_teardown, 15144 test_kasumi_encryption_test_case_5), 15145 15146 /** KASUMI decrypt only (UEA1) */ 15147 TEST_CASE_ST(ut_setup, ut_teardown, 15148 test_kasumi_decryption_test_case_1), 15149 TEST_CASE_ST(ut_setup, ut_teardown, 15150 test_kasumi_decryption_test_case_2), 15151 TEST_CASE_ST(ut_setup, ut_teardown, 15152 test_kasumi_decryption_test_case_3), 15153 TEST_CASE_ST(ut_setup, ut_teardown, 15154 test_kasumi_decryption_test_case_4), 15155 TEST_CASE_ST(ut_setup, ut_teardown, 15156 test_kasumi_decryption_test_case_5), 15157 TEST_CASE_ST(ut_setup, ut_teardown, 15158 test_kasumi_decryption_test_case_1_oop), 15159 TEST_CASE_ST(ut_setup, ut_teardown, 15160 test_kasumi_cipher_auth_test_case_1), 15161 15162 /** KASUMI generate auth, then encrypt (F8) */ 15163 TEST_CASE_ST(ut_setup, ut_teardown, 15164 test_kasumi_auth_cipher_test_case_1), 15165 TEST_CASE_ST(ut_setup, ut_teardown, 15166 test_kasumi_auth_cipher_test_case_2), 15167 TEST_CASE_ST(ut_setup, ut_teardown, 15168 test_kasumi_auth_cipher_test_case_2_oop), 15169 TEST_CASE_ST(ut_setup, ut_teardown, 15170 test_kasumi_auth_cipher_test_case_2_sgl), 15171 TEST_CASE_ST(ut_setup, ut_teardown, 15172 test_kasumi_auth_cipher_test_case_2_oop_sgl), 15173 15174 /** KASUMI decrypt (F8), then verify auth */ 15175 TEST_CASE_ST(ut_setup, ut_teardown, 15176 test_kasumi_auth_cipher_verify_test_case_1), 15177 TEST_CASE_ST(ut_setup, ut_teardown, 15178 test_kasumi_auth_cipher_verify_test_case_2), 15179 TEST_CASE_ST(ut_setup, ut_teardown, 15180 test_kasumi_auth_cipher_verify_test_case_2_oop), 15181 TEST_CASE_ST(ut_setup, ut_teardown, 15182 test_kasumi_auth_cipher_verify_test_case_2_sgl), 15183 TEST_CASE_ST(ut_setup, ut_teardown, 15184 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 15185 15186 TEST_CASES_END() 15187 } 15188 }; 15189 15190 static struct unit_test_suite cryptodev_esn_testsuite = { 15191 .suite_name = "ESN Test Suite", 15192 .setup = esn_testsuite_setup, 15193 .unit_test_cases = { 15194 TEST_CASE_ST(ut_setup, ut_teardown, 15195 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 15196 TEST_CASE_ST(ut_setup, ut_teardown, 15197 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 15198 TEST_CASES_END() 15199 } 15200 }; 15201 15202 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 15203 .suite_name = "Negative AES GCM Test Suite", 15204 .setup = negative_aes_gcm_testsuite_setup, 15205 .unit_test_cases = { 15206 TEST_CASE_ST(ut_setup, ut_teardown, 15207 test_AES_GCM_auth_encryption_fail_iv_corrupt), 15208 TEST_CASE_ST(ut_setup, ut_teardown, 15209 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 15210 TEST_CASE_ST(ut_setup, ut_teardown, 15211 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 15212 TEST_CASE_ST(ut_setup, ut_teardown, 15213 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 15214 TEST_CASE_ST(ut_setup, ut_teardown, 15215 test_AES_GCM_auth_encryption_fail_aad_corrupt), 15216 TEST_CASE_ST(ut_setup, ut_teardown, 15217 test_AES_GCM_auth_encryption_fail_tag_corrupt), 15218 TEST_CASE_ST(ut_setup, ut_teardown, 15219 test_AES_GCM_auth_decryption_fail_iv_corrupt), 15220 TEST_CASE_ST(ut_setup, ut_teardown, 15221 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 15222 TEST_CASE_ST(ut_setup, ut_teardown, 15223 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 15224 TEST_CASE_ST(ut_setup, ut_teardown, 15225 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 15226 TEST_CASE_ST(ut_setup, ut_teardown, 15227 test_AES_GCM_auth_decryption_fail_aad_corrupt), 15228 TEST_CASE_ST(ut_setup, ut_teardown, 15229 test_AES_GCM_auth_decryption_fail_tag_corrupt), 15230 15231 TEST_CASES_END() 15232 } 15233 }; 15234 15235 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 15236 .suite_name = "Negative AES GMAC Test Suite", 15237 .setup = negative_aes_gmac_testsuite_setup, 15238 .unit_test_cases = { 15239 TEST_CASE_ST(ut_setup, ut_teardown, 15240 authentication_verify_AES128_GMAC_fail_data_corrupt), 15241 TEST_CASE_ST(ut_setup, ut_teardown, 15242 authentication_verify_AES128_GMAC_fail_tag_corrupt), 15243 15244 TEST_CASES_END() 15245 } 15246 }; 15247 15248 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 15249 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 15250 .setup = mixed_cipher_hash_testsuite_setup, 15251 .unit_test_cases = { 15252 /** AUTH AES CMAC + CIPHER AES CTR */ 15253 TEST_CASE_ST(ut_setup, ut_teardown, 15254 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 15255 TEST_CASE_ST(ut_setup, ut_teardown, 15256 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15257 TEST_CASE_ST(ut_setup, ut_teardown, 15258 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15259 TEST_CASE_ST(ut_setup, ut_teardown, 15260 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15261 TEST_CASE_ST(ut_setup, ut_teardown, 15262 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 15263 TEST_CASE_ST(ut_setup, ut_teardown, 15264 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15265 TEST_CASE_ST(ut_setup, ut_teardown, 15266 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15267 TEST_CASE_ST(ut_setup, ut_teardown, 15268 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15269 15270 /** AUTH ZUC + CIPHER SNOW3G */ 15271 TEST_CASE_ST(ut_setup, ut_teardown, 15272 test_auth_zuc_cipher_snow_test_case_1), 15273 TEST_CASE_ST(ut_setup, ut_teardown, 15274 test_verify_auth_zuc_cipher_snow_test_case_1), 15275 /** AUTH AES CMAC + CIPHER SNOW3G */ 15276 TEST_CASE_ST(ut_setup, ut_teardown, 15277 test_auth_aes_cmac_cipher_snow_test_case_1), 15278 TEST_CASE_ST(ut_setup, ut_teardown, 15279 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 15280 /** AUTH ZUC + CIPHER AES CTR */ 15281 TEST_CASE_ST(ut_setup, ut_teardown, 15282 test_auth_zuc_cipher_aes_ctr_test_case_1), 15283 TEST_CASE_ST(ut_setup, ut_teardown, 15284 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 15285 /** AUTH SNOW3G + CIPHER AES CTR */ 15286 TEST_CASE_ST(ut_setup, ut_teardown, 15287 test_auth_snow_cipher_aes_ctr_test_case_1), 15288 TEST_CASE_ST(ut_setup, ut_teardown, 15289 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 15290 /** AUTH SNOW3G + CIPHER ZUC */ 15291 TEST_CASE_ST(ut_setup, ut_teardown, 15292 test_auth_snow_cipher_zuc_test_case_1), 15293 TEST_CASE_ST(ut_setup, ut_teardown, 15294 test_verify_auth_snow_cipher_zuc_test_case_1), 15295 /** AUTH AES CMAC + CIPHER ZUC */ 15296 TEST_CASE_ST(ut_setup, ut_teardown, 15297 test_auth_aes_cmac_cipher_zuc_test_case_1), 15298 TEST_CASE_ST(ut_setup, ut_teardown, 15299 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 15300 15301 /** AUTH NULL + CIPHER SNOW3G */ 15302 TEST_CASE_ST(ut_setup, ut_teardown, 15303 test_auth_null_cipher_snow_test_case_1), 15304 TEST_CASE_ST(ut_setup, ut_teardown, 15305 test_verify_auth_null_cipher_snow_test_case_1), 15306 /** AUTH NULL + CIPHER ZUC */ 15307 TEST_CASE_ST(ut_setup, ut_teardown, 15308 test_auth_null_cipher_zuc_test_case_1), 15309 TEST_CASE_ST(ut_setup, ut_teardown, 15310 test_verify_auth_null_cipher_zuc_test_case_1), 15311 /** AUTH SNOW3G + CIPHER NULL */ 15312 TEST_CASE_ST(ut_setup, ut_teardown, 15313 test_auth_snow_cipher_null_test_case_1), 15314 TEST_CASE_ST(ut_setup, ut_teardown, 15315 test_verify_auth_snow_cipher_null_test_case_1), 15316 /** AUTH ZUC + CIPHER NULL */ 15317 TEST_CASE_ST(ut_setup, ut_teardown, 15318 test_auth_zuc_cipher_null_test_case_1), 15319 TEST_CASE_ST(ut_setup, ut_teardown, 15320 test_verify_auth_zuc_cipher_null_test_case_1), 15321 /** AUTH NULL + CIPHER AES CTR */ 15322 TEST_CASE_ST(ut_setup, ut_teardown, 15323 test_auth_null_cipher_aes_ctr_test_case_1), 15324 TEST_CASE_ST(ut_setup, ut_teardown, 15325 test_verify_auth_null_cipher_aes_ctr_test_case_1), 15326 /** AUTH AES CMAC + CIPHER NULL */ 15327 TEST_CASE_ST(ut_setup, ut_teardown, 15328 test_auth_aes_cmac_cipher_null_test_case_1), 15329 TEST_CASE_ST(ut_setup, ut_teardown, 15330 test_verify_auth_aes_cmac_cipher_null_test_case_1), 15331 TEST_CASES_END() 15332 } 15333 }; 15334 15335 static int 15336 run_cryptodev_testsuite(const char *pmd_name) 15337 { 15338 uint8_t ret, j, i = 0, blk_start_idx = 0; 15339 const enum blockcipher_test_type blk_suites[] = { 15340 BLKCIPHER_AES_CHAIN_TYPE, 15341 BLKCIPHER_AES_CIPHERONLY_TYPE, 15342 BLKCIPHER_AES_DOCSIS_TYPE, 15343 BLKCIPHER_3DES_CHAIN_TYPE, 15344 BLKCIPHER_3DES_CIPHERONLY_TYPE, 15345 BLKCIPHER_DES_CIPHERONLY_TYPE, 15346 BLKCIPHER_DES_DOCSIS_TYPE, 15347 BLKCIPHER_AUTHONLY_TYPE}; 15348 struct unit_test_suite *static_suites[] = { 15349 &cryptodev_multi_session_testsuite, 15350 &cryptodev_null_testsuite, 15351 &cryptodev_aes_ccm_auth_testsuite, 15352 &cryptodev_aes_gcm_auth_testsuite, 15353 &cryptodev_aes_gmac_auth_testsuite, 15354 &cryptodev_snow3g_testsuite, 15355 &cryptodev_chacha20_poly1305_testsuite, 15356 &cryptodev_zuc_testsuite, 15357 &cryptodev_hmac_md5_auth_testsuite, 15358 &cryptodev_kasumi_testsuite, 15359 &cryptodev_esn_testsuite, 15360 &cryptodev_negative_aes_gcm_testsuite, 15361 &cryptodev_negative_aes_gmac_testsuite, 15362 &cryptodev_mixed_cipher_hash_testsuite, 15363 &cryptodev_negative_hmac_sha1_testsuite, 15364 &cryptodev_gen_testsuite, 15365 #ifdef RTE_LIB_SECURITY 15366 &ipsec_proto_testsuite, 15367 &pdcp_proto_testsuite, 15368 &docsis_proto_testsuite, 15369 #endif 15370 &end_testsuite 15371 }; 15372 static struct unit_test_suite ts = { 15373 .suite_name = "Cryptodev Unit Test Suite", 15374 .setup = testsuite_setup, 15375 .teardown = testsuite_teardown, 15376 .unit_test_cases = {TEST_CASES_END()} 15377 }; 15378 15379 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 15380 15381 if (gbl_driver_id == -1) { 15382 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 15383 return TEST_SKIPPED; 15384 } 15385 15386 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15387 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 15388 15389 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 15390 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15391 ret = unit_test_suite_runner(&ts); 15392 15393 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 15394 free(ts.unit_test_suites); 15395 return ret; 15396 } 15397 15398 static int 15399 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 15400 { 15401 struct rte_cryptodev_info dev_info; 15402 uint8_t i, nb_devs; 15403 int driver_id; 15404 15405 driver_id = rte_cryptodev_driver_id_get(pmd_name); 15406 if (driver_id == -1) { 15407 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 15408 return TEST_SKIPPED; 15409 } 15410 15411 nb_devs = rte_cryptodev_count(); 15412 if (nb_devs < 1) { 15413 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 15414 return TEST_SKIPPED; 15415 } 15416 15417 for (i = 0; i < nb_devs; i++) { 15418 rte_cryptodev_info_get(i, &dev_info); 15419 if (dev_info.driver_id == driver_id) { 15420 if (!(dev_info.feature_flags & flag)) { 15421 RTE_LOG(INFO, USER1, "%s not supported\n", 15422 flag_name); 15423 return TEST_SKIPPED; 15424 } 15425 return 0; /* found */ 15426 } 15427 } 15428 15429 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 15430 return TEST_SKIPPED; 15431 } 15432 15433 static int 15434 test_cryptodev_qat(void) 15435 { 15436 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 15437 } 15438 15439 static int 15440 test_cryptodev_virtio(void) 15441 { 15442 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 15443 } 15444 15445 static int 15446 test_cryptodev_aesni_mb(void) 15447 { 15448 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15449 } 15450 15451 static int 15452 test_cryptodev_cpu_aesni_mb(void) 15453 { 15454 int32_t rc; 15455 enum rte_security_session_action_type at = gbl_action_type; 15456 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15457 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15458 gbl_action_type = at; 15459 return rc; 15460 } 15461 15462 static int 15463 test_cryptodev_chacha_poly_mb(void) 15464 { 15465 int32_t rc; 15466 enum rte_security_session_action_type at = gbl_action_type; 15467 rc = run_cryptodev_testsuite( 15468 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 15469 gbl_action_type = at; 15470 return rc; 15471 } 15472 15473 static int 15474 test_cryptodev_openssl(void) 15475 { 15476 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 15477 } 15478 15479 static int 15480 test_cryptodev_aesni_gcm(void) 15481 { 15482 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15483 } 15484 15485 static int 15486 test_cryptodev_cpu_aesni_gcm(void) 15487 { 15488 int32_t rc; 15489 enum rte_security_session_action_type at = gbl_action_type; 15490 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15491 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15492 gbl_action_type = at; 15493 return rc; 15494 } 15495 15496 static int 15497 test_cryptodev_mlx5(void) 15498 { 15499 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 15500 } 15501 15502 static int 15503 test_cryptodev_null(void) 15504 { 15505 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 15506 } 15507 15508 static int 15509 test_cryptodev_sw_snow3g(void) 15510 { 15511 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 15512 } 15513 15514 static int 15515 test_cryptodev_sw_kasumi(void) 15516 { 15517 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 15518 } 15519 15520 static int 15521 test_cryptodev_sw_zuc(void) 15522 { 15523 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 15524 } 15525 15526 static int 15527 test_cryptodev_armv8(void) 15528 { 15529 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 15530 } 15531 15532 static int 15533 test_cryptodev_mrvl(void) 15534 { 15535 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 15536 } 15537 15538 #ifdef RTE_CRYPTO_SCHEDULER 15539 15540 static int 15541 test_cryptodev_scheduler(void) 15542 { 15543 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 15544 const enum blockcipher_test_type blk_suites[] = { 15545 BLKCIPHER_AES_CHAIN_TYPE, 15546 BLKCIPHER_AES_CIPHERONLY_TYPE, 15547 BLKCIPHER_AUTHONLY_TYPE 15548 }; 15549 static struct unit_test_suite scheduler_multicore = { 15550 .suite_name = "Scheduler Multicore Unit Test Suite", 15551 .setup = scheduler_multicore_testsuite_setup, 15552 .teardown = scheduler_mode_testsuite_teardown, 15553 .unit_test_cases = {TEST_CASES_END()} 15554 }; 15555 static struct unit_test_suite scheduler_round_robin = { 15556 .suite_name = "Scheduler Round Robin Unit Test Suite", 15557 .setup = scheduler_roundrobin_testsuite_setup, 15558 .teardown = scheduler_mode_testsuite_teardown, 15559 .unit_test_cases = {TEST_CASES_END()} 15560 }; 15561 static struct unit_test_suite scheduler_failover = { 15562 .suite_name = "Scheduler Failover Unit Test Suite", 15563 .setup = scheduler_failover_testsuite_setup, 15564 .teardown = scheduler_mode_testsuite_teardown, 15565 .unit_test_cases = {TEST_CASES_END()} 15566 }; 15567 static struct unit_test_suite scheduler_pkt_size_distr = { 15568 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 15569 .setup = scheduler_pkt_size_distr_testsuite_setup, 15570 .teardown = scheduler_mode_testsuite_teardown, 15571 .unit_test_cases = {TEST_CASES_END()} 15572 }; 15573 struct unit_test_suite *sched_mode_suites[] = { 15574 &scheduler_multicore, 15575 &scheduler_round_robin, 15576 &scheduler_failover, 15577 &scheduler_pkt_size_distr 15578 }; 15579 static struct unit_test_suite scheduler_config = { 15580 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 15581 .unit_test_cases = { 15582 TEST_CASE(test_scheduler_attach_worker_op), 15583 TEST_CASE(test_scheduler_mode_multicore_op), 15584 TEST_CASE(test_scheduler_mode_roundrobin_op), 15585 TEST_CASE(test_scheduler_mode_failover_op), 15586 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 15587 TEST_CASE(test_scheduler_detach_worker_op), 15588 15589 TEST_CASES_END() /**< NULL terminate array */ 15590 } 15591 }; 15592 struct unit_test_suite *static_suites[] = { 15593 &scheduler_config, 15594 &end_testsuite 15595 }; 15596 static struct unit_test_suite ts = { 15597 .suite_name = "Scheduler Unit Test Suite", 15598 .setup = scheduler_testsuite_setup, 15599 .teardown = testsuite_teardown, 15600 .unit_test_cases = {TEST_CASES_END()} 15601 }; 15602 15603 gbl_driver_id = rte_cryptodev_driver_id_get( 15604 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15605 15606 if (gbl_driver_id == -1) { 15607 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 15608 return TEST_SKIPPED; 15609 } 15610 15611 if (rte_cryptodev_driver_id_get( 15612 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 15613 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 15614 return TEST_SKIPPED; 15615 } 15616 15617 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15618 uint8_t blk_i = 0; 15619 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 15620 (struct unit_test_suite *) * 15621 (RTE_DIM(blk_suites) + 1)); 15622 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 15623 blk_suites, RTE_DIM(blk_suites)); 15624 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 15625 } 15626 15627 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15628 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 15629 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 15630 RTE_DIM(sched_mode_suites)); 15631 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15632 ret = unit_test_suite_runner(&ts); 15633 15634 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15635 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 15636 (*sched_mode_suites[sched_i]), 15637 RTE_DIM(blk_suites)); 15638 free(sched_mode_suites[sched_i]->unit_test_suites); 15639 } 15640 free(ts.unit_test_suites); 15641 return ret; 15642 } 15643 15644 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 15645 15646 #endif 15647 15648 static int 15649 test_cryptodev_dpaa2_sec(void) 15650 { 15651 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 15652 } 15653 15654 static int 15655 test_cryptodev_dpaa_sec(void) 15656 { 15657 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 15658 } 15659 15660 static int 15661 test_cryptodev_ccp(void) 15662 { 15663 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 15664 } 15665 15666 static int 15667 test_cryptodev_octeontx(void) 15668 { 15669 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 15670 } 15671 15672 static int 15673 test_cryptodev_caam_jr(void) 15674 { 15675 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 15676 } 15677 15678 static int 15679 test_cryptodev_nitrox(void) 15680 { 15681 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 15682 } 15683 15684 static int 15685 test_cryptodev_bcmfs(void) 15686 { 15687 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 15688 } 15689 15690 static int 15691 test_cryptodev_qat_raw_api(void) 15692 { 15693 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 15694 int ret; 15695 15696 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15697 "RAW API"); 15698 if (ret) 15699 return ret; 15700 15701 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15702 ret = run_cryptodev_testsuite(pmd_name); 15703 global_api_test_type = CRYPTODEV_API_TEST; 15704 15705 return ret; 15706 } 15707 15708 static int 15709 test_cryptodev_cn9k(void) 15710 { 15711 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 15712 } 15713 15714 static int 15715 test_cryptodev_cn10k(void) 15716 { 15717 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 15718 } 15719 15720 static int 15721 test_cryptodev_dpaa2_sec_raw_api(void) 15722 { 15723 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15724 int ret; 15725 15726 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15727 "RAW API"); 15728 if (ret) 15729 return ret; 15730 15731 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15732 ret = run_cryptodev_testsuite(pmd_name); 15733 global_api_test_type = CRYPTODEV_API_TEST; 15734 15735 return ret; 15736 } 15737 15738 static int 15739 test_cryptodev_dpaa_sec_raw_api(void) 15740 { 15741 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15742 int ret; 15743 15744 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15745 "RAW API"); 15746 if (ret) 15747 return ret; 15748 15749 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15750 ret = run_cryptodev_testsuite(pmd_name); 15751 global_api_test_type = CRYPTODEV_API_TEST; 15752 15753 return ret; 15754 } 15755 15756 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 15757 test_cryptodev_dpaa2_sec_raw_api); 15758 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 15759 test_cryptodev_dpaa_sec_raw_api); 15760 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 15761 test_cryptodev_qat_raw_api); 15762 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 15763 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 15764 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 15765 test_cryptodev_cpu_aesni_mb); 15766 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 15767 test_cryptodev_chacha_poly_mb); 15768 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 15769 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 15770 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 15771 test_cryptodev_cpu_aesni_gcm); 15772 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 15773 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 15774 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 15775 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 15776 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 15777 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 15778 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 15779 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 15780 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 15781 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 15782 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 15783 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 15784 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 15785 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 15786 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 15787 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 15788 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 15789