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 int is_oop = 0; 213 214 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 215 if (ctx_service_size < 0) { 216 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 217 return; 218 } 219 220 ctx = malloc(ctx_service_size); 221 if (!ctx) { 222 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 223 return; 224 } 225 226 /* Both are enums, setting crypto_sess will suit any session type */ 227 sess.crypto_sess = op->sym->session; 228 229 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 230 op->sess_type, sess, 0) < 0) { 231 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 232 goto exit; 233 } 234 235 cipher_iv.iova = 0; 236 cipher_iv.va = NULL; 237 aad_auth_iv.iova = 0; 238 aad_auth_iv.va = NULL; 239 digest.iova = 0; 240 digest.va = NULL; 241 sgl.vec = data_vec; 242 vec.num = 1; 243 vec.src_sgl = &sgl; 244 vec.iv = &cipher_iv; 245 vec.digest = &digest; 246 vec.aad = &aad_auth_iv; 247 vec.status = &status; 248 249 ofs.raw = 0; 250 251 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 252 is_oop = 1; 253 254 if (is_cipher && is_auth) { 255 cipher_offset = sop->cipher.data.offset; 256 cipher_len = sop->cipher.data.length; 257 auth_offset = sop->auth.data.offset; 258 auth_len = sop->auth.data.length; 259 max_len = RTE_MAX(cipher_offset + cipher_len, 260 auth_offset + auth_len); 261 if (len_in_bits) { 262 max_len = max_len >> 3; 263 cipher_offset = cipher_offset >> 3; 264 auth_offset = auth_offset >> 3; 265 cipher_len = cipher_len >> 3; 266 auth_len = auth_len >> 3; 267 } 268 ofs.ofs.cipher.head = cipher_offset; 269 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 270 ofs.ofs.auth.head = auth_offset; 271 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 272 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 273 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 274 aad_auth_iv.va = rte_crypto_op_ctod_offset( 275 op, void *, IV_OFFSET + cipher_iv_len); 276 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 277 cipher_iv_len); 278 digest.va = (void *)sop->auth.digest.data; 279 digest.iova = sop->auth.digest.phys_addr; 280 281 if (is_sgl) { 282 uint32_t remaining_off = auth_offset + auth_len; 283 struct rte_mbuf *sgl_buf = sop->m_src; 284 if (is_oop) 285 sgl_buf = sop->m_dst; 286 287 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 288 && sgl_buf->next != NULL) { 289 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 290 sgl_buf = sgl_buf->next; 291 } 292 293 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 294 sgl_buf, remaining_off); 295 } else { 296 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 297 auth_offset + auth_len; 298 } 299 /* Then check if digest-encrypted conditions are met */ 300 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 301 (digest.iova == auth_end_iova) && is_sgl) 302 max_len = RTE_MAX(max_len, 303 auth_offset + auth_len + 304 ut_params->auth_xform.auth.digest_length); 305 306 } else if (is_cipher) { 307 cipher_offset = sop->cipher.data.offset; 308 cipher_len = sop->cipher.data.length; 309 max_len = cipher_len + cipher_offset; 310 if (len_in_bits) { 311 max_len = max_len >> 3; 312 cipher_offset = cipher_offset >> 3; 313 cipher_len = cipher_len >> 3; 314 } 315 ofs.ofs.cipher.head = cipher_offset; 316 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 317 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 318 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 319 320 } else if (is_auth) { 321 auth_offset = sop->auth.data.offset; 322 auth_len = sop->auth.data.length; 323 max_len = auth_len + auth_offset; 324 if (len_in_bits) { 325 max_len = max_len >> 3; 326 auth_offset = auth_offset >> 3; 327 auth_len = auth_len >> 3; 328 } 329 ofs.ofs.auth.head = auth_offset; 330 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 331 aad_auth_iv.va = rte_crypto_op_ctod_offset( 332 op, void *, IV_OFFSET + cipher_iv_len); 333 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 334 cipher_iv_len); 335 digest.va = (void *)sop->auth.digest.data; 336 digest.iova = sop->auth.digest.phys_addr; 337 338 } else { /* aead */ 339 cipher_offset = sop->aead.data.offset; 340 cipher_len = sop->aead.data.length; 341 max_len = cipher_len + cipher_offset; 342 if (len_in_bits) { 343 max_len = max_len >> 3; 344 cipher_offset = cipher_offset >> 3; 345 cipher_len = cipher_len >> 3; 346 } 347 ofs.ofs.cipher.head = cipher_offset; 348 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 349 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 350 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 351 aad_auth_iv.va = (void *)sop->aead.aad.data; 352 aad_auth_iv.iova = sop->aead.aad.phys_addr; 353 digest.va = (void *)sop->aead.digest.data; 354 digest.iova = sop->aead.digest.phys_addr; 355 } 356 357 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 358 data_vec, RTE_DIM(data_vec)); 359 if (n < 0 || n > sop->m_src->nb_segs) { 360 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 361 goto exit; 362 } 363 364 sgl.num = n; 365 /* Out of place */ 366 if (is_oop) { 367 dest_sgl.vec = dest_data_vec; 368 vec.dest_sgl = &dest_sgl; 369 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 370 dest_data_vec, RTE_DIM(dest_data_vec)); 371 if (n < 0 || n > sop->m_dst->nb_segs) { 372 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 373 goto exit; 374 } 375 dest_sgl.num = n; 376 } else 377 vec.dest_sgl = NULL; 378 379 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 380 &enqueue_status) < 1) { 381 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 382 goto exit; 383 } 384 385 if (enqueue_status == 0) { 386 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 387 if (status < 0) { 388 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 389 goto exit; 390 } 391 } else if (enqueue_status < 0) { 392 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 393 goto exit; 394 } 395 396 n = n_success = 0; 397 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 398 n = rte_cryptodev_raw_dequeue_burst(ctx, 399 NULL, 1, post_process_raw_dp_op, 400 (void **)&ret_op, 0, &n_success, 401 &dequeue_status); 402 if (dequeue_status < 0) { 403 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 404 goto exit; 405 } 406 if (n == 0) 407 rte_pause(); 408 } 409 410 if (n == 1 && dequeue_status == 0) { 411 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 412 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 413 goto exit; 414 } 415 } 416 417 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 418 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 419 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 420 RTE_CRYPTO_OP_STATUS_SUCCESS; 421 422 exit: 423 free(ctx); 424 } 425 426 static void 427 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 428 { 429 int32_t n, st; 430 struct rte_crypto_sym_op *sop; 431 union rte_crypto_sym_ofs ofs; 432 struct rte_crypto_sgl sgl; 433 struct rte_crypto_sym_vec symvec; 434 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 435 struct rte_crypto_vec vec[UINT8_MAX]; 436 437 sop = op->sym; 438 439 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 440 sop->aead.data.length, vec, RTE_DIM(vec)); 441 442 if (n < 0 || n != sop->m_src->nb_segs) { 443 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 444 return; 445 } 446 447 sgl.vec = vec; 448 sgl.num = n; 449 symvec.src_sgl = &sgl; 450 symvec.iv = &iv_ptr; 451 symvec.digest = &digest_ptr; 452 symvec.aad = &aad_ptr; 453 symvec.status = &st; 454 symvec.num = 1; 455 456 /* for CPU crypto the IOVA address is not required */ 457 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 458 digest_ptr.va = (void *)sop->aead.digest.data; 459 aad_ptr.va = (void *)sop->aead.aad.data; 460 461 ofs.raw = 0; 462 463 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 464 &symvec); 465 466 if (n != 1) 467 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 468 else 469 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 470 } 471 472 static void 473 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 474 { 475 int32_t n, st; 476 struct rte_crypto_sym_op *sop; 477 union rte_crypto_sym_ofs ofs; 478 struct rte_crypto_sgl sgl; 479 struct rte_crypto_sym_vec symvec; 480 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 481 struct rte_crypto_vec vec[UINT8_MAX]; 482 483 sop = op->sym; 484 485 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 486 sop->auth.data.length, vec, RTE_DIM(vec)); 487 488 if (n < 0 || n != sop->m_src->nb_segs) { 489 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 490 return; 491 } 492 493 sgl.vec = vec; 494 sgl.num = n; 495 symvec.src_sgl = &sgl; 496 symvec.iv = &iv_ptr; 497 symvec.digest = &digest_ptr; 498 symvec.status = &st; 499 symvec.num = 1; 500 501 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 502 digest_ptr.va = (void *)sop->auth.digest.data; 503 504 ofs.raw = 0; 505 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 506 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 507 (sop->cipher.data.offset + sop->cipher.data.length); 508 509 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 510 &symvec); 511 512 if (n != 1) 513 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 514 else 515 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 516 } 517 518 static struct rte_crypto_op * 519 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 520 { 521 522 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 523 524 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 525 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 526 return NULL; 527 } 528 529 op = NULL; 530 531 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 532 rte_pause(); 533 534 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 535 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 536 return NULL; 537 } 538 539 return op; 540 } 541 542 static int 543 testsuite_setup(void) 544 { 545 struct crypto_testsuite_params *ts_params = &testsuite_params; 546 struct rte_cryptodev_info info; 547 uint32_t i = 0, nb_devs, dev_id; 548 uint16_t qp_id; 549 550 memset(ts_params, 0, sizeof(*ts_params)); 551 552 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 553 if (ts_params->mbuf_pool == NULL) { 554 /* Not already created so create */ 555 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 556 "CRYPTO_MBUFPOOL", 557 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 558 rte_socket_id()); 559 if (ts_params->mbuf_pool == NULL) { 560 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 561 return TEST_FAILED; 562 } 563 } 564 565 ts_params->large_mbuf_pool = rte_mempool_lookup( 566 "CRYPTO_LARGE_MBUFPOOL"); 567 if (ts_params->large_mbuf_pool == NULL) { 568 /* Not already created so create */ 569 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 570 "CRYPTO_LARGE_MBUFPOOL", 571 1, 0, 0, UINT16_MAX, 572 rte_socket_id()); 573 if (ts_params->large_mbuf_pool == NULL) { 574 RTE_LOG(ERR, USER1, 575 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 576 return TEST_FAILED; 577 } 578 } 579 580 ts_params->op_mpool = rte_crypto_op_pool_create( 581 "MBUF_CRYPTO_SYM_OP_POOL", 582 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 583 NUM_MBUFS, MBUF_CACHE_SIZE, 584 DEFAULT_NUM_XFORMS * 585 sizeof(struct rte_crypto_sym_xform) + 586 MAXIMUM_IV_LENGTH, 587 rte_socket_id()); 588 if (ts_params->op_mpool == NULL) { 589 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 590 return TEST_FAILED; 591 } 592 593 nb_devs = rte_cryptodev_count(); 594 if (nb_devs < 1) { 595 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 596 return TEST_SKIPPED; 597 } 598 599 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 600 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 601 rte_cryptodev_driver_name_get(gbl_driver_id)); 602 return TEST_SKIPPED; 603 } 604 605 /* Create list of valid crypto devs */ 606 for (i = 0; i < nb_devs; i++) { 607 rte_cryptodev_info_get(i, &info); 608 if (info.driver_id == gbl_driver_id) 609 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 610 } 611 612 if (ts_params->valid_dev_count < 1) 613 return TEST_FAILED; 614 615 /* Set up all the qps on the first of the valid devices found */ 616 617 dev_id = ts_params->valid_devs[0]; 618 619 rte_cryptodev_info_get(dev_id, &info); 620 621 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 622 ts_params->conf.socket_id = SOCKET_ID_ANY; 623 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 624 625 unsigned int session_size = 626 rte_cryptodev_sym_get_private_session_size(dev_id); 627 628 #ifdef RTE_LIB_SECURITY 629 unsigned int security_session_size = rte_security_session_get_size( 630 rte_cryptodev_get_sec_ctx(dev_id)); 631 632 if (session_size < security_session_size) 633 session_size = security_session_size; 634 #endif 635 /* 636 * Create mempool with maximum number of sessions. 637 */ 638 if (info.sym.max_nb_sessions != 0 && 639 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 640 RTE_LOG(ERR, USER1, "Device does not support " 641 "at least %u sessions\n", 642 MAX_NB_SESSIONS); 643 return TEST_FAILED; 644 } 645 646 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 647 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 648 SOCKET_ID_ANY); 649 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 650 "session mempool allocation failed"); 651 652 ts_params->session_priv_mpool = rte_mempool_create( 653 "test_sess_mp_priv", 654 MAX_NB_SESSIONS, 655 session_size, 656 0, 0, NULL, NULL, NULL, 657 NULL, SOCKET_ID_ANY, 658 0); 659 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 660 "session mempool allocation failed"); 661 662 663 664 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 665 &ts_params->conf), 666 "Failed to configure cryptodev %u with %u qps", 667 dev_id, ts_params->conf.nb_queue_pairs); 668 669 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 670 ts_params->qp_conf.mp_session = ts_params->session_mpool; 671 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 672 673 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 674 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 675 dev_id, qp_id, &ts_params->qp_conf, 676 rte_cryptodev_socket_id(dev_id)), 677 "Failed to setup queue pair %u on cryptodev %u", 678 qp_id, dev_id); 679 } 680 681 return TEST_SUCCESS; 682 } 683 684 static void 685 testsuite_teardown(void) 686 { 687 struct crypto_testsuite_params *ts_params = &testsuite_params; 688 int res; 689 690 if (ts_params->mbuf_pool != NULL) { 691 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 692 rte_mempool_avail_count(ts_params->mbuf_pool)); 693 } 694 695 if (ts_params->op_mpool != NULL) { 696 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 697 rte_mempool_avail_count(ts_params->op_mpool)); 698 } 699 700 /* Free session mempools */ 701 if (ts_params->session_priv_mpool != NULL) { 702 rte_mempool_free(ts_params->session_priv_mpool); 703 ts_params->session_priv_mpool = NULL; 704 } 705 706 if (ts_params->session_mpool != NULL) { 707 rte_mempool_free(ts_params->session_mpool); 708 ts_params->session_mpool = NULL; 709 } 710 711 res = rte_cryptodev_close(ts_params->valid_devs[0]); 712 if (res) 713 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 714 } 715 716 static int 717 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 718 const int *algs, uint16_t num_algs) 719 { 720 uint8_t dev_id = testsuite_params.valid_devs[0]; 721 bool some_alg_supported = FALSE; 722 uint16_t i; 723 724 for (i = 0; i < num_algs && !some_alg_supported; i++) { 725 struct rte_cryptodev_sym_capability_idx alg = { 726 type, {algs[i]} 727 }; 728 if (rte_cryptodev_sym_capability_get(dev_id, 729 &alg) != NULL) 730 some_alg_supported = TRUE; 731 } 732 if (!some_alg_supported) 733 return TEST_SKIPPED; 734 735 return 0; 736 } 737 738 int 739 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 740 uint16_t num_ciphers) 741 { 742 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 743 (const int *) ciphers, num_ciphers); 744 } 745 746 int 747 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 748 uint16_t num_auths) 749 { 750 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 751 (const int *) auths, num_auths); 752 } 753 754 int 755 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 756 uint16_t num_aeads) 757 { 758 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 759 (const int *) aeads, num_aeads); 760 } 761 762 static int 763 null_testsuite_setup(void) 764 { 765 struct crypto_testsuite_params *ts_params = &testsuite_params; 766 uint8_t dev_id = ts_params->valid_devs[0]; 767 struct rte_cryptodev_info dev_info; 768 const enum rte_crypto_cipher_algorithm ciphers[] = { 769 RTE_CRYPTO_CIPHER_NULL 770 }; 771 const enum rte_crypto_auth_algorithm auths[] = { 772 RTE_CRYPTO_AUTH_NULL 773 }; 774 775 rte_cryptodev_info_get(dev_id, &dev_info); 776 777 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 778 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 779 "testsuite not met\n"); 780 return TEST_SKIPPED; 781 } 782 783 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 784 && check_auth_capabilities_supported(auths, 785 RTE_DIM(auths)) != 0) { 786 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 787 "testsuite not met\n"); 788 return TEST_SKIPPED; 789 } 790 791 return 0; 792 } 793 794 static int 795 crypto_gen_testsuite_setup(void) 796 { 797 struct crypto_testsuite_params *ts_params = &testsuite_params; 798 uint8_t dev_id = ts_params->valid_devs[0]; 799 struct rte_cryptodev_info dev_info; 800 801 rte_cryptodev_info_get(dev_id, &dev_info); 802 803 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 804 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 805 "testsuite not met\n"); 806 return TEST_SKIPPED; 807 } 808 809 return 0; 810 } 811 812 #ifdef RTE_LIB_SECURITY 813 static int 814 ipsec_proto_testsuite_setup(void) 815 { 816 struct crypto_testsuite_params *ts_params = &testsuite_params; 817 struct crypto_unittest_params *ut_params = &unittest_params; 818 struct rte_cryptodev_info dev_info; 819 int ret = 0; 820 821 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 822 823 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 824 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 825 "testsuite not met\n"); 826 return TEST_SKIPPED; 827 } 828 829 /* Reconfigure to enable security */ 830 ret = dev_configure_and_start(0); 831 if (ret != TEST_SUCCESS) 832 return ret; 833 834 /* Set action type */ 835 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 836 837 if (security_proto_supported( 838 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 839 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 840 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 841 "test not met\n"); 842 ret = TEST_SKIPPED; 843 } 844 845 test_ipsec_alg_list_populate(); 846 test_ipsec_ah_alg_list_populate(); 847 848 /* 849 * Stop the device. Device would be started again by individual test 850 * case setup routine. 851 */ 852 rte_cryptodev_stop(ts_params->valid_devs[0]); 853 854 return ret; 855 } 856 857 static int 858 pdcp_proto_testsuite_setup(void) 859 { 860 struct crypto_testsuite_params *ts_params = &testsuite_params; 861 uint8_t dev_id = ts_params->valid_devs[0]; 862 struct rte_cryptodev_info dev_info; 863 const enum rte_crypto_cipher_algorithm ciphers[] = { 864 RTE_CRYPTO_CIPHER_NULL, 865 RTE_CRYPTO_CIPHER_AES_CTR, 866 RTE_CRYPTO_CIPHER_ZUC_EEA3, 867 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 868 }; 869 const enum rte_crypto_auth_algorithm auths[] = { 870 RTE_CRYPTO_AUTH_NULL, 871 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 872 RTE_CRYPTO_AUTH_AES_CMAC, 873 RTE_CRYPTO_AUTH_ZUC_EIA3 874 }; 875 876 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 877 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 878 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 879 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 880 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 881 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 882 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 883 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 884 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 885 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 886 887 rte_cryptodev_info_get(dev_id, &dev_info); 888 889 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 890 !(dev_info.feature_flags & 891 RTE_CRYPTODEV_FF_SECURITY)) { 892 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 893 "testsuite not met\n"); 894 return TEST_SKIPPED; 895 } 896 897 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 898 && check_auth_capabilities_supported(auths, 899 RTE_DIM(auths)) != 0) { 900 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 901 "testsuite not met\n"); 902 return TEST_SKIPPED; 903 } 904 905 return 0; 906 } 907 908 static int 909 docsis_proto_testsuite_setup(void) 910 { 911 struct crypto_testsuite_params *ts_params = &testsuite_params; 912 uint8_t dev_id = ts_params->valid_devs[0]; 913 struct rte_cryptodev_info dev_info; 914 const enum rte_crypto_cipher_algorithm ciphers[] = { 915 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 916 }; 917 918 rte_cryptodev_info_get(dev_id, &dev_info); 919 920 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 921 !(dev_info.feature_flags & 922 RTE_CRYPTODEV_FF_SECURITY)) { 923 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 924 "Proto testsuite not met\n"); 925 return TEST_SKIPPED; 926 } 927 928 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 929 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 930 "testsuite not met\n"); 931 return TEST_SKIPPED; 932 } 933 934 return 0; 935 } 936 #endif 937 938 static int 939 aes_ccm_auth_testsuite_setup(void) 940 { 941 struct crypto_testsuite_params *ts_params = &testsuite_params; 942 uint8_t dev_id = ts_params->valid_devs[0]; 943 struct rte_cryptodev_info dev_info; 944 const enum rte_crypto_aead_algorithm aeads[] = { 945 RTE_CRYPTO_AEAD_AES_CCM 946 }; 947 948 rte_cryptodev_info_get(dev_id, &dev_info); 949 950 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 951 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 952 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 953 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 954 "testsuite not met\n"); 955 return TEST_SKIPPED; 956 } 957 958 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 959 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 960 "testsuite not met\n"); 961 return TEST_SKIPPED; 962 } 963 964 return 0; 965 } 966 967 static int 968 aes_gcm_auth_testsuite_setup(void) 969 { 970 struct crypto_testsuite_params *ts_params = &testsuite_params; 971 uint8_t dev_id = ts_params->valid_devs[0]; 972 struct rte_cryptodev_info dev_info; 973 const enum rte_crypto_aead_algorithm aeads[] = { 974 RTE_CRYPTO_AEAD_AES_GCM 975 }; 976 977 rte_cryptodev_info_get(dev_id, &dev_info); 978 979 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 980 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 981 "testsuite not met\n"); 982 return TEST_SKIPPED; 983 } 984 985 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 986 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 987 "testsuite not met\n"); 988 return TEST_SKIPPED; 989 } 990 991 return 0; 992 } 993 994 static int 995 aes_gmac_auth_testsuite_setup(void) 996 { 997 struct crypto_testsuite_params *ts_params = &testsuite_params; 998 uint8_t dev_id = ts_params->valid_devs[0]; 999 struct rte_cryptodev_info dev_info; 1000 const enum rte_crypto_auth_algorithm auths[] = { 1001 RTE_CRYPTO_AUTH_AES_GMAC 1002 }; 1003 1004 rte_cryptodev_info_get(dev_id, &dev_info); 1005 1006 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1007 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1008 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1009 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 1010 "testsuite not met\n"); 1011 return TEST_SKIPPED; 1012 } 1013 1014 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1015 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1016 "testsuite not met\n"); 1017 return TEST_SKIPPED; 1018 } 1019 1020 return 0; 1021 } 1022 1023 static int 1024 chacha20_poly1305_testsuite_setup(void) 1025 { 1026 struct crypto_testsuite_params *ts_params = &testsuite_params; 1027 uint8_t dev_id = ts_params->valid_devs[0]; 1028 struct rte_cryptodev_info dev_info; 1029 const enum rte_crypto_aead_algorithm aeads[] = { 1030 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1031 }; 1032 1033 rte_cryptodev_info_get(dev_id, &dev_info); 1034 1035 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1036 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1037 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1038 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1039 "Chacha20-Poly1305 testsuite not met\n"); 1040 return TEST_SKIPPED; 1041 } 1042 1043 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1044 RTE_LOG(INFO, USER1, "Capability requirements for " 1045 "Chacha20-Poly1305 testsuite not met\n"); 1046 return TEST_SKIPPED; 1047 } 1048 1049 return 0; 1050 } 1051 1052 static int 1053 snow3g_testsuite_setup(void) 1054 { 1055 struct crypto_testsuite_params *ts_params = &testsuite_params; 1056 uint8_t dev_id = ts_params->valid_devs[0]; 1057 struct rte_cryptodev_info dev_info; 1058 const enum rte_crypto_cipher_algorithm ciphers[] = { 1059 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1060 1061 }; 1062 const enum rte_crypto_auth_algorithm auths[] = { 1063 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1064 }; 1065 1066 rte_cryptodev_info_get(dev_id, &dev_info); 1067 1068 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1069 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1070 "testsuite not met\n"); 1071 return TEST_SKIPPED; 1072 } 1073 1074 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1075 && check_auth_capabilities_supported(auths, 1076 RTE_DIM(auths)) != 0) { 1077 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1078 "testsuite not met\n"); 1079 return TEST_SKIPPED; 1080 } 1081 1082 return 0; 1083 } 1084 1085 static int 1086 zuc_testsuite_setup(void) 1087 { 1088 struct crypto_testsuite_params *ts_params = &testsuite_params; 1089 uint8_t dev_id = ts_params->valid_devs[0]; 1090 struct rte_cryptodev_info dev_info; 1091 const enum rte_crypto_cipher_algorithm ciphers[] = { 1092 RTE_CRYPTO_CIPHER_ZUC_EEA3 1093 }; 1094 const enum rte_crypto_auth_algorithm auths[] = { 1095 RTE_CRYPTO_AUTH_ZUC_EIA3 1096 }; 1097 1098 rte_cryptodev_info_get(dev_id, &dev_info); 1099 1100 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1101 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1102 "testsuite not met\n"); 1103 return TEST_SKIPPED; 1104 } 1105 1106 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1107 && check_auth_capabilities_supported(auths, 1108 RTE_DIM(auths)) != 0) { 1109 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1110 "testsuite not met\n"); 1111 return TEST_SKIPPED; 1112 } 1113 1114 return 0; 1115 } 1116 1117 static int 1118 hmac_md5_auth_testsuite_setup(void) 1119 { 1120 struct crypto_testsuite_params *ts_params = &testsuite_params; 1121 uint8_t dev_id = ts_params->valid_devs[0]; 1122 struct rte_cryptodev_info dev_info; 1123 const enum rte_crypto_auth_algorithm auths[] = { 1124 RTE_CRYPTO_AUTH_MD5_HMAC 1125 }; 1126 1127 rte_cryptodev_info_get(dev_id, &dev_info); 1128 1129 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1130 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1131 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1132 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1133 "Auth testsuite not met\n"); 1134 return TEST_SKIPPED; 1135 } 1136 1137 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1138 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1139 "testsuite not met\n"); 1140 return TEST_SKIPPED; 1141 } 1142 1143 return 0; 1144 } 1145 1146 static int 1147 kasumi_testsuite_setup(void) 1148 { 1149 struct crypto_testsuite_params *ts_params = &testsuite_params; 1150 uint8_t dev_id = ts_params->valid_devs[0]; 1151 struct rte_cryptodev_info dev_info; 1152 const enum rte_crypto_cipher_algorithm ciphers[] = { 1153 RTE_CRYPTO_CIPHER_KASUMI_F8 1154 }; 1155 const enum rte_crypto_auth_algorithm auths[] = { 1156 RTE_CRYPTO_AUTH_KASUMI_F9 1157 }; 1158 1159 rte_cryptodev_info_get(dev_id, &dev_info); 1160 1161 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1162 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1163 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1164 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1165 "testsuite not met\n"); 1166 return TEST_SKIPPED; 1167 } 1168 1169 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1170 && check_auth_capabilities_supported(auths, 1171 RTE_DIM(auths)) != 0) { 1172 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1173 "testsuite not met\n"); 1174 return TEST_SKIPPED; 1175 } 1176 1177 return 0; 1178 } 1179 1180 static int 1181 negative_aes_gcm_testsuite_setup(void) 1182 { 1183 struct crypto_testsuite_params *ts_params = &testsuite_params; 1184 uint8_t dev_id = ts_params->valid_devs[0]; 1185 struct rte_cryptodev_info dev_info; 1186 const enum rte_crypto_aead_algorithm aeads[] = { 1187 RTE_CRYPTO_AEAD_AES_GCM 1188 }; 1189 1190 rte_cryptodev_info_get(dev_id, &dev_info); 1191 1192 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1193 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1194 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1195 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1196 "AES GCM testsuite not met\n"); 1197 return TEST_SKIPPED; 1198 } 1199 1200 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1201 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1202 "AES GCM testsuite not met\n"); 1203 return TEST_SKIPPED; 1204 } 1205 1206 return 0; 1207 } 1208 1209 static int 1210 negative_aes_gmac_testsuite_setup(void) 1211 { 1212 struct crypto_testsuite_params *ts_params = &testsuite_params; 1213 uint8_t dev_id = ts_params->valid_devs[0]; 1214 struct rte_cryptodev_info dev_info; 1215 const enum rte_crypto_auth_algorithm auths[] = { 1216 RTE_CRYPTO_AUTH_AES_GMAC 1217 }; 1218 1219 rte_cryptodev_info_get(dev_id, &dev_info); 1220 1221 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1222 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1223 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1224 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1225 "AES GMAC testsuite not met\n"); 1226 return TEST_SKIPPED; 1227 } 1228 1229 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1230 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1231 "AES GMAC testsuite not met\n"); 1232 return TEST_SKIPPED; 1233 } 1234 1235 return 0; 1236 } 1237 1238 static int 1239 mixed_cipher_hash_testsuite_setup(void) 1240 { 1241 struct crypto_testsuite_params *ts_params = &testsuite_params; 1242 uint8_t dev_id = ts_params->valid_devs[0]; 1243 struct rte_cryptodev_info dev_info; 1244 uint64_t feat_flags; 1245 const enum rte_crypto_cipher_algorithm ciphers[] = { 1246 RTE_CRYPTO_CIPHER_NULL, 1247 RTE_CRYPTO_CIPHER_AES_CTR, 1248 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1249 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1250 }; 1251 const enum rte_crypto_auth_algorithm auths[] = { 1252 RTE_CRYPTO_AUTH_NULL, 1253 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1254 RTE_CRYPTO_AUTH_AES_CMAC, 1255 RTE_CRYPTO_AUTH_ZUC_EIA3 1256 }; 1257 1258 rte_cryptodev_info_get(dev_id, &dev_info); 1259 feat_flags = dev_info.feature_flags; 1260 1261 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1262 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1263 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1264 "Cipher Hash testsuite not met\n"); 1265 return TEST_SKIPPED; 1266 } 1267 1268 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1269 && check_auth_capabilities_supported(auths, 1270 RTE_DIM(auths)) != 0) { 1271 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1272 "Cipher Hash testsuite not met\n"); 1273 return TEST_SKIPPED; 1274 } 1275 1276 return 0; 1277 } 1278 1279 static int 1280 esn_testsuite_setup(void) 1281 { 1282 struct crypto_testsuite_params *ts_params = &testsuite_params; 1283 uint8_t dev_id = ts_params->valid_devs[0]; 1284 struct rte_cryptodev_info dev_info; 1285 const enum rte_crypto_cipher_algorithm ciphers[] = { 1286 RTE_CRYPTO_CIPHER_AES_CBC 1287 }; 1288 const enum rte_crypto_auth_algorithm auths[] = { 1289 RTE_CRYPTO_AUTH_SHA1_HMAC 1290 }; 1291 1292 rte_cryptodev_info_get(dev_id, &dev_info); 1293 1294 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1295 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1296 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1297 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1298 "testsuite not met\n"); 1299 return TEST_SKIPPED; 1300 } 1301 1302 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1303 && check_auth_capabilities_supported(auths, 1304 RTE_DIM(auths)) != 0) { 1305 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1306 "testsuite not met\n"); 1307 return TEST_SKIPPED; 1308 } 1309 1310 return 0; 1311 } 1312 1313 static int 1314 multi_session_testsuite_setup(void) 1315 { 1316 struct crypto_testsuite_params *ts_params = &testsuite_params; 1317 uint8_t dev_id = ts_params->valid_devs[0]; 1318 struct rte_cryptodev_info dev_info; 1319 const enum rte_crypto_cipher_algorithm ciphers[] = { 1320 RTE_CRYPTO_CIPHER_AES_CBC 1321 }; 1322 const enum rte_crypto_auth_algorithm auths[] = { 1323 RTE_CRYPTO_AUTH_SHA512_HMAC 1324 }; 1325 1326 rte_cryptodev_info_get(dev_id, &dev_info); 1327 1328 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1329 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1330 "Session testsuite not met\n"); 1331 return TEST_SKIPPED; 1332 } 1333 1334 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1335 && check_auth_capabilities_supported(auths, 1336 RTE_DIM(auths)) != 0) { 1337 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1338 "Session testsuite not met\n"); 1339 return TEST_SKIPPED; 1340 } 1341 1342 return 0; 1343 } 1344 1345 static int 1346 negative_hmac_sha1_testsuite_setup(void) 1347 { 1348 struct crypto_testsuite_params *ts_params = &testsuite_params; 1349 uint8_t dev_id = ts_params->valid_devs[0]; 1350 struct rte_cryptodev_info dev_info; 1351 const enum rte_crypto_cipher_algorithm ciphers[] = { 1352 RTE_CRYPTO_CIPHER_AES_CBC 1353 }; 1354 const enum rte_crypto_auth_algorithm auths[] = { 1355 RTE_CRYPTO_AUTH_SHA1_HMAC 1356 }; 1357 1358 rte_cryptodev_info_get(dev_id, &dev_info); 1359 1360 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1361 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1362 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1363 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1364 "HMAC SHA1 testsuite not met\n"); 1365 return TEST_SKIPPED; 1366 } 1367 1368 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1369 && check_auth_capabilities_supported(auths, 1370 RTE_DIM(auths)) != 0) { 1371 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1372 "HMAC SHA1 testsuite not met\n"); 1373 return TEST_SKIPPED; 1374 } 1375 1376 return 0; 1377 } 1378 1379 static int 1380 dev_configure_and_start(uint64_t ff_disable) 1381 { 1382 struct crypto_testsuite_params *ts_params = &testsuite_params; 1383 struct crypto_unittest_params *ut_params = &unittest_params; 1384 1385 uint16_t qp_id; 1386 1387 /* Clear unit test parameters before running test */ 1388 memset(ut_params, 0, sizeof(*ut_params)); 1389 1390 /* Reconfigure device to default parameters */ 1391 ts_params->conf.socket_id = SOCKET_ID_ANY; 1392 ts_params->conf.ff_disable = ff_disable; 1393 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1394 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1395 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 1396 1397 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1398 &ts_params->conf), 1399 "Failed to configure cryptodev %u", 1400 ts_params->valid_devs[0]); 1401 1402 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1403 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1404 ts_params->valid_devs[0], qp_id, 1405 &ts_params->qp_conf, 1406 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1407 "Failed to setup queue pair %u on cryptodev %u", 1408 qp_id, ts_params->valid_devs[0]); 1409 } 1410 1411 1412 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1413 1414 /* Start the device */ 1415 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1416 "Failed to start cryptodev %u", 1417 ts_params->valid_devs[0]); 1418 1419 return TEST_SUCCESS; 1420 } 1421 1422 int 1423 ut_setup(void) 1424 { 1425 /* Configure and start the device with security feature disabled */ 1426 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1427 } 1428 1429 static int 1430 ut_setup_security(void) 1431 { 1432 /* Configure and start the device with no features disabled */ 1433 return dev_configure_and_start(0); 1434 } 1435 1436 void 1437 ut_teardown(void) 1438 { 1439 struct crypto_testsuite_params *ts_params = &testsuite_params; 1440 struct crypto_unittest_params *ut_params = &unittest_params; 1441 1442 /* free crypto session structure */ 1443 #ifdef RTE_LIB_SECURITY 1444 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1445 if (ut_params->sec_session) { 1446 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1447 (ts_params->valid_devs[0]), 1448 ut_params->sec_session); 1449 ut_params->sec_session = NULL; 1450 } 1451 } else 1452 #endif 1453 { 1454 if (ut_params->sess) { 1455 rte_cryptodev_sym_session_clear( 1456 ts_params->valid_devs[0], 1457 ut_params->sess); 1458 rte_cryptodev_sym_session_free(ut_params->sess); 1459 ut_params->sess = NULL; 1460 } 1461 } 1462 1463 /* free crypto operation structure */ 1464 rte_crypto_op_free(ut_params->op); 1465 1466 /* 1467 * free mbuf - both obuf and ibuf are usually the same, 1468 * so check if they point at the same address is necessary, 1469 * to avoid freeing the mbuf twice. 1470 */ 1471 if (ut_params->obuf) { 1472 rte_pktmbuf_free(ut_params->obuf); 1473 if (ut_params->ibuf == ut_params->obuf) 1474 ut_params->ibuf = 0; 1475 ut_params->obuf = 0; 1476 } 1477 if (ut_params->ibuf) { 1478 rte_pktmbuf_free(ut_params->ibuf); 1479 ut_params->ibuf = 0; 1480 } 1481 1482 if (ts_params->mbuf_pool != NULL) 1483 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1484 rte_mempool_avail_count(ts_params->mbuf_pool)); 1485 1486 /* Stop the device */ 1487 rte_cryptodev_stop(ts_params->valid_devs[0]); 1488 } 1489 1490 static int 1491 test_device_configure_invalid_dev_id(void) 1492 { 1493 struct crypto_testsuite_params *ts_params = &testsuite_params; 1494 uint16_t dev_id, num_devs = 0; 1495 1496 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1497 "Need at least %d devices for test", 1); 1498 1499 /* valid dev_id values */ 1500 dev_id = ts_params->valid_devs[0]; 1501 1502 /* Stop the device in case it's started so it can be configured */ 1503 rte_cryptodev_stop(dev_id); 1504 1505 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1506 "Failed test for rte_cryptodev_configure: " 1507 "invalid dev_num %u", dev_id); 1508 1509 /* invalid dev_id values */ 1510 dev_id = num_devs; 1511 1512 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1513 "Failed test for rte_cryptodev_configure: " 1514 "invalid dev_num %u", dev_id); 1515 1516 dev_id = 0xff; 1517 1518 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1519 "Failed test for rte_cryptodev_configure:" 1520 "invalid dev_num %u", dev_id); 1521 1522 return TEST_SUCCESS; 1523 } 1524 1525 static int 1526 test_device_configure_invalid_queue_pair_ids(void) 1527 { 1528 struct crypto_testsuite_params *ts_params = &testsuite_params; 1529 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1530 1531 /* Stop the device in case it's started so it can be configured */ 1532 rte_cryptodev_stop(ts_params->valid_devs[0]); 1533 1534 /* valid - max value queue pairs */ 1535 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1536 1537 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1538 &ts_params->conf), 1539 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1540 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1541 1542 /* valid - one queue pairs */ 1543 ts_params->conf.nb_queue_pairs = 1; 1544 1545 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1546 &ts_params->conf), 1547 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1548 ts_params->valid_devs[0], 1549 ts_params->conf.nb_queue_pairs); 1550 1551 1552 /* invalid - zero queue pairs */ 1553 ts_params->conf.nb_queue_pairs = 0; 1554 1555 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1556 &ts_params->conf), 1557 "Failed test for rte_cryptodev_configure, dev_id %u," 1558 " invalid qps: %u", 1559 ts_params->valid_devs[0], 1560 ts_params->conf.nb_queue_pairs); 1561 1562 1563 /* invalid - max value supported by field queue pairs */ 1564 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1565 1566 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1567 &ts_params->conf), 1568 "Failed test for rte_cryptodev_configure, dev_id %u," 1569 " invalid qps: %u", 1570 ts_params->valid_devs[0], 1571 ts_params->conf.nb_queue_pairs); 1572 1573 1574 /* invalid - max value + 1 queue pairs */ 1575 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1576 1577 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1578 &ts_params->conf), 1579 "Failed test for rte_cryptodev_configure, dev_id %u," 1580 " invalid qps: %u", 1581 ts_params->valid_devs[0], 1582 ts_params->conf.nb_queue_pairs); 1583 1584 /* revert to original testsuite value */ 1585 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1586 1587 return TEST_SUCCESS; 1588 } 1589 1590 static int 1591 test_queue_pair_descriptor_setup(void) 1592 { 1593 struct crypto_testsuite_params *ts_params = &testsuite_params; 1594 struct rte_cryptodev_qp_conf qp_conf = { 1595 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1596 }; 1597 uint16_t qp_id; 1598 1599 /* Stop the device in case it's started so it can be configured */ 1600 rte_cryptodev_stop(ts_params->valid_devs[0]); 1601 1602 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1603 &ts_params->conf), 1604 "Failed to configure cryptodev %u", 1605 ts_params->valid_devs[0]); 1606 1607 /* 1608 * Test various ring sizes on this device. memzones can't be 1609 * freed so are re-used if ring is released and re-created. 1610 */ 1611 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1612 qp_conf.mp_session = ts_params->session_mpool; 1613 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1614 1615 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1616 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1617 ts_params->valid_devs[0], qp_id, &qp_conf, 1618 rte_cryptodev_socket_id( 1619 ts_params->valid_devs[0])), 1620 "Failed test for " 1621 "rte_cryptodev_queue_pair_setup: num_inflights " 1622 "%u on qp %u on cryptodev %u", 1623 qp_conf.nb_descriptors, qp_id, 1624 ts_params->valid_devs[0]); 1625 } 1626 1627 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1628 1629 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1630 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1631 ts_params->valid_devs[0], qp_id, &qp_conf, 1632 rte_cryptodev_socket_id( 1633 ts_params->valid_devs[0])), 1634 "Failed test for" 1635 " rte_cryptodev_queue_pair_setup: num_inflights" 1636 " %u on qp %u on cryptodev %u", 1637 qp_conf.nb_descriptors, qp_id, 1638 ts_params->valid_devs[0]); 1639 } 1640 1641 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1642 1643 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1644 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1645 ts_params->valid_devs[0], qp_id, &qp_conf, 1646 rte_cryptodev_socket_id( 1647 ts_params->valid_devs[0])), 1648 "Failed test for " 1649 "rte_cryptodev_queue_pair_setup: num_inflights" 1650 " %u on qp %u on cryptodev %u", 1651 qp_conf.nb_descriptors, qp_id, 1652 ts_params->valid_devs[0]); 1653 } 1654 1655 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1656 1657 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1658 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1659 ts_params->valid_devs[0], qp_id, &qp_conf, 1660 rte_cryptodev_socket_id( 1661 ts_params->valid_devs[0])), 1662 "Failed test for" 1663 " rte_cryptodev_queue_pair_setup:" 1664 "num_inflights %u on qp %u on cryptodev %u", 1665 qp_conf.nb_descriptors, qp_id, 1666 ts_params->valid_devs[0]); 1667 } 1668 1669 /* test invalid queue pair id */ 1670 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1671 1672 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1673 1674 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1675 ts_params->valid_devs[0], 1676 qp_id, &qp_conf, 1677 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1678 "Failed test for rte_cryptodev_queue_pair_setup:" 1679 "invalid qp %u on cryptodev %u", 1680 qp_id, ts_params->valid_devs[0]); 1681 1682 qp_id = 0xffff; /*invalid*/ 1683 1684 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1685 ts_params->valid_devs[0], 1686 qp_id, &qp_conf, 1687 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1688 "Failed test for rte_cryptodev_queue_pair_setup:" 1689 "invalid qp %u on cryptodev %u", 1690 qp_id, ts_params->valid_devs[0]); 1691 1692 return TEST_SUCCESS; 1693 } 1694 1695 /* ***** Plaintext data for tests ***** */ 1696 1697 const char catch_22_quote_1[] = 1698 "There was only one catch and that was Catch-22, which " 1699 "specified that a concern for one's safety in the face of " 1700 "dangers that were real and immediate was the process of a " 1701 "rational mind. Orr was crazy and could be grounded. All he " 1702 "had to do was ask; and as soon as he did, he would no longer " 1703 "be crazy and would have to fly more missions. Orr would be " 1704 "crazy to fly more missions and sane if he didn't, but if he " 1705 "was sane he had to fly them. If he flew them he was crazy " 1706 "and didn't have to; but if he didn't want to he was sane and " 1707 "had to. Yossarian was moved very deeply by the absolute " 1708 "simplicity of this clause of Catch-22 and let out a " 1709 "respectful whistle. \"That's some catch, that Catch-22\", he " 1710 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1711 1712 const char catch_22_quote[] = 1713 "What a lousy earth! He wondered how many people were " 1714 "destitute that same night even in his own prosperous country, " 1715 "how many homes were shanties, how many husbands were drunk " 1716 "and wives socked, and how many children were bullied, abused, " 1717 "or abandoned. How many families hungered for food they could " 1718 "not afford to buy? How many hearts were broken? How many " 1719 "suicides would take place that same night, how many people " 1720 "would go insane? How many cockroaches and landlords would " 1721 "triumph? How many winners were losers, successes failures, " 1722 "and rich men poor men? How many wise guys were stupid? How " 1723 "many happy endings were unhappy endings? How many honest men " 1724 "were liars, brave men cowards, loyal men traitors, how many " 1725 "sainted men were corrupt, how many people in positions of " 1726 "trust had sold their souls to bodyguards, how many had never " 1727 "had souls? How many straight-and-narrow paths were crooked " 1728 "paths? How many best families were worst families and how " 1729 "many good people were bad people? When you added them all up " 1730 "and then subtracted, you might be left with only the children, " 1731 "and perhaps with Albert Einstein and an old violinist or " 1732 "sculptor somewhere."; 1733 1734 #define QUOTE_480_BYTES (480) 1735 #define QUOTE_512_BYTES (512) 1736 #define QUOTE_768_BYTES (768) 1737 #define QUOTE_1024_BYTES (1024) 1738 1739 1740 1741 /* ***** SHA1 Hash Tests ***** */ 1742 1743 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1744 1745 static uint8_t hmac_sha1_key[] = { 1746 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1747 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1748 0xDE, 0xF4, 0xDE, 0xAD }; 1749 1750 /* ***** SHA224 Hash Tests ***** */ 1751 1752 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1753 1754 1755 /* ***** AES-CBC Cipher Tests ***** */ 1756 1757 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1758 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1759 1760 static uint8_t aes_cbc_key[] = { 1761 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1762 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1763 1764 static uint8_t aes_cbc_iv[] = { 1765 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1766 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1767 1768 1769 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1770 1771 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1772 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1773 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1774 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1775 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1776 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1777 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1778 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1779 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1780 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1781 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1782 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1783 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1784 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1785 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1786 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1787 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1788 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1789 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1790 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1791 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1792 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1793 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1794 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1795 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1796 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1797 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1798 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1799 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1800 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1801 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1802 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1803 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1804 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1805 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1806 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1807 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1808 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1809 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1810 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1811 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1812 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1813 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1814 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1815 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1816 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1817 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1818 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1819 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1820 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1821 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1822 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1823 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1824 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1825 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1826 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1827 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1828 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1829 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1830 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1831 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1832 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1833 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1834 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1835 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1836 }; 1837 1838 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1839 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1840 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1841 0x18, 0x8c, 0x1d, 0x32 1842 }; 1843 1844 1845 /* Multisession Vector context Test */ 1846 /*Begin Session 0 */ 1847 static uint8_t ms_aes_cbc_key0[] = { 1848 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1849 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1850 }; 1851 1852 static uint8_t ms_aes_cbc_iv0[] = { 1853 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1854 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1855 }; 1856 1857 static const uint8_t ms_aes_cbc_cipher0[] = { 1858 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1859 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1860 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1861 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1862 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1863 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1864 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1865 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1866 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1867 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1868 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1869 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1870 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1871 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1872 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1873 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1874 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1875 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1876 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1877 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1878 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1879 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1880 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1881 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1882 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1883 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1884 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1885 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1886 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1887 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1888 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1889 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1890 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1891 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1892 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1893 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1894 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1895 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1896 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1897 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1898 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1899 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1900 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1901 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1902 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1903 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1904 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1905 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1906 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1907 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1908 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1909 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1910 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1911 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1912 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1913 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1914 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1915 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1916 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1917 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1918 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1919 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1920 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1921 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1922 }; 1923 1924 1925 static uint8_t ms_hmac_key0[] = { 1926 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1927 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1928 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1929 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1930 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1931 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1932 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1933 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1934 }; 1935 1936 static const uint8_t ms_hmac_digest0[] = { 1937 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1938 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1939 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1940 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1941 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1942 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1943 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1944 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1945 }; 1946 1947 /* End Session 0 */ 1948 /* Begin session 1 */ 1949 1950 static uint8_t ms_aes_cbc_key1[] = { 1951 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1952 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1953 }; 1954 1955 static uint8_t ms_aes_cbc_iv1[] = { 1956 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1957 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1958 }; 1959 1960 static const uint8_t ms_aes_cbc_cipher1[] = { 1961 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1962 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1963 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1964 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1965 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1966 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1967 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1968 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1969 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1970 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1971 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1972 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1973 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1974 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1975 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1976 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1977 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1978 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1979 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1980 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1981 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1982 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1983 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1984 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1985 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1986 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1987 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1988 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1989 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1990 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1991 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1992 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1993 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1994 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1995 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1996 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1997 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1998 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1999 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 2000 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 2001 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 2002 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 2003 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 2004 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 2005 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 2006 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 2007 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 2008 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 2009 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2010 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2011 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2012 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2013 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2014 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2015 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2016 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2017 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2018 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2019 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2020 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2021 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2022 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2023 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2024 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2025 2026 }; 2027 2028 static uint8_t ms_hmac_key1[] = { 2029 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2030 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2031 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2032 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2033 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2034 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2035 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2036 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2037 }; 2038 2039 static const uint8_t ms_hmac_digest1[] = { 2040 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2041 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2042 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2043 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2044 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2045 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2046 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2047 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2048 }; 2049 /* End Session 1 */ 2050 /* Begin Session 2 */ 2051 static uint8_t ms_aes_cbc_key2[] = { 2052 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2053 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2054 }; 2055 2056 static uint8_t ms_aes_cbc_iv2[] = { 2057 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2058 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2059 }; 2060 2061 static const uint8_t ms_aes_cbc_cipher2[] = { 2062 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2063 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2064 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2065 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2066 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2067 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2068 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2069 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2070 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2071 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2072 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2073 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2074 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2075 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2076 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2077 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2078 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2079 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2080 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2081 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2082 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2083 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2084 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2085 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2086 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2087 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2088 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2089 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2090 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2091 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2092 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2093 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2094 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2095 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2096 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2097 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2098 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2099 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2100 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2101 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2102 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2103 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2104 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2105 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2106 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2107 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2108 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2109 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2110 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2111 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2112 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2113 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2114 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2115 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2116 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2117 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2118 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2119 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2120 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2121 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2122 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2123 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2124 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2125 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2126 }; 2127 2128 static uint8_t ms_hmac_key2[] = { 2129 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2130 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2131 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2132 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2133 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2134 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2135 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2136 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2137 }; 2138 2139 static const uint8_t ms_hmac_digest2[] = { 2140 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2141 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2142 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2143 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2144 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2145 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2146 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2147 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2148 }; 2149 2150 /* End Session 2 */ 2151 2152 2153 static int 2154 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2155 { 2156 struct crypto_testsuite_params *ts_params = &testsuite_params; 2157 struct crypto_unittest_params *ut_params = &unittest_params; 2158 int status; 2159 2160 /* Verify the capabilities */ 2161 struct rte_cryptodev_sym_capability_idx cap_idx; 2162 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2163 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2164 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2165 &cap_idx) == NULL) 2166 return TEST_SKIPPED; 2167 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2168 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2169 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2170 &cap_idx) == NULL) 2171 return TEST_SKIPPED; 2172 2173 /* Generate test mbuf data and space for digest */ 2174 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2175 catch_22_quote, QUOTE_512_BYTES, 0); 2176 2177 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2178 DIGEST_BYTE_LENGTH_SHA1); 2179 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2180 2181 /* Setup Cipher Parameters */ 2182 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2183 ut_params->cipher_xform.next = &ut_params->auth_xform; 2184 2185 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2186 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2187 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2188 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2189 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2190 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2191 2192 /* Setup HMAC Parameters */ 2193 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2194 2195 ut_params->auth_xform.next = NULL; 2196 2197 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2198 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2199 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2200 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2201 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2202 2203 ut_params->sess = rte_cryptodev_sym_session_create( 2204 ts_params->session_mpool); 2205 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2206 2207 /* Create crypto session*/ 2208 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2209 ut_params->sess, &ut_params->cipher_xform, 2210 ts_params->session_priv_mpool); 2211 2212 if (status == -ENOTSUP) 2213 return TEST_SKIPPED; 2214 2215 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 2216 2217 /* Generate crypto op data structure */ 2218 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2219 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2220 TEST_ASSERT_NOT_NULL(ut_params->op, 2221 "Failed to allocate symmetric crypto operation struct"); 2222 2223 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2224 2225 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2226 2227 /* set crypto operation source mbuf */ 2228 sym_op->m_src = ut_params->ibuf; 2229 2230 /* Set crypto operation authentication parameters */ 2231 sym_op->auth.digest.data = ut_params->digest; 2232 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2233 ut_params->ibuf, QUOTE_512_BYTES); 2234 2235 sym_op->auth.data.offset = 0; 2236 sym_op->auth.data.length = QUOTE_512_BYTES; 2237 2238 /* Copy IV at the end of the crypto operation */ 2239 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2240 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2241 2242 /* Set crypto operation cipher parameters */ 2243 sym_op->cipher.data.offset = 0; 2244 sym_op->cipher.data.length = QUOTE_512_BYTES; 2245 2246 /* Process crypto operation */ 2247 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2248 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2249 ut_params->op); 2250 else 2251 TEST_ASSERT_NOT_NULL( 2252 process_crypto_request(ts_params->valid_devs[0], 2253 ut_params->op), 2254 "failed to process sym crypto op"); 2255 2256 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2257 "crypto op processing failed"); 2258 2259 /* Validate obuf */ 2260 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2261 uint8_t *); 2262 2263 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2264 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2265 QUOTE_512_BYTES, 2266 "ciphertext data not as expected"); 2267 2268 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2269 2270 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2271 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2272 gbl_driver_id == rte_cryptodev_driver_id_get( 2273 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2274 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2275 DIGEST_BYTE_LENGTH_SHA1, 2276 "Generated digest data not as expected"); 2277 2278 return TEST_SUCCESS; 2279 } 2280 2281 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2282 2283 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2284 2285 static uint8_t hmac_sha512_key[] = { 2286 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2287 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2288 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2289 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2290 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2291 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2292 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2293 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2294 2295 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2296 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2297 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2298 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2299 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2300 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2301 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2302 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2303 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2304 2305 2306 2307 static int 2308 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2309 struct crypto_unittest_params *ut_params, 2310 uint8_t *cipher_key, 2311 uint8_t *hmac_key); 2312 2313 static int 2314 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2315 struct crypto_unittest_params *ut_params, 2316 struct crypto_testsuite_params *ts_params, 2317 const uint8_t *cipher, 2318 const uint8_t *digest, 2319 const uint8_t *iv); 2320 2321 2322 static int 2323 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2324 struct crypto_unittest_params *ut_params, 2325 uint8_t *cipher_key, 2326 uint8_t *hmac_key) 2327 { 2328 2329 /* Setup Cipher Parameters */ 2330 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2331 ut_params->cipher_xform.next = NULL; 2332 2333 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2334 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2335 ut_params->cipher_xform.cipher.key.data = cipher_key; 2336 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2337 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2338 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2339 2340 /* Setup HMAC Parameters */ 2341 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2342 ut_params->auth_xform.next = &ut_params->cipher_xform; 2343 2344 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2345 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2346 ut_params->auth_xform.auth.key.data = hmac_key; 2347 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2348 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2349 2350 return TEST_SUCCESS; 2351 } 2352 2353 2354 static int 2355 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2356 struct crypto_unittest_params *ut_params, 2357 struct crypto_testsuite_params *ts_params, 2358 const uint8_t *cipher, 2359 const uint8_t *digest, 2360 const uint8_t *iv) 2361 { 2362 /* Generate test mbuf data and digest */ 2363 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2364 (const char *) 2365 cipher, 2366 QUOTE_512_BYTES, 0); 2367 2368 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2369 DIGEST_BYTE_LENGTH_SHA512); 2370 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2371 2372 rte_memcpy(ut_params->digest, 2373 digest, 2374 DIGEST_BYTE_LENGTH_SHA512); 2375 2376 /* Generate Crypto op data structure */ 2377 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2378 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2379 TEST_ASSERT_NOT_NULL(ut_params->op, 2380 "Failed to allocate symmetric crypto operation struct"); 2381 2382 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2383 2384 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2385 2386 /* set crypto operation source mbuf */ 2387 sym_op->m_src = ut_params->ibuf; 2388 2389 sym_op->auth.digest.data = ut_params->digest; 2390 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2391 ut_params->ibuf, QUOTE_512_BYTES); 2392 2393 sym_op->auth.data.offset = 0; 2394 sym_op->auth.data.length = QUOTE_512_BYTES; 2395 2396 /* Copy IV at the end of the crypto operation */ 2397 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2398 iv, CIPHER_IV_LENGTH_AES_CBC); 2399 2400 sym_op->cipher.data.offset = 0; 2401 sym_op->cipher.data.length = QUOTE_512_BYTES; 2402 2403 /* Process crypto operation */ 2404 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2405 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2406 ut_params->op); 2407 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2408 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2409 ut_params->op, 1, 1, 0, 0); 2410 else 2411 TEST_ASSERT_NOT_NULL( 2412 process_crypto_request(ts_params->valid_devs[0], 2413 ut_params->op), 2414 "failed to process sym crypto op"); 2415 2416 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2417 "crypto op processing failed"); 2418 2419 ut_params->obuf = ut_params->op->sym->m_src; 2420 2421 /* Validate obuf */ 2422 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2423 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2424 catch_22_quote, 2425 QUOTE_512_BYTES, 2426 "Plaintext data not as expected"); 2427 2428 /* Validate obuf */ 2429 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2430 "Digest verification failed"); 2431 2432 return TEST_SUCCESS; 2433 } 2434 2435 /* ***** SNOW 3G Tests ***** */ 2436 static int 2437 create_wireless_algo_hash_session(uint8_t dev_id, 2438 const uint8_t *key, const uint8_t key_len, 2439 const uint8_t iv_len, const uint8_t auth_len, 2440 enum rte_crypto_auth_operation op, 2441 enum rte_crypto_auth_algorithm algo) 2442 { 2443 uint8_t hash_key[key_len]; 2444 int status; 2445 2446 struct crypto_testsuite_params *ts_params = &testsuite_params; 2447 struct crypto_unittest_params *ut_params = &unittest_params; 2448 2449 memcpy(hash_key, key, key_len); 2450 2451 debug_hexdump(stdout, "key:", key, key_len); 2452 2453 /* Setup Authentication Parameters */ 2454 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2455 ut_params->auth_xform.next = NULL; 2456 2457 ut_params->auth_xform.auth.op = op; 2458 ut_params->auth_xform.auth.algo = algo; 2459 ut_params->auth_xform.auth.key.length = key_len; 2460 ut_params->auth_xform.auth.key.data = hash_key; 2461 ut_params->auth_xform.auth.digest_length = auth_len; 2462 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2463 ut_params->auth_xform.auth.iv.length = iv_len; 2464 ut_params->sess = rte_cryptodev_sym_session_create( 2465 ts_params->session_mpool); 2466 2467 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2468 &ut_params->auth_xform, 2469 ts_params->session_priv_mpool); 2470 if (status == -ENOTSUP) 2471 return TEST_SKIPPED; 2472 2473 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2474 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2475 return 0; 2476 } 2477 2478 static int 2479 create_wireless_algo_cipher_session(uint8_t dev_id, 2480 enum rte_crypto_cipher_operation op, 2481 enum rte_crypto_cipher_algorithm algo, 2482 const uint8_t *key, const uint8_t key_len, 2483 uint8_t iv_len) 2484 { 2485 uint8_t cipher_key[key_len]; 2486 int status; 2487 struct crypto_testsuite_params *ts_params = &testsuite_params; 2488 struct crypto_unittest_params *ut_params = &unittest_params; 2489 2490 memcpy(cipher_key, key, key_len); 2491 2492 /* Setup Cipher Parameters */ 2493 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2494 ut_params->cipher_xform.next = NULL; 2495 2496 ut_params->cipher_xform.cipher.algo = algo; 2497 ut_params->cipher_xform.cipher.op = op; 2498 ut_params->cipher_xform.cipher.key.data = cipher_key; 2499 ut_params->cipher_xform.cipher.key.length = key_len; 2500 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2501 ut_params->cipher_xform.cipher.iv.length = iv_len; 2502 2503 debug_hexdump(stdout, "key:", key, key_len); 2504 2505 /* Create Crypto session */ 2506 ut_params->sess = rte_cryptodev_sym_session_create( 2507 ts_params->session_mpool); 2508 2509 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2510 &ut_params->cipher_xform, 2511 ts_params->session_priv_mpool); 2512 if (status == -ENOTSUP) 2513 return TEST_SKIPPED; 2514 2515 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2516 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2517 return 0; 2518 } 2519 2520 static int 2521 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2522 unsigned int cipher_len, 2523 unsigned int cipher_offset) 2524 { 2525 struct crypto_testsuite_params *ts_params = &testsuite_params; 2526 struct crypto_unittest_params *ut_params = &unittest_params; 2527 2528 /* Generate Crypto op data structure */ 2529 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2530 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2531 TEST_ASSERT_NOT_NULL(ut_params->op, 2532 "Failed to allocate pktmbuf offload"); 2533 2534 /* Set crypto operation data parameters */ 2535 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2536 2537 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2538 2539 /* set crypto operation source mbuf */ 2540 sym_op->m_src = ut_params->ibuf; 2541 2542 /* iv */ 2543 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2544 iv, iv_len); 2545 sym_op->cipher.data.length = cipher_len; 2546 sym_op->cipher.data.offset = cipher_offset; 2547 return 0; 2548 } 2549 2550 static int 2551 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2552 unsigned int cipher_len, 2553 unsigned int cipher_offset) 2554 { 2555 struct crypto_testsuite_params *ts_params = &testsuite_params; 2556 struct crypto_unittest_params *ut_params = &unittest_params; 2557 2558 /* Generate Crypto op data structure */ 2559 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2560 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2561 TEST_ASSERT_NOT_NULL(ut_params->op, 2562 "Failed to allocate pktmbuf offload"); 2563 2564 /* Set crypto operation data parameters */ 2565 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2566 2567 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2568 2569 /* set crypto operation source mbuf */ 2570 sym_op->m_src = ut_params->ibuf; 2571 sym_op->m_dst = ut_params->obuf; 2572 2573 /* iv */ 2574 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2575 iv, iv_len); 2576 sym_op->cipher.data.length = cipher_len; 2577 sym_op->cipher.data.offset = cipher_offset; 2578 return 0; 2579 } 2580 2581 static int 2582 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2583 enum rte_crypto_cipher_operation cipher_op, 2584 enum rte_crypto_auth_operation auth_op, 2585 enum rte_crypto_auth_algorithm auth_algo, 2586 enum rte_crypto_cipher_algorithm cipher_algo, 2587 const uint8_t *key, uint8_t key_len, 2588 uint8_t auth_iv_len, uint8_t auth_len, 2589 uint8_t cipher_iv_len) 2590 2591 { 2592 uint8_t cipher_auth_key[key_len]; 2593 int status; 2594 2595 struct crypto_testsuite_params *ts_params = &testsuite_params; 2596 struct crypto_unittest_params *ut_params = &unittest_params; 2597 2598 memcpy(cipher_auth_key, key, key_len); 2599 2600 /* Setup Authentication Parameters */ 2601 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2602 ut_params->auth_xform.next = NULL; 2603 2604 ut_params->auth_xform.auth.op = auth_op; 2605 ut_params->auth_xform.auth.algo = auth_algo; 2606 ut_params->auth_xform.auth.key.length = key_len; 2607 /* Hash key = cipher key */ 2608 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2609 ut_params->auth_xform.auth.digest_length = auth_len; 2610 /* Auth IV will be after cipher IV */ 2611 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2612 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2613 2614 /* Setup Cipher Parameters */ 2615 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2616 ut_params->cipher_xform.next = &ut_params->auth_xform; 2617 2618 ut_params->cipher_xform.cipher.algo = cipher_algo; 2619 ut_params->cipher_xform.cipher.op = cipher_op; 2620 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2621 ut_params->cipher_xform.cipher.key.length = key_len; 2622 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2623 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2624 2625 debug_hexdump(stdout, "key:", key, key_len); 2626 2627 /* Create Crypto session*/ 2628 ut_params->sess = rte_cryptodev_sym_session_create( 2629 ts_params->session_mpool); 2630 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2631 2632 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2633 &ut_params->cipher_xform, 2634 ts_params->session_priv_mpool); 2635 if (status == -ENOTSUP) 2636 return TEST_SKIPPED; 2637 2638 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2639 return 0; 2640 } 2641 2642 static int 2643 create_wireless_cipher_auth_session(uint8_t dev_id, 2644 enum rte_crypto_cipher_operation cipher_op, 2645 enum rte_crypto_auth_operation auth_op, 2646 enum rte_crypto_auth_algorithm auth_algo, 2647 enum rte_crypto_cipher_algorithm cipher_algo, 2648 const struct wireless_test_data *tdata) 2649 { 2650 const uint8_t key_len = tdata->key.len; 2651 uint8_t cipher_auth_key[key_len]; 2652 int status; 2653 2654 struct crypto_testsuite_params *ts_params = &testsuite_params; 2655 struct crypto_unittest_params *ut_params = &unittest_params; 2656 const uint8_t *key = tdata->key.data; 2657 const uint8_t auth_len = tdata->digest.len; 2658 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2659 uint8_t auth_iv_len = tdata->auth_iv.len; 2660 2661 memcpy(cipher_auth_key, key, key_len); 2662 2663 /* Setup Authentication Parameters */ 2664 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2665 ut_params->auth_xform.next = NULL; 2666 2667 ut_params->auth_xform.auth.op = auth_op; 2668 ut_params->auth_xform.auth.algo = auth_algo; 2669 ut_params->auth_xform.auth.key.length = key_len; 2670 /* Hash key = cipher key */ 2671 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2672 ut_params->auth_xform.auth.digest_length = auth_len; 2673 /* Auth IV will be after cipher IV */ 2674 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2675 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2676 2677 /* Setup Cipher Parameters */ 2678 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2679 ut_params->cipher_xform.next = &ut_params->auth_xform; 2680 2681 ut_params->cipher_xform.cipher.algo = cipher_algo; 2682 ut_params->cipher_xform.cipher.op = cipher_op; 2683 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2684 ut_params->cipher_xform.cipher.key.length = key_len; 2685 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2686 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2687 2688 2689 debug_hexdump(stdout, "key:", key, key_len); 2690 2691 /* Create Crypto session*/ 2692 ut_params->sess = rte_cryptodev_sym_session_create( 2693 ts_params->session_mpool); 2694 2695 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2696 &ut_params->cipher_xform, 2697 ts_params->session_priv_mpool); 2698 if (status == -ENOTSUP) 2699 return TEST_SKIPPED; 2700 2701 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2702 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2703 return 0; 2704 } 2705 2706 static int 2707 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2708 const struct wireless_test_data *tdata) 2709 { 2710 return create_wireless_cipher_auth_session(dev_id, 2711 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2712 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2713 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2714 } 2715 2716 static int 2717 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2718 enum rte_crypto_cipher_operation cipher_op, 2719 enum rte_crypto_auth_operation auth_op, 2720 enum rte_crypto_auth_algorithm auth_algo, 2721 enum rte_crypto_cipher_algorithm cipher_algo, 2722 const uint8_t *key, const uint8_t key_len, 2723 uint8_t auth_iv_len, uint8_t auth_len, 2724 uint8_t cipher_iv_len) 2725 { 2726 uint8_t auth_cipher_key[key_len]; 2727 int status; 2728 struct crypto_testsuite_params *ts_params = &testsuite_params; 2729 struct crypto_unittest_params *ut_params = &unittest_params; 2730 2731 memcpy(auth_cipher_key, key, key_len); 2732 2733 /* Setup Authentication Parameters */ 2734 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2735 ut_params->auth_xform.auth.op = auth_op; 2736 ut_params->auth_xform.next = &ut_params->cipher_xform; 2737 ut_params->auth_xform.auth.algo = auth_algo; 2738 ut_params->auth_xform.auth.key.length = key_len; 2739 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2740 ut_params->auth_xform.auth.digest_length = auth_len; 2741 /* Auth IV will be after cipher IV */ 2742 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2743 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2744 2745 /* Setup Cipher Parameters */ 2746 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2747 ut_params->cipher_xform.next = NULL; 2748 ut_params->cipher_xform.cipher.algo = cipher_algo; 2749 ut_params->cipher_xform.cipher.op = cipher_op; 2750 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2751 ut_params->cipher_xform.cipher.key.length = key_len; 2752 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2753 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2754 2755 debug_hexdump(stdout, "key:", key, key_len); 2756 2757 /* Create Crypto session*/ 2758 ut_params->sess = rte_cryptodev_sym_session_create( 2759 ts_params->session_mpool); 2760 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2761 2762 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2763 ut_params->auth_xform.next = NULL; 2764 ut_params->cipher_xform.next = &ut_params->auth_xform; 2765 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2766 &ut_params->cipher_xform, 2767 ts_params->session_priv_mpool); 2768 2769 } else 2770 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2771 &ut_params->auth_xform, 2772 ts_params->session_priv_mpool); 2773 2774 if (status == -ENOTSUP) 2775 return TEST_SKIPPED; 2776 2777 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2778 2779 return 0; 2780 } 2781 2782 static int 2783 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2784 unsigned int auth_tag_len, 2785 const uint8_t *iv, unsigned int iv_len, 2786 unsigned int data_pad_len, 2787 enum rte_crypto_auth_operation op, 2788 unsigned int auth_len, unsigned int auth_offset) 2789 { 2790 struct crypto_testsuite_params *ts_params = &testsuite_params; 2791 2792 struct crypto_unittest_params *ut_params = &unittest_params; 2793 2794 /* Generate Crypto op data structure */ 2795 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2796 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2797 TEST_ASSERT_NOT_NULL(ut_params->op, 2798 "Failed to allocate pktmbuf offload"); 2799 2800 /* Set crypto operation data parameters */ 2801 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2802 2803 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2804 2805 /* set crypto operation source mbuf */ 2806 sym_op->m_src = ut_params->ibuf; 2807 2808 /* iv */ 2809 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2810 iv, iv_len); 2811 /* digest */ 2812 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2813 ut_params->ibuf, auth_tag_len); 2814 2815 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2816 "no room to append auth tag"); 2817 ut_params->digest = sym_op->auth.digest.data; 2818 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2819 ut_params->ibuf, data_pad_len); 2820 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2821 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2822 else 2823 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2824 2825 debug_hexdump(stdout, "digest:", 2826 sym_op->auth.digest.data, 2827 auth_tag_len); 2828 2829 sym_op->auth.data.length = auth_len; 2830 sym_op->auth.data.offset = auth_offset; 2831 2832 return 0; 2833 } 2834 2835 static int 2836 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2837 enum rte_crypto_auth_operation op) 2838 { 2839 struct crypto_testsuite_params *ts_params = &testsuite_params; 2840 struct crypto_unittest_params *ut_params = &unittest_params; 2841 2842 const uint8_t *auth_tag = tdata->digest.data; 2843 const unsigned int auth_tag_len = tdata->digest.len; 2844 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2845 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2846 2847 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2848 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2849 const uint8_t *auth_iv = tdata->auth_iv.data; 2850 const uint8_t auth_iv_len = tdata->auth_iv.len; 2851 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2852 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2853 2854 /* Generate Crypto op data structure */ 2855 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2856 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2857 TEST_ASSERT_NOT_NULL(ut_params->op, 2858 "Failed to allocate pktmbuf offload"); 2859 /* Set crypto operation data parameters */ 2860 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2861 2862 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2863 2864 /* set crypto operation source mbuf */ 2865 sym_op->m_src = ut_params->ibuf; 2866 2867 /* digest */ 2868 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2869 ut_params->ibuf, auth_tag_len); 2870 2871 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2872 "no room to append auth tag"); 2873 ut_params->digest = sym_op->auth.digest.data; 2874 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2875 ut_params->ibuf, data_pad_len); 2876 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2877 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2878 else 2879 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2880 2881 debug_hexdump(stdout, "digest:", 2882 sym_op->auth.digest.data, 2883 auth_tag_len); 2884 2885 /* Copy cipher and auth IVs at the end of the crypto operation */ 2886 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2887 IV_OFFSET); 2888 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2889 iv_ptr += cipher_iv_len; 2890 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2891 2892 sym_op->cipher.data.length = cipher_len; 2893 sym_op->cipher.data.offset = 0; 2894 sym_op->auth.data.length = auth_len; 2895 sym_op->auth.data.offset = 0; 2896 2897 return 0; 2898 } 2899 2900 static int 2901 create_zuc_cipher_hash_generate_operation( 2902 const struct wireless_test_data *tdata) 2903 { 2904 return create_wireless_cipher_hash_operation(tdata, 2905 RTE_CRYPTO_AUTH_OP_GENERATE); 2906 } 2907 2908 static int 2909 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2910 const unsigned auth_tag_len, 2911 const uint8_t *auth_iv, uint8_t auth_iv_len, 2912 unsigned data_pad_len, 2913 enum rte_crypto_auth_operation op, 2914 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2915 const unsigned cipher_len, const unsigned cipher_offset, 2916 const unsigned auth_len, const unsigned auth_offset) 2917 { 2918 struct crypto_testsuite_params *ts_params = &testsuite_params; 2919 struct crypto_unittest_params *ut_params = &unittest_params; 2920 2921 enum rte_crypto_cipher_algorithm cipher_algo = 2922 ut_params->cipher_xform.cipher.algo; 2923 enum rte_crypto_auth_algorithm auth_algo = 2924 ut_params->auth_xform.auth.algo; 2925 2926 /* Generate Crypto op data structure */ 2927 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2928 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2929 TEST_ASSERT_NOT_NULL(ut_params->op, 2930 "Failed to allocate pktmbuf offload"); 2931 /* Set crypto operation data parameters */ 2932 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2933 2934 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2935 2936 /* set crypto operation source mbuf */ 2937 sym_op->m_src = ut_params->ibuf; 2938 2939 /* digest */ 2940 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2941 ut_params->ibuf, auth_tag_len); 2942 2943 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2944 "no room to append auth tag"); 2945 ut_params->digest = sym_op->auth.digest.data; 2946 2947 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2948 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2949 ut_params->ibuf, data_pad_len); 2950 } else { 2951 struct rte_mbuf *m = ut_params->ibuf; 2952 unsigned int offset = data_pad_len; 2953 2954 while (offset > m->data_len && m->next != NULL) { 2955 offset -= m->data_len; 2956 m = m->next; 2957 } 2958 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2959 m, offset); 2960 } 2961 2962 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2963 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2964 else 2965 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2966 2967 debug_hexdump(stdout, "digest:", 2968 sym_op->auth.digest.data, 2969 auth_tag_len); 2970 2971 /* Copy cipher and auth IVs at the end of the crypto operation */ 2972 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2973 IV_OFFSET); 2974 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2975 iv_ptr += cipher_iv_len; 2976 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2977 2978 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2979 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2980 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2981 sym_op->cipher.data.length = cipher_len; 2982 sym_op->cipher.data.offset = cipher_offset; 2983 } else { 2984 sym_op->cipher.data.length = cipher_len >> 3; 2985 sym_op->cipher.data.offset = cipher_offset >> 3; 2986 } 2987 2988 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2989 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2990 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2991 sym_op->auth.data.length = auth_len; 2992 sym_op->auth.data.offset = auth_offset; 2993 } else { 2994 sym_op->auth.data.length = auth_len >> 3; 2995 sym_op->auth.data.offset = auth_offset >> 3; 2996 } 2997 2998 return 0; 2999 } 3000 3001 static int 3002 create_wireless_algo_auth_cipher_operation( 3003 const uint8_t *auth_tag, unsigned int auth_tag_len, 3004 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3005 const uint8_t *auth_iv, uint8_t auth_iv_len, 3006 unsigned int data_pad_len, 3007 unsigned int cipher_len, unsigned int cipher_offset, 3008 unsigned int auth_len, unsigned int auth_offset, 3009 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3010 { 3011 struct crypto_testsuite_params *ts_params = &testsuite_params; 3012 struct crypto_unittest_params *ut_params = &unittest_params; 3013 3014 enum rte_crypto_cipher_algorithm cipher_algo = 3015 ut_params->cipher_xform.cipher.algo; 3016 enum rte_crypto_auth_algorithm auth_algo = 3017 ut_params->auth_xform.auth.algo; 3018 3019 /* Generate Crypto op data structure */ 3020 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3021 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3022 TEST_ASSERT_NOT_NULL(ut_params->op, 3023 "Failed to allocate pktmbuf offload"); 3024 3025 /* Set crypto operation data parameters */ 3026 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3027 3028 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3029 3030 /* set crypto operation mbufs */ 3031 sym_op->m_src = ut_params->ibuf; 3032 if (op_mode == OUT_OF_PLACE) 3033 sym_op->m_dst = ut_params->obuf; 3034 3035 /* digest */ 3036 if (!do_sgl) { 3037 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3038 (op_mode == IN_PLACE ? 3039 ut_params->ibuf : ut_params->obuf), 3040 uint8_t *, data_pad_len); 3041 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3042 (op_mode == IN_PLACE ? 3043 ut_params->ibuf : ut_params->obuf), 3044 data_pad_len); 3045 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3046 } else { 3047 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3048 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3049 sym_op->m_src : sym_op->m_dst); 3050 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3051 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3052 sgl_buf = sgl_buf->next; 3053 } 3054 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3055 uint8_t *, remaining_off); 3056 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3057 remaining_off); 3058 memset(sym_op->auth.digest.data, 0, remaining_off); 3059 while (sgl_buf->next != NULL) { 3060 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3061 0, rte_pktmbuf_data_len(sgl_buf)); 3062 sgl_buf = sgl_buf->next; 3063 } 3064 } 3065 3066 /* Copy digest for the verification */ 3067 if (verify) 3068 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3069 3070 /* Copy cipher and auth IVs at the end of the crypto operation */ 3071 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3072 ut_params->op, uint8_t *, IV_OFFSET); 3073 3074 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3075 iv_ptr += cipher_iv_len; 3076 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3077 3078 /* Only copy over the offset data needed from src to dst in OOP, 3079 * if the auth and cipher offsets are not aligned 3080 */ 3081 if (op_mode == OUT_OF_PLACE) { 3082 if (cipher_offset > auth_offset) 3083 rte_memcpy( 3084 rte_pktmbuf_mtod_offset( 3085 sym_op->m_dst, 3086 uint8_t *, auth_offset >> 3), 3087 rte_pktmbuf_mtod_offset( 3088 sym_op->m_src, 3089 uint8_t *, auth_offset >> 3), 3090 ((cipher_offset >> 3) - (auth_offset >> 3))); 3091 } 3092 3093 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3094 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3095 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3096 sym_op->cipher.data.length = cipher_len; 3097 sym_op->cipher.data.offset = cipher_offset; 3098 } else { 3099 sym_op->cipher.data.length = cipher_len >> 3; 3100 sym_op->cipher.data.offset = cipher_offset >> 3; 3101 } 3102 3103 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3104 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3105 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3106 sym_op->auth.data.length = auth_len; 3107 sym_op->auth.data.offset = auth_offset; 3108 } else { 3109 sym_op->auth.data.length = auth_len >> 3; 3110 sym_op->auth.data.offset = auth_offset >> 3; 3111 } 3112 3113 return 0; 3114 } 3115 3116 static int 3117 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3118 { 3119 struct crypto_testsuite_params *ts_params = &testsuite_params; 3120 struct crypto_unittest_params *ut_params = &unittest_params; 3121 3122 int retval; 3123 unsigned plaintext_pad_len; 3124 unsigned plaintext_len; 3125 uint8_t *plaintext; 3126 struct rte_cryptodev_info dev_info; 3127 3128 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3129 uint64_t feat_flags = dev_info.feature_flags; 3130 3131 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3132 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3133 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3134 return TEST_SKIPPED; 3135 } 3136 3137 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3138 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3139 printf("Device doesn't support RAW data-path APIs.\n"); 3140 return TEST_SKIPPED; 3141 } 3142 3143 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3144 return TEST_SKIPPED; 3145 3146 /* Verify the capabilities */ 3147 struct rte_cryptodev_sym_capability_idx cap_idx; 3148 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3149 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3150 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3151 &cap_idx) == NULL) 3152 return TEST_SKIPPED; 3153 3154 /* Create SNOW 3G session */ 3155 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3156 tdata->key.data, tdata->key.len, 3157 tdata->auth_iv.len, tdata->digest.len, 3158 RTE_CRYPTO_AUTH_OP_GENERATE, 3159 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3160 if (retval < 0) 3161 return retval; 3162 3163 /* alloc mbuf and set payload */ 3164 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3165 3166 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3167 rte_pktmbuf_tailroom(ut_params->ibuf)); 3168 3169 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3170 /* Append data which is padded to a multiple of */ 3171 /* the algorithms block size */ 3172 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3173 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3174 plaintext_pad_len); 3175 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3176 3177 /* Create SNOW 3G operation */ 3178 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3179 tdata->auth_iv.data, tdata->auth_iv.len, 3180 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3181 tdata->validAuthLenInBits.len, 3182 0); 3183 if (retval < 0) 3184 return retval; 3185 3186 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3187 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3188 ut_params->op, 0, 1, 1, 0); 3189 else 3190 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3191 ut_params->op); 3192 ut_params->obuf = ut_params->op->sym->m_src; 3193 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3194 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3195 + plaintext_pad_len; 3196 3197 /* Validate obuf */ 3198 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3199 ut_params->digest, 3200 tdata->digest.data, 3201 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3202 "SNOW 3G Generated auth tag not as expected"); 3203 3204 return 0; 3205 } 3206 3207 static int 3208 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3209 { 3210 struct crypto_testsuite_params *ts_params = &testsuite_params; 3211 struct crypto_unittest_params *ut_params = &unittest_params; 3212 3213 int retval; 3214 unsigned plaintext_pad_len; 3215 unsigned plaintext_len; 3216 uint8_t *plaintext; 3217 struct rte_cryptodev_info dev_info; 3218 3219 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3220 uint64_t feat_flags = dev_info.feature_flags; 3221 3222 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3223 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3224 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3225 return TEST_SKIPPED; 3226 } 3227 3228 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3229 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3230 printf("Device doesn't support RAW data-path APIs.\n"); 3231 return TEST_SKIPPED; 3232 } 3233 3234 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3235 return TEST_SKIPPED; 3236 3237 /* Verify the capabilities */ 3238 struct rte_cryptodev_sym_capability_idx cap_idx; 3239 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3240 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3241 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3242 &cap_idx) == NULL) 3243 return TEST_SKIPPED; 3244 3245 /* Create SNOW 3G session */ 3246 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3247 tdata->key.data, tdata->key.len, 3248 tdata->auth_iv.len, tdata->digest.len, 3249 RTE_CRYPTO_AUTH_OP_VERIFY, 3250 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3251 if (retval < 0) 3252 return retval; 3253 /* alloc mbuf and set payload */ 3254 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3255 3256 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3257 rte_pktmbuf_tailroom(ut_params->ibuf)); 3258 3259 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3260 /* Append data which is padded to a multiple of */ 3261 /* the algorithms block size */ 3262 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3263 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3264 plaintext_pad_len); 3265 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3266 3267 /* Create SNOW 3G operation */ 3268 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3269 tdata->digest.len, 3270 tdata->auth_iv.data, tdata->auth_iv.len, 3271 plaintext_pad_len, 3272 RTE_CRYPTO_AUTH_OP_VERIFY, 3273 tdata->validAuthLenInBits.len, 3274 0); 3275 if (retval < 0) 3276 return retval; 3277 3278 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3279 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3280 ut_params->op, 0, 1, 1, 0); 3281 else 3282 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3283 ut_params->op); 3284 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3285 ut_params->obuf = ut_params->op->sym->m_src; 3286 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3287 + plaintext_pad_len; 3288 3289 /* Validate obuf */ 3290 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3291 return 0; 3292 else 3293 return -1; 3294 3295 return 0; 3296 } 3297 3298 static int 3299 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3300 { 3301 struct crypto_testsuite_params *ts_params = &testsuite_params; 3302 struct crypto_unittest_params *ut_params = &unittest_params; 3303 3304 int retval; 3305 unsigned plaintext_pad_len; 3306 unsigned plaintext_len; 3307 uint8_t *plaintext; 3308 struct rte_cryptodev_info dev_info; 3309 3310 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3311 uint64_t feat_flags = dev_info.feature_flags; 3312 3313 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3314 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3315 printf("Device doesn't support RAW data-path APIs.\n"); 3316 return TEST_SKIPPED; 3317 } 3318 3319 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3320 return TEST_SKIPPED; 3321 3322 /* Verify the capabilities */ 3323 struct rte_cryptodev_sym_capability_idx cap_idx; 3324 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3325 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3326 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3327 &cap_idx) == NULL) 3328 return TEST_SKIPPED; 3329 3330 /* Create KASUMI session */ 3331 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3332 tdata->key.data, tdata->key.len, 3333 0, tdata->digest.len, 3334 RTE_CRYPTO_AUTH_OP_GENERATE, 3335 RTE_CRYPTO_AUTH_KASUMI_F9); 3336 if (retval < 0) 3337 return retval; 3338 3339 /* alloc mbuf and set payload */ 3340 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3341 3342 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3343 rte_pktmbuf_tailroom(ut_params->ibuf)); 3344 3345 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3346 /* Append data which is padded to a multiple of */ 3347 /* the algorithms block size */ 3348 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3349 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3350 plaintext_pad_len); 3351 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3352 3353 /* Create KASUMI operation */ 3354 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3355 NULL, 0, 3356 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3357 tdata->plaintext.len, 3358 0); 3359 if (retval < 0) 3360 return retval; 3361 3362 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3363 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3364 ut_params->op); 3365 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3366 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3367 ut_params->op, 0, 1, 1, 0); 3368 else 3369 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3370 ut_params->op); 3371 3372 ut_params->obuf = ut_params->op->sym->m_src; 3373 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3374 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3375 + plaintext_pad_len; 3376 3377 /* Validate obuf */ 3378 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3379 ut_params->digest, 3380 tdata->digest.data, 3381 DIGEST_BYTE_LENGTH_KASUMI_F9, 3382 "KASUMI Generated auth tag not as expected"); 3383 3384 return 0; 3385 } 3386 3387 static int 3388 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3389 { 3390 struct crypto_testsuite_params *ts_params = &testsuite_params; 3391 struct crypto_unittest_params *ut_params = &unittest_params; 3392 3393 int retval; 3394 unsigned plaintext_pad_len; 3395 unsigned plaintext_len; 3396 uint8_t *plaintext; 3397 struct rte_cryptodev_info dev_info; 3398 3399 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3400 uint64_t feat_flags = dev_info.feature_flags; 3401 3402 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3403 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3404 printf("Device doesn't support RAW data-path APIs.\n"); 3405 return TEST_SKIPPED; 3406 } 3407 3408 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3409 return TEST_SKIPPED; 3410 3411 /* Verify the capabilities */ 3412 struct rte_cryptodev_sym_capability_idx cap_idx; 3413 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3414 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3415 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3416 &cap_idx) == NULL) 3417 return TEST_SKIPPED; 3418 3419 /* Create KASUMI session */ 3420 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3421 tdata->key.data, tdata->key.len, 3422 0, tdata->digest.len, 3423 RTE_CRYPTO_AUTH_OP_VERIFY, 3424 RTE_CRYPTO_AUTH_KASUMI_F9); 3425 if (retval < 0) 3426 return retval; 3427 /* alloc mbuf and set payload */ 3428 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3429 3430 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3431 rte_pktmbuf_tailroom(ut_params->ibuf)); 3432 3433 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3434 /* Append data which is padded to a multiple */ 3435 /* of the algorithms block size */ 3436 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3437 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3438 plaintext_pad_len); 3439 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3440 3441 /* Create KASUMI operation */ 3442 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3443 tdata->digest.len, 3444 NULL, 0, 3445 plaintext_pad_len, 3446 RTE_CRYPTO_AUTH_OP_VERIFY, 3447 tdata->plaintext.len, 3448 0); 3449 if (retval < 0) 3450 return retval; 3451 3452 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3453 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3454 ut_params->op, 0, 1, 1, 0); 3455 else 3456 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3457 ut_params->op); 3458 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3459 ut_params->obuf = ut_params->op->sym->m_src; 3460 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3461 + plaintext_pad_len; 3462 3463 /* Validate obuf */ 3464 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3465 return 0; 3466 else 3467 return -1; 3468 3469 return 0; 3470 } 3471 3472 static int 3473 test_snow3g_hash_generate_test_case_1(void) 3474 { 3475 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3476 } 3477 3478 static int 3479 test_snow3g_hash_generate_test_case_2(void) 3480 { 3481 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3482 } 3483 3484 static int 3485 test_snow3g_hash_generate_test_case_3(void) 3486 { 3487 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3488 } 3489 3490 static int 3491 test_snow3g_hash_generate_test_case_4(void) 3492 { 3493 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3494 } 3495 3496 static int 3497 test_snow3g_hash_generate_test_case_5(void) 3498 { 3499 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3500 } 3501 3502 static int 3503 test_snow3g_hash_generate_test_case_6(void) 3504 { 3505 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3506 } 3507 3508 static int 3509 test_snow3g_hash_verify_test_case_1(void) 3510 { 3511 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3512 3513 } 3514 3515 static int 3516 test_snow3g_hash_verify_test_case_2(void) 3517 { 3518 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3519 } 3520 3521 static int 3522 test_snow3g_hash_verify_test_case_3(void) 3523 { 3524 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3525 } 3526 3527 static int 3528 test_snow3g_hash_verify_test_case_4(void) 3529 { 3530 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3531 } 3532 3533 static int 3534 test_snow3g_hash_verify_test_case_5(void) 3535 { 3536 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3537 } 3538 3539 static int 3540 test_snow3g_hash_verify_test_case_6(void) 3541 { 3542 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3543 } 3544 3545 static int 3546 test_kasumi_hash_generate_test_case_1(void) 3547 { 3548 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3549 } 3550 3551 static int 3552 test_kasumi_hash_generate_test_case_2(void) 3553 { 3554 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3555 } 3556 3557 static int 3558 test_kasumi_hash_generate_test_case_3(void) 3559 { 3560 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3561 } 3562 3563 static int 3564 test_kasumi_hash_generate_test_case_4(void) 3565 { 3566 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3567 } 3568 3569 static int 3570 test_kasumi_hash_generate_test_case_5(void) 3571 { 3572 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3573 } 3574 3575 static int 3576 test_kasumi_hash_generate_test_case_6(void) 3577 { 3578 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3579 } 3580 3581 static int 3582 test_kasumi_hash_verify_test_case_1(void) 3583 { 3584 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3585 } 3586 3587 static int 3588 test_kasumi_hash_verify_test_case_2(void) 3589 { 3590 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3591 } 3592 3593 static int 3594 test_kasumi_hash_verify_test_case_3(void) 3595 { 3596 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3597 } 3598 3599 static int 3600 test_kasumi_hash_verify_test_case_4(void) 3601 { 3602 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3603 } 3604 3605 static int 3606 test_kasumi_hash_verify_test_case_5(void) 3607 { 3608 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3609 } 3610 3611 static int 3612 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3613 { 3614 struct crypto_testsuite_params *ts_params = &testsuite_params; 3615 struct crypto_unittest_params *ut_params = &unittest_params; 3616 3617 int retval; 3618 uint8_t *plaintext, *ciphertext; 3619 unsigned plaintext_pad_len; 3620 unsigned plaintext_len; 3621 struct rte_cryptodev_info dev_info; 3622 3623 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3624 uint64_t feat_flags = dev_info.feature_flags; 3625 3626 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3627 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3628 printf("Device doesn't support RAW data-path APIs.\n"); 3629 return TEST_SKIPPED; 3630 } 3631 3632 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3633 return TEST_SKIPPED; 3634 3635 /* Verify the capabilities */ 3636 struct rte_cryptodev_sym_capability_idx cap_idx; 3637 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3638 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3639 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3640 &cap_idx) == NULL) 3641 return TEST_SKIPPED; 3642 3643 /* Create KASUMI session */ 3644 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3645 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3646 RTE_CRYPTO_CIPHER_KASUMI_F8, 3647 tdata->key.data, tdata->key.len, 3648 tdata->cipher_iv.len); 3649 if (retval < 0) 3650 return retval; 3651 3652 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3653 3654 /* Clear mbuf payload */ 3655 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3656 rte_pktmbuf_tailroom(ut_params->ibuf)); 3657 3658 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3659 /* Append data which is padded to a multiple */ 3660 /* of the algorithms block size */ 3661 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3662 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3663 plaintext_pad_len); 3664 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3665 3666 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3667 3668 /* Create KASUMI operation */ 3669 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3670 tdata->cipher_iv.len, 3671 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3672 tdata->validCipherOffsetInBits.len); 3673 if (retval < 0) 3674 return retval; 3675 3676 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3677 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3678 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3679 else 3680 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3681 ut_params->op); 3682 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3683 3684 ut_params->obuf = ut_params->op->sym->m_dst; 3685 if (ut_params->obuf) 3686 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3687 else 3688 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3689 3690 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3691 3692 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3693 (tdata->validCipherOffsetInBits.len >> 3); 3694 /* Validate obuf */ 3695 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3696 ciphertext, 3697 reference_ciphertext, 3698 tdata->validCipherLenInBits.len, 3699 "KASUMI Ciphertext data not as expected"); 3700 return 0; 3701 } 3702 3703 static int 3704 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3705 { 3706 struct crypto_testsuite_params *ts_params = &testsuite_params; 3707 struct crypto_unittest_params *ut_params = &unittest_params; 3708 3709 int retval; 3710 3711 unsigned int plaintext_pad_len; 3712 unsigned int plaintext_len; 3713 3714 uint8_t buffer[10000]; 3715 const uint8_t *ciphertext; 3716 3717 struct rte_cryptodev_info dev_info; 3718 3719 /* Verify the capabilities */ 3720 struct rte_cryptodev_sym_capability_idx cap_idx; 3721 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3722 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3723 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3724 &cap_idx) == NULL) 3725 return TEST_SKIPPED; 3726 3727 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3728 3729 uint64_t feat_flags = dev_info.feature_flags; 3730 3731 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3732 printf("Device doesn't support in-place scatter-gather. " 3733 "Test Skipped.\n"); 3734 return TEST_SKIPPED; 3735 } 3736 3737 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3738 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3739 printf("Device doesn't support RAW data-path APIs.\n"); 3740 return TEST_SKIPPED; 3741 } 3742 3743 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3744 return TEST_SKIPPED; 3745 3746 /* Create KASUMI session */ 3747 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3748 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3749 RTE_CRYPTO_CIPHER_KASUMI_F8, 3750 tdata->key.data, tdata->key.len, 3751 tdata->cipher_iv.len); 3752 if (retval < 0) 3753 return retval; 3754 3755 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3756 3757 3758 /* Append data which is padded to a multiple */ 3759 /* of the algorithms block size */ 3760 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3761 3762 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3763 plaintext_pad_len, 10, 0); 3764 3765 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3766 3767 /* Create KASUMI operation */ 3768 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3769 tdata->cipher_iv.len, 3770 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3771 tdata->validCipherOffsetInBits.len); 3772 if (retval < 0) 3773 return retval; 3774 3775 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3776 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3777 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3778 else 3779 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3780 ut_params->op); 3781 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3782 3783 ut_params->obuf = ut_params->op->sym->m_dst; 3784 3785 if (ut_params->obuf) 3786 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3787 plaintext_len, buffer); 3788 else 3789 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3790 tdata->validCipherOffsetInBits.len >> 3, 3791 plaintext_len, buffer); 3792 3793 /* Validate obuf */ 3794 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3795 3796 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3797 (tdata->validCipherOffsetInBits.len >> 3); 3798 /* Validate obuf */ 3799 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3800 ciphertext, 3801 reference_ciphertext, 3802 tdata->validCipherLenInBits.len, 3803 "KASUMI Ciphertext data not as expected"); 3804 return 0; 3805 } 3806 3807 static int 3808 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3809 { 3810 struct crypto_testsuite_params *ts_params = &testsuite_params; 3811 struct crypto_unittest_params *ut_params = &unittest_params; 3812 3813 int retval; 3814 uint8_t *plaintext, *ciphertext; 3815 unsigned plaintext_pad_len; 3816 unsigned plaintext_len; 3817 3818 /* Verify the capabilities */ 3819 struct rte_cryptodev_sym_capability_idx cap_idx; 3820 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3821 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3822 /* Data-path service does not support OOP */ 3823 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3824 &cap_idx) == NULL) 3825 return TEST_SKIPPED; 3826 3827 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3828 return TEST_SKIPPED; 3829 3830 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3831 return TEST_SKIPPED; 3832 3833 /* Create KASUMI session */ 3834 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3835 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3836 RTE_CRYPTO_CIPHER_KASUMI_F8, 3837 tdata->key.data, tdata->key.len, 3838 tdata->cipher_iv.len); 3839 if (retval < 0) 3840 return retval; 3841 3842 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3843 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3844 3845 /* Clear mbuf payload */ 3846 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3847 rte_pktmbuf_tailroom(ut_params->ibuf)); 3848 3849 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3850 /* Append data which is padded to a multiple */ 3851 /* of the algorithms block size */ 3852 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3853 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3854 plaintext_pad_len); 3855 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3856 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3857 3858 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3859 3860 /* Create KASUMI operation */ 3861 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3862 tdata->cipher_iv.len, 3863 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3864 tdata->validCipherOffsetInBits.len); 3865 if (retval < 0) 3866 return retval; 3867 3868 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3869 ut_params->op); 3870 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3871 3872 ut_params->obuf = ut_params->op->sym->m_dst; 3873 if (ut_params->obuf) 3874 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3875 else 3876 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3877 3878 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3879 3880 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3881 (tdata->validCipherOffsetInBits.len >> 3); 3882 /* Validate obuf */ 3883 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3884 ciphertext, 3885 reference_ciphertext, 3886 tdata->validCipherLenInBits.len, 3887 "KASUMI Ciphertext data not as expected"); 3888 return 0; 3889 } 3890 3891 static int 3892 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3893 { 3894 struct crypto_testsuite_params *ts_params = &testsuite_params; 3895 struct crypto_unittest_params *ut_params = &unittest_params; 3896 3897 int retval; 3898 unsigned int plaintext_pad_len; 3899 unsigned int plaintext_len; 3900 3901 const uint8_t *ciphertext; 3902 uint8_t buffer[2048]; 3903 3904 struct rte_cryptodev_info dev_info; 3905 3906 /* Verify the capabilities */ 3907 struct rte_cryptodev_sym_capability_idx cap_idx; 3908 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3909 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3910 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3911 &cap_idx) == NULL) 3912 return TEST_SKIPPED; 3913 3914 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3915 return TEST_SKIPPED; 3916 3917 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3918 return TEST_SKIPPED; 3919 3920 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3921 3922 uint64_t feat_flags = dev_info.feature_flags; 3923 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3924 printf("Device doesn't support out-of-place scatter-gather " 3925 "in both input and output mbufs. " 3926 "Test Skipped.\n"); 3927 return TEST_SKIPPED; 3928 } 3929 3930 /* Create KASUMI session */ 3931 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3932 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3933 RTE_CRYPTO_CIPHER_KASUMI_F8, 3934 tdata->key.data, tdata->key.len, 3935 tdata->cipher_iv.len); 3936 if (retval < 0) 3937 return retval; 3938 3939 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3940 /* Append data which is padded to a multiple */ 3941 /* of the algorithms block size */ 3942 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3943 3944 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3945 plaintext_pad_len, 10, 0); 3946 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3947 plaintext_pad_len, 3, 0); 3948 3949 /* Append data which is padded to a multiple */ 3950 /* of the algorithms block size */ 3951 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3952 3953 /* Create KASUMI operation */ 3954 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3955 tdata->cipher_iv.len, 3956 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3957 tdata->validCipherOffsetInBits.len); 3958 if (retval < 0) 3959 return retval; 3960 3961 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3962 ut_params->op); 3963 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3964 3965 ut_params->obuf = ut_params->op->sym->m_dst; 3966 if (ut_params->obuf) 3967 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3968 plaintext_pad_len, buffer); 3969 else 3970 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3971 tdata->validCipherOffsetInBits.len >> 3, 3972 plaintext_pad_len, buffer); 3973 3974 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3975 (tdata->validCipherOffsetInBits.len >> 3); 3976 /* Validate obuf */ 3977 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3978 ciphertext, 3979 reference_ciphertext, 3980 tdata->validCipherLenInBits.len, 3981 "KASUMI Ciphertext data not as expected"); 3982 return 0; 3983 } 3984 3985 3986 static int 3987 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3988 { 3989 struct crypto_testsuite_params *ts_params = &testsuite_params; 3990 struct crypto_unittest_params *ut_params = &unittest_params; 3991 3992 int retval; 3993 uint8_t *ciphertext, *plaintext; 3994 unsigned ciphertext_pad_len; 3995 unsigned ciphertext_len; 3996 3997 /* Verify the capabilities */ 3998 struct rte_cryptodev_sym_capability_idx cap_idx; 3999 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4000 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4001 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4002 &cap_idx) == NULL) 4003 return TEST_SKIPPED; 4004 4005 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4006 return TEST_SKIPPED; 4007 4008 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4009 return TEST_SKIPPED; 4010 4011 /* Create KASUMI session */ 4012 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4013 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4014 RTE_CRYPTO_CIPHER_KASUMI_F8, 4015 tdata->key.data, tdata->key.len, 4016 tdata->cipher_iv.len); 4017 if (retval < 0) 4018 return retval; 4019 4020 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4021 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4022 4023 /* Clear mbuf payload */ 4024 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4025 rte_pktmbuf_tailroom(ut_params->ibuf)); 4026 4027 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4028 /* Append data which is padded to a multiple */ 4029 /* of the algorithms block size */ 4030 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4031 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4032 ciphertext_pad_len); 4033 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4034 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4035 4036 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4037 4038 /* Create KASUMI operation */ 4039 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4040 tdata->cipher_iv.len, 4041 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4042 tdata->validCipherOffsetInBits.len); 4043 if (retval < 0) 4044 return retval; 4045 4046 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4047 ut_params->op); 4048 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4049 4050 ut_params->obuf = ut_params->op->sym->m_dst; 4051 if (ut_params->obuf) 4052 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4053 else 4054 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4055 4056 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4057 4058 const uint8_t *reference_plaintext = tdata->plaintext.data + 4059 (tdata->validCipherOffsetInBits.len >> 3); 4060 /* Validate obuf */ 4061 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4062 plaintext, 4063 reference_plaintext, 4064 tdata->validCipherLenInBits.len, 4065 "KASUMI Plaintext data not as expected"); 4066 return 0; 4067 } 4068 4069 static int 4070 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4071 { 4072 struct crypto_testsuite_params *ts_params = &testsuite_params; 4073 struct crypto_unittest_params *ut_params = &unittest_params; 4074 4075 int retval; 4076 uint8_t *ciphertext, *plaintext; 4077 unsigned ciphertext_pad_len; 4078 unsigned ciphertext_len; 4079 struct rte_cryptodev_info dev_info; 4080 4081 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4082 uint64_t feat_flags = dev_info.feature_flags; 4083 4084 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4085 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4086 printf("Device doesn't support RAW data-path APIs.\n"); 4087 return TEST_SKIPPED; 4088 } 4089 4090 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4091 return TEST_SKIPPED; 4092 4093 /* Verify the capabilities */ 4094 struct rte_cryptodev_sym_capability_idx cap_idx; 4095 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4096 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4097 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4098 &cap_idx) == NULL) 4099 return TEST_SKIPPED; 4100 4101 /* Create KASUMI session */ 4102 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4103 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4104 RTE_CRYPTO_CIPHER_KASUMI_F8, 4105 tdata->key.data, tdata->key.len, 4106 tdata->cipher_iv.len); 4107 if (retval < 0) 4108 return retval; 4109 4110 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4111 4112 /* Clear mbuf payload */ 4113 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4114 rte_pktmbuf_tailroom(ut_params->ibuf)); 4115 4116 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4117 /* Append data which is padded to a multiple */ 4118 /* of the algorithms block size */ 4119 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4120 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4121 ciphertext_pad_len); 4122 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4123 4124 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4125 4126 /* Create KASUMI operation */ 4127 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4128 tdata->cipher_iv.len, 4129 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4130 tdata->validCipherOffsetInBits.len); 4131 if (retval < 0) 4132 return retval; 4133 4134 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4135 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4136 ut_params->op, 1, 0, 1, 0); 4137 else 4138 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4139 ut_params->op); 4140 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4141 4142 ut_params->obuf = ut_params->op->sym->m_dst; 4143 if (ut_params->obuf) 4144 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4145 else 4146 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4147 4148 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4149 4150 const uint8_t *reference_plaintext = tdata->plaintext.data + 4151 (tdata->validCipherOffsetInBits.len >> 3); 4152 /* Validate obuf */ 4153 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4154 plaintext, 4155 reference_plaintext, 4156 tdata->validCipherLenInBits.len, 4157 "KASUMI Plaintext data not as expected"); 4158 return 0; 4159 } 4160 4161 static int 4162 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4163 { 4164 struct crypto_testsuite_params *ts_params = &testsuite_params; 4165 struct crypto_unittest_params *ut_params = &unittest_params; 4166 4167 int retval; 4168 uint8_t *plaintext, *ciphertext; 4169 unsigned plaintext_pad_len; 4170 unsigned plaintext_len; 4171 struct rte_cryptodev_info dev_info; 4172 4173 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4174 uint64_t feat_flags = dev_info.feature_flags; 4175 4176 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4177 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4178 printf("Device doesn't support RAW data-path APIs.\n"); 4179 return TEST_SKIPPED; 4180 } 4181 4182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4183 return TEST_SKIPPED; 4184 4185 /* Verify the capabilities */ 4186 struct rte_cryptodev_sym_capability_idx cap_idx; 4187 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4188 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4189 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4190 &cap_idx) == NULL) 4191 return TEST_SKIPPED; 4192 4193 /* Create SNOW 3G session */ 4194 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4195 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4196 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4197 tdata->key.data, tdata->key.len, 4198 tdata->cipher_iv.len); 4199 if (retval < 0) 4200 return retval; 4201 4202 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4203 4204 /* Clear mbuf payload */ 4205 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4206 rte_pktmbuf_tailroom(ut_params->ibuf)); 4207 4208 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4209 /* Append data which is padded to a multiple of */ 4210 /* the algorithms block size */ 4211 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4212 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4213 plaintext_pad_len); 4214 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4215 4216 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4217 4218 /* Create SNOW 3G operation */ 4219 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4220 tdata->cipher_iv.len, 4221 tdata->validCipherLenInBits.len, 4222 0); 4223 if (retval < 0) 4224 return retval; 4225 4226 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4227 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4228 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4229 else 4230 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4231 ut_params->op); 4232 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4233 4234 ut_params->obuf = ut_params->op->sym->m_dst; 4235 if (ut_params->obuf) 4236 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4237 else 4238 ciphertext = plaintext; 4239 4240 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4241 4242 /* Validate obuf */ 4243 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4244 ciphertext, 4245 tdata->ciphertext.data, 4246 tdata->validDataLenInBits.len, 4247 "SNOW 3G Ciphertext data not as expected"); 4248 return 0; 4249 } 4250 4251 4252 static int 4253 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4254 { 4255 struct crypto_testsuite_params *ts_params = &testsuite_params; 4256 struct crypto_unittest_params *ut_params = &unittest_params; 4257 uint8_t *plaintext, *ciphertext; 4258 4259 int retval; 4260 unsigned plaintext_pad_len; 4261 unsigned plaintext_len; 4262 struct rte_cryptodev_info dev_info; 4263 4264 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4265 uint64_t feat_flags = dev_info.feature_flags; 4266 4267 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4268 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4269 printf("Device does not support RAW data-path APIs.\n"); 4270 return -ENOTSUP; 4271 } 4272 4273 /* Verify the capabilities */ 4274 struct rte_cryptodev_sym_capability_idx cap_idx; 4275 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4276 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4277 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4278 &cap_idx) == NULL) 4279 return TEST_SKIPPED; 4280 4281 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4282 return TEST_SKIPPED; 4283 4284 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4285 return TEST_SKIPPED; 4286 4287 /* Create SNOW 3G session */ 4288 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4289 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4290 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4291 tdata->key.data, tdata->key.len, 4292 tdata->cipher_iv.len); 4293 if (retval < 0) 4294 return retval; 4295 4296 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4297 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4298 4299 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4300 "Failed to allocate input buffer in mempool"); 4301 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4302 "Failed to allocate output buffer in mempool"); 4303 4304 /* Clear mbuf payload */ 4305 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4306 rte_pktmbuf_tailroom(ut_params->ibuf)); 4307 4308 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4309 /* Append data which is padded to a multiple of */ 4310 /* the algorithms block size */ 4311 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4312 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4313 plaintext_pad_len); 4314 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4315 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4316 4317 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4318 4319 /* Create SNOW 3G operation */ 4320 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4321 tdata->cipher_iv.len, 4322 tdata->validCipherLenInBits.len, 4323 0); 4324 if (retval < 0) 4325 return retval; 4326 4327 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4328 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4329 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4330 else 4331 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4332 ut_params->op); 4333 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4334 4335 ut_params->obuf = ut_params->op->sym->m_dst; 4336 if (ut_params->obuf) 4337 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4338 else 4339 ciphertext = plaintext; 4340 4341 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4342 4343 /* Validate obuf */ 4344 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4345 ciphertext, 4346 tdata->ciphertext.data, 4347 tdata->validDataLenInBits.len, 4348 "SNOW 3G Ciphertext data not as expected"); 4349 return 0; 4350 } 4351 4352 static int 4353 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4354 { 4355 struct crypto_testsuite_params *ts_params = &testsuite_params; 4356 struct crypto_unittest_params *ut_params = &unittest_params; 4357 4358 int retval; 4359 unsigned int plaintext_pad_len; 4360 unsigned int plaintext_len; 4361 uint8_t buffer[10000]; 4362 const uint8_t *ciphertext; 4363 4364 struct rte_cryptodev_info dev_info; 4365 4366 /* Verify the capabilities */ 4367 struct rte_cryptodev_sym_capability_idx cap_idx; 4368 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4369 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4370 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4371 &cap_idx) == NULL) 4372 return TEST_SKIPPED; 4373 4374 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4375 return TEST_SKIPPED; 4376 4377 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4378 return TEST_SKIPPED; 4379 4380 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4381 4382 uint64_t feat_flags = dev_info.feature_flags; 4383 4384 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4385 printf("Device doesn't support out-of-place scatter-gather " 4386 "in both input and output mbufs. " 4387 "Test Skipped.\n"); 4388 return TEST_SKIPPED; 4389 } 4390 4391 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4392 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4393 printf("Device does not support RAW data-path APIs.\n"); 4394 return -ENOTSUP; 4395 } 4396 4397 /* Create SNOW 3G session */ 4398 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4399 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4400 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4401 tdata->key.data, tdata->key.len, 4402 tdata->cipher_iv.len); 4403 if (retval < 0) 4404 return retval; 4405 4406 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4407 /* Append data which is padded to a multiple of */ 4408 /* the algorithms block size */ 4409 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4410 4411 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4412 plaintext_pad_len, 10, 0); 4413 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4414 plaintext_pad_len, 3, 0); 4415 4416 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4417 "Failed to allocate input buffer in mempool"); 4418 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4419 "Failed to allocate output buffer in mempool"); 4420 4421 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4422 4423 /* Create SNOW 3G operation */ 4424 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4425 tdata->cipher_iv.len, 4426 tdata->validCipherLenInBits.len, 4427 0); 4428 if (retval < 0) 4429 return retval; 4430 4431 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4432 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4433 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4434 else 4435 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4436 ut_params->op); 4437 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4438 4439 ut_params->obuf = ut_params->op->sym->m_dst; 4440 if (ut_params->obuf) 4441 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4442 plaintext_len, buffer); 4443 else 4444 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4445 plaintext_len, buffer); 4446 4447 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4448 4449 /* Validate obuf */ 4450 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4451 ciphertext, 4452 tdata->ciphertext.data, 4453 tdata->validDataLenInBits.len, 4454 "SNOW 3G Ciphertext data not as expected"); 4455 4456 return 0; 4457 } 4458 4459 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4460 static void 4461 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4462 { 4463 uint8_t curr_byte, prev_byte; 4464 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4465 uint8_t lower_byte_mask = (1 << offset) - 1; 4466 unsigned i; 4467 4468 prev_byte = buffer[0]; 4469 buffer[0] >>= offset; 4470 4471 for (i = 1; i < length_in_bytes; i++) { 4472 curr_byte = buffer[i]; 4473 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4474 (curr_byte >> offset); 4475 prev_byte = curr_byte; 4476 } 4477 } 4478 4479 static int 4480 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4481 { 4482 struct crypto_testsuite_params *ts_params = &testsuite_params; 4483 struct crypto_unittest_params *ut_params = &unittest_params; 4484 uint8_t *plaintext, *ciphertext; 4485 int retval; 4486 uint32_t plaintext_len; 4487 uint32_t plaintext_pad_len; 4488 uint8_t extra_offset = 4; 4489 uint8_t *expected_ciphertext_shifted; 4490 struct rte_cryptodev_info dev_info; 4491 4492 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4493 uint64_t feat_flags = dev_info.feature_flags; 4494 4495 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4496 ((tdata->validDataLenInBits.len % 8) != 0)) { 4497 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4498 return TEST_SKIPPED; 4499 } 4500 4501 /* Verify the capabilities */ 4502 struct rte_cryptodev_sym_capability_idx cap_idx; 4503 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4504 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4505 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4506 &cap_idx) == NULL) 4507 return TEST_SKIPPED; 4508 4509 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4510 return TEST_SKIPPED; 4511 4512 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4513 return TEST_SKIPPED; 4514 4515 /* Create SNOW 3G session */ 4516 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4517 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4518 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4519 tdata->key.data, tdata->key.len, 4520 tdata->cipher_iv.len); 4521 if (retval < 0) 4522 return retval; 4523 4524 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4525 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4526 4527 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4528 "Failed to allocate input buffer in mempool"); 4529 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4530 "Failed to allocate output buffer in mempool"); 4531 4532 /* Clear mbuf payload */ 4533 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4534 rte_pktmbuf_tailroom(ut_params->ibuf)); 4535 4536 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4537 /* 4538 * Append data which is padded to a 4539 * multiple of the algorithms block size 4540 */ 4541 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4542 4543 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4544 plaintext_pad_len); 4545 4546 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4547 4548 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4549 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4550 4551 #ifdef RTE_APP_TEST_DEBUG 4552 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4553 #endif 4554 /* Create SNOW 3G operation */ 4555 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4556 tdata->cipher_iv.len, 4557 tdata->validCipherLenInBits.len, 4558 extra_offset); 4559 if (retval < 0) 4560 return retval; 4561 4562 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4563 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4564 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4565 else 4566 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4567 ut_params->op); 4568 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4569 4570 ut_params->obuf = ut_params->op->sym->m_dst; 4571 if (ut_params->obuf) 4572 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4573 else 4574 ciphertext = plaintext; 4575 4576 #ifdef RTE_APP_TEST_DEBUG 4577 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4578 #endif 4579 4580 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4581 4582 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4583 "failed to reserve memory for ciphertext shifted\n"); 4584 4585 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4586 ceil_byte_length(tdata->ciphertext.len)); 4587 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4588 extra_offset); 4589 /* Validate obuf */ 4590 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4591 ciphertext, 4592 expected_ciphertext_shifted, 4593 tdata->validDataLenInBits.len, 4594 extra_offset, 4595 "SNOW 3G Ciphertext data not as expected"); 4596 return 0; 4597 } 4598 4599 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4600 { 4601 struct crypto_testsuite_params *ts_params = &testsuite_params; 4602 struct crypto_unittest_params *ut_params = &unittest_params; 4603 4604 int retval; 4605 4606 uint8_t *plaintext, *ciphertext; 4607 unsigned ciphertext_pad_len; 4608 unsigned ciphertext_len; 4609 struct rte_cryptodev_info dev_info; 4610 4611 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4612 uint64_t feat_flags = dev_info.feature_flags; 4613 4614 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4615 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4616 printf("Device doesn't support RAW data-path APIs.\n"); 4617 return TEST_SKIPPED; 4618 } 4619 4620 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4621 return TEST_SKIPPED; 4622 4623 /* Verify the capabilities */ 4624 struct rte_cryptodev_sym_capability_idx cap_idx; 4625 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4626 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4627 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4628 &cap_idx) == NULL) 4629 return TEST_SKIPPED; 4630 4631 /* Create SNOW 3G session */ 4632 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4633 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4634 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4635 tdata->key.data, tdata->key.len, 4636 tdata->cipher_iv.len); 4637 if (retval < 0) 4638 return retval; 4639 4640 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4641 4642 /* Clear mbuf payload */ 4643 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4644 rte_pktmbuf_tailroom(ut_params->ibuf)); 4645 4646 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4647 /* Append data which is padded to a multiple of */ 4648 /* the algorithms block size */ 4649 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4650 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4651 ciphertext_pad_len); 4652 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4653 4654 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4655 4656 /* Create SNOW 3G operation */ 4657 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4658 tdata->cipher_iv.len, 4659 tdata->validCipherLenInBits.len, 4660 tdata->cipher.offset_bits); 4661 if (retval < 0) 4662 return retval; 4663 4664 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4665 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4666 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4667 else 4668 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4669 ut_params->op); 4670 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4671 ut_params->obuf = ut_params->op->sym->m_dst; 4672 if (ut_params->obuf) 4673 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4674 else 4675 plaintext = ciphertext; 4676 4677 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4678 4679 /* Validate obuf */ 4680 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4681 tdata->plaintext.data, 4682 tdata->validDataLenInBits.len, 4683 "SNOW 3G Plaintext data not as expected"); 4684 return 0; 4685 } 4686 4687 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4688 { 4689 struct crypto_testsuite_params *ts_params = &testsuite_params; 4690 struct crypto_unittest_params *ut_params = &unittest_params; 4691 4692 int retval; 4693 4694 uint8_t *plaintext, *ciphertext; 4695 unsigned ciphertext_pad_len; 4696 unsigned ciphertext_len; 4697 struct rte_cryptodev_info dev_info; 4698 4699 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4700 uint64_t feat_flags = dev_info.feature_flags; 4701 4702 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4703 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4704 printf("Device does not support RAW data-path APIs.\n"); 4705 return -ENOTSUP; 4706 } 4707 /* Verify the capabilities */ 4708 struct rte_cryptodev_sym_capability_idx cap_idx; 4709 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4710 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4711 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4712 &cap_idx) == NULL) 4713 return TEST_SKIPPED; 4714 4715 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4716 return TEST_SKIPPED; 4717 4718 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4719 return TEST_SKIPPED; 4720 4721 /* Create SNOW 3G session */ 4722 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4723 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4724 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4725 tdata->key.data, tdata->key.len, 4726 tdata->cipher_iv.len); 4727 if (retval < 0) 4728 return retval; 4729 4730 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4731 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4732 4733 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4734 "Failed to allocate input buffer"); 4735 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4736 "Failed to allocate output buffer"); 4737 4738 /* Clear mbuf payload */ 4739 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4740 rte_pktmbuf_tailroom(ut_params->ibuf)); 4741 4742 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4743 rte_pktmbuf_tailroom(ut_params->obuf)); 4744 4745 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4746 /* Append data which is padded to a multiple of */ 4747 /* the algorithms block size */ 4748 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4749 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4750 ciphertext_pad_len); 4751 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4752 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4753 4754 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4755 4756 /* Create SNOW 3G operation */ 4757 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4758 tdata->cipher_iv.len, 4759 tdata->validCipherLenInBits.len, 4760 0); 4761 if (retval < 0) 4762 return retval; 4763 4764 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4765 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4766 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4767 else 4768 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4769 ut_params->op); 4770 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4771 ut_params->obuf = ut_params->op->sym->m_dst; 4772 if (ut_params->obuf) 4773 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4774 else 4775 plaintext = ciphertext; 4776 4777 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4778 4779 /* Validate obuf */ 4780 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4781 tdata->plaintext.data, 4782 tdata->validDataLenInBits.len, 4783 "SNOW 3G Plaintext data not as expected"); 4784 return 0; 4785 } 4786 4787 static int 4788 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4789 { 4790 struct crypto_testsuite_params *ts_params = &testsuite_params; 4791 struct crypto_unittest_params *ut_params = &unittest_params; 4792 4793 int retval; 4794 4795 uint8_t *plaintext, *ciphertext; 4796 unsigned int plaintext_pad_len; 4797 unsigned int plaintext_len; 4798 4799 struct rte_cryptodev_info dev_info; 4800 struct rte_cryptodev_sym_capability_idx cap_idx; 4801 4802 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4803 uint64_t feat_flags = dev_info.feature_flags; 4804 4805 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4806 ((tdata->validAuthLenInBits.len % 8 != 0) || 4807 (tdata->validDataLenInBits.len % 8 != 0))) { 4808 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4809 return TEST_SKIPPED; 4810 } 4811 4812 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4813 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4814 printf("Device doesn't support RAW data-path APIs.\n"); 4815 return TEST_SKIPPED; 4816 } 4817 4818 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4819 return TEST_SKIPPED; 4820 4821 /* Check if device supports ZUC EEA3 */ 4822 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4823 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4824 4825 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4826 &cap_idx) == NULL) 4827 return TEST_SKIPPED; 4828 4829 /* Check if device supports ZUC EIA3 */ 4830 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4831 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4832 4833 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4834 &cap_idx) == NULL) 4835 return TEST_SKIPPED; 4836 4837 /* Create ZUC session */ 4838 retval = create_zuc_cipher_auth_encrypt_generate_session( 4839 ts_params->valid_devs[0], 4840 tdata); 4841 if (retval != 0) 4842 return retval; 4843 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4844 4845 /* clear mbuf payload */ 4846 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4847 rte_pktmbuf_tailroom(ut_params->ibuf)); 4848 4849 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4850 /* Append data which is padded to a multiple of */ 4851 /* the algorithms block size */ 4852 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4853 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4854 plaintext_pad_len); 4855 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4856 4857 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4858 4859 /* Create ZUC operation */ 4860 retval = create_zuc_cipher_hash_generate_operation(tdata); 4861 if (retval < 0) 4862 return retval; 4863 4864 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4865 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4866 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4867 else 4868 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4869 ut_params->op); 4870 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4871 ut_params->obuf = ut_params->op->sym->m_src; 4872 if (ut_params->obuf) 4873 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4874 else 4875 ciphertext = plaintext; 4876 4877 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4878 /* Validate obuf */ 4879 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4880 ciphertext, 4881 tdata->ciphertext.data, 4882 tdata->validDataLenInBits.len, 4883 "ZUC Ciphertext data not as expected"); 4884 4885 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4886 + plaintext_pad_len; 4887 4888 /* Validate obuf */ 4889 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4890 ut_params->digest, 4891 tdata->digest.data, 4892 4, 4893 "ZUC Generated auth tag not as expected"); 4894 return 0; 4895 } 4896 4897 static int 4898 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4899 { 4900 struct crypto_testsuite_params *ts_params = &testsuite_params; 4901 struct crypto_unittest_params *ut_params = &unittest_params; 4902 4903 int retval; 4904 4905 uint8_t *plaintext, *ciphertext; 4906 unsigned plaintext_pad_len; 4907 unsigned plaintext_len; 4908 struct rte_cryptodev_info dev_info; 4909 4910 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4911 uint64_t feat_flags = dev_info.feature_flags; 4912 4913 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4914 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4915 printf("Device doesn't support RAW data-path APIs.\n"); 4916 return TEST_SKIPPED; 4917 } 4918 4919 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4920 return TEST_SKIPPED; 4921 4922 /* Verify the capabilities */ 4923 struct rte_cryptodev_sym_capability_idx cap_idx; 4924 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4925 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4926 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4927 &cap_idx) == NULL) 4928 return TEST_SKIPPED; 4929 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4930 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4931 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4932 &cap_idx) == NULL) 4933 return TEST_SKIPPED; 4934 4935 /* Create SNOW 3G session */ 4936 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4937 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4938 RTE_CRYPTO_AUTH_OP_GENERATE, 4939 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4940 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4941 tdata->key.data, tdata->key.len, 4942 tdata->auth_iv.len, tdata->digest.len, 4943 tdata->cipher_iv.len); 4944 if (retval != 0) 4945 return retval; 4946 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4947 4948 /* clear mbuf payload */ 4949 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4950 rte_pktmbuf_tailroom(ut_params->ibuf)); 4951 4952 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4953 /* Append data which is padded to a multiple of */ 4954 /* the algorithms block size */ 4955 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4956 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4957 plaintext_pad_len); 4958 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4959 4960 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4961 4962 /* Create SNOW 3G operation */ 4963 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4964 tdata->digest.len, tdata->auth_iv.data, 4965 tdata->auth_iv.len, 4966 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4967 tdata->cipher_iv.data, tdata->cipher_iv.len, 4968 tdata->validCipherLenInBits.len, 4969 0, 4970 tdata->validAuthLenInBits.len, 4971 0 4972 ); 4973 if (retval < 0) 4974 return retval; 4975 4976 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4977 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4978 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4979 else 4980 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4981 ut_params->op); 4982 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4983 ut_params->obuf = ut_params->op->sym->m_src; 4984 if (ut_params->obuf) 4985 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4986 else 4987 ciphertext = plaintext; 4988 4989 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4990 /* Validate obuf */ 4991 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4992 ciphertext, 4993 tdata->ciphertext.data, 4994 tdata->validDataLenInBits.len, 4995 "SNOW 3G Ciphertext data not as expected"); 4996 4997 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4998 + plaintext_pad_len; 4999 5000 /* Validate obuf */ 5001 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5002 ut_params->digest, 5003 tdata->digest.data, 5004 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5005 "SNOW 3G Generated auth tag not as expected"); 5006 return 0; 5007 } 5008 5009 static int 5010 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5011 uint8_t op_mode, uint8_t verify) 5012 { 5013 struct crypto_testsuite_params *ts_params = &testsuite_params; 5014 struct crypto_unittest_params *ut_params = &unittest_params; 5015 5016 int retval; 5017 5018 uint8_t *plaintext = NULL, *ciphertext = NULL; 5019 unsigned int plaintext_pad_len; 5020 unsigned int plaintext_len; 5021 unsigned int ciphertext_pad_len; 5022 unsigned int ciphertext_len; 5023 5024 struct rte_cryptodev_info dev_info; 5025 5026 /* Verify the capabilities */ 5027 struct rte_cryptodev_sym_capability_idx cap_idx; 5028 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5029 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5030 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5031 &cap_idx) == NULL) 5032 return TEST_SKIPPED; 5033 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5034 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5035 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5036 &cap_idx) == NULL) 5037 return TEST_SKIPPED; 5038 5039 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5040 return TEST_SKIPPED; 5041 5042 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5043 5044 uint64_t feat_flags = dev_info.feature_flags; 5045 5046 if (op_mode == OUT_OF_PLACE) { 5047 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5048 printf("Device doesn't support digest encrypted.\n"); 5049 return TEST_SKIPPED; 5050 } 5051 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5052 return TEST_SKIPPED; 5053 } 5054 5055 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5056 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5057 printf("Device doesn't support RAW data-path APIs.\n"); 5058 return TEST_SKIPPED; 5059 } 5060 5061 /* Create SNOW 3G session */ 5062 retval = create_wireless_algo_auth_cipher_session( 5063 ts_params->valid_devs[0], 5064 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5065 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5066 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5067 : RTE_CRYPTO_AUTH_OP_GENERATE), 5068 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5069 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5070 tdata->key.data, tdata->key.len, 5071 tdata->auth_iv.len, tdata->digest.len, 5072 tdata->cipher_iv.len); 5073 if (retval != 0) 5074 return retval; 5075 5076 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5077 if (op_mode == OUT_OF_PLACE) 5078 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5079 5080 /* clear mbuf payload */ 5081 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5082 rte_pktmbuf_tailroom(ut_params->ibuf)); 5083 if (op_mode == OUT_OF_PLACE) 5084 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5085 rte_pktmbuf_tailroom(ut_params->obuf)); 5086 5087 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5088 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5089 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5090 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5091 5092 if (verify) { 5093 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5094 ciphertext_pad_len); 5095 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5096 if (op_mode == OUT_OF_PLACE) 5097 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5098 debug_hexdump(stdout, "ciphertext:", ciphertext, 5099 ciphertext_len); 5100 } else { 5101 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5102 plaintext_pad_len); 5103 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5104 if (op_mode == OUT_OF_PLACE) 5105 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5106 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5107 } 5108 5109 /* Create SNOW 3G operation */ 5110 retval = create_wireless_algo_auth_cipher_operation( 5111 tdata->digest.data, tdata->digest.len, 5112 tdata->cipher_iv.data, tdata->cipher_iv.len, 5113 tdata->auth_iv.data, tdata->auth_iv.len, 5114 (tdata->digest.offset_bytes == 0 ? 5115 (verify ? ciphertext_pad_len : plaintext_pad_len) 5116 : tdata->digest.offset_bytes), 5117 tdata->validCipherLenInBits.len, 5118 tdata->cipher.offset_bits, 5119 tdata->validAuthLenInBits.len, 5120 tdata->auth.offset_bits, 5121 op_mode, 0, verify); 5122 5123 if (retval < 0) 5124 return retval; 5125 5126 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5127 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5128 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5129 else 5130 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5131 ut_params->op); 5132 5133 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5134 5135 ut_params->obuf = (op_mode == IN_PLACE ? 5136 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5137 5138 if (verify) { 5139 if (ut_params->obuf) 5140 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5141 uint8_t *); 5142 else 5143 plaintext = ciphertext + 5144 (tdata->cipher.offset_bits >> 3); 5145 5146 debug_hexdump(stdout, "plaintext:", plaintext, 5147 (tdata->plaintext.len >> 3) - tdata->digest.len); 5148 debug_hexdump(stdout, "plaintext expected:", 5149 tdata->plaintext.data, 5150 (tdata->plaintext.len >> 3) - tdata->digest.len); 5151 } else { 5152 if (ut_params->obuf) 5153 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5154 uint8_t *); 5155 else 5156 ciphertext = plaintext; 5157 5158 debug_hexdump(stdout, "ciphertext:", ciphertext, 5159 ciphertext_len); 5160 debug_hexdump(stdout, "ciphertext expected:", 5161 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5162 5163 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5164 + (tdata->digest.offset_bytes == 0 ? 5165 plaintext_pad_len : tdata->digest.offset_bytes); 5166 5167 debug_hexdump(stdout, "digest:", ut_params->digest, 5168 tdata->digest.len); 5169 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5170 tdata->digest.len); 5171 } 5172 5173 /* Validate obuf */ 5174 if (verify) { 5175 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5176 plaintext, 5177 tdata->plaintext.data, 5178 (tdata->plaintext.len - tdata->cipher.offset_bits - 5179 (tdata->digest.len << 3)), 5180 tdata->cipher.offset_bits, 5181 "SNOW 3G Plaintext data not as expected"); 5182 } else { 5183 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5184 ciphertext, 5185 tdata->ciphertext.data, 5186 (tdata->validDataLenInBits.len - 5187 tdata->cipher.offset_bits), 5188 tdata->cipher.offset_bits, 5189 "SNOW 3G Ciphertext data not as expected"); 5190 5191 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5192 ut_params->digest, 5193 tdata->digest.data, 5194 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5195 "SNOW 3G Generated auth tag not as expected"); 5196 } 5197 return 0; 5198 } 5199 5200 static int 5201 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5202 uint8_t op_mode, uint8_t verify) 5203 { 5204 struct crypto_testsuite_params *ts_params = &testsuite_params; 5205 struct crypto_unittest_params *ut_params = &unittest_params; 5206 5207 int retval; 5208 5209 const uint8_t *plaintext = NULL; 5210 const uint8_t *ciphertext = NULL; 5211 const uint8_t *digest = NULL; 5212 unsigned int plaintext_pad_len; 5213 unsigned int plaintext_len; 5214 unsigned int ciphertext_pad_len; 5215 unsigned int ciphertext_len; 5216 uint8_t buffer[10000]; 5217 uint8_t digest_buffer[10000]; 5218 5219 struct rte_cryptodev_info dev_info; 5220 5221 /* Verify the capabilities */ 5222 struct rte_cryptodev_sym_capability_idx cap_idx; 5223 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5224 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5225 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5226 &cap_idx) == NULL) 5227 return TEST_SKIPPED; 5228 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5229 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5230 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5231 &cap_idx) == NULL) 5232 return TEST_SKIPPED; 5233 5234 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5235 return TEST_SKIPPED; 5236 5237 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5238 5239 uint64_t feat_flags = dev_info.feature_flags; 5240 5241 if (op_mode == IN_PLACE) { 5242 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5243 printf("Device doesn't support in-place scatter-gather " 5244 "in both input and output mbufs.\n"); 5245 return TEST_SKIPPED; 5246 } 5247 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5248 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5249 printf("Device doesn't support RAW data-path APIs.\n"); 5250 return TEST_SKIPPED; 5251 } 5252 } else { 5253 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5254 return TEST_SKIPPED; 5255 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5256 printf("Device doesn't support out-of-place scatter-gather " 5257 "in both input and output mbufs.\n"); 5258 return TEST_SKIPPED; 5259 } 5260 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5261 printf("Device doesn't support digest encrypted.\n"); 5262 return TEST_SKIPPED; 5263 } 5264 } 5265 5266 /* Create SNOW 3G session */ 5267 retval = create_wireless_algo_auth_cipher_session( 5268 ts_params->valid_devs[0], 5269 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5270 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5271 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5272 : RTE_CRYPTO_AUTH_OP_GENERATE), 5273 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5274 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5275 tdata->key.data, tdata->key.len, 5276 tdata->auth_iv.len, tdata->digest.len, 5277 tdata->cipher_iv.len); 5278 5279 if (retval != 0) 5280 return retval; 5281 5282 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5283 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5284 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5285 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5286 5287 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5288 plaintext_pad_len, 15, 0); 5289 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5290 "Failed to allocate input buffer in mempool"); 5291 5292 if (op_mode == OUT_OF_PLACE) { 5293 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5294 plaintext_pad_len, 15, 0); 5295 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5296 "Failed to allocate output buffer in mempool"); 5297 } 5298 5299 if (verify) { 5300 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5301 tdata->ciphertext.data); 5302 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5303 ciphertext_len, buffer); 5304 debug_hexdump(stdout, "ciphertext:", ciphertext, 5305 ciphertext_len); 5306 } else { 5307 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5308 tdata->plaintext.data); 5309 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5310 plaintext_len, buffer); 5311 debug_hexdump(stdout, "plaintext:", plaintext, 5312 plaintext_len); 5313 } 5314 memset(buffer, 0, sizeof(buffer)); 5315 5316 /* Create SNOW 3G operation */ 5317 retval = create_wireless_algo_auth_cipher_operation( 5318 tdata->digest.data, tdata->digest.len, 5319 tdata->cipher_iv.data, tdata->cipher_iv.len, 5320 tdata->auth_iv.data, tdata->auth_iv.len, 5321 (tdata->digest.offset_bytes == 0 ? 5322 (verify ? ciphertext_pad_len : plaintext_pad_len) 5323 : tdata->digest.offset_bytes), 5324 tdata->validCipherLenInBits.len, 5325 tdata->cipher.offset_bits, 5326 tdata->validAuthLenInBits.len, 5327 tdata->auth.offset_bits, 5328 op_mode, 1, verify); 5329 5330 if (retval < 0) 5331 return retval; 5332 5333 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5334 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5335 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5336 else 5337 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5338 ut_params->op); 5339 5340 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5341 5342 ut_params->obuf = (op_mode == IN_PLACE ? 5343 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5344 5345 if (verify) { 5346 if (ut_params->obuf) 5347 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5348 plaintext_len, buffer); 5349 else 5350 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5351 plaintext_len, buffer); 5352 5353 debug_hexdump(stdout, "plaintext:", plaintext, 5354 (tdata->plaintext.len >> 3) - tdata->digest.len); 5355 debug_hexdump(stdout, "plaintext expected:", 5356 tdata->plaintext.data, 5357 (tdata->plaintext.len >> 3) - tdata->digest.len); 5358 } else { 5359 if (ut_params->obuf) 5360 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5361 ciphertext_len, buffer); 5362 else 5363 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5364 ciphertext_len, buffer); 5365 5366 debug_hexdump(stdout, "ciphertext:", ciphertext, 5367 ciphertext_len); 5368 debug_hexdump(stdout, "ciphertext expected:", 5369 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5370 5371 if (ut_params->obuf) 5372 digest = rte_pktmbuf_read(ut_params->obuf, 5373 (tdata->digest.offset_bytes == 0 ? 5374 plaintext_pad_len : tdata->digest.offset_bytes), 5375 tdata->digest.len, digest_buffer); 5376 else 5377 digest = rte_pktmbuf_read(ut_params->ibuf, 5378 (tdata->digest.offset_bytes == 0 ? 5379 plaintext_pad_len : tdata->digest.offset_bytes), 5380 tdata->digest.len, digest_buffer); 5381 5382 debug_hexdump(stdout, "digest:", digest, 5383 tdata->digest.len); 5384 debug_hexdump(stdout, "digest expected:", 5385 tdata->digest.data, tdata->digest.len); 5386 } 5387 5388 /* Validate obuf */ 5389 if (verify) { 5390 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5391 plaintext, 5392 tdata->plaintext.data, 5393 (tdata->plaintext.len - tdata->cipher.offset_bits - 5394 (tdata->digest.len << 3)), 5395 tdata->cipher.offset_bits, 5396 "SNOW 3G Plaintext data not as expected"); 5397 } else { 5398 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5399 ciphertext, 5400 tdata->ciphertext.data, 5401 (tdata->validDataLenInBits.len - 5402 tdata->cipher.offset_bits), 5403 tdata->cipher.offset_bits, 5404 "SNOW 3G Ciphertext data not as expected"); 5405 5406 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5407 digest, 5408 tdata->digest.data, 5409 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5410 "SNOW 3G Generated auth tag not as expected"); 5411 } 5412 return 0; 5413 } 5414 5415 static int 5416 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5417 uint8_t op_mode, uint8_t verify) 5418 { 5419 struct crypto_testsuite_params *ts_params = &testsuite_params; 5420 struct crypto_unittest_params *ut_params = &unittest_params; 5421 5422 int retval; 5423 5424 uint8_t *plaintext = NULL, *ciphertext = NULL; 5425 unsigned int plaintext_pad_len; 5426 unsigned int plaintext_len; 5427 unsigned int ciphertext_pad_len; 5428 unsigned int ciphertext_len; 5429 5430 struct rte_cryptodev_info dev_info; 5431 5432 /* Verify the capabilities */ 5433 struct rte_cryptodev_sym_capability_idx cap_idx; 5434 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5435 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5436 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5437 &cap_idx) == NULL) 5438 return TEST_SKIPPED; 5439 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5440 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5441 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5442 &cap_idx) == NULL) 5443 return TEST_SKIPPED; 5444 5445 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5446 5447 uint64_t feat_flags = dev_info.feature_flags; 5448 5449 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5450 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5451 printf("Device doesn't support RAW data-path APIs.\n"); 5452 return TEST_SKIPPED; 5453 } 5454 5455 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5456 return TEST_SKIPPED; 5457 5458 if (op_mode == OUT_OF_PLACE) { 5459 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5460 return TEST_SKIPPED; 5461 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5462 printf("Device doesn't support digest encrypted.\n"); 5463 return TEST_SKIPPED; 5464 } 5465 } 5466 5467 /* Create KASUMI session */ 5468 retval = create_wireless_algo_auth_cipher_session( 5469 ts_params->valid_devs[0], 5470 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5471 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5472 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5473 : RTE_CRYPTO_AUTH_OP_GENERATE), 5474 RTE_CRYPTO_AUTH_KASUMI_F9, 5475 RTE_CRYPTO_CIPHER_KASUMI_F8, 5476 tdata->key.data, tdata->key.len, 5477 0, tdata->digest.len, 5478 tdata->cipher_iv.len); 5479 5480 if (retval != 0) 5481 return retval; 5482 5483 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5484 if (op_mode == OUT_OF_PLACE) 5485 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5486 5487 /* clear mbuf payload */ 5488 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5489 rte_pktmbuf_tailroom(ut_params->ibuf)); 5490 if (op_mode == OUT_OF_PLACE) 5491 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5492 rte_pktmbuf_tailroom(ut_params->obuf)); 5493 5494 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5495 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5496 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5497 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5498 5499 if (verify) { 5500 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5501 ciphertext_pad_len); 5502 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5503 if (op_mode == OUT_OF_PLACE) 5504 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5505 debug_hexdump(stdout, "ciphertext:", ciphertext, 5506 ciphertext_len); 5507 } else { 5508 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5509 plaintext_pad_len); 5510 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5511 if (op_mode == OUT_OF_PLACE) 5512 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5513 debug_hexdump(stdout, "plaintext:", plaintext, 5514 plaintext_len); 5515 } 5516 5517 /* Create KASUMI operation */ 5518 retval = create_wireless_algo_auth_cipher_operation( 5519 tdata->digest.data, tdata->digest.len, 5520 tdata->cipher_iv.data, tdata->cipher_iv.len, 5521 NULL, 0, 5522 (tdata->digest.offset_bytes == 0 ? 5523 (verify ? ciphertext_pad_len : plaintext_pad_len) 5524 : tdata->digest.offset_bytes), 5525 tdata->validCipherLenInBits.len, 5526 tdata->validCipherOffsetInBits.len, 5527 tdata->validAuthLenInBits.len, 5528 0, 5529 op_mode, 0, verify); 5530 5531 if (retval < 0) 5532 return retval; 5533 5534 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5535 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5536 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5537 else 5538 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5539 ut_params->op); 5540 5541 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5542 5543 ut_params->obuf = (op_mode == IN_PLACE ? 5544 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5545 5546 5547 if (verify) { 5548 if (ut_params->obuf) 5549 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5550 uint8_t *); 5551 else 5552 plaintext = ciphertext; 5553 5554 debug_hexdump(stdout, "plaintext:", plaintext, 5555 (tdata->plaintext.len >> 3) - tdata->digest.len); 5556 debug_hexdump(stdout, "plaintext expected:", 5557 tdata->plaintext.data, 5558 (tdata->plaintext.len >> 3) - tdata->digest.len); 5559 } else { 5560 if (ut_params->obuf) 5561 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5562 uint8_t *); 5563 else 5564 ciphertext = plaintext; 5565 5566 debug_hexdump(stdout, "ciphertext:", ciphertext, 5567 ciphertext_len); 5568 debug_hexdump(stdout, "ciphertext expected:", 5569 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5570 5571 ut_params->digest = rte_pktmbuf_mtod( 5572 ut_params->obuf, uint8_t *) + 5573 (tdata->digest.offset_bytes == 0 ? 5574 plaintext_pad_len : tdata->digest.offset_bytes); 5575 5576 debug_hexdump(stdout, "digest:", ut_params->digest, 5577 tdata->digest.len); 5578 debug_hexdump(stdout, "digest expected:", 5579 tdata->digest.data, tdata->digest.len); 5580 } 5581 5582 /* Validate obuf */ 5583 if (verify) { 5584 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5585 plaintext, 5586 tdata->plaintext.data, 5587 tdata->plaintext.len >> 3, 5588 "KASUMI Plaintext data not as expected"); 5589 } else { 5590 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5591 ciphertext, 5592 tdata->ciphertext.data, 5593 tdata->ciphertext.len >> 3, 5594 "KASUMI Ciphertext data not as expected"); 5595 5596 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5597 ut_params->digest, 5598 tdata->digest.data, 5599 DIGEST_BYTE_LENGTH_KASUMI_F9, 5600 "KASUMI Generated auth tag not as expected"); 5601 } 5602 return 0; 5603 } 5604 5605 static int 5606 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5607 uint8_t op_mode, uint8_t verify) 5608 { 5609 struct crypto_testsuite_params *ts_params = &testsuite_params; 5610 struct crypto_unittest_params *ut_params = &unittest_params; 5611 5612 int retval; 5613 5614 const uint8_t *plaintext = NULL; 5615 const uint8_t *ciphertext = NULL; 5616 const uint8_t *digest = NULL; 5617 unsigned int plaintext_pad_len; 5618 unsigned int plaintext_len; 5619 unsigned int ciphertext_pad_len; 5620 unsigned int ciphertext_len; 5621 uint8_t buffer[10000]; 5622 uint8_t digest_buffer[10000]; 5623 5624 struct rte_cryptodev_info dev_info; 5625 5626 /* Verify the capabilities */ 5627 struct rte_cryptodev_sym_capability_idx cap_idx; 5628 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5629 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5630 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5631 &cap_idx) == NULL) 5632 return TEST_SKIPPED; 5633 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5634 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5635 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5636 &cap_idx) == NULL) 5637 return TEST_SKIPPED; 5638 5639 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5640 return TEST_SKIPPED; 5641 5642 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5643 5644 uint64_t feat_flags = dev_info.feature_flags; 5645 5646 if (op_mode == IN_PLACE) { 5647 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5648 printf("Device doesn't support in-place scatter-gather " 5649 "in both input and output mbufs.\n"); 5650 return TEST_SKIPPED; 5651 } 5652 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5653 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5654 printf("Device doesn't support RAW data-path APIs.\n"); 5655 return TEST_SKIPPED; 5656 } 5657 } else { 5658 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5659 return TEST_SKIPPED; 5660 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5661 printf("Device doesn't support out-of-place scatter-gather " 5662 "in both input and output mbufs.\n"); 5663 return TEST_SKIPPED; 5664 } 5665 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5666 printf("Device doesn't support digest encrypted.\n"); 5667 return TEST_SKIPPED; 5668 } 5669 } 5670 5671 /* Create KASUMI session */ 5672 retval = create_wireless_algo_auth_cipher_session( 5673 ts_params->valid_devs[0], 5674 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5675 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5676 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5677 : RTE_CRYPTO_AUTH_OP_GENERATE), 5678 RTE_CRYPTO_AUTH_KASUMI_F9, 5679 RTE_CRYPTO_CIPHER_KASUMI_F8, 5680 tdata->key.data, tdata->key.len, 5681 0, tdata->digest.len, 5682 tdata->cipher_iv.len); 5683 5684 if (retval != 0) 5685 return retval; 5686 5687 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5688 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5689 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5690 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5691 5692 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5693 plaintext_pad_len, 15, 0); 5694 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5695 "Failed to allocate input buffer in mempool"); 5696 5697 if (op_mode == OUT_OF_PLACE) { 5698 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5699 plaintext_pad_len, 15, 0); 5700 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5701 "Failed to allocate output buffer in mempool"); 5702 } 5703 5704 if (verify) { 5705 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5706 tdata->ciphertext.data); 5707 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5708 ciphertext_len, buffer); 5709 debug_hexdump(stdout, "ciphertext:", ciphertext, 5710 ciphertext_len); 5711 } else { 5712 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5713 tdata->plaintext.data); 5714 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5715 plaintext_len, buffer); 5716 debug_hexdump(stdout, "plaintext:", plaintext, 5717 plaintext_len); 5718 } 5719 memset(buffer, 0, sizeof(buffer)); 5720 5721 /* Create KASUMI operation */ 5722 retval = create_wireless_algo_auth_cipher_operation( 5723 tdata->digest.data, tdata->digest.len, 5724 tdata->cipher_iv.data, tdata->cipher_iv.len, 5725 NULL, 0, 5726 (tdata->digest.offset_bytes == 0 ? 5727 (verify ? ciphertext_pad_len : plaintext_pad_len) 5728 : tdata->digest.offset_bytes), 5729 tdata->validCipherLenInBits.len, 5730 tdata->validCipherOffsetInBits.len, 5731 tdata->validAuthLenInBits.len, 5732 0, 5733 op_mode, 1, verify); 5734 5735 if (retval < 0) 5736 return retval; 5737 5738 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5739 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5740 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5741 else 5742 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5743 ut_params->op); 5744 5745 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5746 5747 ut_params->obuf = (op_mode == IN_PLACE ? 5748 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5749 5750 if (verify) { 5751 if (ut_params->obuf) 5752 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5753 plaintext_len, buffer); 5754 else 5755 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5756 plaintext_len, buffer); 5757 5758 debug_hexdump(stdout, "plaintext:", plaintext, 5759 (tdata->plaintext.len >> 3) - tdata->digest.len); 5760 debug_hexdump(stdout, "plaintext expected:", 5761 tdata->plaintext.data, 5762 (tdata->plaintext.len >> 3) - tdata->digest.len); 5763 } else { 5764 if (ut_params->obuf) 5765 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5766 ciphertext_len, buffer); 5767 else 5768 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5769 ciphertext_len, buffer); 5770 5771 debug_hexdump(stdout, "ciphertext:", ciphertext, 5772 ciphertext_len); 5773 debug_hexdump(stdout, "ciphertext expected:", 5774 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5775 5776 if (ut_params->obuf) 5777 digest = rte_pktmbuf_read(ut_params->obuf, 5778 (tdata->digest.offset_bytes == 0 ? 5779 plaintext_pad_len : tdata->digest.offset_bytes), 5780 tdata->digest.len, digest_buffer); 5781 else 5782 digest = rte_pktmbuf_read(ut_params->ibuf, 5783 (tdata->digest.offset_bytes == 0 ? 5784 plaintext_pad_len : tdata->digest.offset_bytes), 5785 tdata->digest.len, digest_buffer); 5786 5787 debug_hexdump(stdout, "digest:", digest, 5788 tdata->digest.len); 5789 debug_hexdump(stdout, "digest expected:", 5790 tdata->digest.data, tdata->digest.len); 5791 } 5792 5793 /* Validate obuf */ 5794 if (verify) { 5795 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5796 plaintext, 5797 tdata->plaintext.data, 5798 tdata->plaintext.len >> 3, 5799 "KASUMI Plaintext data not as expected"); 5800 } else { 5801 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5802 ciphertext, 5803 tdata->ciphertext.data, 5804 tdata->validDataLenInBits.len, 5805 "KASUMI Ciphertext data not as expected"); 5806 5807 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5808 digest, 5809 tdata->digest.data, 5810 DIGEST_BYTE_LENGTH_KASUMI_F9, 5811 "KASUMI Generated auth tag not as expected"); 5812 } 5813 return 0; 5814 } 5815 5816 static int 5817 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5818 { 5819 struct crypto_testsuite_params *ts_params = &testsuite_params; 5820 struct crypto_unittest_params *ut_params = &unittest_params; 5821 5822 int retval; 5823 5824 uint8_t *plaintext, *ciphertext; 5825 unsigned plaintext_pad_len; 5826 unsigned plaintext_len; 5827 struct rte_cryptodev_info dev_info; 5828 5829 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5830 uint64_t feat_flags = dev_info.feature_flags; 5831 5832 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5833 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5834 printf("Device doesn't support RAW data-path APIs.\n"); 5835 return TEST_SKIPPED; 5836 } 5837 5838 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5839 return TEST_SKIPPED; 5840 5841 /* Verify the capabilities */ 5842 struct rte_cryptodev_sym_capability_idx cap_idx; 5843 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5844 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5845 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5846 &cap_idx) == NULL) 5847 return TEST_SKIPPED; 5848 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5849 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5850 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5851 &cap_idx) == NULL) 5852 return TEST_SKIPPED; 5853 5854 /* Create KASUMI session */ 5855 retval = create_wireless_algo_cipher_auth_session( 5856 ts_params->valid_devs[0], 5857 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5858 RTE_CRYPTO_AUTH_OP_GENERATE, 5859 RTE_CRYPTO_AUTH_KASUMI_F9, 5860 RTE_CRYPTO_CIPHER_KASUMI_F8, 5861 tdata->key.data, tdata->key.len, 5862 0, tdata->digest.len, 5863 tdata->cipher_iv.len); 5864 if (retval != 0) 5865 return retval; 5866 5867 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5868 5869 /* clear mbuf payload */ 5870 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5871 rte_pktmbuf_tailroom(ut_params->ibuf)); 5872 5873 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5874 /* Append data which is padded to a multiple of */ 5875 /* the algorithms block size */ 5876 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5877 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5878 plaintext_pad_len); 5879 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5880 5881 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5882 5883 /* Create KASUMI operation */ 5884 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5885 tdata->digest.len, NULL, 0, 5886 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5887 tdata->cipher_iv.data, tdata->cipher_iv.len, 5888 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5889 tdata->validCipherOffsetInBits.len, 5890 tdata->validAuthLenInBits.len, 5891 0 5892 ); 5893 if (retval < 0) 5894 return retval; 5895 5896 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5897 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5898 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5899 else 5900 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5901 ut_params->op); 5902 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5903 5904 if (ut_params->op->sym->m_dst) 5905 ut_params->obuf = ut_params->op->sym->m_dst; 5906 else 5907 ut_params->obuf = ut_params->op->sym->m_src; 5908 5909 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5910 tdata->validCipherOffsetInBits.len >> 3); 5911 5912 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5913 + plaintext_pad_len; 5914 5915 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5916 (tdata->validCipherOffsetInBits.len >> 3); 5917 /* Validate obuf */ 5918 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5919 ciphertext, 5920 reference_ciphertext, 5921 tdata->validCipherLenInBits.len, 5922 "KASUMI Ciphertext data not as expected"); 5923 5924 /* Validate obuf */ 5925 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5926 ut_params->digest, 5927 tdata->digest.data, 5928 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5929 "KASUMI Generated auth tag not as expected"); 5930 return 0; 5931 } 5932 5933 static int 5934 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5935 const enum rte_crypto_cipher_algorithm cipher_algo, 5936 const uint16_t key_size, const uint16_t iv_size) 5937 { 5938 struct rte_cryptodev_sym_capability_idx cap_idx; 5939 const struct rte_cryptodev_symmetric_capability *cap; 5940 5941 /* Check if device supports the algorithm */ 5942 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5943 cap_idx.algo.cipher = cipher_algo; 5944 5945 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5946 &cap_idx); 5947 5948 if (cap == NULL) 5949 return -1; 5950 5951 /* Check if device supports key size and IV size */ 5952 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5953 iv_size) < 0) { 5954 return -1; 5955 } 5956 5957 return 0; 5958 } 5959 5960 static int 5961 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5962 const enum rte_crypto_auth_algorithm auth_algo, 5963 const uint16_t key_size, const uint16_t iv_size, 5964 const uint16_t tag_size) 5965 { 5966 struct rte_cryptodev_sym_capability_idx cap_idx; 5967 const struct rte_cryptodev_symmetric_capability *cap; 5968 5969 /* Check if device supports the algorithm */ 5970 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5971 cap_idx.algo.auth = auth_algo; 5972 5973 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5974 &cap_idx); 5975 5976 if (cap == NULL) 5977 return -1; 5978 5979 /* Check if device supports key size and IV size */ 5980 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5981 tag_size, iv_size) < 0) { 5982 return -1; 5983 } 5984 5985 return 0; 5986 } 5987 5988 static int 5989 test_zuc_encryption(const struct wireless_test_data *tdata) 5990 { 5991 struct crypto_testsuite_params *ts_params = &testsuite_params; 5992 struct crypto_unittest_params *ut_params = &unittest_params; 5993 5994 int retval; 5995 uint8_t *plaintext, *ciphertext; 5996 unsigned plaintext_pad_len; 5997 unsigned plaintext_len; 5998 struct rte_cryptodev_info dev_info; 5999 6000 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6001 uint64_t feat_flags = dev_info.feature_flags; 6002 6003 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6004 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6005 printf("Device doesn't support RAW data-path APIs.\n"); 6006 return TEST_SKIPPED; 6007 } 6008 6009 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6010 return TEST_SKIPPED; 6011 6012 /* Check if device supports ZUC EEA3 */ 6013 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6014 tdata->key.len, tdata->cipher_iv.len) < 0) 6015 return TEST_SKIPPED; 6016 6017 /* Create ZUC session */ 6018 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6019 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6020 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6021 tdata->key.data, tdata->key.len, 6022 tdata->cipher_iv.len); 6023 if (retval != 0) 6024 return retval; 6025 6026 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6027 6028 /* Clear mbuf payload */ 6029 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6030 rte_pktmbuf_tailroom(ut_params->ibuf)); 6031 6032 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6033 /* Append data which is padded to a multiple */ 6034 /* of the algorithms block size */ 6035 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6036 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6037 plaintext_pad_len); 6038 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6039 6040 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6041 6042 /* Create ZUC operation */ 6043 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6044 tdata->cipher_iv.len, 6045 tdata->plaintext.len, 6046 tdata->validCipherOffsetInBits.len); 6047 if (retval < 0) 6048 return retval; 6049 6050 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6051 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6052 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6053 else 6054 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6055 ut_params->op); 6056 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6057 6058 ut_params->obuf = ut_params->op->sym->m_dst; 6059 if (ut_params->obuf) 6060 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6061 else 6062 ciphertext = plaintext; 6063 6064 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6065 6066 /* Validate obuf */ 6067 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6068 ciphertext, 6069 tdata->ciphertext.data, 6070 tdata->validCipherLenInBits.len, 6071 "ZUC Ciphertext data not as expected"); 6072 return 0; 6073 } 6074 6075 static int 6076 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6077 { 6078 struct crypto_testsuite_params *ts_params = &testsuite_params; 6079 struct crypto_unittest_params *ut_params = &unittest_params; 6080 6081 int retval; 6082 6083 unsigned int plaintext_pad_len; 6084 unsigned int plaintext_len; 6085 const uint8_t *ciphertext; 6086 uint8_t ciphertext_buffer[2048]; 6087 struct rte_cryptodev_info dev_info; 6088 6089 /* Check if device supports ZUC EEA3 */ 6090 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6091 tdata->key.len, tdata->cipher_iv.len) < 0) 6092 return TEST_SKIPPED; 6093 6094 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6095 return TEST_SKIPPED; 6096 6097 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6098 6099 uint64_t feat_flags = dev_info.feature_flags; 6100 6101 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6102 printf("Device doesn't support in-place scatter-gather. " 6103 "Test Skipped.\n"); 6104 return TEST_SKIPPED; 6105 } 6106 6107 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6108 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6109 printf("Device doesn't support RAW data-path APIs.\n"); 6110 return TEST_SKIPPED; 6111 } 6112 6113 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6114 6115 /* Append data which is padded to a multiple */ 6116 /* of the algorithms block size */ 6117 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6118 6119 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6120 plaintext_pad_len, 10, 0); 6121 6122 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6123 tdata->plaintext.data); 6124 6125 /* Create ZUC session */ 6126 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6127 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6128 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6129 tdata->key.data, tdata->key.len, 6130 tdata->cipher_iv.len); 6131 if (retval < 0) 6132 return retval; 6133 6134 /* Clear mbuf payload */ 6135 6136 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6137 6138 /* Create ZUC operation */ 6139 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6140 tdata->cipher_iv.len, tdata->plaintext.len, 6141 tdata->validCipherOffsetInBits.len); 6142 if (retval < 0) 6143 return retval; 6144 6145 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6146 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6147 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6148 else 6149 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6150 ut_params->op); 6151 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6152 6153 ut_params->obuf = ut_params->op->sym->m_dst; 6154 if (ut_params->obuf) 6155 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6156 0, plaintext_len, ciphertext_buffer); 6157 else 6158 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6159 0, plaintext_len, ciphertext_buffer); 6160 6161 /* Validate obuf */ 6162 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6163 6164 /* Validate obuf */ 6165 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6166 ciphertext, 6167 tdata->ciphertext.data, 6168 tdata->validCipherLenInBits.len, 6169 "ZUC Ciphertext data not as expected"); 6170 6171 return 0; 6172 } 6173 6174 static int 6175 test_zuc_authentication(const struct wireless_test_data *tdata) 6176 { 6177 struct crypto_testsuite_params *ts_params = &testsuite_params; 6178 struct crypto_unittest_params *ut_params = &unittest_params; 6179 6180 int retval; 6181 unsigned plaintext_pad_len; 6182 unsigned plaintext_len; 6183 uint8_t *plaintext; 6184 6185 struct rte_cryptodev_info dev_info; 6186 6187 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6188 uint64_t feat_flags = dev_info.feature_flags; 6189 6190 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6191 (tdata->validAuthLenInBits.len % 8 != 0)) { 6192 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6193 return TEST_SKIPPED; 6194 } 6195 6196 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6197 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6198 printf("Device doesn't support RAW data-path APIs.\n"); 6199 return TEST_SKIPPED; 6200 } 6201 6202 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6203 return TEST_SKIPPED; 6204 6205 /* Check if device supports ZUC EIA3 */ 6206 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6207 tdata->key.len, tdata->auth_iv.len, 6208 tdata->digest.len) < 0) 6209 return TEST_SKIPPED; 6210 6211 /* Create ZUC session */ 6212 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6213 tdata->key.data, tdata->key.len, 6214 tdata->auth_iv.len, tdata->digest.len, 6215 RTE_CRYPTO_AUTH_OP_GENERATE, 6216 RTE_CRYPTO_AUTH_ZUC_EIA3); 6217 if (retval != 0) 6218 return retval; 6219 6220 /* alloc mbuf and set payload */ 6221 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6222 6223 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6224 rte_pktmbuf_tailroom(ut_params->ibuf)); 6225 6226 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6227 /* Append data which is padded to a multiple of */ 6228 /* the algorithms block size */ 6229 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6230 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6231 plaintext_pad_len); 6232 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6233 6234 /* Create ZUC operation */ 6235 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6236 tdata->auth_iv.data, tdata->auth_iv.len, 6237 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6238 tdata->validAuthLenInBits.len, 6239 0); 6240 if (retval < 0) 6241 return retval; 6242 6243 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6244 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6245 ut_params->op, 0, 1, 1, 0); 6246 else 6247 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6248 ut_params->op); 6249 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6250 ut_params->obuf = ut_params->op->sym->m_src; 6251 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6252 + plaintext_pad_len; 6253 6254 /* Validate obuf */ 6255 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6256 ut_params->digest, 6257 tdata->digest.data, 6258 tdata->digest.len, 6259 "ZUC Generated auth tag not as expected"); 6260 6261 return 0; 6262 } 6263 6264 static int 6265 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6266 uint8_t op_mode, uint8_t verify) 6267 { 6268 struct crypto_testsuite_params *ts_params = &testsuite_params; 6269 struct crypto_unittest_params *ut_params = &unittest_params; 6270 6271 int retval; 6272 6273 uint8_t *plaintext = NULL, *ciphertext = NULL; 6274 unsigned int plaintext_pad_len; 6275 unsigned int plaintext_len; 6276 unsigned int ciphertext_pad_len; 6277 unsigned int ciphertext_len; 6278 6279 struct rte_cryptodev_info dev_info; 6280 6281 /* Check if device supports ZUC EEA3 */ 6282 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6283 tdata->key.len, tdata->cipher_iv.len) < 0) 6284 return TEST_SKIPPED; 6285 6286 /* Check if device supports ZUC EIA3 */ 6287 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6288 tdata->key.len, tdata->auth_iv.len, 6289 tdata->digest.len) < 0) 6290 return TEST_SKIPPED; 6291 6292 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6293 6294 uint64_t feat_flags = dev_info.feature_flags; 6295 6296 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6297 printf("Device doesn't support digest encrypted.\n"); 6298 return TEST_SKIPPED; 6299 } 6300 if (op_mode == IN_PLACE) { 6301 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6302 printf("Device doesn't support in-place scatter-gather " 6303 "in both input and output mbufs.\n"); 6304 return TEST_SKIPPED; 6305 } 6306 6307 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6308 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6309 printf("Device doesn't support RAW data-path APIs.\n"); 6310 return TEST_SKIPPED; 6311 } 6312 } else { 6313 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6314 return TEST_SKIPPED; 6315 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6316 printf("Device doesn't support out-of-place scatter-gather " 6317 "in both input and output mbufs.\n"); 6318 return TEST_SKIPPED; 6319 } 6320 } 6321 6322 /* Create ZUC session */ 6323 retval = create_wireless_algo_auth_cipher_session( 6324 ts_params->valid_devs[0], 6325 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6326 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6327 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6328 : RTE_CRYPTO_AUTH_OP_GENERATE), 6329 RTE_CRYPTO_AUTH_ZUC_EIA3, 6330 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6331 tdata->key.data, tdata->key.len, 6332 tdata->auth_iv.len, tdata->digest.len, 6333 tdata->cipher_iv.len); 6334 6335 if (retval != 0) 6336 return retval; 6337 6338 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6339 if (op_mode == OUT_OF_PLACE) 6340 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6341 6342 /* clear mbuf payload */ 6343 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6344 rte_pktmbuf_tailroom(ut_params->ibuf)); 6345 if (op_mode == OUT_OF_PLACE) 6346 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6347 rte_pktmbuf_tailroom(ut_params->obuf)); 6348 6349 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6350 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6351 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6352 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6353 6354 if (verify) { 6355 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6356 ciphertext_pad_len); 6357 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6358 debug_hexdump(stdout, "ciphertext:", ciphertext, 6359 ciphertext_len); 6360 } else { 6361 /* make sure enough space to cover partial digest verify case */ 6362 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6363 ciphertext_pad_len); 6364 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6365 debug_hexdump(stdout, "plaintext:", plaintext, 6366 plaintext_len); 6367 } 6368 6369 if (op_mode == OUT_OF_PLACE) 6370 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6371 6372 /* Create ZUC operation */ 6373 retval = create_wireless_algo_auth_cipher_operation( 6374 tdata->digest.data, tdata->digest.len, 6375 tdata->cipher_iv.data, tdata->cipher_iv.len, 6376 tdata->auth_iv.data, tdata->auth_iv.len, 6377 (tdata->digest.offset_bytes == 0 ? 6378 (verify ? ciphertext_pad_len : plaintext_pad_len) 6379 : tdata->digest.offset_bytes), 6380 tdata->validCipherLenInBits.len, 6381 tdata->validCipherOffsetInBits.len, 6382 tdata->validAuthLenInBits.len, 6383 0, 6384 op_mode, 0, verify); 6385 6386 if (retval < 0) 6387 return retval; 6388 6389 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6390 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6391 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6392 else 6393 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6394 ut_params->op); 6395 6396 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6397 6398 ut_params->obuf = (op_mode == IN_PLACE ? 6399 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6400 6401 6402 if (verify) { 6403 if (ut_params->obuf) 6404 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6405 uint8_t *); 6406 else 6407 plaintext = ciphertext; 6408 6409 debug_hexdump(stdout, "plaintext:", plaintext, 6410 (tdata->plaintext.len >> 3) - tdata->digest.len); 6411 debug_hexdump(stdout, "plaintext expected:", 6412 tdata->plaintext.data, 6413 (tdata->plaintext.len >> 3) - tdata->digest.len); 6414 } else { 6415 if (ut_params->obuf) 6416 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6417 uint8_t *); 6418 else 6419 ciphertext = plaintext; 6420 6421 debug_hexdump(stdout, "ciphertext:", ciphertext, 6422 ciphertext_len); 6423 debug_hexdump(stdout, "ciphertext expected:", 6424 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6425 6426 ut_params->digest = rte_pktmbuf_mtod( 6427 ut_params->obuf, uint8_t *) + 6428 (tdata->digest.offset_bytes == 0 ? 6429 plaintext_pad_len : tdata->digest.offset_bytes); 6430 6431 debug_hexdump(stdout, "digest:", ut_params->digest, 6432 tdata->digest.len); 6433 debug_hexdump(stdout, "digest expected:", 6434 tdata->digest.data, tdata->digest.len); 6435 } 6436 6437 /* Validate obuf */ 6438 if (verify) { 6439 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6440 plaintext, 6441 tdata->plaintext.data, 6442 tdata->plaintext.len >> 3, 6443 "ZUC Plaintext data not as expected"); 6444 } else { 6445 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6446 ciphertext, 6447 tdata->ciphertext.data, 6448 tdata->ciphertext.len >> 3, 6449 "ZUC Ciphertext data not as expected"); 6450 6451 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6452 ut_params->digest, 6453 tdata->digest.data, 6454 DIGEST_BYTE_LENGTH_KASUMI_F9, 6455 "ZUC Generated auth tag not as expected"); 6456 } 6457 return 0; 6458 } 6459 6460 static int 6461 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6462 uint8_t op_mode, uint8_t verify) 6463 { 6464 struct crypto_testsuite_params *ts_params = &testsuite_params; 6465 struct crypto_unittest_params *ut_params = &unittest_params; 6466 6467 int retval; 6468 6469 const uint8_t *plaintext = NULL; 6470 const uint8_t *ciphertext = NULL; 6471 const uint8_t *digest = NULL; 6472 unsigned int plaintext_pad_len; 6473 unsigned int plaintext_len; 6474 unsigned int ciphertext_pad_len; 6475 unsigned int ciphertext_len; 6476 uint8_t buffer[10000]; 6477 uint8_t digest_buffer[10000]; 6478 6479 struct rte_cryptodev_info dev_info; 6480 6481 /* Check if device supports ZUC EEA3 */ 6482 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6483 tdata->key.len, tdata->cipher_iv.len) < 0) 6484 return TEST_SKIPPED; 6485 6486 /* Check if device supports ZUC EIA3 */ 6487 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6488 tdata->key.len, tdata->auth_iv.len, 6489 tdata->digest.len) < 0) 6490 return TEST_SKIPPED; 6491 6492 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6493 6494 uint64_t feat_flags = dev_info.feature_flags; 6495 6496 if (op_mode == IN_PLACE) { 6497 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6498 printf("Device doesn't support in-place scatter-gather " 6499 "in both input and output mbufs.\n"); 6500 return TEST_SKIPPED; 6501 } 6502 6503 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6504 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6505 printf("Device doesn't support RAW data-path APIs.\n"); 6506 return TEST_SKIPPED; 6507 } 6508 } else { 6509 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6510 return TEST_SKIPPED; 6511 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6512 printf("Device doesn't support out-of-place scatter-gather " 6513 "in both input and output mbufs.\n"); 6514 return TEST_SKIPPED; 6515 } 6516 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6517 printf("Device doesn't support digest encrypted.\n"); 6518 return TEST_SKIPPED; 6519 } 6520 } 6521 6522 /* Create ZUC session */ 6523 retval = create_wireless_algo_auth_cipher_session( 6524 ts_params->valid_devs[0], 6525 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6526 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6527 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6528 : RTE_CRYPTO_AUTH_OP_GENERATE), 6529 RTE_CRYPTO_AUTH_ZUC_EIA3, 6530 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6531 tdata->key.data, tdata->key.len, 6532 tdata->auth_iv.len, tdata->digest.len, 6533 tdata->cipher_iv.len); 6534 6535 if (retval != 0) 6536 return retval; 6537 6538 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6539 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6540 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6541 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6542 6543 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6544 plaintext_pad_len, 15, 0); 6545 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6546 "Failed to allocate input buffer in mempool"); 6547 6548 if (op_mode == OUT_OF_PLACE) { 6549 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6550 plaintext_pad_len, 15, 0); 6551 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6552 "Failed to allocate output buffer in mempool"); 6553 } 6554 6555 if (verify) { 6556 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6557 tdata->ciphertext.data); 6558 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6559 ciphertext_len, buffer); 6560 debug_hexdump(stdout, "ciphertext:", ciphertext, 6561 ciphertext_len); 6562 } else { 6563 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6564 tdata->plaintext.data); 6565 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6566 plaintext_len, buffer); 6567 debug_hexdump(stdout, "plaintext:", plaintext, 6568 plaintext_len); 6569 } 6570 memset(buffer, 0, sizeof(buffer)); 6571 6572 /* Create ZUC operation */ 6573 retval = create_wireless_algo_auth_cipher_operation( 6574 tdata->digest.data, tdata->digest.len, 6575 tdata->cipher_iv.data, tdata->cipher_iv.len, 6576 tdata->auth_iv.data, tdata->auth_iv.len, 6577 (tdata->digest.offset_bytes == 0 ? 6578 (verify ? ciphertext_pad_len : plaintext_pad_len) 6579 : tdata->digest.offset_bytes), 6580 tdata->validCipherLenInBits.len, 6581 tdata->validCipherOffsetInBits.len, 6582 tdata->validAuthLenInBits.len, 6583 0, 6584 op_mode, 1, verify); 6585 6586 if (retval < 0) 6587 return retval; 6588 6589 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6590 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6591 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6592 else 6593 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6594 ut_params->op); 6595 6596 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6597 6598 ut_params->obuf = (op_mode == IN_PLACE ? 6599 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6600 6601 if (verify) { 6602 if (ut_params->obuf) 6603 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6604 plaintext_len, buffer); 6605 else 6606 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6607 plaintext_len, buffer); 6608 6609 debug_hexdump(stdout, "plaintext:", plaintext, 6610 (tdata->plaintext.len >> 3) - tdata->digest.len); 6611 debug_hexdump(stdout, "plaintext expected:", 6612 tdata->plaintext.data, 6613 (tdata->plaintext.len >> 3) - tdata->digest.len); 6614 } else { 6615 if (ut_params->obuf) 6616 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6617 ciphertext_len, buffer); 6618 else 6619 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6620 ciphertext_len, buffer); 6621 6622 debug_hexdump(stdout, "ciphertext:", ciphertext, 6623 ciphertext_len); 6624 debug_hexdump(stdout, "ciphertext expected:", 6625 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6626 6627 if (ut_params->obuf) 6628 digest = rte_pktmbuf_read(ut_params->obuf, 6629 (tdata->digest.offset_bytes == 0 ? 6630 plaintext_pad_len : tdata->digest.offset_bytes), 6631 tdata->digest.len, digest_buffer); 6632 else 6633 digest = rte_pktmbuf_read(ut_params->ibuf, 6634 (tdata->digest.offset_bytes == 0 ? 6635 plaintext_pad_len : tdata->digest.offset_bytes), 6636 tdata->digest.len, digest_buffer); 6637 6638 debug_hexdump(stdout, "digest:", digest, 6639 tdata->digest.len); 6640 debug_hexdump(stdout, "digest expected:", 6641 tdata->digest.data, tdata->digest.len); 6642 } 6643 6644 /* Validate obuf */ 6645 if (verify) { 6646 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6647 plaintext, 6648 tdata->plaintext.data, 6649 tdata->plaintext.len >> 3, 6650 "ZUC Plaintext data not as expected"); 6651 } else { 6652 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6653 ciphertext, 6654 tdata->ciphertext.data, 6655 tdata->validDataLenInBits.len, 6656 "ZUC Ciphertext data not as expected"); 6657 6658 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6659 digest, 6660 tdata->digest.data, 6661 DIGEST_BYTE_LENGTH_KASUMI_F9, 6662 "ZUC Generated auth tag not as expected"); 6663 } 6664 return 0; 6665 } 6666 6667 static int 6668 test_kasumi_encryption_test_case_1(void) 6669 { 6670 return test_kasumi_encryption(&kasumi_test_case_1); 6671 } 6672 6673 static int 6674 test_kasumi_encryption_test_case_1_sgl(void) 6675 { 6676 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6677 } 6678 6679 static int 6680 test_kasumi_encryption_test_case_1_oop(void) 6681 { 6682 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6683 } 6684 6685 static int 6686 test_kasumi_encryption_test_case_1_oop_sgl(void) 6687 { 6688 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6689 } 6690 6691 static int 6692 test_kasumi_encryption_test_case_2(void) 6693 { 6694 return test_kasumi_encryption(&kasumi_test_case_2); 6695 } 6696 6697 static int 6698 test_kasumi_encryption_test_case_3(void) 6699 { 6700 return test_kasumi_encryption(&kasumi_test_case_3); 6701 } 6702 6703 static int 6704 test_kasumi_encryption_test_case_4(void) 6705 { 6706 return test_kasumi_encryption(&kasumi_test_case_4); 6707 } 6708 6709 static int 6710 test_kasumi_encryption_test_case_5(void) 6711 { 6712 return test_kasumi_encryption(&kasumi_test_case_5); 6713 } 6714 6715 static int 6716 test_kasumi_decryption_test_case_1(void) 6717 { 6718 return test_kasumi_decryption(&kasumi_test_case_1); 6719 } 6720 6721 static int 6722 test_kasumi_decryption_test_case_1_oop(void) 6723 { 6724 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6725 } 6726 6727 static int 6728 test_kasumi_decryption_test_case_2(void) 6729 { 6730 return test_kasumi_decryption(&kasumi_test_case_2); 6731 } 6732 6733 static int 6734 test_kasumi_decryption_test_case_3(void) 6735 { 6736 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6737 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6738 return TEST_SKIPPED; 6739 return test_kasumi_decryption(&kasumi_test_case_3); 6740 } 6741 6742 static int 6743 test_kasumi_decryption_test_case_4(void) 6744 { 6745 return test_kasumi_decryption(&kasumi_test_case_4); 6746 } 6747 6748 static int 6749 test_kasumi_decryption_test_case_5(void) 6750 { 6751 return test_kasumi_decryption(&kasumi_test_case_5); 6752 } 6753 static int 6754 test_snow3g_encryption_test_case_1(void) 6755 { 6756 return test_snow3g_encryption(&snow3g_test_case_1); 6757 } 6758 6759 static int 6760 test_snow3g_encryption_test_case_1_oop(void) 6761 { 6762 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6763 } 6764 6765 static int 6766 test_snow3g_encryption_test_case_1_oop_sgl(void) 6767 { 6768 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6769 } 6770 6771 6772 static int 6773 test_snow3g_encryption_test_case_1_offset_oop(void) 6774 { 6775 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6776 } 6777 6778 static int 6779 test_snow3g_encryption_test_case_2(void) 6780 { 6781 return test_snow3g_encryption(&snow3g_test_case_2); 6782 } 6783 6784 static int 6785 test_snow3g_encryption_test_case_3(void) 6786 { 6787 return test_snow3g_encryption(&snow3g_test_case_3); 6788 } 6789 6790 static int 6791 test_snow3g_encryption_test_case_4(void) 6792 { 6793 return test_snow3g_encryption(&snow3g_test_case_4); 6794 } 6795 6796 static int 6797 test_snow3g_encryption_test_case_5(void) 6798 { 6799 return test_snow3g_encryption(&snow3g_test_case_5); 6800 } 6801 6802 static int 6803 test_snow3g_decryption_test_case_1(void) 6804 { 6805 return test_snow3g_decryption(&snow3g_test_case_1); 6806 } 6807 6808 static int 6809 test_snow3g_decryption_test_case_1_oop(void) 6810 { 6811 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6812 } 6813 6814 static int 6815 test_snow3g_decryption_test_case_2(void) 6816 { 6817 return test_snow3g_decryption(&snow3g_test_case_2); 6818 } 6819 6820 static int 6821 test_snow3g_decryption_test_case_3(void) 6822 { 6823 return test_snow3g_decryption(&snow3g_test_case_3); 6824 } 6825 6826 static int 6827 test_snow3g_decryption_test_case_4(void) 6828 { 6829 return test_snow3g_decryption(&snow3g_test_case_4); 6830 } 6831 6832 static int 6833 test_snow3g_decryption_test_case_5(void) 6834 { 6835 return test_snow3g_decryption(&snow3g_test_case_5); 6836 } 6837 6838 /* 6839 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6840 * Pattern digest from snow3g_test_data must be allocated as 6841 * 4 last bytes in plaintext. 6842 */ 6843 static void 6844 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6845 struct snow3g_hash_test_data *output) 6846 { 6847 if ((pattern != NULL) && (output != NULL)) { 6848 output->key.len = pattern->key.len; 6849 6850 memcpy(output->key.data, 6851 pattern->key.data, pattern->key.len); 6852 6853 output->auth_iv.len = pattern->auth_iv.len; 6854 6855 memcpy(output->auth_iv.data, 6856 pattern->auth_iv.data, pattern->auth_iv.len); 6857 6858 output->plaintext.len = pattern->plaintext.len; 6859 6860 memcpy(output->plaintext.data, 6861 pattern->plaintext.data, pattern->plaintext.len >> 3); 6862 6863 output->digest.len = pattern->digest.len; 6864 6865 memcpy(output->digest.data, 6866 &pattern->plaintext.data[pattern->digest.offset_bytes], 6867 pattern->digest.len); 6868 6869 output->validAuthLenInBits.len = 6870 pattern->validAuthLenInBits.len; 6871 } 6872 } 6873 6874 /* 6875 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6876 */ 6877 static int 6878 test_snow3g_decryption_with_digest_test_case_1(void) 6879 { 6880 struct snow3g_hash_test_data snow3g_hash_data; 6881 struct rte_cryptodev_info dev_info; 6882 struct crypto_testsuite_params *ts_params = &testsuite_params; 6883 6884 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6885 uint64_t feat_flags = dev_info.feature_flags; 6886 6887 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6888 printf("Device doesn't support encrypted digest operations.\n"); 6889 return TEST_SKIPPED; 6890 } 6891 6892 /* 6893 * Function prepare data for hash verification test case. 6894 * Digest is allocated in 4 last bytes in plaintext, pattern. 6895 */ 6896 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6897 6898 return test_snow3g_decryption(&snow3g_test_case_7) & 6899 test_snow3g_authentication_verify(&snow3g_hash_data); 6900 } 6901 6902 static int 6903 test_snow3g_cipher_auth_test_case_1(void) 6904 { 6905 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6906 } 6907 6908 static int 6909 test_snow3g_auth_cipher_test_case_1(void) 6910 { 6911 return test_snow3g_auth_cipher( 6912 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6913 } 6914 6915 static int 6916 test_snow3g_auth_cipher_test_case_2(void) 6917 { 6918 return test_snow3g_auth_cipher( 6919 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6920 } 6921 6922 static int 6923 test_snow3g_auth_cipher_test_case_2_oop(void) 6924 { 6925 return test_snow3g_auth_cipher( 6926 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6927 } 6928 6929 static int 6930 test_snow3g_auth_cipher_part_digest_enc(void) 6931 { 6932 return test_snow3g_auth_cipher( 6933 &snow3g_auth_cipher_partial_digest_encryption, 6934 IN_PLACE, 0); 6935 } 6936 6937 static int 6938 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6939 { 6940 return test_snow3g_auth_cipher( 6941 &snow3g_auth_cipher_partial_digest_encryption, 6942 OUT_OF_PLACE, 0); 6943 } 6944 6945 static int 6946 test_snow3g_auth_cipher_test_case_3_sgl(void) 6947 { 6948 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6949 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6950 return TEST_SKIPPED; 6951 return test_snow3g_auth_cipher_sgl( 6952 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6953 } 6954 6955 static int 6956 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6957 { 6958 return test_snow3g_auth_cipher_sgl( 6959 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6960 } 6961 6962 static int 6963 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6964 { 6965 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6966 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6967 return TEST_SKIPPED; 6968 return test_snow3g_auth_cipher_sgl( 6969 &snow3g_auth_cipher_partial_digest_encryption, 6970 IN_PLACE, 0); 6971 } 6972 6973 static int 6974 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6975 { 6976 return test_snow3g_auth_cipher_sgl( 6977 &snow3g_auth_cipher_partial_digest_encryption, 6978 OUT_OF_PLACE, 0); 6979 } 6980 6981 static int 6982 test_snow3g_auth_cipher_total_digest_enc_1(void) 6983 { 6984 return test_snow3g_auth_cipher( 6985 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 6986 } 6987 6988 static int 6989 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 6990 { 6991 return test_snow3g_auth_cipher( 6992 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 6993 } 6994 6995 static int 6996 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 6997 { 6998 return test_snow3g_auth_cipher_sgl( 6999 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7000 } 7001 7002 static int 7003 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7004 { 7005 return test_snow3g_auth_cipher_sgl( 7006 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7007 } 7008 7009 static int 7010 test_snow3g_auth_cipher_verify_test_case_1(void) 7011 { 7012 return test_snow3g_auth_cipher( 7013 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7014 } 7015 7016 static int 7017 test_snow3g_auth_cipher_verify_test_case_2(void) 7018 { 7019 return test_snow3g_auth_cipher( 7020 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7021 } 7022 7023 static int 7024 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7025 { 7026 return test_snow3g_auth_cipher( 7027 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7028 } 7029 7030 static int 7031 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7032 { 7033 return test_snow3g_auth_cipher( 7034 &snow3g_auth_cipher_partial_digest_encryption, 7035 IN_PLACE, 1); 7036 } 7037 7038 static int 7039 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7040 { 7041 return test_snow3g_auth_cipher( 7042 &snow3g_auth_cipher_partial_digest_encryption, 7043 OUT_OF_PLACE, 1); 7044 } 7045 7046 static int 7047 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7048 { 7049 return test_snow3g_auth_cipher_sgl( 7050 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7051 } 7052 7053 static int 7054 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7055 { 7056 return test_snow3g_auth_cipher_sgl( 7057 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7058 } 7059 7060 static int 7061 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7062 { 7063 return test_snow3g_auth_cipher_sgl( 7064 &snow3g_auth_cipher_partial_digest_encryption, 7065 IN_PLACE, 1); 7066 } 7067 7068 static int 7069 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7070 { 7071 return test_snow3g_auth_cipher_sgl( 7072 &snow3g_auth_cipher_partial_digest_encryption, 7073 OUT_OF_PLACE, 1); 7074 } 7075 7076 static int 7077 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7078 { 7079 return test_snow3g_auth_cipher( 7080 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7081 } 7082 7083 static int 7084 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7085 { 7086 return test_snow3g_auth_cipher( 7087 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7088 } 7089 7090 static int 7091 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7092 { 7093 return test_snow3g_auth_cipher_sgl( 7094 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7095 } 7096 7097 static int 7098 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7099 { 7100 return test_snow3g_auth_cipher_sgl( 7101 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7102 } 7103 7104 static int 7105 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7106 { 7107 return test_snow3g_auth_cipher( 7108 &snow3g_test_case_7, IN_PLACE, 0); 7109 } 7110 7111 static int 7112 test_kasumi_auth_cipher_test_case_1(void) 7113 { 7114 return test_kasumi_auth_cipher( 7115 &kasumi_test_case_3, IN_PLACE, 0); 7116 } 7117 7118 static int 7119 test_kasumi_auth_cipher_test_case_2(void) 7120 { 7121 return test_kasumi_auth_cipher( 7122 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7123 } 7124 7125 static int 7126 test_kasumi_auth_cipher_test_case_2_oop(void) 7127 { 7128 return test_kasumi_auth_cipher( 7129 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7130 } 7131 7132 static int 7133 test_kasumi_auth_cipher_test_case_2_sgl(void) 7134 { 7135 return test_kasumi_auth_cipher_sgl( 7136 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7137 } 7138 7139 static int 7140 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7141 { 7142 return test_kasumi_auth_cipher_sgl( 7143 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7144 } 7145 7146 static int 7147 test_kasumi_auth_cipher_verify_test_case_1(void) 7148 { 7149 return test_kasumi_auth_cipher( 7150 &kasumi_test_case_3, IN_PLACE, 1); 7151 } 7152 7153 static int 7154 test_kasumi_auth_cipher_verify_test_case_2(void) 7155 { 7156 return test_kasumi_auth_cipher( 7157 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7158 } 7159 7160 static int 7161 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7162 { 7163 return test_kasumi_auth_cipher( 7164 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7165 } 7166 7167 static int 7168 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7169 { 7170 return test_kasumi_auth_cipher_sgl( 7171 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7172 } 7173 7174 static int 7175 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7176 { 7177 return test_kasumi_auth_cipher_sgl( 7178 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7179 } 7180 7181 static int 7182 test_kasumi_cipher_auth_test_case_1(void) 7183 { 7184 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7185 } 7186 7187 static int 7188 test_zuc_encryption_test_case_1(void) 7189 { 7190 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7191 } 7192 7193 static int 7194 test_zuc_encryption_test_case_2(void) 7195 { 7196 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7197 } 7198 7199 static int 7200 test_zuc_encryption_test_case_3(void) 7201 { 7202 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7203 } 7204 7205 static int 7206 test_zuc_encryption_test_case_4(void) 7207 { 7208 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7209 } 7210 7211 static int 7212 test_zuc_encryption_test_case_5(void) 7213 { 7214 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7215 } 7216 7217 static int 7218 test_zuc_encryption_test_case_6_sgl(void) 7219 { 7220 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7221 } 7222 7223 static int 7224 test_zuc_hash_generate_test_case_1(void) 7225 { 7226 return test_zuc_authentication(&zuc_test_case_auth_1b); 7227 } 7228 7229 static int 7230 test_zuc_hash_generate_test_case_2(void) 7231 { 7232 return test_zuc_authentication(&zuc_test_case_auth_90b); 7233 } 7234 7235 static int 7236 test_zuc_hash_generate_test_case_3(void) 7237 { 7238 return test_zuc_authentication(&zuc_test_case_auth_577b); 7239 } 7240 7241 static int 7242 test_zuc_hash_generate_test_case_4(void) 7243 { 7244 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7245 } 7246 7247 static int 7248 test_zuc_hash_generate_test_case_5(void) 7249 { 7250 return test_zuc_authentication(&zuc_test_auth_5670b); 7251 } 7252 7253 static int 7254 test_zuc_hash_generate_test_case_6(void) 7255 { 7256 return test_zuc_authentication(&zuc_test_case_auth_128b); 7257 } 7258 7259 static int 7260 test_zuc_hash_generate_test_case_7(void) 7261 { 7262 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7263 } 7264 7265 static int 7266 test_zuc_hash_generate_test_case_8(void) 7267 { 7268 return test_zuc_authentication(&zuc_test_case_auth_584b); 7269 } 7270 7271 static int 7272 test_zuc_hash_generate_test_case_9(void) 7273 { 7274 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b); 7275 } 7276 7277 static int 7278 test_zuc_hash_generate_test_case_10(void) 7279 { 7280 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b); 7281 } 7282 7283 static int 7284 test_zuc_hash_generate_test_case_11(void) 7285 { 7286 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b); 7287 } 7288 7289 static int 7290 test_zuc_cipher_auth_test_case_1(void) 7291 { 7292 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7293 } 7294 7295 static int 7296 test_zuc_cipher_auth_test_case_2(void) 7297 { 7298 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7299 } 7300 7301 static int 7302 test_zuc_auth_cipher_test_case_1(void) 7303 { 7304 return test_zuc_auth_cipher( 7305 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7306 } 7307 7308 static int 7309 test_zuc_auth_cipher_test_case_1_oop(void) 7310 { 7311 return test_zuc_auth_cipher( 7312 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7313 } 7314 7315 static int 7316 test_zuc_auth_cipher_test_case_1_sgl(void) 7317 { 7318 return test_zuc_auth_cipher_sgl( 7319 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7320 } 7321 7322 static int 7323 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7324 { 7325 return test_zuc_auth_cipher_sgl( 7326 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7327 } 7328 7329 static int 7330 test_zuc_auth_cipher_test_case_2(void) 7331 { 7332 return test_zuc_auth_cipher( 7333 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7334 } 7335 7336 static int 7337 test_zuc_auth_cipher_test_case_2_oop(void) 7338 { 7339 return test_zuc_auth_cipher( 7340 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7341 } 7342 7343 static int 7344 test_zuc_auth_cipher_verify_test_case_1(void) 7345 { 7346 return test_zuc_auth_cipher( 7347 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7348 } 7349 7350 static int 7351 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7352 { 7353 return test_zuc_auth_cipher( 7354 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7355 } 7356 7357 static int 7358 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7359 { 7360 return test_zuc_auth_cipher_sgl( 7361 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7362 } 7363 7364 static int 7365 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7366 { 7367 return test_zuc_auth_cipher_sgl( 7368 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7369 } 7370 7371 static int 7372 test_zuc_auth_cipher_verify_test_case_2(void) 7373 { 7374 return test_zuc_auth_cipher( 7375 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7376 } 7377 7378 static int 7379 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7380 { 7381 return test_zuc_auth_cipher( 7382 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7383 } 7384 7385 static int 7386 test_zuc256_encryption_test_case_1(void) 7387 { 7388 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7389 } 7390 7391 static int 7392 test_zuc256_encryption_test_case_2(void) 7393 { 7394 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7395 } 7396 7397 static int 7398 test_zuc256_authentication_test_case_1(void) 7399 { 7400 return test_zuc_authentication(&zuc256_test_case_auth_1); 7401 } 7402 7403 static int 7404 test_zuc256_authentication_test_case_2(void) 7405 { 7406 return test_zuc_authentication(&zuc256_test_case_auth_2); 7407 } 7408 7409 static int 7410 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7411 { 7412 uint8_t dev_id = testsuite_params.valid_devs[0]; 7413 7414 struct rte_cryptodev_sym_capability_idx cap_idx; 7415 7416 /* Check if device supports particular cipher algorithm */ 7417 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7418 cap_idx.algo.cipher = tdata->cipher_algo; 7419 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7420 return TEST_SKIPPED; 7421 7422 /* Check if device supports particular hash algorithm */ 7423 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7424 cap_idx.algo.auth = tdata->auth_algo; 7425 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7426 return TEST_SKIPPED; 7427 7428 return 0; 7429 } 7430 7431 static int 7432 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7433 uint8_t op_mode, uint8_t verify) 7434 { 7435 struct crypto_testsuite_params *ts_params = &testsuite_params; 7436 struct crypto_unittest_params *ut_params = &unittest_params; 7437 7438 int retval; 7439 7440 uint8_t *plaintext = NULL, *ciphertext = NULL; 7441 unsigned int plaintext_pad_len; 7442 unsigned int plaintext_len; 7443 unsigned int ciphertext_pad_len; 7444 unsigned int ciphertext_len; 7445 7446 struct rte_cryptodev_info dev_info; 7447 struct rte_crypto_op *op; 7448 7449 /* Check if device supports particular algorithms separately */ 7450 if (test_mixed_check_if_unsupported(tdata)) 7451 return TEST_SKIPPED; 7452 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7453 return TEST_SKIPPED; 7454 7455 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7456 7457 uint64_t feat_flags = dev_info.feature_flags; 7458 7459 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7460 printf("Device doesn't support digest encrypted.\n"); 7461 return TEST_SKIPPED; 7462 } 7463 7464 /* Create the session */ 7465 if (verify) 7466 retval = create_wireless_algo_cipher_auth_session( 7467 ts_params->valid_devs[0], 7468 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7469 RTE_CRYPTO_AUTH_OP_VERIFY, 7470 tdata->auth_algo, 7471 tdata->cipher_algo, 7472 tdata->auth_key.data, tdata->auth_key.len, 7473 tdata->auth_iv.len, tdata->digest_enc.len, 7474 tdata->cipher_iv.len); 7475 else 7476 retval = create_wireless_algo_auth_cipher_session( 7477 ts_params->valid_devs[0], 7478 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7479 RTE_CRYPTO_AUTH_OP_GENERATE, 7480 tdata->auth_algo, 7481 tdata->cipher_algo, 7482 tdata->auth_key.data, tdata->auth_key.len, 7483 tdata->auth_iv.len, tdata->digest_enc.len, 7484 tdata->cipher_iv.len); 7485 if (retval != 0) 7486 return retval; 7487 7488 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7489 if (op_mode == OUT_OF_PLACE) 7490 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7491 7492 /* clear mbuf payload */ 7493 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7494 rte_pktmbuf_tailroom(ut_params->ibuf)); 7495 if (op_mode == OUT_OF_PLACE) { 7496 7497 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7498 rte_pktmbuf_tailroom(ut_params->obuf)); 7499 } 7500 7501 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7502 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7503 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7504 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7505 7506 if (verify) { 7507 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7508 ciphertext_pad_len); 7509 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7510 debug_hexdump(stdout, "ciphertext:", ciphertext, 7511 ciphertext_len); 7512 } else { 7513 /* make sure enough space to cover partial digest verify case */ 7514 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7515 ciphertext_pad_len); 7516 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7517 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7518 } 7519 7520 if (op_mode == OUT_OF_PLACE) 7521 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7522 7523 /* Create the operation */ 7524 retval = create_wireless_algo_auth_cipher_operation( 7525 tdata->digest_enc.data, tdata->digest_enc.len, 7526 tdata->cipher_iv.data, tdata->cipher_iv.len, 7527 tdata->auth_iv.data, tdata->auth_iv.len, 7528 (tdata->digest_enc.offset == 0 ? 7529 plaintext_pad_len 7530 : tdata->digest_enc.offset), 7531 tdata->validCipherLen.len_bits, 7532 tdata->cipher.offset_bits, 7533 tdata->validAuthLen.len_bits, 7534 tdata->auth.offset_bits, 7535 op_mode, 0, verify); 7536 7537 if (retval < 0) 7538 return retval; 7539 7540 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7541 7542 /* Check if the op failed because the device doesn't */ 7543 /* support this particular combination of algorithms */ 7544 if (op == NULL && ut_params->op->status == 7545 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7546 printf("Device doesn't support this mixed combination. " 7547 "Test Skipped.\n"); 7548 return TEST_SKIPPED; 7549 } 7550 ut_params->op = op; 7551 7552 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7553 7554 ut_params->obuf = (op_mode == IN_PLACE ? 7555 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7556 7557 if (verify) { 7558 if (ut_params->obuf) 7559 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7560 uint8_t *); 7561 else 7562 plaintext = ciphertext + 7563 (tdata->cipher.offset_bits >> 3); 7564 7565 debug_hexdump(stdout, "plaintext:", plaintext, 7566 tdata->plaintext.len_bits >> 3); 7567 debug_hexdump(stdout, "plaintext expected:", 7568 tdata->plaintext.data, 7569 tdata->plaintext.len_bits >> 3); 7570 } else { 7571 if (ut_params->obuf) 7572 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7573 uint8_t *); 7574 else 7575 ciphertext = plaintext; 7576 7577 debug_hexdump(stdout, "ciphertext:", ciphertext, 7578 ciphertext_len); 7579 debug_hexdump(stdout, "ciphertext expected:", 7580 tdata->ciphertext.data, 7581 tdata->ciphertext.len_bits >> 3); 7582 7583 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7584 + (tdata->digest_enc.offset == 0 ? 7585 plaintext_pad_len : tdata->digest_enc.offset); 7586 7587 debug_hexdump(stdout, "digest:", ut_params->digest, 7588 tdata->digest_enc.len); 7589 debug_hexdump(stdout, "digest expected:", 7590 tdata->digest_enc.data, 7591 tdata->digest_enc.len); 7592 } 7593 7594 if (!verify) { 7595 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7596 ut_params->digest, 7597 tdata->digest_enc.data, 7598 tdata->digest_enc.len, 7599 "Generated auth tag not as expected"); 7600 } 7601 7602 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7603 if (verify) { 7604 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7605 plaintext, 7606 tdata->plaintext.data, 7607 tdata->plaintext.len_bits >> 3, 7608 "Plaintext data not as expected"); 7609 } else { 7610 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7611 ciphertext, 7612 tdata->ciphertext.data, 7613 tdata->validDataLen.len_bits, 7614 "Ciphertext data not as expected"); 7615 } 7616 } 7617 7618 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7619 "crypto op processing failed"); 7620 7621 return 0; 7622 } 7623 7624 static int 7625 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7626 uint8_t op_mode, uint8_t verify) 7627 { 7628 struct crypto_testsuite_params *ts_params = &testsuite_params; 7629 struct crypto_unittest_params *ut_params = &unittest_params; 7630 7631 int retval; 7632 7633 const uint8_t *plaintext = NULL; 7634 const uint8_t *ciphertext = NULL; 7635 const uint8_t *digest = NULL; 7636 unsigned int plaintext_pad_len; 7637 unsigned int plaintext_len; 7638 unsigned int ciphertext_pad_len; 7639 unsigned int ciphertext_len; 7640 uint8_t buffer[10000]; 7641 uint8_t digest_buffer[10000]; 7642 7643 struct rte_cryptodev_info dev_info; 7644 struct rte_crypto_op *op; 7645 7646 /* Check if device supports particular algorithms */ 7647 if (test_mixed_check_if_unsupported(tdata)) 7648 return TEST_SKIPPED; 7649 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7650 return TEST_SKIPPED; 7651 7652 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7653 7654 uint64_t feat_flags = dev_info.feature_flags; 7655 7656 if (op_mode == IN_PLACE) { 7657 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7658 printf("Device doesn't support in-place scatter-gather " 7659 "in both input and output mbufs.\n"); 7660 return TEST_SKIPPED; 7661 } 7662 } else { 7663 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7664 printf("Device doesn't support out-of-place scatter-gather " 7665 "in both input and output mbufs.\n"); 7666 return TEST_SKIPPED; 7667 } 7668 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7669 printf("Device doesn't support digest encrypted.\n"); 7670 return TEST_SKIPPED; 7671 } 7672 } 7673 7674 /* Create the session */ 7675 if (verify) 7676 retval = create_wireless_algo_cipher_auth_session( 7677 ts_params->valid_devs[0], 7678 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7679 RTE_CRYPTO_AUTH_OP_VERIFY, 7680 tdata->auth_algo, 7681 tdata->cipher_algo, 7682 tdata->auth_key.data, tdata->auth_key.len, 7683 tdata->auth_iv.len, tdata->digest_enc.len, 7684 tdata->cipher_iv.len); 7685 else 7686 retval = create_wireless_algo_auth_cipher_session( 7687 ts_params->valid_devs[0], 7688 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7689 RTE_CRYPTO_AUTH_OP_GENERATE, 7690 tdata->auth_algo, 7691 tdata->cipher_algo, 7692 tdata->auth_key.data, tdata->auth_key.len, 7693 tdata->auth_iv.len, tdata->digest_enc.len, 7694 tdata->cipher_iv.len); 7695 if (retval != 0) 7696 return retval; 7697 7698 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7699 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7700 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7701 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7702 7703 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7704 ciphertext_pad_len, 15, 0); 7705 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7706 "Failed to allocate input buffer in mempool"); 7707 7708 if (op_mode == OUT_OF_PLACE) { 7709 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7710 plaintext_pad_len, 15, 0); 7711 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7712 "Failed to allocate output buffer in mempool"); 7713 } 7714 7715 if (verify) { 7716 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7717 tdata->ciphertext.data); 7718 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7719 ciphertext_len, buffer); 7720 debug_hexdump(stdout, "ciphertext:", ciphertext, 7721 ciphertext_len); 7722 } else { 7723 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7724 tdata->plaintext.data); 7725 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7726 plaintext_len, buffer); 7727 debug_hexdump(stdout, "plaintext:", plaintext, 7728 plaintext_len); 7729 } 7730 memset(buffer, 0, sizeof(buffer)); 7731 7732 /* Create the operation */ 7733 retval = create_wireless_algo_auth_cipher_operation( 7734 tdata->digest_enc.data, tdata->digest_enc.len, 7735 tdata->cipher_iv.data, tdata->cipher_iv.len, 7736 tdata->auth_iv.data, tdata->auth_iv.len, 7737 (tdata->digest_enc.offset == 0 ? 7738 plaintext_pad_len 7739 : tdata->digest_enc.offset), 7740 tdata->validCipherLen.len_bits, 7741 tdata->cipher.offset_bits, 7742 tdata->validAuthLen.len_bits, 7743 tdata->auth.offset_bits, 7744 op_mode, 1, verify); 7745 7746 if (retval < 0) 7747 return retval; 7748 7749 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7750 7751 /* Check if the op failed because the device doesn't */ 7752 /* support this particular combination of algorithms */ 7753 if (op == NULL && ut_params->op->status == 7754 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7755 printf("Device doesn't support this mixed combination. " 7756 "Test Skipped.\n"); 7757 return TEST_SKIPPED; 7758 } 7759 ut_params->op = op; 7760 7761 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7762 7763 ut_params->obuf = (op_mode == IN_PLACE ? 7764 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7765 7766 if (verify) { 7767 if (ut_params->obuf) 7768 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7769 plaintext_len, buffer); 7770 else 7771 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7772 plaintext_len, buffer); 7773 7774 debug_hexdump(stdout, "plaintext:", plaintext, 7775 (tdata->plaintext.len_bits >> 3) - 7776 tdata->digest_enc.len); 7777 debug_hexdump(stdout, "plaintext expected:", 7778 tdata->plaintext.data, 7779 (tdata->plaintext.len_bits >> 3) - 7780 tdata->digest_enc.len); 7781 } else { 7782 if (ut_params->obuf) 7783 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7784 ciphertext_len, buffer); 7785 else 7786 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7787 ciphertext_len, buffer); 7788 7789 debug_hexdump(stdout, "ciphertext:", ciphertext, 7790 ciphertext_len); 7791 debug_hexdump(stdout, "ciphertext expected:", 7792 tdata->ciphertext.data, 7793 tdata->ciphertext.len_bits >> 3); 7794 7795 if (ut_params->obuf) 7796 digest = rte_pktmbuf_read(ut_params->obuf, 7797 (tdata->digest_enc.offset == 0 ? 7798 plaintext_pad_len : 7799 tdata->digest_enc.offset), 7800 tdata->digest_enc.len, digest_buffer); 7801 else 7802 digest = rte_pktmbuf_read(ut_params->ibuf, 7803 (tdata->digest_enc.offset == 0 ? 7804 plaintext_pad_len : 7805 tdata->digest_enc.offset), 7806 tdata->digest_enc.len, digest_buffer); 7807 7808 debug_hexdump(stdout, "digest:", digest, 7809 tdata->digest_enc.len); 7810 debug_hexdump(stdout, "digest expected:", 7811 tdata->digest_enc.data, tdata->digest_enc.len); 7812 } 7813 7814 if (!verify) { 7815 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7816 digest, 7817 tdata->digest_enc.data, 7818 tdata->digest_enc.len, 7819 "Generated auth tag not as expected"); 7820 } 7821 7822 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7823 if (verify) { 7824 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7825 plaintext, 7826 tdata->plaintext.data, 7827 tdata->plaintext.len_bits >> 3, 7828 "Plaintext data not as expected"); 7829 } else { 7830 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7831 ciphertext, 7832 tdata->ciphertext.data, 7833 tdata->validDataLen.len_bits, 7834 "Ciphertext data not as expected"); 7835 } 7836 } 7837 7838 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7839 "crypto op processing failed"); 7840 7841 return 0; 7842 } 7843 7844 /** AUTH AES CMAC + CIPHER AES CTR */ 7845 7846 static int 7847 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7848 { 7849 return test_mixed_auth_cipher( 7850 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7851 } 7852 7853 static int 7854 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7855 { 7856 return test_mixed_auth_cipher( 7857 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7858 } 7859 7860 static int 7861 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7862 { 7863 return test_mixed_auth_cipher_sgl( 7864 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7865 } 7866 7867 static int 7868 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7869 { 7870 return test_mixed_auth_cipher_sgl( 7871 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7872 } 7873 7874 static int 7875 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 7876 { 7877 return test_mixed_auth_cipher( 7878 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 7879 } 7880 7881 static int 7882 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 7883 { 7884 return test_mixed_auth_cipher( 7885 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 7886 } 7887 7888 static int 7889 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7890 { 7891 return test_mixed_auth_cipher( 7892 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7893 } 7894 7895 static int 7896 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 7897 { 7898 return test_mixed_auth_cipher( 7899 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 7900 } 7901 7902 static int 7903 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7904 { 7905 return test_mixed_auth_cipher( 7906 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7907 } 7908 7909 static int 7910 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7911 { 7912 return test_mixed_auth_cipher_sgl( 7913 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7914 } 7915 7916 static int 7917 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7918 { 7919 return test_mixed_auth_cipher_sgl( 7920 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7921 } 7922 7923 static int 7924 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 7925 { 7926 return test_mixed_auth_cipher( 7927 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 7928 } 7929 7930 /** MIXED AUTH + CIPHER */ 7931 7932 static int 7933 test_auth_zuc_cipher_snow_test_case_1(void) 7934 { 7935 return test_mixed_auth_cipher( 7936 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7937 } 7938 7939 static int 7940 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7941 { 7942 return test_mixed_auth_cipher( 7943 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7944 } 7945 7946 static int 7947 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 7948 { 7949 return test_mixed_auth_cipher( 7950 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 7951 } 7952 7953 static int 7954 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 7955 { 7956 return test_mixed_auth_cipher( 7957 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 7958 } 7959 7960 7961 static int 7962 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7963 { 7964 return test_mixed_auth_cipher( 7965 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7966 } 7967 7968 static int 7969 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7970 { 7971 return test_mixed_auth_cipher( 7972 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7973 } 7974 7975 static int 7976 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 7977 { 7978 return test_mixed_auth_cipher( 7979 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 7980 } 7981 7982 static int 7983 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 7984 { 7985 return test_mixed_auth_cipher( 7986 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 7987 } 7988 7989 static int 7990 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7991 { 7992 return test_mixed_auth_cipher( 7993 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7994 } 7995 7996 static int 7997 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7998 { 7999 return test_mixed_auth_cipher( 8000 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8001 } 8002 8003 static int 8004 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8005 { 8006 return test_mixed_auth_cipher( 8007 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8008 } 8009 8010 static int 8011 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8012 { 8013 return test_mixed_auth_cipher( 8014 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8015 } 8016 8017 static int 8018 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8019 { 8020 return test_mixed_auth_cipher( 8021 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8022 } 8023 8024 static int 8025 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8026 { 8027 return test_mixed_auth_cipher( 8028 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8029 } 8030 8031 static int 8032 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8033 { 8034 return test_mixed_auth_cipher_sgl( 8035 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8036 } 8037 8038 static int 8039 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8040 { 8041 return test_mixed_auth_cipher( 8042 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8043 } 8044 8045 static int 8046 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8047 { 8048 return test_mixed_auth_cipher_sgl( 8049 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8050 } 8051 8052 static int 8053 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8054 { 8055 return test_mixed_auth_cipher( 8056 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8057 } 8058 8059 static int 8060 test_auth_snow_cipher_zuc_test_case_1(void) 8061 { 8062 return test_mixed_auth_cipher( 8063 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8064 } 8065 8066 static int 8067 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8068 { 8069 return test_mixed_auth_cipher( 8070 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8071 } 8072 8073 static int 8074 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8075 { 8076 return test_mixed_auth_cipher( 8077 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8078 } 8079 8080 static int 8081 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8082 { 8083 return test_mixed_auth_cipher( 8084 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8085 } 8086 8087 static int 8088 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8089 { 8090 return test_mixed_auth_cipher( 8091 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8092 } 8093 8094 static int 8095 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8096 { 8097 return test_mixed_auth_cipher( 8098 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8099 } 8100 static int 8101 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8102 { 8103 return test_mixed_auth_cipher( 8104 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8105 } 8106 8107 static int 8108 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8109 { 8110 return test_mixed_auth_cipher( 8111 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8112 } 8113 8114 static int 8115 test_auth_null_cipher_snow_test_case_1(void) 8116 { 8117 return test_mixed_auth_cipher( 8118 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8119 } 8120 8121 static int 8122 test_verify_auth_null_cipher_snow_test_case_1(void) 8123 { 8124 return test_mixed_auth_cipher( 8125 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8126 } 8127 8128 static int 8129 test_auth_null_cipher_zuc_test_case_1(void) 8130 { 8131 return test_mixed_auth_cipher( 8132 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8133 } 8134 8135 static int 8136 test_verify_auth_null_cipher_zuc_test_case_1(void) 8137 { 8138 return test_mixed_auth_cipher( 8139 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8140 } 8141 8142 static int 8143 test_auth_snow_cipher_null_test_case_1(void) 8144 { 8145 return test_mixed_auth_cipher( 8146 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8147 } 8148 8149 static int 8150 test_verify_auth_snow_cipher_null_test_case_1(void) 8151 { 8152 return test_mixed_auth_cipher( 8153 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8154 } 8155 8156 static int 8157 test_auth_zuc_cipher_null_test_case_1(void) 8158 { 8159 return test_mixed_auth_cipher( 8160 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8161 } 8162 8163 static int 8164 test_verify_auth_zuc_cipher_null_test_case_1(void) 8165 { 8166 return test_mixed_auth_cipher( 8167 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8168 } 8169 8170 static int 8171 test_auth_null_cipher_aes_ctr_test_case_1(void) 8172 { 8173 return test_mixed_auth_cipher( 8174 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8175 } 8176 8177 static int 8178 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8179 { 8180 return test_mixed_auth_cipher( 8181 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8182 } 8183 8184 static int 8185 test_auth_aes_cmac_cipher_null_test_case_1(void) 8186 { 8187 return test_mixed_auth_cipher( 8188 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8189 } 8190 8191 static int 8192 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8193 { 8194 return test_mixed_auth_cipher( 8195 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8196 } 8197 8198 /* ***** AEAD algorithm Tests ***** */ 8199 8200 static int 8201 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8202 enum rte_crypto_aead_operation op, 8203 const uint8_t *key, const uint8_t key_len, 8204 const uint16_t aad_len, const uint8_t auth_len, 8205 uint8_t iv_len) 8206 { 8207 uint8_t aead_key[key_len]; 8208 int status; 8209 8210 struct crypto_testsuite_params *ts_params = &testsuite_params; 8211 struct crypto_unittest_params *ut_params = &unittest_params; 8212 8213 memcpy(aead_key, key, key_len); 8214 8215 /* Setup AEAD Parameters */ 8216 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8217 ut_params->aead_xform.next = NULL; 8218 ut_params->aead_xform.aead.algo = algo; 8219 ut_params->aead_xform.aead.op = op; 8220 ut_params->aead_xform.aead.key.data = aead_key; 8221 ut_params->aead_xform.aead.key.length = key_len; 8222 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8223 ut_params->aead_xform.aead.iv.length = iv_len; 8224 ut_params->aead_xform.aead.digest_length = auth_len; 8225 ut_params->aead_xform.aead.aad_length = aad_len; 8226 8227 debug_hexdump(stdout, "key:", key, key_len); 8228 8229 /* Create Crypto session*/ 8230 ut_params->sess = rte_cryptodev_sym_session_create( 8231 ts_params->session_mpool); 8232 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8233 8234 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 8235 &ut_params->aead_xform, 8236 ts_params->session_priv_mpool); 8237 8238 return status; 8239 } 8240 8241 static int 8242 create_aead_xform(struct rte_crypto_op *op, 8243 enum rte_crypto_aead_algorithm algo, 8244 enum rte_crypto_aead_operation aead_op, 8245 uint8_t *key, const uint8_t key_len, 8246 const uint8_t aad_len, const uint8_t auth_len, 8247 uint8_t iv_len) 8248 { 8249 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8250 "failed to allocate space for crypto transform"); 8251 8252 struct rte_crypto_sym_op *sym_op = op->sym; 8253 8254 /* Setup AEAD Parameters */ 8255 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8256 sym_op->xform->next = NULL; 8257 sym_op->xform->aead.algo = algo; 8258 sym_op->xform->aead.op = aead_op; 8259 sym_op->xform->aead.key.data = key; 8260 sym_op->xform->aead.key.length = key_len; 8261 sym_op->xform->aead.iv.offset = IV_OFFSET; 8262 sym_op->xform->aead.iv.length = iv_len; 8263 sym_op->xform->aead.digest_length = auth_len; 8264 sym_op->xform->aead.aad_length = aad_len; 8265 8266 debug_hexdump(stdout, "key:", key, key_len); 8267 8268 return 0; 8269 } 8270 8271 static int 8272 create_aead_operation(enum rte_crypto_aead_operation op, 8273 const struct aead_test_data *tdata) 8274 { 8275 struct crypto_testsuite_params *ts_params = &testsuite_params; 8276 struct crypto_unittest_params *ut_params = &unittest_params; 8277 8278 uint8_t *plaintext, *ciphertext; 8279 unsigned int aad_pad_len, plaintext_pad_len; 8280 8281 /* Generate Crypto op data structure */ 8282 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8283 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8284 TEST_ASSERT_NOT_NULL(ut_params->op, 8285 "Failed to allocate symmetric crypto operation struct"); 8286 8287 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8288 8289 /* Append aad data */ 8290 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8291 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8292 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8293 aad_pad_len); 8294 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8295 "no room to append aad"); 8296 8297 sym_op->aead.aad.phys_addr = 8298 rte_pktmbuf_iova(ut_params->ibuf); 8299 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8300 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8301 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8302 tdata->aad.len); 8303 8304 /* Append IV at the end of the crypto operation*/ 8305 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8306 uint8_t *, IV_OFFSET); 8307 8308 /* Copy IV 1 byte after the IV pointer, according to the API */ 8309 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8310 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8311 tdata->iv.len); 8312 } else { 8313 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8314 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8315 aad_pad_len); 8316 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8317 "no room to append aad"); 8318 8319 sym_op->aead.aad.phys_addr = 8320 rte_pktmbuf_iova(ut_params->ibuf); 8321 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8322 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8323 tdata->aad.len); 8324 8325 /* Append IV at the end of the crypto operation*/ 8326 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8327 uint8_t *, IV_OFFSET); 8328 8329 if (tdata->iv.len == 0) { 8330 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8331 debug_hexdump(stdout, "iv:", iv_ptr, 8332 AES_GCM_J0_LENGTH); 8333 } else { 8334 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8335 debug_hexdump(stdout, "iv:", iv_ptr, 8336 tdata->iv.len); 8337 } 8338 } 8339 8340 /* Append plaintext/ciphertext */ 8341 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8342 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8343 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8344 plaintext_pad_len); 8345 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8346 8347 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8348 debug_hexdump(stdout, "plaintext:", plaintext, 8349 tdata->plaintext.len); 8350 8351 if (ut_params->obuf) { 8352 ciphertext = (uint8_t *)rte_pktmbuf_append( 8353 ut_params->obuf, 8354 plaintext_pad_len + aad_pad_len); 8355 TEST_ASSERT_NOT_NULL(ciphertext, 8356 "no room to append ciphertext"); 8357 8358 memset(ciphertext + aad_pad_len, 0, 8359 tdata->ciphertext.len); 8360 } 8361 } else { 8362 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8363 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8364 plaintext_pad_len); 8365 TEST_ASSERT_NOT_NULL(ciphertext, 8366 "no room to append ciphertext"); 8367 8368 memcpy(ciphertext, tdata->ciphertext.data, 8369 tdata->ciphertext.len); 8370 debug_hexdump(stdout, "ciphertext:", ciphertext, 8371 tdata->ciphertext.len); 8372 8373 if (ut_params->obuf) { 8374 plaintext = (uint8_t *)rte_pktmbuf_append( 8375 ut_params->obuf, 8376 plaintext_pad_len + aad_pad_len); 8377 TEST_ASSERT_NOT_NULL(plaintext, 8378 "no room to append plaintext"); 8379 8380 memset(plaintext + aad_pad_len, 0, 8381 tdata->plaintext.len); 8382 } 8383 } 8384 8385 /* Append digest data */ 8386 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8387 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8388 ut_params->obuf ? ut_params->obuf : 8389 ut_params->ibuf, 8390 tdata->auth_tag.len); 8391 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8392 "no room to append digest"); 8393 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8394 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8395 ut_params->obuf ? ut_params->obuf : 8396 ut_params->ibuf, 8397 plaintext_pad_len + 8398 aad_pad_len); 8399 } else { 8400 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8401 ut_params->ibuf, tdata->auth_tag.len); 8402 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8403 "no room to append digest"); 8404 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8405 ut_params->ibuf, 8406 plaintext_pad_len + aad_pad_len); 8407 8408 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8409 tdata->auth_tag.len); 8410 debug_hexdump(stdout, "digest:", 8411 sym_op->aead.digest.data, 8412 tdata->auth_tag.len); 8413 } 8414 8415 sym_op->aead.data.length = tdata->plaintext.len; 8416 sym_op->aead.data.offset = aad_pad_len; 8417 8418 return 0; 8419 } 8420 8421 static int 8422 test_authenticated_encryption(const struct aead_test_data *tdata) 8423 { 8424 struct crypto_testsuite_params *ts_params = &testsuite_params; 8425 struct crypto_unittest_params *ut_params = &unittest_params; 8426 8427 int retval; 8428 uint8_t *ciphertext, *auth_tag; 8429 uint16_t plaintext_pad_len; 8430 uint32_t i; 8431 struct rte_cryptodev_info dev_info; 8432 8433 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8434 uint64_t feat_flags = dev_info.feature_flags; 8435 8436 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8437 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8438 printf("Device doesn't support RAW data-path APIs.\n"); 8439 return TEST_SKIPPED; 8440 } 8441 8442 /* Verify the capabilities */ 8443 struct rte_cryptodev_sym_capability_idx cap_idx; 8444 const struct rte_cryptodev_symmetric_capability *capability; 8445 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8446 cap_idx.algo.aead = tdata->algo; 8447 capability = rte_cryptodev_sym_capability_get( 8448 ts_params->valid_devs[0], &cap_idx); 8449 if (capability == NULL) 8450 return TEST_SKIPPED; 8451 if (rte_cryptodev_sym_capability_check_aead( 8452 capability, tdata->key.len, tdata->auth_tag.len, 8453 tdata->aad.len, tdata->iv.len)) 8454 return TEST_SKIPPED; 8455 8456 /* Create AEAD session */ 8457 retval = create_aead_session(ts_params->valid_devs[0], 8458 tdata->algo, 8459 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8460 tdata->key.data, tdata->key.len, 8461 tdata->aad.len, tdata->auth_tag.len, 8462 tdata->iv.len); 8463 if (retval < 0) 8464 return retval; 8465 8466 if (tdata->aad.len > MBUF_SIZE) { 8467 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8468 /* Populate full size of add data */ 8469 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8470 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8471 } else 8472 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8473 8474 /* clear mbuf payload */ 8475 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8476 rte_pktmbuf_tailroom(ut_params->ibuf)); 8477 8478 /* Create AEAD operation */ 8479 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8480 if (retval < 0) 8481 return retval; 8482 8483 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8484 8485 ut_params->op->sym->m_src = ut_params->ibuf; 8486 8487 /* Process crypto operation */ 8488 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8489 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8490 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8491 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8492 ut_params->op, 0, 0, 0, 0); 8493 else 8494 TEST_ASSERT_NOT_NULL( 8495 process_crypto_request(ts_params->valid_devs[0], 8496 ut_params->op), "failed to process sym crypto op"); 8497 8498 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8499 "crypto op processing failed"); 8500 8501 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8502 8503 if (ut_params->op->sym->m_dst) { 8504 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8505 uint8_t *); 8506 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8507 uint8_t *, plaintext_pad_len); 8508 } else { 8509 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8510 uint8_t *, 8511 ut_params->op->sym->cipher.data.offset); 8512 auth_tag = ciphertext + plaintext_pad_len; 8513 } 8514 8515 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8516 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8517 8518 /* Validate obuf */ 8519 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8520 ciphertext, 8521 tdata->ciphertext.data, 8522 tdata->ciphertext.len, 8523 "Ciphertext data not as expected"); 8524 8525 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8526 auth_tag, 8527 tdata->auth_tag.data, 8528 tdata->auth_tag.len, 8529 "Generated auth tag not as expected"); 8530 8531 return 0; 8532 8533 } 8534 8535 #ifdef RTE_LIB_SECURITY 8536 static int 8537 security_proto_supported(enum rte_security_session_action_type action, 8538 enum rte_security_session_protocol proto) 8539 { 8540 struct crypto_testsuite_params *ts_params = &testsuite_params; 8541 8542 const struct rte_security_capability *capabilities; 8543 const struct rte_security_capability *capability; 8544 uint16_t i = 0; 8545 8546 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8547 rte_cryptodev_get_sec_ctx( 8548 ts_params->valid_devs[0]); 8549 8550 8551 capabilities = rte_security_capabilities_get(ctx); 8552 8553 if (capabilities == NULL) 8554 return -ENOTSUP; 8555 8556 while ((capability = &capabilities[i++])->action != 8557 RTE_SECURITY_ACTION_TYPE_NONE) { 8558 if (capability->action == action && 8559 capability->protocol == proto) 8560 return 0; 8561 } 8562 8563 return -ENOTSUP; 8564 } 8565 8566 /* Basic algorithm run function for async inplace mode. 8567 * Creates a session from input parameters and runs one operation 8568 * on input_vec. Checks the output of the crypto operation against 8569 * output_vec. 8570 */ 8571 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8572 enum rte_crypto_auth_operation opa, 8573 const uint8_t *input_vec, unsigned int input_vec_len, 8574 const uint8_t *output_vec, 8575 unsigned int output_vec_len, 8576 enum rte_crypto_cipher_algorithm cipher_alg, 8577 const uint8_t *cipher_key, uint32_t cipher_key_len, 8578 enum rte_crypto_auth_algorithm auth_alg, 8579 const uint8_t *auth_key, uint32_t auth_key_len, 8580 uint8_t bearer, enum rte_security_pdcp_domain domain, 8581 uint8_t packet_direction, uint8_t sn_size, 8582 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8583 { 8584 struct crypto_testsuite_params *ts_params = &testsuite_params; 8585 struct crypto_unittest_params *ut_params = &unittest_params; 8586 uint8_t *plaintext; 8587 int ret = TEST_SUCCESS; 8588 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8589 rte_cryptodev_get_sec_ctx( 8590 ts_params->valid_devs[0]); 8591 struct rte_cryptodev_info dev_info; 8592 uint64_t feat_flags; 8593 8594 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8595 feat_flags = dev_info.feature_flags; 8596 8597 /* Verify the capabilities */ 8598 struct rte_security_capability_idx sec_cap_idx; 8599 8600 sec_cap_idx.action = ut_params->type; 8601 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8602 sec_cap_idx.pdcp.domain = domain; 8603 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8604 return TEST_SKIPPED; 8605 8606 /* Generate test mbuf data */ 8607 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8608 8609 /* clear mbuf payload */ 8610 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8611 rte_pktmbuf_tailroom(ut_params->ibuf)); 8612 8613 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8614 input_vec_len); 8615 memcpy(plaintext, input_vec, input_vec_len); 8616 8617 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8618 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8619 printf("Device does not support RAW data-path APIs.\n"); 8620 return TEST_SKIPPED; 8621 } 8622 /* Out of place support */ 8623 if (oop) { 8624 /* 8625 * For out-op-place we need to alloc another mbuf 8626 */ 8627 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8628 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8629 } 8630 8631 /* Setup Cipher Parameters */ 8632 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8633 ut_params->cipher_xform.cipher.algo = cipher_alg; 8634 ut_params->cipher_xform.cipher.op = opc; 8635 ut_params->cipher_xform.cipher.key.data = cipher_key; 8636 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8637 ut_params->cipher_xform.cipher.iv.length = 8638 packet_direction ? 4 : 0; 8639 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8640 8641 /* Setup HMAC Parameters if ICV header is required */ 8642 if (auth_alg != 0) { 8643 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8644 ut_params->auth_xform.next = NULL; 8645 ut_params->auth_xform.auth.algo = auth_alg; 8646 ut_params->auth_xform.auth.op = opa; 8647 ut_params->auth_xform.auth.key.data = auth_key; 8648 ut_params->auth_xform.auth.key.length = auth_key_len; 8649 8650 ut_params->cipher_xform.next = &ut_params->auth_xform; 8651 } else { 8652 ut_params->cipher_xform.next = NULL; 8653 } 8654 8655 struct rte_security_session_conf sess_conf = { 8656 .action_type = ut_params->type, 8657 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8658 {.pdcp = { 8659 .bearer = bearer, 8660 .domain = domain, 8661 .pkt_dir = packet_direction, 8662 .sn_size = sn_size, 8663 .hfn = packet_direction ? 0 : hfn, 8664 /** 8665 * hfn can be set as pdcp_test_hfn[i] 8666 * if hfn_ovrd is not set. Here, PDCP 8667 * packet direction is just used to 8668 * run half of the cases with session 8669 * HFN and other half with per packet 8670 * HFN. 8671 */ 8672 .hfn_threshold = hfn_threshold, 8673 .hfn_ovrd = packet_direction ? 1 : 0, 8674 .sdap_enabled = sdap, 8675 } }, 8676 .crypto_xform = &ut_params->cipher_xform 8677 }; 8678 8679 /* Create security session */ 8680 ut_params->sec_session = rte_security_session_create(ctx, 8681 &sess_conf, ts_params->session_mpool, 8682 ts_params->session_priv_mpool); 8683 8684 if (!ut_params->sec_session) { 8685 printf("TestCase %s()-%d line %d failed %s: ", 8686 __func__, i, __LINE__, "Failed to allocate session"); 8687 ret = TEST_FAILED; 8688 goto on_err; 8689 } 8690 8691 /* Generate crypto op data structure */ 8692 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8693 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8694 if (!ut_params->op) { 8695 printf("TestCase %s()-%d line %d failed %s: ", 8696 __func__, i, __LINE__, 8697 "Failed to allocate symmetric crypto operation struct"); 8698 ret = TEST_FAILED; 8699 goto on_err; 8700 } 8701 8702 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8703 uint32_t *, IV_OFFSET); 8704 *per_pkt_hfn = packet_direction ? hfn : 0; 8705 8706 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8707 8708 /* set crypto operation source mbuf */ 8709 ut_params->op->sym->m_src = ut_params->ibuf; 8710 if (oop) 8711 ut_params->op->sym->m_dst = ut_params->obuf; 8712 8713 /* Process crypto operation */ 8714 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8715 /* filling lengths */ 8716 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 8717 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 8718 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8719 ut_params->op, 1, 1, 0, 0); 8720 } else { 8721 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8722 } 8723 if (ut_params->op == NULL) { 8724 printf("TestCase %s()-%d line %d failed %s: ", 8725 __func__, i, __LINE__, 8726 "failed to process sym crypto op"); 8727 ret = TEST_FAILED; 8728 goto on_err; 8729 } 8730 8731 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8732 printf("TestCase %s()-%d line %d failed %s: ", 8733 __func__, i, __LINE__, "crypto op processing failed"); 8734 ret = TEST_FAILED; 8735 goto on_err; 8736 } 8737 8738 /* Validate obuf */ 8739 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8740 uint8_t *); 8741 if (oop) { 8742 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8743 uint8_t *); 8744 } 8745 8746 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8747 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8748 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8749 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8750 ret = TEST_FAILED; 8751 goto on_err; 8752 } 8753 8754 on_err: 8755 rte_crypto_op_free(ut_params->op); 8756 ut_params->op = NULL; 8757 8758 if (ut_params->sec_session) 8759 rte_security_session_destroy(ctx, ut_params->sec_session); 8760 ut_params->sec_session = NULL; 8761 8762 rte_pktmbuf_free(ut_params->ibuf); 8763 ut_params->ibuf = NULL; 8764 if (oop) { 8765 rte_pktmbuf_free(ut_params->obuf); 8766 ut_params->obuf = NULL; 8767 } 8768 8769 return ret; 8770 } 8771 8772 static int 8773 test_pdcp_proto_SGL(int i, int oop, 8774 enum rte_crypto_cipher_operation opc, 8775 enum rte_crypto_auth_operation opa, 8776 uint8_t *input_vec, 8777 unsigned int input_vec_len, 8778 uint8_t *output_vec, 8779 unsigned int output_vec_len, 8780 uint32_t fragsz, 8781 uint32_t fragsz_oop) 8782 { 8783 struct crypto_testsuite_params *ts_params = &testsuite_params; 8784 struct crypto_unittest_params *ut_params = &unittest_params; 8785 uint8_t *plaintext; 8786 struct rte_mbuf *buf, *buf_oop = NULL; 8787 int ret = TEST_SUCCESS; 8788 int to_trn = 0; 8789 int to_trn_tbl[16]; 8790 int segs = 1; 8791 unsigned int trn_data = 0; 8792 struct rte_cryptodev_info dev_info; 8793 uint64_t feat_flags; 8794 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8795 rte_cryptodev_get_sec_ctx( 8796 ts_params->valid_devs[0]); 8797 struct rte_mbuf *temp_mbuf; 8798 8799 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8800 feat_flags = dev_info.feature_flags; 8801 8802 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8803 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8804 printf("Device does not support RAW data-path APIs.\n"); 8805 return -ENOTSUP; 8806 } 8807 /* Verify the capabilities */ 8808 struct rte_security_capability_idx sec_cap_idx; 8809 8810 sec_cap_idx.action = ut_params->type; 8811 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8812 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8813 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8814 return TEST_SKIPPED; 8815 8816 if (fragsz > input_vec_len) 8817 fragsz = input_vec_len; 8818 8819 uint16_t plaintext_len = fragsz; 8820 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8821 8822 if (fragsz_oop > output_vec_len) 8823 frag_size_oop = output_vec_len; 8824 8825 int ecx = 0; 8826 if (input_vec_len % fragsz != 0) { 8827 if (input_vec_len / fragsz + 1 > 16) 8828 return 1; 8829 } else if (input_vec_len / fragsz > 16) 8830 return 1; 8831 8832 /* Out of place support */ 8833 if (oop) { 8834 /* 8835 * For out-op-place we need to alloc another mbuf 8836 */ 8837 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8838 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8839 buf_oop = ut_params->obuf; 8840 } 8841 8842 /* Generate test mbuf data */ 8843 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8844 8845 /* clear mbuf payload */ 8846 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8847 rte_pktmbuf_tailroom(ut_params->ibuf)); 8848 8849 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8850 plaintext_len); 8851 memcpy(plaintext, input_vec, plaintext_len); 8852 trn_data += plaintext_len; 8853 8854 buf = ut_params->ibuf; 8855 8856 /* 8857 * Loop until no more fragments 8858 */ 8859 8860 while (trn_data < input_vec_len) { 8861 ++segs; 8862 to_trn = (input_vec_len - trn_data < fragsz) ? 8863 (input_vec_len - trn_data) : fragsz; 8864 8865 to_trn_tbl[ecx++] = to_trn; 8866 8867 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8868 buf = buf->next; 8869 8870 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8871 rte_pktmbuf_tailroom(buf)); 8872 8873 /* OOP */ 8874 if (oop && !fragsz_oop) { 8875 buf_oop->next = 8876 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8877 buf_oop = buf_oop->next; 8878 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8879 0, rte_pktmbuf_tailroom(buf_oop)); 8880 rte_pktmbuf_append(buf_oop, to_trn); 8881 } 8882 8883 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8884 to_trn); 8885 8886 memcpy(plaintext, input_vec + trn_data, to_trn); 8887 trn_data += to_trn; 8888 } 8889 8890 ut_params->ibuf->nb_segs = segs; 8891 8892 segs = 1; 8893 if (fragsz_oop && oop) { 8894 to_trn = 0; 8895 ecx = 0; 8896 8897 trn_data = frag_size_oop; 8898 while (trn_data < output_vec_len) { 8899 ++segs; 8900 to_trn = 8901 (output_vec_len - trn_data < 8902 frag_size_oop) ? 8903 (output_vec_len - trn_data) : 8904 frag_size_oop; 8905 8906 to_trn_tbl[ecx++] = to_trn; 8907 8908 buf_oop->next = 8909 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8910 buf_oop = buf_oop->next; 8911 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8912 0, rte_pktmbuf_tailroom(buf_oop)); 8913 rte_pktmbuf_append(buf_oop, to_trn); 8914 8915 trn_data += to_trn; 8916 } 8917 ut_params->obuf->nb_segs = segs; 8918 } 8919 8920 /* Setup Cipher Parameters */ 8921 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8922 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8923 ut_params->cipher_xform.cipher.op = opc; 8924 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8925 ut_params->cipher_xform.cipher.key.length = 8926 pdcp_test_params[i].cipher_key_len; 8927 ut_params->cipher_xform.cipher.iv.length = 0; 8928 8929 /* Setup HMAC Parameters if ICV header is required */ 8930 if (pdcp_test_params[i].auth_alg != 0) { 8931 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8932 ut_params->auth_xform.next = NULL; 8933 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8934 ut_params->auth_xform.auth.op = opa; 8935 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8936 ut_params->auth_xform.auth.key.length = 8937 pdcp_test_params[i].auth_key_len; 8938 8939 ut_params->cipher_xform.next = &ut_params->auth_xform; 8940 } else { 8941 ut_params->cipher_xform.next = NULL; 8942 } 8943 8944 struct rte_security_session_conf sess_conf = { 8945 .action_type = ut_params->type, 8946 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8947 {.pdcp = { 8948 .bearer = pdcp_test_bearer[i], 8949 .domain = pdcp_test_params[i].domain, 8950 .pkt_dir = pdcp_test_packet_direction[i], 8951 .sn_size = pdcp_test_data_sn_size[i], 8952 .hfn = pdcp_test_hfn[i], 8953 .hfn_threshold = pdcp_test_hfn_threshold[i], 8954 .hfn_ovrd = 0, 8955 } }, 8956 .crypto_xform = &ut_params->cipher_xform 8957 }; 8958 8959 /* Create security session */ 8960 ut_params->sec_session = rte_security_session_create(ctx, 8961 &sess_conf, ts_params->session_mpool, 8962 ts_params->session_priv_mpool); 8963 8964 if (!ut_params->sec_session) { 8965 printf("TestCase %s()-%d line %d failed %s: ", 8966 __func__, i, __LINE__, "Failed to allocate session"); 8967 ret = TEST_FAILED; 8968 goto on_err; 8969 } 8970 8971 /* Generate crypto op data structure */ 8972 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8973 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8974 if (!ut_params->op) { 8975 printf("TestCase %s()-%d line %d failed %s: ", 8976 __func__, i, __LINE__, 8977 "Failed to allocate symmetric crypto operation struct"); 8978 ret = TEST_FAILED; 8979 goto on_err; 8980 } 8981 8982 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8983 8984 /* set crypto operation source mbuf */ 8985 ut_params->op->sym->m_src = ut_params->ibuf; 8986 if (oop) 8987 ut_params->op->sym->m_dst = ut_params->obuf; 8988 8989 /* Process crypto operation */ 8990 temp_mbuf = ut_params->op->sym->m_src; 8991 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8992 /* filling lengths */ 8993 while (temp_mbuf) { 8994 ut_params->op->sym->cipher.data.length 8995 += temp_mbuf->pkt_len; 8996 ut_params->op->sym->auth.data.length 8997 += temp_mbuf->pkt_len; 8998 temp_mbuf = temp_mbuf->next; 8999 } 9000 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9001 ut_params->op, 1, 1, 0, 0); 9002 } else { 9003 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9004 ut_params->op); 9005 } 9006 if (ut_params->op == NULL) { 9007 printf("TestCase %s()-%d line %d failed %s: ", 9008 __func__, i, __LINE__, 9009 "failed to process sym crypto op"); 9010 ret = TEST_FAILED; 9011 goto on_err; 9012 } 9013 9014 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9015 printf("TestCase %s()-%d line %d failed %s: ", 9016 __func__, i, __LINE__, "crypto op processing failed"); 9017 ret = TEST_FAILED; 9018 goto on_err; 9019 } 9020 9021 /* Validate obuf */ 9022 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9023 uint8_t *); 9024 if (oop) { 9025 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9026 uint8_t *); 9027 } 9028 if (fragsz_oop) 9029 fragsz = frag_size_oop; 9030 if (memcmp(ciphertext, output_vec, fragsz)) { 9031 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9032 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9033 rte_hexdump(stdout, "reference", output_vec, fragsz); 9034 ret = TEST_FAILED; 9035 goto on_err; 9036 } 9037 9038 buf = ut_params->op->sym->m_src->next; 9039 if (oop) 9040 buf = ut_params->op->sym->m_dst->next; 9041 9042 unsigned int off = fragsz; 9043 9044 ecx = 0; 9045 while (buf) { 9046 ciphertext = rte_pktmbuf_mtod(buf, 9047 uint8_t *); 9048 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9049 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9050 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9051 rte_hexdump(stdout, "reference", output_vec + off, 9052 to_trn_tbl[ecx]); 9053 ret = TEST_FAILED; 9054 goto on_err; 9055 } 9056 off += to_trn_tbl[ecx++]; 9057 buf = buf->next; 9058 } 9059 on_err: 9060 rte_crypto_op_free(ut_params->op); 9061 ut_params->op = NULL; 9062 9063 if (ut_params->sec_session) 9064 rte_security_session_destroy(ctx, ut_params->sec_session); 9065 ut_params->sec_session = NULL; 9066 9067 rte_pktmbuf_free(ut_params->ibuf); 9068 ut_params->ibuf = NULL; 9069 if (oop) { 9070 rte_pktmbuf_free(ut_params->obuf); 9071 ut_params->obuf = NULL; 9072 } 9073 9074 return ret; 9075 } 9076 9077 int 9078 test_pdcp_proto_cplane_encap(int i) 9079 { 9080 return test_pdcp_proto( 9081 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9082 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9083 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9084 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9085 pdcp_test_params[i].cipher_key_len, 9086 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9087 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9088 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9089 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9090 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9091 } 9092 9093 int 9094 test_pdcp_proto_uplane_encap(int i) 9095 { 9096 return test_pdcp_proto( 9097 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9098 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9099 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9100 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9101 pdcp_test_params[i].cipher_key_len, 9102 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9103 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9104 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9105 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9106 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9107 } 9108 9109 int 9110 test_pdcp_proto_uplane_encap_with_int(int i) 9111 { 9112 return test_pdcp_proto( 9113 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9114 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9115 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9116 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9117 pdcp_test_params[i].cipher_key_len, 9118 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9119 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9120 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9121 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9122 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9123 } 9124 9125 int 9126 test_pdcp_proto_cplane_decap(int i) 9127 { 9128 return test_pdcp_proto( 9129 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9130 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9131 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9132 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9133 pdcp_test_params[i].cipher_key_len, 9134 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9135 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9136 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9137 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9138 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9139 } 9140 9141 int 9142 test_pdcp_proto_uplane_decap(int i) 9143 { 9144 return test_pdcp_proto( 9145 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9146 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9147 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9148 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9149 pdcp_test_params[i].cipher_key_len, 9150 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9151 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9152 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9153 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9154 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9155 } 9156 9157 int 9158 test_pdcp_proto_uplane_decap_with_int(int i) 9159 { 9160 return test_pdcp_proto( 9161 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9162 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9163 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9164 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9165 pdcp_test_params[i].cipher_key_len, 9166 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9167 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9168 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9169 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9170 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9171 } 9172 9173 static int 9174 test_PDCP_PROTO_SGL_in_place_32B(void) 9175 { 9176 /* i can be used for running any PDCP case 9177 * In this case it is uplane 12-bit AES-SNOW DL encap 9178 */ 9179 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9180 return test_pdcp_proto_SGL(i, IN_PLACE, 9181 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9182 RTE_CRYPTO_AUTH_OP_GENERATE, 9183 pdcp_test_data_in[i], 9184 pdcp_test_data_in_len[i], 9185 pdcp_test_data_out[i], 9186 pdcp_test_data_in_len[i]+4, 9187 32, 0); 9188 } 9189 static int 9190 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9191 { 9192 /* i can be used for running any PDCP case 9193 * In this case it is uplane 18-bit NULL-NULL DL encap 9194 */ 9195 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9196 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9197 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9198 RTE_CRYPTO_AUTH_OP_GENERATE, 9199 pdcp_test_data_in[i], 9200 pdcp_test_data_in_len[i], 9201 pdcp_test_data_out[i], 9202 pdcp_test_data_in_len[i]+4, 9203 32, 128); 9204 } 9205 static int 9206 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9207 { 9208 /* i can be used for running any PDCP case 9209 * In this case it is uplane 18-bit AES DL encap 9210 */ 9211 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9212 + DOWNLINK; 9213 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9214 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9215 RTE_CRYPTO_AUTH_OP_GENERATE, 9216 pdcp_test_data_in[i], 9217 pdcp_test_data_in_len[i], 9218 pdcp_test_data_out[i], 9219 pdcp_test_data_in_len[i], 9220 32, 40); 9221 } 9222 static int 9223 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9224 { 9225 /* i can be used for running any PDCP case 9226 * In this case it is cplane 12-bit AES-ZUC DL encap 9227 */ 9228 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9229 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9230 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9231 RTE_CRYPTO_AUTH_OP_GENERATE, 9232 pdcp_test_data_in[i], 9233 pdcp_test_data_in_len[i], 9234 pdcp_test_data_out[i], 9235 pdcp_test_data_in_len[i]+4, 9236 128, 32); 9237 } 9238 9239 static int 9240 test_PDCP_SDAP_PROTO_encap_all(void) 9241 { 9242 int i = 0, size = 0; 9243 int err, all_err = TEST_SUCCESS; 9244 const struct pdcp_sdap_test *cur_test; 9245 9246 size = RTE_DIM(list_pdcp_sdap_tests); 9247 9248 for (i = 0; i < size; i++) { 9249 cur_test = &list_pdcp_sdap_tests[i]; 9250 err = test_pdcp_proto( 9251 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9252 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9253 cur_test->in_len, cur_test->data_out, 9254 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9255 cur_test->param.cipher_alg, cur_test->cipher_key, 9256 cur_test->param.cipher_key_len, 9257 cur_test->param.auth_alg, 9258 cur_test->auth_key, cur_test->param.auth_key_len, 9259 cur_test->bearer, cur_test->param.domain, 9260 cur_test->packet_direction, cur_test->sn_size, 9261 cur_test->hfn, 9262 cur_test->hfn_threshold, SDAP_ENABLED); 9263 if (err) { 9264 printf("\t%d) %s: Encapsulation failed\n", 9265 cur_test->test_idx, 9266 cur_test->param.name); 9267 err = TEST_FAILED; 9268 } else { 9269 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9270 cur_test->param.name); 9271 err = TEST_SUCCESS; 9272 } 9273 all_err += err; 9274 } 9275 9276 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9277 9278 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9279 } 9280 9281 static int 9282 test_PDCP_PROTO_short_mac(void) 9283 { 9284 int i = 0, size = 0; 9285 int err, all_err = TEST_SUCCESS; 9286 const struct pdcp_short_mac_test *cur_test; 9287 9288 size = RTE_DIM(list_pdcp_smac_tests); 9289 9290 for (i = 0; i < size; i++) { 9291 cur_test = &list_pdcp_smac_tests[i]; 9292 err = test_pdcp_proto( 9293 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9294 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9295 cur_test->in_len, cur_test->data_out, 9296 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9297 RTE_CRYPTO_CIPHER_NULL, NULL, 9298 0, cur_test->param.auth_alg, 9299 cur_test->auth_key, cur_test->param.auth_key_len, 9300 0, cur_test->param.domain, 0, 0, 9301 0, 0, 0); 9302 if (err) { 9303 printf("\t%d) %s: Short MAC test failed\n", 9304 cur_test->test_idx, 9305 cur_test->param.name); 9306 err = TEST_FAILED; 9307 } else { 9308 printf("\t%d) %s: Short MAC test PASS\n", 9309 cur_test->test_idx, 9310 cur_test->param.name); 9311 rte_hexdump(stdout, "MAC I", 9312 cur_test->data_out + cur_test->in_len + 2, 9313 2); 9314 err = TEST_SUCCESS; 9315 } 9316 all_err += err; 9317 } 9318 9319 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9320 9321 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9322 9323 } 9324 9325 static int 9326 test_PDCP_SDAP_PROTO_decap_all(void) 9327 { 9328 int i = 0, size = 0; 9329 int err, all_err = TEST_SUCCESS; 9330 const struct pdcp_sdap_test *cur_test; 9331 9332 size = RTE_DIM(list_pdcp_sdap_tests); 9333 9334 for (i = 0; i < size; i++) { 9335 cur_test = &list_pdcp_sdap_tests[i]; 9336 err = test_pdcp_proto( 9337 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9338 RTE_CRYPTO_AUTH_OP_VERIFY, 9339 cur_test->data_out, 9340 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9341 cur_test->data_in, cur_test->in_len, 9342 cur_test->param.cipher_alg, 9343 cur_test->cipher_key, cur_test->param.cipher_key_len, 9344 cur_test->param.auth_alg, cur_test->auth_key, 9345 cur_test->param.auth_key_len, cur_test->bearer, 9346 cur_test->param.domain, cur_test->packet_direction, 9347 cur_test->sn_size, cur_test->hfn, 9348 cur_test->hfn_threshold, SDAP_ENABLED); 9349 if (err) { 9350 printf("\t%d) %s: Decapsulation failed\n", 9351 cur_test->test_idx, 9352 cur_test->param.name); 9353 err = TEST_FAILED; 9354 } else { 9355 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9356 cur_test->param.name); 9357 err = TEST_SUCCESS; 9358 } 9359 all_err += err; 9360 } 9361 9362 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9363 9364 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9365 } 9366 9367 static int 9368 test_ipsec_proto_process(const struct ipsec_test_data td[], 9369 struct ipsec_test_data res_d[], 9370 int nb_td, 9371 bool silent, 9372 const struct ipsec_test_flags *flags) 9373 { 9374 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 9375 0x0000, 0x001a}; 9376 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 9377 0xe82c, 0x4887}; 9378 const struct rte_ipv4_hdr *ipv4 = 9379 (const struct rte_ipv4_hdr *)td[0].output_text.data; 9380 struct crypto_testsuite_params *ts_params = &testsuite_params; 9381 struct crypto_unittest_params *ut_params = &unittest_params; 9382 struct rte_security_capability_idx sec_cap_idx; 9383 const struct rte_security_capability *sec_cap; 9384 struct rte_security_ipsec_xform ipsec_xform; 9385 uint8_t dev_id = ts_params->valid_devs[0]; 9386 enum rte_security_ipsec_sa_direction dir; 9387 struct ipsec_test_data *res_d_tmp = NULL; 9388 int salt_len, i, ret = TEST_SUCCESS; 9389 struct rte_security_ctx *ctx; 9390 uint8_t *input_text; 9391 uint32_t src, dst; 9392 uint32_t verify; 9393 9394 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9395 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9396 9397 /* Use first test data to create session */ 9398 9399 /* Copy IPsec xform */ 9400 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9401 9402 dir = ipsec_xform.direction; 9403 verify = flags->tunnel_hdr_verify; 9404 9405 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 9406 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 9407 9408 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9409 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9410 src += 1; 9411 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9412 dst += 1; 9413 } 9414 9415 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 9416 if (td->ipsec_xform.tunnel.type == 9417 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 9418 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 9419 sizeof(src)); 9420 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 9421 sizeof(dst)); 9422 9423 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 9424 ipsec_xform.tunnel.ipv4.df = 0; 9425 9426 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 9427 ipsec_xform.tunnel.ipv4.df = 1; 9428 9429 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9430 ipsec_xform.tunnel.ipv4.dscp = 0; 9431 9432 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9433 ipsec_xform.tunnel.ipv4.dscp = 9434 TEST_IPSEC_DSCP_VAL; 9435 9436 } else { 9437 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9438 ipsec_xform.tunnel.ipv6.dscp = 0; 9439 9440 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9441 ipsec_xform.tunnel.ipv6.dscp = 9442 TEST_IPSEC_DSCP_VAL; 9443 9444 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 9445 sizeof(v6_src)); 9446 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 9447 sizeof(v6_dst)); 9448 } 9449 } 9450 9451 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9452 9453 sec_cap_idx.action = ut_params->type; 9454 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9455 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9456 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9457 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9458 9459 if (flags->udp_encap) 9460 ipsec_xform.options.udp_encap = 1; 9461 9462 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9463 if (sec_cap == NULL) 9464 return TEST_SKIPPED; 9465 9466 /* Copy cipher session parameters */ 9467 if (td[0].aead) { 9468 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9469 sizeof(ut_params->aead_xform)); 9470 ut_params->aead_xform.aead.key.data = td[0].key.data; 9471 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9472 9473 /* Verify crypto capabilities */ 9474 if (test_ipsec_crypto_caps_aead_verify( 9475 sec_cap, 9476 &ut_params->aead_xform) != 0) { 9477 if (!silent) 9478 RTE_LOG(INFO, USER1, 9479 "Crypto capabilities not supported\n"); 9480 return TEST_SKIPPED; 9481 } 9482 } else if (td[0].auth_only) { 9483 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9484 sizeof(ut_params->auth_xform)); 9485 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9486 9487 if (test_ipsec_crypto_caps_auth_verify( 9488 sec_cap, 9489 &ut_params->auth_xform) != 0) { 9490 if (!silent) 9491 RTE_LOG(INFO, USER1, 9492 "Auth crypto capabilities not supported\n"); 9493 return TEST_SKIPPED; 9494 } 9495 } else { 9496 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 9497 sizeof(ut_params->cipher_xform)); 9498 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9499 sizeof(ut_params->auth_xform)); 9500 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 9501 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9502 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9503 9504 /* Verify crypto capabilities */ 9505 9506 if (test_ipsec_crypto_caps_cipher_verify( 9507 sec_cap, 9508 &ut_params->cipher_xform) != 0) { 9509 if (!silent) 9510 RTE_LOG(INFO, USER1, 9511 "Cipher crypto capabilities not supported\n"); 9512 return TEST_SKIPPED; 9513 } 9514 9515 if (test_ipsec_crypto_caps_auth_verify( 9516 sec_cap, 9517 &ut_params->auth_xform) != 0) { 9518 if (!silent) 9519 RTE_LOG(INFO, USER1, 9520 "Auth crypto capabilities not supported\n"); 9521 return TEST_SKIPPED; 9522 } 9523 } 9524 9525 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9526 return TEST_SKIPPED; 9527 9528 struct rte_security_session_conf sess_conf = { 9529 .action_type = ut_params->type, 9530 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9531 }; 9532 9533 if (td[0].aead || td[0].aes_gmac) { 9534 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9535 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9536 } 9537 9538 if (td[0].aead) { 9539 sess_conf.ipsec = ipsec_xform; 9540 sess_conf.crypto_xform = &ut_params->aead_xform; 9541 } else if (td[0].auth_only) { 9542 sess_conf.ipsec = ipsec_xform; 9543 sess_conf.crypto_xform = &ut_params->auth_xform; 9544 } else { 9545 sess_conf.ipsec = ipsec_xform; 9546 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 9547 sess_conf.crypto_xform = &ut_params->cipher_xform; 9548 ut_params->cipher_xform.next = &ut_params->auth_xform; 9549 } else { 9550 sess_conf.crypto_xform = &ut_params->auth_xform; 9551 ut_params->auth_xform.next = &ut_params->cipher_xform; 9552 } 9553 } 9554 9555 /* Create security session */ 9556 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9557 ts_params->session_mpool, 9558 ts_params->session_priv_mpool); 9559 9560 if (ut_params->sec_session == NULL) 9561 return TEST_SKIPPED; 9562 9563 for (i = 0; i < nb_td; i++) { 9564 if (flags->antireplay && 9565 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 9566 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 9567 ret = rte_security_session_update(ctx, 9568 ut_params->sec_session, &sess_conf); 9569 if (ret) { 9570 printf("Could not update sequence number in " 9571 "session\n"); 9572 return TEST_SKIPPED; 9573 } 9574 } 9575 9576 /* Setup source mbuf payload */ 9577 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9578 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9579 rte_pktmbuf_tailroom(ut_params->ibuf)); 9580 9581 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9582 td[i].input_text.len); 9583 9584 memcpy(input_text, td[i].input_text.data, 9585 td[i].input_text.len); 9586 9587 if (test_ipsec_pkt_update(input_text, flags)) 9588 return TEST_FAILED; 9589 9590 /* Generate crypto op data structure */ 9591 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9592 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9593 if (!ut_params->op) { 9594 printf("TestCase %s line %d: %s\n", 9595 __func__, __LINE__, 9596 "failed to allocate crypto op"); 9597 ret = TEST_FAILED; 9598 goto crypto_op_free; 9599 } 9600 9601 /* Attach session to operation */ 9602 rte_security_attach_session(ut_params->op, 9603 ut_params->sec_session); 9604 9605 /* Set crypto operation mbufs */ 9606 ut_params->op->sym->m_src = ut_params->ibuf; 9607 ut_params->op->sym->m_dst = NULL; 9608 9609 /* Copy IV in crypto operation when IV generation is disabled */ 9610 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9611 ipsec_xform.options.iv_gen_disable == 1) { 9612 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9613 uint8_t *, 9614 IV_OFFSET); 9615 int len; 9616 9617 if (td[i].aead) 9618 len = td[i].xform.aead.aead.iv.length; 9619 else if (td[i].aes_gmac) 9620 len = td[i].xform.chain.auth.auth.iv.length; 9621 else 9622 len = td[i].xform.chain.cipher.cipher.iv.length; 9623 9624 memcpy(iv, td[i].iv.data, len); 9625 } 9626 9627 /* Process crypto operation */ 9628 process_crypto_request(dev_id, ut_params->op); 9629 9630 ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir, 9631 i + 1); 9632 if (ret != TEST_SUCCESS) 9633 goto crypto_op_free; 9634 9635 if (res_d != NULL) 9636 res_d_tmp = &res_d[i]; 9637 9638 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9639 res_d_tmp, silent, flags); 9640 if (ret != TEST_SUCCESS) 9641 goto crypto_op_free; 9642 9643 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 9644 flags, dir); 9645 if (ret != TEST_SUCCESS) 9646 goto crypto_op_free; 9647 9648 rte_crypto_op_free(ut_params->op); 9649 ut_params->op = NULL; 9650 9651 rte_pktmbuf_free(ut_params->ibuf); 9652 ut_params->ibuf = NULL; 9653 } 9654 9655 crypto_op_free: 9656 rte_crypto_op_free(ut_params->op); 9657 ut_params->op = NULL; 9658 9659 rte_pktmbuf_free(ut_params->ibuf); 9660 ut_params->ibuf = NULL; 9661 9662 if (ut_params->sec_session) 9663 rte_security_session_destroy(ctx, ut_params->sec_session); 9664 ut_params->sec_session = NULL; 9665 9666 return ret; 9667 } 9668 9669 static int 9670 test_ipsec_proto_known_vec(const void *test_data) 9671 { 9672 struct ipsec_test_data td_outb; 9673 struct ipsec_test_flags flags; 9674 9675 memset(&flags, 0, sizeof(flags)); 9676 9677 memcpy(&td_outb, test_data, sizeof(td_outb)); 9678 9679 if (td_outb.aes_gmac || td_outb.aead || 9680 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 9681 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 9682 /* Disable IV gen to be able to test with known vectors */ 9683 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9684 } 9685 9686 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9687 } 9688 9689 static int 9690 test_ipsec_proto_known_vec_inb(const void *test_data) 9691 { 9692 const struct ipsec_test_data *td = test_data; 9693 struct ipsec_test_flags flags; 9694 struct ipsec_test_data td_inb; 9695 9696 memset(&flags, 0, sizeof(flags)); 9697 9698 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 9699 test_ipsec_td_in_from_out(td, &td_inb); 9700 else 9701 memcpy(&td_inb, td, sizeof(td_inb)); 9702 9703 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9704 } 9705 9706 static int 9707 test_ipsec_proto_known_vec_fragmented(const void *test_data) 9708 { 9709 struct ipsec_test_data td_outb; 9710 struct ipsec_test_flags flags; 9711 9712 memset(&flags, 0, sizeof(flags)); 9713 flags.fragment = true; 9714 9715 memcpy(&td_outb, test_data, sizeof(td_outb)); 9716 9717 /* Disable IV gen to be able to test with known vectors */ 9718 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9719 9720 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9721 } 9722 9723 static int 9724 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9725 { 9726 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9727 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9728 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9729 int ret; 9730 9731 if (flags->iv_gen || 9732 flags->sa_expiry_pkts_soft || 9733 flags->sa_expiry_pkts_hard) 9734 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9735 9736 for (i = 0; i < RTE_DIM(alg_list); i++) { 9737 test_ipsec_td_prepare(alg_list[i].param1, 9738 alg_list[i].param2, 9739 flags, 9740 td_outb, 9741 nb_pkts); 9742 9743 if (!td_outb->aead) { 9744 enum rte_crypto_cipher_algorithm cipher_alg; 9745 enum rte_crypto_auth_algorithm auth_alg; 9746 9747 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 9748 auth_alg = td_outb->xform.chain.auth.auth.algo; 9749 9750 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 9751 continue; 9752 9753 /* ICV is not applicable for NULL auth */ 9754 if (flags->icv_corrupt && 9755 auth_alg == RTE_CRYPTO_AUTH_NULL) 9756 continue; 9757 9758 /* IV is not applicable for NULL cipher */ 9759 if (flags->iv_gen && 9760 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 9761 continue; 9762 } 9763 9764 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9765 flags); 9766 if (ret == TEST_SKIPPED) 9767 continue; 9768 9769 if (ret == TEST_FAILED) 9770 return TEST_FAILED; 9771 9772 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9773 9774 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9775 flags); 9776 if (ret == TEST_SKIPPED) 9777 continue; 9778 9779 if (ret == TEST_FAILED) 9780 return TEST_FAILED; 9781 9782 if (flags->display_alg) 9783 test_ipsec_display_alg(alg_list[i].param1, 9784 alg_list[i].param2); 9785 9786 pass_cnt++; 9787 } 9788 9789 if (pass_cnt > 0) 9790 return TEST_SUCCESS; 9791 else 9792 return TEST_SKIPPED; 9793 } 9794 9795 static int 9796 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 9797 { 9798 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9799 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9800 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9801 int ret; 9802 9803 for (i = 0; i < RTE_DIM(ah_alg_list); i++) { 9804 test_ipsec_td_prepare(ah_alg_list[i].param1, 9805 ah_alg_list[i].param2, 9806 flags, 9807 td_outb, 9808 nb_pkts); 9809 9810 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9811 flags); 9812 if (ret == TEST_SKIPPED) 9813 continue; 9814 9815 if (ret == TEST_FAILED) 9816 return TEST_FAILED; 9817 9818 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9819 9820 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9821 flags); 9822 if (ret == TEST_SKIPPED) 9823 continue; 9824 9825 if (ret == TEST_FAILED) 9826 return TEST_FAILED; 9827 9828 if (flags->display_alg) 9829 test_ipsec_display_alg(ah_alg_list[i].param1, 9830 ah_alg_list[i].param2); 9831 9832 pass_cnt++; 9833 } 9834 9835 if (pass_cnt > 0) 9836 return TEST_SUCCESS; 9837 else 9838 return TEST_SKIPPED; 9839 } 9840 9841 static int 9842 test_ipsec_proto_display_list(const void *data __rte_unused) 9843 { 9844 struct ipsec_test_flags flags; 9845 9846 memset(&flags, 0, sizeof(flags)); 9847 9848 flags.display_alg = true; 9849 9850 return test_ipsec_proto_all(&flags); 9851 } 9852 9853 static int 9854 test_ipsec_proto_ah_tunnel_ipv4(const void *data __rte_unused) 9855 { 9856 struct ipsec_test_flags flags; 9857 9858 memset(&flags, 0, sizeof(flags)); 9859 9860 flags.ah = true; 9861 flags.display_alg = true; 9862 9863 return test_ipsec_ah_proto_all(&flags); 9864 } 9865 9866 static int 9867 test_ipsec_proto_ah_transport_ipv4(const void *data __rte_unused) 9868 { 9869 struct ipsec_test_flags flags; 9870 9871 memset(&flags, 0, sizeof(flags)); 9872 9873 flags.ah = true; 9874 flags.transport = true; 9875 9876 return test_ipsec_ah_proto_all(&flags); 9877 } 9878 9879 static int 9880 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9881 { 9882 struct ipsec_test_flags flags; 9883 9884 memset(&flags, 0, sizeof(flags)); 9885 9886 flags.iv_gen = true; 9887 9888 return test_ipsec_proto_all(&flags); 9889 } 9890 9891 static int 9892 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9893 { 9894 struct ipsec_test_flags flags; 9895 9896 memset(&flags, 0, sizeof(flags)); 9897 9898 flags.sa_expiry_pkts_soft = true; 9899 9900 return test_ipsec_proto_all(&flags); 9901 } 9902 9903 static int 9904 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9905 { 9906 struct ipsec_test_flags flags; 9907 9908 memset(&flags, 0, sizeof(flags)); 9909 9910 flags.sa_expiry_pkts_hard = true; 9911 9912 return test_ipsec_proto_all(&flags); 9913 } 9914 9915 static int 9916 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9917 { 9918 struct ipsec_test_flags flags; 9919 9920 memset(&flags, 0, sizeof(flags)); 9921 9922 flags.icv_corrupt = true; 9923 9924 return test_ipsec_proto_all(&flags); 9925 } 9926 9927 static int 9928 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9929 { 9930 struct ipsec_test_flags flags; 9931 9932 memset(&flags, 0, sizeof(flags)); 9933 9934 flags.udp_encap = true; 9935 9936 return test_ipsec_proto_all(&flags); 9937 } 9938 9939 static int 9940 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9941 { 9942 struct ipsec_test_flags flags; 9943 9944 memset(&flags, 0, sizeof(flags)); 9945 9946 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9947 9948 return test_ipsec_proto_all(&flags); 9949 } 9950 9951 static int 9952 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9953 { 9954 struct ipsec_test_flags flags; 9955 9956 memset(&flags, 0, sizeof(flags)); 9957 9958 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9959 9960 return test_ipsec_proto_all(&flags); 9961 } 9962 9963 static int 9964 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9965 { 9966 struct ipsec_test_flags flags; 9967 9968 memset(&flags, 0, sizeof(flags)); 9969 9970 flags.udp_encap = true; 9971 flags.udp_ports_verify = true; 9972 9973 return test_ipsec_proto_all(&flags); 9974 } 9975 9976 static int 9977 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9978 { 9979 struct ipsec_test_flags flags; 9980 9981 memset(&flags, 0, sizeof(flags)); 9982 9983 flags.ip_csum = true; 9984 9985 return test_ipsec_proto_all(&flags); 9986 } 9987 9988 static int 9989 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9990 { 9991 struct ipsec_test_flags flags; 9992 9993 memset(&flags, 0, sizeof(flags)); 9994 9995 flags.l4_csum = true; 9996 9997 return test_ipsec_proto_all(&flags); 9998 } 9999 10000 static int 10001 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused) 10002 { 10003 struct ipsec_test_flags flags; 10004 10005 memset(&flags, 0, sizeof(flags)); 10006 10007 flags.ipv6 = false; 10008 flags.tunnel_ipv6 = false; 10009 10010 return test_ipsec_proto_all(&flags); 10011 } 10012 10013 static int 10014 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused) 10015 { 10016 struct ipsec_test_flags flags; 10017 10018 memset(&flags, 0, sizeof(flags)); 10019 10020 flags.ipv6 = true; 10021 flags.tunnel_ipv6 = true; 10022 10023 return test_ipsec_proto_all(&flags); 10024 } 10025 10026 static int 10027 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused) 10028 { 10029 struct ipsec_test_flags flags; 10030 10031 memset(&flags, 0, sizeof(flags)); 10032 10033 flags.ipv6 = false; 10034 flags.tunnel_ipv6 = true; 10035 10036 return test_ipsec_proto_all(&flags); 10037 } 10038 10039 static int 10040 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused) 10041 { 10042 struct ipsec_test_flags flags; 10043 10044 memset(&flags, 0, sizeof(flags)); 10045 10046 flags.ipv6 = true; 10047 flags.tunnel_ipv6 = false; 10048 10049 return test_ipsec_proto_all(&flags); 10050 } 10051 10052 static int 10053 test_ipsec_proto_transport_v4(const void *data __rte_unused) 10054 { 10055 struct ipsec_test_flags flags; 10056 10057 memset(&flags, 0, sizeof(flags)); 10058 10059 flags.ipv6 = false; 10060 flags.transport = true; 10061 10062 return test_ipsec_proto_all(&flags); 10063 } 10064 10065 static int 10066 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused) 10067 { 10068 struct ipsec_test_flags flags = { 10069 .l4_csum = true, 10070 .transport = true, 10071 }; 10072 10073 return test_ipsec_proto_all(&flags); 10074 } 10075 10076 static int 10077 test_ipsec_proto_stats(const void *data __rte_unused) 10078 { 10079 struct ipsec_test_flags flags; 10080 10081 memset(&flags, 0, sizeof(flags)); 10082 10083 flags.stats_success = true; 10084 10085 return test_ipsec_proto_all(&flags); 10086 } 10087 10088 static int 10089 test_ipsec_proto_pkt_fragment(const void *data __rte_unused) 10090 { 10091 struct ipsec_test_flags flags; 10092 10093 memset(&flags, 0, sizeof(flags)); 10094 10095 flags.fragment = true; 10096 10097 return test_ipsec_proto_all(&flags); 10098 10099 } 10100 10101 static int 10102 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused) 10103 { 10104 struct ipsec_test_flags flags; 10105 10106 memset(&flags, 0, sizeof(flags)); 10107 10108 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10109 10110 return test_ipsec_proto_all(&flags); 10111 } 10112 10113 static int 10114 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused) 10115 { 10116 struct ipsec_test_flags flags; 10117 10118 memset(&flags, 0, sizeof(flags)); 10119 10120 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10121 10122 return test_ipsec_proto_all(&flags); 10123 } 10124 10125 static int 10126 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused) 10127 { 10128 struct ipsec_test_flags flags; 10129 10130 memset(&flags, 0, sizeof(flags)); 10131 10132 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10133 10134 return test_ipsec_proto_all(&flags); 10135 } 10136 10137 static int 10138 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused) 10139 { 10140 struct ipsec_test_flags flags; 10141 10142 memset(&flags, 0, sizeof(flags)); 10143 10144 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10145 10146 return test_ipsec_proto_all(&flags); 10147 } 10148 10149 static int 10150 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused) 10151 { 10152 struct ipsec_test_flags flags; 10153 10154 memset(&flags, 0, sizeof(flags)); 10155 10156 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10157 10158 return test_ipsec_proto_all(&flags); 10159 } 10160 10161 static int 10162 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused) 10163 { 10164 struct ipsec_test_flags flags; 10165 10166 memset(&flags, 0, sizeof(flags)); 10167 10168 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10169 10170 return test_ipsec_proto_all(&flags); 10171 } 10172 10173 static int 10174 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused) 10175 { 10176 struct ipsec_test_flags flags; 10177 10178 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10179 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10180 return TEST_SKIPPED; 10181 10182 memset(&flags, 0, sizeof(flags)); 10183 10184 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10185 10186 return test_ipsec_proto_all(&flags); 10187 } 10188 10189 static int 10190 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused) 10191 { 10192 struct ipsec_test_flags flags; 10193 10194 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10195 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10196 return TEST_SKIPPED; 10197 10198 memset(&flags, 0, sizeof(flags)); 10199 10200 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 10201 10202 return test_ipsec_proto_all(&flags); 10203 } 10204 10205 static int 10206 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused) 10207 { 10208 struct ipsec_test_flags flags; 10209 10210 memset(&flags, 0, sizeof(flags)); 10211 10212 flags.ipv6 = true; 10213 flags.tunnel_ipv6 = true; 10214 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10215 10216 return test_ipsec_proto_all(&flags); 10217 } 10218 10219 static int 10220 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused) 10221 { 10222 struct ipsec_test_flags flags; 10223 10224 memset(&flags, 0, sizeof(flags)); 10225 10226 flags.ipv6 = true; 10227 flags.tunnel_ipv6 = true; 10228 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10229 10230 return test_ipsec_proto_all(&flags); 10231 } 10232 10233 static int 10234 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused) 10235 { 10236 struct ipsec_test_flags flags; 10237 10238 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10239 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10240 return TEST_SKIPPED; 10241 10242 memset(&flags, 0, sizeof(flags)); 10243 10244 flags.ipv6 = true; 10245 flags.tunnel_ipv6 = true; 10246 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10247 10248 return test_ipsec_proto_all(&flags); 10249 } 10250 10251 static int 10252 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused) 10253 { 10254 struct ipsec_test_flags flags; 10255 10256 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10257 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10258 return TEST_SKIPPED; 10259 10260 memset(&flags, 0, sizeof(flags)); 10261 10262 flags.ipv6 = true; 10263 flags.tunnel_ipv6 = true; 10264 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 10265 10266 return test_ipsec_proto_all(&flags); 10267 } 10268 10269 static int 10270 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 10271 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 10272 uint64_t winsz) 10273 { 10274 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10275 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10276 struct ipsec_test_flags flags; 10277 uint32_t i = 0, ret = 0; 10278 10279 if (nb_pkts == 0) 10280 return TEST_FAILED; 10281 10282 memset(&flags, 0, sizeof(flags)); 10283 flags.antireplay = true; 10284 10285 for (i = 0; i < nb_pkts; i++) { 10286 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 10287 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 10288 td_outb[i].ipsec_xform.replay_win_sz = winsz; 10289 td_outb[i].ipsec_xform.options.esn = esn_en; 10290 } 10291 10292 for (i = 0; i < nb_pkts; i++) 10293 td_outb[i].ipsec_xform.esn.value = esn[i]; 10294 10295 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10296 &flags); 10297 if (ret != TEST_SUCCESS) 10298 return ret; 10299 10300 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 10301 10302 for (i = 0; i < nb_pkts; i++) { 10303 td_inb[i].ipsec_xform.options.esn = esn_en; 10304 /* Set antireplay flag for packets to be dropped */ 10305 td_inb[i].ar_packet = replayed_pkt[i]; 10306 } 10307 10308 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10309 &flags); 10310 10311 return ret; 10312 } 10313 10314 static int 10315 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 10316 { 10317 10318 uint32_t nb_pkts = 5; 10319 bool replayed_pkt[5]; 10320 uint64_t esn[5]; 10321 10322 /* 1. Advance the TOP of the window to WS * 2 */ 10323 esn[0] = winsz * 2; 10324 /* 2. Test sequence number within the new window(WS + 1) */ 10325 esn[1] = winsz + 1; 10326 /* 3. Test sequence number less than the window BOTTOM */ 10327 esn[2] = winsz; 10328 /* 4. Test sequence number in the middle of the window */ 10329 esn[3] = winsz + (winsz / 2); 10330 /* 5. Test replay of the packet in the middle of the window */ 10331 esn[4] = winsz + (winsz / 2); 10332 10333 replayed_pkt[0] = false; 10334 replayed_pkt[1] = false; 10335 replayed_pkt[2] = true; 10336 replayed_pkt[3] = false; 10337 replayed_pkt[4] = true; 10338 10339 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10340 false, winsz); 10341 } 10342 10343 static int 10344 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 10345 { 10346 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 10347 } 10348 10349 static int 10350 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 10351 { 10352 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 10353 } 10354 10355 static int 10356 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 10357 { 10358 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 10359 } 10360 10361 static int 10362 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 10363 { 10364 10365 uint32_t nb_pkts = 7; 10366 bool replayed_pkt[7]; 10367 uint64_t esn[7]; 10368 10369 /* Set the initial sequence number */ 10370 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 10371 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 10372 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 10373 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 10374 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 10375 /* 3. Test with sequence number within window (1<<32 - 1) */ 10376 esn[3] = (uint64_t)((1ULL << 32) - 1); 10377 /* 4. Test with sequence number within window (1<<32 - 1) */ 10378 esn[4] = (uint64_t)(1ULL << 32); 10379 /* 5. Test with duplicate sequence number within 10380 * new window (1<<32 - 1) 10381 */ 10382 esn[5] = (uint64_t)((1ULL << 32) - 1); 10383 /* 6. Test with duplicate sequence number within new window (1<<32) */ 10384 esn[6] = (uint64_t)(1ULL << 32); 10385 10386 replayed_pkt[0] = false; 10387 replayed_pkt[1] = false; 10388 replayed_pkt[2] = false; 10389 replayed_pkt[3] = false; 10390 replayed_pkt[4] = false; 10391 replayed_pkt[5] = true; 10392 replayed_pkt[6] = true; 10393 10394 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10395 true, winsz); 10396 } 10397 10398 static int 10399 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 10400 { 10401 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 10402 } 10403 10404 static int 10405 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 10406 { 10407 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 10408 } 10409 10410 static int 10411 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 10412 { 10413 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 10414 } 10415 10416 static int 10417 test_PDCP_PROTO_all(void) 10418 { 10419 struct crypto_testsuite_params *ts_params = &testsuite_params; 10420 struct crypto_unittest_params *ut_params = &unittest_params; 10421 struct rte_cryptodev_info dev_info; 10422 int status; 10423 10424 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10425 uint64_t feat_flags = dev_info.feature_flags; 10426 10427 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 10428 return TEST_SKIPPED; 10429 10430 /* Set action type */ 10431 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10432 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10433 gbl_action_type; 10434 10435 if (security_proto_supported(ut_params->type, 10436 RTE_SECURITY_PROTOCOL_PDCP) < 0) 10437 return TEST_SKIPPED; 10438 10439 status = test_PDCP_PROTO_cplane_encap_all(); 10440 status += test_PDCP_PROTO_cplane_decap_all(); 10441 status += test_PDCP_PROTO_uplane_encap_all(); 10442 status += test_PDCP_PROTO_uplane_decap_all(); 10443 status += test_PDCP_PROTO_SGL_in_place_32B(); 10444 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 10445 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 10446 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 10447 status += test_PDCP_SDAP_PROTO_encap_all(); 10448 status += test_PDCP_SDAP_PROTO_decap_all(); 10449 status += test_PDCP_PROTO_short_mac(); 10450 10451 if (status) 10452 return TEST_FAILED; 10453 else 10454 return TEST_SUCCESS; 10455 } 10456 10457 static int 10458 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused) 10459 { 10460 struct ipsec_test_flags flags = { 10461 .dec_ttl_or_hop_limit = true 10462 }; 10463 10464 return test_ipsec_proto_all(&flags); 10465 } 10466 10467 static int 10468 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused) 10469 { 10470 struct ipsec_test_flags flags = { 10471 .ipv6 = true, 10472 .dec_ttl_or_hop_limit = true 10473 }; 10474 10475 return test_ipsec_proto_all(&flags); 10476 } 10477 10478 static int 10479 test_docsis_proto_uplink(const void *data) 10480 { 10481 const struct docsis_test_data *d_td = data; 10482 struct crypto_testsuite_params *ts_params = &testsuite_params; 10483 struct crypto_unittest_params *ut_params = &unittest_params; 10484 uint8_t *plaintext = NULL; 10485 uint8_t *ciphertext = NULL; 10486 uint8_t *iv_ptr; 10487 int32_t cipher_len, crc_len; 10488 uint32_t crc_data_len; 10489 int ret = TEST_SUCCESS; 10490 10491 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10492 rte_cryptodev_get_sec_ctx( 10493 ts_params->valid_devs[0]); 10494 10495 /* Verify the capabilities */ 10496 struct rte_security_capability_idx sec_cap_idx; 10497 const struct rte_security_capability *sec_cap; 10498 const struct rte_cryptodev_capabilities *crypto_cap; 10499 const struct rte_cryptodev_symmetric_capability *sym_cap; 10500 int j = 0; 10501 10502 /* Set action type */ 10503 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10504 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10505 gbl_action_type; 10506 10507 if (security_proto_supported(ut_params->type, 10508 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10509 return TEST_SKIPPED; 10510 10511 sec_cap_idx.action = ut_params->type; 10512 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10513 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 10514 10515 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10516 if (sec_cap == NULL) 10517 return TEST_SKIPPED; 10518 10519 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10520 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10521 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10522 crypto_cap->sym.xform_type == 10523 RTE_CRYPTO_SYM_XFORM_CIPHER && 10524 crypto_cap->sym.cipher.algo == 10525 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10526 sym_cap = &crypto_cap->sym; 10527 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10528 d_td->key.len, 10529 d_td->iv.len) == 0) 10530 break; 10531 } 10532 } 10533 10534 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10535 return TEST_SKIPPED; 10536 10537 /* Setup source mbuf payload */ 10538 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10539 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10540 rte_pktmbuf_tailroom(ut_params->ibuf)); 10541 10542 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10543 d_td->ciphertext.len); 10544 10545 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 10546 10547 /* Setup cipher session parameters */ 10548 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10549 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10550 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 10551 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10552 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10553 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10554 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10555 ut_params->cipher_xform.next = NULL; 10556 10557 /* Setup DOCSIS session parameters */ 10558 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 10559 10560 struct rte_security_session_conf sess_conf = { 10561 .action_type = ut_params->type, 10562 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10563 .docsis = ut_params->docsis_xform, 10564 .crypto_xform = &ut_params->cipher_xform, 10565 }; 10566 10567 /* Create security session */ 10568 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10569 ts_params->session_mpool, 10570 ts_params->session_priv_mpool); 10571 10572 if (!ut_params->sec_session) { 10573 printf("Test function %s line %u: failed to allocate session\n", 10574 __func__, __LINE__); 10575 ret = TEST_FAILED; 10576 goto on_err; 10577 } 10578 10579 /* Generate crypto op data structure */ 10580 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10581 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10582 if (!ut_params->op) { 10583 printf("Test function %s line %u: failed to allocate symmetric " 10584 "crypto operation\n", __func__, __LINE__); 10585 ret = TEST_FAILED; 10586 goto on_err; 10587 } 10588 10589 /* Setup CRC operation parameters */ 10590 crc_len = d_td->ciphertext.no_crc == false ? 10591 (d_td->ciphertext.len - 10592 d_td->ciphertext.crc_offset - 10593 RTE_ETHER_CRC_LEN) : 10594 0; 10595 crc_len = crc_len > 0 ? crc_len : 0; 10596 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 10597 ut_params->op->sym->auth.data.length = crc_len; 10598 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 10599 10600 /* Setup cipher operation parameters */ 10601 cipher_len = d_td->ciphertext.no_cipher == false ? 10602 (d_td->ciphertext.len - 10603 d_td->ciphertext.cipher_offset) : 10604 0; 10605 cipher_len = cipher_len > 0 ? cipher_len : 0; 10606 ut_params->op->sym->cipher.data.length = cipher_len; 10607 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 10608 10609 /* Setup cipher IV */ 10610 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10611 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10612 10613 /* Attach session to operation */ 10614 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10615 10616 /* Set crypto operation mbufs */ 10617 ut_params->op->sym->m_src = ut_params->ibuf; 10618 ut_params->op->sym->m_dst = NULL; 10619 10620 /* Process crypto operation */ 10621 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10622 NULL) { 10623 printf("Test function %s line %u: failed to process security " 10624 "crypto op\n", __func__, __LINE__); 10625 ret = TEST_FAILED; 10626 goto on_err; 10627 } 10628 10629 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10630 printf("Test function %s line %u: failed to process crypto op\n", 10631 __func__, __LINE__); 10632 ret = TEST_FAILED; 10633 goto on_err; 10634 } 10635 10636 /* Validate plaintext */ 10637 plaintext = ciphertext; 10638 10639 if (memcmp(plaintext, d_td->plaintext.data, 10640 d_td->plaintext.len - crc_data_len)) { 10641 printf("Test function %s line %u: plaintext not as expected\n", 10642 __func__, __LINE__); 10643 rte_hexdump(stdout, "expected", d_td->plaintext.data, 10644 d_td->plaintext.len); 10645 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 10646 ret = TEST_FAILED; 10647 goto on_err; 10648 } 10649 10650 on_err: 10651 rte_crypto_op_free(ut_params->op); 10652 ut_params->op = NULL; 10653 10654 if (ut_params->sec_session) 10655 rte_security_session_destroy(ctx, ut_params->sec_session); 10656 ut_params->sec_session = NULL; 10657 10658 rte_pktmbuf_free(ut_params->ibuf); 10659 ut_params->ibuf = NULL; 10660 10661 return ret; 10662 } 10663 10664 static int 10665 test_docsis_proto_downlink(const void *data) 10666 { 10667 const struct docsis_test_data *d_td = data; 10668 struct crypto_testsuite_params *ts_params = &testsuite_params; 10669 struct crypto_unittest_params *ut_params = &unittest_params; 10670 uint8_t *plaintext = NULL; 10671 uint8_t *ciphertext = NULL; 10672 uint8_t *iv_ptr; 10673 int32_t cipher_len, crc_len; 10674 int ret = TEST_SUCCESS; 10675 10676 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10677 rte_cryptodev_get_sec_ctx( 10678 ts_params->valid_devs[0]); 10679 10680 /* Verify the capabilities */ 10681 struct rte_security_capability_idx sec_cap_idx; 10682 const struct rte_security_capability *sec_cap; 10683 const struct rte_cryptodev_capabilities *crypto_cap; 10684 const struct rte_cryptodev_symmetric_capability *sym_cap; 10685 int j = 0; 10686 10687 /* Set action type */ 10688 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10689 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10690 gbl_action_type; 10691 10692 if (security_proto_supported(ut_params->type, 10693 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10694 return TEST_SKIPPED; 10695 10696 sec_cap_idx.action = ut_params->type; 10697 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10698 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10699 10700 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10701 if (sec_cap == NULL) 10702 return TEST_SKIPPED; 10703 10704 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10705 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10706 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10707 crypto_cap->sym.xform_type == 10708 RTE_CRYPTO_SYM_XFORM_CIPHER && 10709 crypto_cap->sym.cipher.algo == 10710 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10711 sym_cap = &crypto_cap->sym; 10712 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10713 d_td->key.len, 10714 d_td->iv.len) == 0) 10715 break; 10716 } 10717 } 10718 10719 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10720 return TEST_SKIPPED; 10721 10722 /* Setup source mbuf payload */ 10723 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10724 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10725 rte_pktmbuf_tailroom(ut_params->ibuf)); 10726 10727 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10728 d_td->plaintext.len); 10729 10730 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 10731 10732 /* Setup cipher session parameters */ 10733 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10734 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10735 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10736 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10737 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10738 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10739 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10740 ut_params->cipher_xform.next = NULL; 10741 10742 /* Setup DOCSIS session parameters */ 10743 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10744 10745 struct rte_security_session_conf sess_conf = { 10746 .action_type = ut_params->type, 10747 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10748 .docsis = ut_params->docsis_xform, 10749 .crypto_xform = &ut_params->cipher_xform, 10750 }; 10751 10752 /* Create security session */ 10753 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10754 ts_params->session_mpool, 10755 ts_params->session_priv_mpool); 10756 10757 if (!ut_params->sec_session) { 10758 printf("Test function %s line %u: failed to allocate session\n", 10759 __func__, __LINE__); 10760 ret = TEST_FAILED; 10761 goto on_err; 10762 } 10763 10764 /* Generate crypto op data structure */ 10765 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10766 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10767 if (!ut_params->op) { 10768 printf("Test function %s line %u: failed to allocate symmetric " 10769 "crypto operation\n", __func__, __LINE__); 10770 ret = TEST_FAILED; 10771 goto on_err; 10772 } 10773 10774 /* Setup CRC operation parameters */ 10775 crc_len = d_td->plaintext.no_crc == false ? 10776 (d_td->plaintext.len - 10777 d_td->plaintext.crc_offset - 10778 RTE_ETHER_CRC_LEN) : 10779 0; 10780 crc_len = crc_len > 0 ? crc_len : 0; 10781 ut_params->op->sym->auth.data.length = crc_len; 10782 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 10783 10784 /* Setup cipher operation parameters */ 10785 cipher_len = d_td->plaintext.no_cipher == false ? 10786 (d_td->plaintext.len - 10787 d_td->plaintext.cipher_offset) : 10788 0; 10789 cipher_len = cipher_len > 0 ? cipher_len : 0; 10790 ut_params->op->sym->cipher.data.length = cipher_len; 10791 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 10792 10793 /* Setup cipher IV */ 10794 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10795 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10796 10797 /* Attach session to operation */ 10798 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10799 10800 /* Set crypto operation mbufs */ 10801 ut_params->op->sym->m_src = ut_params->ibuf; 10802 ut_params->op->sym->m_dst = NULL; 10803 10804 /* Process crypto operation */ 10805 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10806 NULL) { 10807 printf("Test function %s line %u: failed to process crypto op\n", 10808 __func__, __LINE__); 10809 ret = TEST_FAILED; 10810 goto on_err; 10811 } 10812 10813 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10814 printf("Test function %s line %u: crypto op processing failed\n", 10815 __func__, __LINE__); 10816 ret = TEST_FAILED; 10817 goto on_err; 10818 } 10819 10820 /* Validate ciphertext */ 10821 ciphertext = plaintext; 10822 10823 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 10824 printf("Test function %s line %u: plaintext not as expected\n", 10825 __func__, __LINE__); 10826 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 10827 d_td->ciphertext.len); 10828 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 10829 ret = TEST_FAILED; 10830 goto on_err; 10831 } 10832 10833 on_err: 10834 rte_crypto_op_free(ut_params->op); 10835 ut_params->op = NULL; 10836 10837 if (ut_params->sec_session) 10838 rte_security_session_destroy(ctx, ut_params->sec_session); 10839 ut_params->sec_session = NULL; 10840 10841 rte_pktmbuf_free(ut_params->ibuf); 10842 ut_params->ibuf = NULL; 10843 10844 return ret; 10845 } 10846 #endif 10847 10848 static int 10849 test_AES_GCM_authenticated_encryption_test_case_1(void) 10850 { 10851 return test_authenticated_encryption(&gcm_test_case_1); 10852 } 10853 10854 static int 10855 test_AES_GCM_authenticated_encryption_test_case_2(void) 10856 { 10857 return test_authenticated_encryption(&gcm_test_case_2); 10858 } 10859 10860 static int 10861 test_AES_GCM_authenticated_encryption_test_case_3(void) 10862 { 10863 return test_authenticated_encryption(&gcm_test_case_3); 10864 } 10865 10866 static int 10867 test_AES_GCM_authenticated_encryption_test_case_4(void) 10868 { 10869 return test_authenticated_encryption(&gcm_test_case_4); 10870 } 10871 10872 static int 10873 test_AES_GCM_authenticated_encryption_test_case_5(void) 10874 { 10875 return test_authenticated_encryption(&gcm_test_case_5); 10876 } 10877 10878 static int 10879 test_AES_GCM_authenticated_encryption_test_case_6(void) 10880 { 10881 return test_authenticated_encryption(&gcm_test_case_6); 10882 } 10883 10884 static int 10885 test_AES_GCM_authenticated_encryption_test_case_7(void) 10886 { 10887 return test_authenticated_encryption(&gcm_test_case_7); 10888 } 10889 10890 static int 10891 test_AES_GCM_authenticated_encryption_test_case_8(void) 10892 { 10893 return test_authenticated_encryption(&gcm_test_case_8); 10894 } 10895 10896 static int 10897 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 10898 { 10899 return test_authenticated_encryption(&gcm_J0_test_case_1); 10900 } 10901 10902 static int 10903 test_AES_GCM_auth_encryption_test_case_192_1(void) 10904 { 10905 return test_authenticated_encryption(&gcm_test_case_192_1); 10906 } 10907 10908 static int 10909 test_AES_GCM_auth_encryption_test_case_192_2(void) 10910 { 10911 return test_authenticated_encryption(&gcm_test_case_192_2); 10912 } 10913 10914 static int 10915 test_AES_GCM_auth_encryption_test_case_192_3(void) 10916 { 10917 return test_authenticated_encryption(&gcm_test_case_192_3); 10918 } 10919 10920 static int 10921 test_AES_GCM_auth_encryption_test_case_192_4(void) 10922 { 10923 return test_authenticated_encryption(&gcm_test_case_192_4); 10924 } 10925 10926 static int 10927 test_AES_GCM_auth_encryption_test_case_192_5(void) 10928 { 10929 return test_authenticated_encryption(&gcm_test_case_192_5); 10930 } 10931 10932 static int 10933 test_AES_GCM_auth_encryption_test_case_192_6(void) 10934 { 10935 return test_authenticated_encryption(&gcm_test_case_192_6); 10936 } 10937 10938 static int 10939 test_AES_GCM_auth_encryption_test_case_192_7(void) 10940 { 10941 return test_authenticated_encryption(&gcm_test_case_192_7); 10942 } 10943 10944 static int 10945 test_AES_GCM_auth_encryption_test_case_256_1(void) 10946 { 10947 return test_authenticated_encryption(&gcm_test_case_256_1); 10948 } 10949 10950 static int 10951 test_AES_GCM_auth_encryption_test_case_256_2(void) 10952 { 10953 return test_authenticated_encryption(&gcm_test_case_256_2); 10954 } 10955 10956 static int 10957 test_AES_GCM_auth_encryption_test_case_256_3(void) 10958 { 10959 return test_authenticated_encryption(&gcm_test_case_256_3); 10960 } 10961 10962 static int 10963 test_AES_GCM_auth_encryption_test_case_256_4(void) 10964 { 10965 return test_authenticated_encryption(&gcm_test_case_256_4); 10966 } 10967 10968 static int 10969 test_AES_GCM_auth_encryption_test_case_256_5(void) 10970 { 10971 return test_authenticated_encryption(&gcm_test_case_256_5); 10972 } 10973 10974 static int 10975 test_AES_GCM_auth_encryption_test_case_256_6(void) 10976 { 10977 return test_authenticated_encryption(&gcm_test_case_256_6); 10978 } 10979 10980 static int 10981 test_AES_GCM_auth_encryption_test_case_256_7(void) 10982 { 10983 return test_authenticated_encryption(&gcm_test_case_256_7); 10984 } 10985 10986 static int 10987 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10988 { 10989 return test_authenticated_encryption(&gcm_test_case_aad_1); 10990 } 10991 10992 static int 10993 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10994 { 10995 return test_authenticated_encryption(&gcm_test_case_aad_2); 10996 } 10997 10998 static int 10999 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 11000 { 11001 struct aead_test_data tdata; 11002 int res; 11003 11004 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11005 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11006 tdata.iv.data[0] += 1; 11007 res = test_authenticated_encryption(&tdata); 11008 if (res == TEST_SKIPPED) 11009 return res; 11010 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11011 return TEST_SUCCESS; 11012 } 11013 11014 static int 11015 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 11016 { 11017 struct aead_test_data tdata; 11018 int res; 11019 11020 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11021 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11022 tdata.plaintext.data[0] += 1; 11023 res = test_authenticated_encryption(&tdata); 11024 if (res == TEST_SKIPPED) 11025 return res; 11026 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11027 return TEST_SUCCESS; 11028 } 11029 11030 static int 11031 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 11032 { 11033 struct aead_test_data tdata; 11034 int res; 11035 11036 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11037 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11038 tdata.ciphertext.data[0] += 1; 11039 res = test_authenticated_encryption(&tdata); 11040 if (res == TEST_SKIPPED) 11041 return res; 11042 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11043 return TEST_SUCCESS; 11044 } 11045 11046 static int 11047 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 11048 { 11049 struct aead_test_data tdata; 11050 int res; 11051 11052 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11053 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11054 tdata.aad.len += 1; 11055 res = test_authenticated_encryption(&tdata); 11056 if (res == TEST_SKIPPED) 11057 return res; 11058 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11059 return TEST_SUCCESS; 11060 } 11061 11062 static int 11063 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 11064 { 11065 struct aead_test_data tdata; 11066 uint8_t aad[gcm_test_case_7.aad.len]; 11067 int res; 11068 11069 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11070 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11071 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11072 aad[0] += 1; 11073 tdata.aad.data = aad; 11074 res = test_authenticated_encryption(&tdata); 11075 if (res == TEST_SKIPPED) 11076 return res; 11077 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11078 return TEST_SUCCESS; 11079 } 11080 11081 static int 11082 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 11083 { 11084 struct aead_test_data tdata; 11085 int res; 11086 11087 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11088 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11089 tdata.auth_tag.data[0] += 1; 11090 res = test_authenticated_encryption(&tdata); 11091 if (res == TEST_SKIPPED) 11092 return res; 11093 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11094 return TEST_SUCCESS; 11095 } 11096 11097 static int 11098 test_authenticated_decryption(const struct aead_test_data *tdata) 11099 { 11100 struct crypto_testsuite_params *ts_params = &testsuite_params; 11101 struct crypto_unittest_params *ut_params = &unittest_params; 11102 11103 int retval; 11104 uint8_t *plaintext; 11105 uint32_t i; 11106 struct rte_cryptodev_info dev_info; 11107 11108 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11109 uint64_t feat_flags = dev_info.feature_flags; 11110 11111 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11112 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11113 printf("Device doesn't support RAW data-path APIs.\n"); 11114 return TEST_SKIPPED; 11115 } 11116 11117 /* Verify the capabilities */ 11118 struct rte_cryptodev_sym_capability_idx cap_idx; 11119 const struct rte_cryptodev_symmetric_capability *capability; 11120 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11121 cap_idx.algo.aead = tdata->algo; 11122 capability = rte_cryptodev_sym_capability_get( 11123 ts_params->valid_devs[0], &cap_idx); 11124 if (capability == NULL) 11125 return TEST_SKIPPED; 11126 if (rte_cryptodev_sym_capability_check_aead( 11127 capability, tdata->key.len, tdata->auth_tag.len, 11128 tdata->aad.len, tdata->iv.len)) 11129 return TEST_SKIPPED; 11130 11131 /* Create AEAD session */ 11132 retval = create_aead_session(ts_params->valid_devs[0], 11133 tdata->algo, 11134 RTE_CRYPTO_AEAD_OP_DECRYPT, 11135 tdata->key.data, tdata->key.len, 11136 tdata->aad.len, tdata->auth_tag.len, 11137 tdata->iv.len); 11138 if (retval < 0) 11139 return retval; 11140 11141 /* alloc mbuf and set payload */ 11142 if (tdata->aad.len > MBUF_SIZE) { 11143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11144 /* Populate full size of add data */ 11145 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 11146 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 11147 } else 11148 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11149 11150 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11151 rte_pktmbuf_tailroom(ut_params->ibuf)); 11152 11153 /* Create AEAD operation */ 11154 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11155 if (retval < 0) 11156 return retval; 11157 11158 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11159 11160 ut_params->op->sym->m_src = ut_params->ibuf; 11161 11162 /* Process crypto operation */ 11163 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11164 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 11165 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11166 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11167 ut_params->op, 0, 0, 0, 0); 11168 else 11169 TEST_ASSERT_NOT_NULL( 11170 process_crypto_request(ts_params->valid_devs[0], 11171 ut_params->op), "failed to process sym crypto op"); 11172 11173 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11174 "crypto op processing failed"); 11175 11176 if (ut_params->op->sym->m_dst) 11177 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 11178 uint8_t *); 11179 else 11180 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 11181 uint8_t *, 11182 ut_params->op->sym->cipher.data.offset); 11183 11184 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11185 11186 /* Validate obuf */ 11187 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11188 plaintext, 11189 tdata->plaintext.data, 11190 tdata->plaintext.len, 11191 "Plaintext data not as expected"); 11192 11193 TEST_ASSERT_EQUAL(ut_params->op->status, 11194 RTE_CRYPTO_OP_STATUS_SUCCESS, 11195 "Authentication failed"); 11196 11197 return 0; 11198 } 11199 11200 static int 11201 test_AES_GCM_authenticated_decryption_test_case_1(void) 11202 { 11203 return test_authenticated_decryption(&gcm_test_case_1); 11204 } 11205 11206 static int 11207 test_AES_GCM_authenticated_decryption_test_case_2(void) 11208 { 11209 return test_authenticated_decryption(&gcm_test_case_2); 11210 } 11211 11212 static int 11213 test_AES_GCM_authenticated_decryption_test_case_3(void) 11214 { 11215 return test_authenticated_decryption(&gcm_test_case_3); 11216 } 11217 11218 static int 11219 test_AES_GCM_authenticated_decryption_test_case_4(void) 11220 { 11221 return test_authenticated_decryption(&gcm_test_case_4); 11222 } 11223 11224 static int 11225 test_AES_GCM_authenticated_decryption_test_case_5(void) 11226 { 11227 return test_authenticated_decryption(&gcm_test_case_5); 11228 } 11229 11230 static int 11231 test_AES_GCM_authenticated_decryption_test_case_6(void) 11232 { 11233 return test_authenticated_decryption(&gcm_test_case_6); 11234 } 11235 11236 static int 11237 test_AES_GCM_authenticated_decryption_test_case_7(void) 11238 { 11239 return test_authenticated_decryption(&gcm_test_case_7); 11240 } 11241 11242 static int 11243 test_AES_GCM_authenticated_decryption_test_case_8(void) 11244 { 11245 return test_authenticated_decryption(&gcm_test_case_8); 11246 } 11247 11248 static int 11249 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 11250 { 11251 return test_authenticated_decryption(&gcm_J0_test_case_1); 11252 } 11253 11254 static int 11255 test_AES_GCM_auth_decryption_test_case_192_1(void) 11256 { 11257 return test_authenticated_decryption(&gcm_test_case_192_1); 11258 } 11259 11260 static int 11261 test_AES_GCM_auth_decryption_test_case_192_2(void) 11262 { 11263 return test_authenticated_decryption(&gcm_test_case_192_2); 11264 } 11265 11266 static int 11267 test_AES_GCM_auth_decryption_test_case_192_3(void) 11268 { 11269 return test_authenticated_decryption(&gcm_test_case_192_3); 11270 } 11271 11272 static int 11273 test_AES_GCM_auth_decryption_test_case_192_4(void) 11274 { 11275 return test_authenticated_decryption(&gcm_test_case_192_4); 11276 } 11277 11278 static int 11279 test_AES_GCM_auth_decryption_test_case_192_5(void) 11280 { 11281 return test_authenticated_decryption(&gcm_test_case_192_5); 11282 } 11283 11284 static int 11285 test_AES_GCM_auth_decryption_test_case_192_6(void) 11286 { 11287 return test_authenticated_decryption(&gcm_test_case_192_6); 11288 } 11289 11290 static int 11291 test_AES_GCM_auth_decryption_test_case_192_7(void) 11292 { 11293 return test_authenticated_decryption(&gcm_test_case_192_7); 11294 } 11295 11296 static int 11297 test_AES_GCM_auth_decryption_test_case_256_1(void) 11298 { 11299 return test_authenticated_decryption(&gcm_test_case_256_1); 11300 } 11301 11302 static int 11303 test_AES_GCM_auth_decryption_test_case_256_2(void) 11304 { 11305 return test_authenticated_decryption(&gcm_test_case_256_2); 11306 } 11307 11308 static int 11309 test_AES_GCM_auth_decryption_test_case_256_3(void) 11310 { 11311 return test_authenticated_decryption(&gcm_test_case_256_3); 11312 } 11313 11314 static int 11315 test_AES_GCM_auth_decryption_test_case_256_4(void) 11316 { 11317 return test_authenticated_decryption(&gcm_test_case_256_4); 11318 } 11319 11320 static int 11321 test_AES_GCM_auth_decryption_test_case_256_5(void) 11322 { 11323 return test_authenticated_decryption(&gcm_test_case_256_5); 11324 } 11325 11326 static int 11327 test_AES_GCM_auth_decryption_test_case_256_6(void) 11328 { 11329 return test_authenticated_decryption(&gcm_test_case_256_6); 11330 } 11331 11332 static int 11333 test_AES_GCM_auth_decryption_test_case_256_7(void) 11334 { 11335 return test_authenticated_decryption(&gcm_test_case_256_7); 11336 } 11337 11338 static int 11339 test_AES_GCM_auth_decryption_test_case_aad_1(void) 11340 { 11341 return test_authenticated_decryption(&gcm_test_case_aad_1); 11342 } 11343 11344 static int 11345 test_AES_GCM_auth_decryption_test_case_aad_2(void) 11346 { 11347 return test_authenticated_decryption(&gcm_test_case_aad_2); 11348 } 11349 11350 static int 11351 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 11352 { 11353 struct aead_test_data tdata; 11354 int res; 11355 11356 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11357 tdata.iv.data[0] += 1; 11358 res = test_authenticated_decryption(&tdata); 11359 if (res == TEST_SKIPPED) 11360 return res; 11361 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11362 return TEST_SUCCESS; 11363 } 11364 11365 static int 11366 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 11367 { 11368 struct aead_test_data tdata; 11369 int res; 11370 11371 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11372 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11373 tdata.plaintext.data[0] += 1; 11374 res = test_authenticated_decryption(&tdata); 11375 if (res == TEST_SKIPPED) 11376 return res; 11377 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11378 return TEST_SUCCESS; 11379 } 11380 11381 static int 11382 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 11383 { 11384 struct aead_test_data tdata; 11385 int res; 11386 11387 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11388 tdata.ciphertext.data[0] += 1; 11389 res = test_authenticated_decryption(&tdata); 11390 if (res == TEST_SKIPPED) 11391 return res; 11392 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11393 return TEST_SUCCESS; 11394 } 11395 11396 static int 11397 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 11398 { 11399 struct aead_test_data tdata; 11400 int res; 11401 11402 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11403 tdata.aad.len += 1; 11404 res = test_authenticated_decryption(&tdata); 11405 if (res == TEST_SKIPPED) 11406 return res; 11407 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11408 return TEST_SUCCESS; 11409 } 11410 11411 static int 11412 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 11413 { 11414 struct aead_test_data tdata; 11415 uint8_t aad[gcm_test_case_7.aad.len]; 11416 int res; 11417 11418 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11419 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11420 aad[0] += 1; 11421 tdata.aad.data = aad; 11422 res = test_authenticated_decryption(&tdata); 11423 if (res == TEST_SKIPPED) 11424 return res; 11425 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11426 return TEST_SUCCESS; 11427 } 11428 11429 static int 11430 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 11431 { 11432 struct aead_test_data tdata; 11433 int res; 11434 11435 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11436 tdata.auth_tag.data[0] += 1; 11437 res = test_authenticated_decryption(&tdata); 11438 if (res == TEST_SKIPPED) 11439 return res; 11440 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 11441 return TEST_SUCCESS; 11442 } 11443 11444 static int 11445 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 11446 { 11447 struct crypto_testsuite_params *ts_params = &testsuite_params; 11448 struct crypto_unittest_params *ut_params = &unittest_params; 11449 11450 int retval; 11451 uint8_t *ciphertext, *auth_tag; 11452 uint16_t plaintext_pad_len; 11453 struct rte_cryptodev_info dev_info; 11454 11455 /* Verify the capabilities */ 11456 struct rte_cryptodev_sym_capability_idx cap_idx; 11457 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11458 cap_idx.algo.aead = tdata->algo; 11459 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11460 &cap_idx) == NULL) 11461 return TEST_SKIPPED; 11462 11463 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11464 uint64_t feat_flags = dev_info.feature_flags; 11465 11466 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11467 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 11468 return TEST_SKIPPED; 11469 11470 /* not supported with CPU crypto */ 11471 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11472 return TEST_SKIPPED; 11473 11474 /* Create AEAD session */ 11475 retval = create_aead_session(ts_params->valid_devs[0], 11476 tdata->algo, 11477 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11478 tdata->key.data, tdata->key.len, 11479 tdata->aad.len, tdata->auth_tag.len, 11480 tdata->iv.len); 11481 if (retval < 0) 11482 return retval; 11483 11484 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11485 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11486 11487 /* clear mbuf payload */ 11488 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11489 rte_pktmbuf_tailroom(ut_params->ibuf)); 11490 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11491 rte_pktmbuf_tailroom(ut_params->obuf)); 11492 11493 /* Create AEAD operation */ 11494 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11495 if (retval < 0) 11496 return retval; 11497 11498 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11499 11500 ut_params->op->sym->m_src = ut_params->ibuf; 11501 ut_params->op->sym->m_dst = ut_params->obuf; 11502 11503 /* Process crypto operation */ 11504 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11505 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11506 ut_params->op, 0, 0, 0, 0); 11507 else 11508 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11509 ut_params->op), "failed to process sym crypto op"); 11510 11511 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11512 "crypto op processing failed"); 11513 11514 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11515 11516 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11517 ut_params->op->sym->cipher.data.offset); 11518 auth_tag = ciphertext + plaintext_pad_len; 11519 11520 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11521 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11522 11523 /* Validate obuf */ 11524 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11525 ciphertext, 11526 tdata->ciphertext.data, 11527 tdata->ciphertext.len, 11528 "Ciphertext data not as expected"); 11529 11530 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11531 auth_tag, 11532 tdata->auth_tag.data, 11533 tdata->auth_tag.len, 11534 "Generated auth tag not as expected"); 11535 11536 return 0; 11537 11538 } 11539 11540 static int 11541 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 11542 { 11543 return test_authenticated_encryption_oop(&gcm_test_case_5); 11544 } 11545 11546 static int 11547 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 11548 { 11549 struct crypto_testsuite_params *ts_params = &testsuite_params; 11550 struct crypto_unittest_params *ut_params = &unittest_params; 11551 11552 int retval; 11553 uint8_t *plaintext; 11554 struct rte_cryptodev_info dev_info; 11555 11556 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11557 uint64_t feat_flags = dev_info.feature_flags; 11558 11559 /* Verify the capabilities */ 11560 struct rte_cryptodev_sym_capability_idx cap_idx; 11561 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11562 cap_idx.algo.aead = tdata->algo; 11563 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11564 &cap_idx) == NULL) 11565 return TEST_SKIPPED; 11566 11567 /* not supported with CPU crypto and raw data-path APIs*/ 11568 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 11569 global_api_test_type == CRYPTODEV_RAW_API_TEST) 11570 return TEST_SKIPPED; 11571 11572 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11573 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11574 printf("Device does not support RAW data-path APIs.\n"); 11575 return TEST_SKIPPED; 11576 } 11577 11578 /* Create AEAD session */ 11579 retval = create_aead_session(ts_params->valid_devs[0], 11580 tdata->algo, 11581 RTE_CRYPTO_AEAD_OP_DECRYPT, 11582 tdata->key.data, tdata->key.len, 11583 tdata->aad.len, tdata->auth_tag.len, 11584 tdata->iv.len); 11585 if (retval < 0) 11586 return retval; 11587 11588 /* alloc mbuf and set payload */ 11589 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11590 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11591 11592 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11593 rte_pktmbuf_tailroom(ut_params->ibuf)); 11594 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11595 rte_pktmbuf_tailroom(ut_params->obuf)); 11596 11597 /* Create AEAD operation */ 11598 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11599 if (retval < 0) 11600 return retval; 11601 11602 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11603 11604 ut_params->op->sym->m_src = ut_params->ibuf; 11605 ut_params->op->sym->m_dst = ut_params->obuf; 11606 11607 /* Process crypto operation */ 11608 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11609 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11610 ut_params->op, 0, 0, 0, 0); 11611 else 11612 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11613 ut_params->op), "failed to process sym crypto op"); 11614 11615 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11616 "crypto op processing failed"); 11617 11618 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11619 ut_params->op->sym->cipher.data.offset); 11620 11621 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11622 11623 /* Validate obuf */ 11624 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11625 plaintext, 11626 tdata->plaintext.data, 11627 tdata->plaintext.len, 11628 "Plaintext data not as expected"); 11629 11630 TEST_ASSERT_EQUAL(ut_params->op->status, 11631 RTE_CRYPTO_OP_STATUS_SUCCESS, 11632 "Authentication failed"); 11633 return 0; 11634 } 11635 11636 static int 11637 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 11638 { 11639 return test_authenticated_decryption_oop(&gcm_test_case_5); 11640 } 11641 11642 static int 11643 test_authenticated_encryption_sessionless( 11644 const struct aead_test_data *tdata) 11645 { 11646 struct crypto_testsuite_params *ts_params = &testsuite_params; 11647 struct crypto_unittest_params *ut_params = &unittest_params; 11648 11649 int retval; 11650 uint8_t *ciphertext, *auth_tag; 11651 uint16_t plaintext_pad_len; 11652 uint8_t key[tdata->key.len + 1]; 11653 struct rte_cryptodev_info dev_info; 11654 11655 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11656 uint64_t feat_flags = dev_info.feature_flags; 11657 11658 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11659 printf("Device doesn't support Sessionless ops.\n"); 11660 return TEST_SKIPPED; 11661 } 11662 11663 /* not supported with CPU crypto */ 11664 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11665 return TEST_SKIPPED; 11666 11667 /* Verify the capabilities */ 11668 struct rte_cryptodev_sym_capability_idx cap_idx; 11669 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11670 cap_idx.algo.aead = tdata->algo; 11671 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11672 &cap_idx) == NULL) 11673 return TEST_SKIPPED; 11674 11675 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11676 11677 /* clear mbuf payload */ 11678 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11679 rte_pktmbuf_tailroom(ut_params->ibuf)); 11680 11681 /* Create AEAD operation */ 11682 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11683 if (retval < 0) 11684 return retval; 11685 11686 /* Create GCM xform */ 11687 memcpy(key, tdata->key.data, tdata->key.len); 11688 retval = create_aead_xform(ut_params->op, 11689 tdata->algo, 11690 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11691 key, tdata->key.len, 11692 tdata->aad.len, tdata->auth_tag.len, 11693 tdata->iv.len); 11694 if (retval < 0) 11695 return retval; 11696 11697 ut_params->op->sym->m_src = ut_params->ibuf; 11698 11699 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11700 RTE_CRYPTO_OP_SESSIONLESS, 11701 "crypto op session type not sessionless"); 11702 11703 /* Process crypto operation */ 11704 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11705 ut_params->op), "failed to process sym crypto op"); 11706 11707 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11708 11709 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11710 "crypto op status not success"); 11711 11712 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11713 11714 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11715 ut_params->op->sym->cipher.data.offset); 11716 auth_tag = ciphertext + plaintext_pad_len; 11717 11718 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11719 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11720 11721 /* Validate obuf */ 11722 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11723 ciphertext, 11724 tdata->ciphertext.data, 11725 tdata->ciphertext.len, 11726 "Ciphertext data not as expected"); 11727 11728 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11729 auth_tag, 11730 tdata->auth_tag.data, 11731 tdata->auth_tag.len, 11732 "Generated auth tag not as expected"); 11733 11734 return 0; 11735 11736 } 11737 11738 static int 11739 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 11740 { 11741 return test_authenticated_encryption_sessionless( 11742 &gcm_test_case_5); 11743 } 11744 11745 static int 11746 test_authenticated_decryption_sessionless( 11747 const struct aead_test_data *tdata) 11748 { 11749 struct crypto_testsuite_params *ts_params = &testsuite_params; 11750 struct crypto_unittest_params *ut_params = &unittest_params; 11751 11752 int retval; 11753 uint8_t *plaintext; 11754 uint8_t key[tdata->key.len + 1]; 11755 struct rte_cryptodev_info dev_info; 11756 11757 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11758 uint64_t feat_flags = dev_info.feature_flags; 11759 11760 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11761 printf("Device doesn't support Sessionless ops.\n"); 11762 return TEST_SKIPPED; 11763 } 11764 11765 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11766 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11767 printf("Device doesn't support RAW data-path APIs.\n"); 11768 return TEST_SKIPPED; 11769 } 11770 11771 /* not supported with CPU crypto */ 11772 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11773 return TEST_SKIPPED; 11774 11775 /* Verify the capabilities */ 11776 struct rte_cryptodev_sym_capability_idx cap_idx; 11777 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11778 cap_idx.algo.aead = tdata->algo; 11779 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11780 &cap_idx) == NULL) 11781 return TEST_SKIPPED; 11782 11783 /* alloc mbuf and set payload */ 11784 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11785 11786 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11787 rte_pktmbuf_tailroom(ut_params->ibuf)); 11788 11789 /* Create AEAD operation */ 11790 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11791 if (retval < 0) 11792 return retval; 11793 11794 /* Create AEAD xform */ 11795 memcpy(key, tdata->key.data, tdata->key.len); 11796 retval = create_aead_xform(ut_params->op, 11797 tdata->algo, 11798 RTE_CRYPTO_AEAD_OP_DECRYPT, 11799 key, tdata->key.len, 11800 tdata->aad.len, tdata->auth_tag.len, 11801 tdata->iv.len); 11802 if (retval < 0) 11803 return retval; 11804 11805 ut_params->op->sym->m_src = ut_params->ibuf; 11806 11807 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11808 RTE_CRYPTO_OP_SESSIONLESS, 11809 "crypto op session type not sessionless"); 11810 11811 /* Process crypto operation */ 11812 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11813 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11814 ut_params->op, 0, 0, 0, 0); 11815 else 11816 TEST_ASSERT_NOT_NULL(process_crypto_request( 11817 ts_params->valid_devs[0], ut_params->op), 11818 "failed to process sym crypto op"); 11819 11820 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11821 11822 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11823 "crypto op status not success"); 11824 11825 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11826 ut_params->op->sym->cipher.data.offset); 11827 11828 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11829 11830 /* Validate obuf */ 11831 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11832 plaintext, 11833 tdata->plaintext.data, 11834 tdata->plaintext.len, 11835 "Plaintext data not as expected"); 11836 11837 TEST_ASSERT_EQUAL(ut_params->op->status, 11838 RTE_CRYPTO_OP_STATUS_SUCCESS, 11839 "Authentication failed"); 11840 return 0; 11841 } 11842 11843 static int 11844 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 11845 { 11846 return test_authenticated_decryption_sessionless( 11847 &gcm_test_case_5); 11848 } 11849 11850 static int 11851 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 11852 { 11853 return test_authenticated_encryption(&ccm_test_case_128_1); 11854 } 11855 11856 static int 11857 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 11858 { 11859 return test_authenticated_encryption(&ccm_test_case_128_2); 11860 } 11861 11862 static int 11863 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 11864 { 11865 return test_authenticated_encryption(&ccm_test_case_128_3); 11866 } 11867 11868 static int 11869 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 11870 { 11871 return test_authenticated_decryption(&ccm_test_case_128_1); 11872 } 11873 11874 static int 11875 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 11876 { 11877 return test_authenticated_decryption(&ccm_test_case_128_2); 11878 } 11879 11880 static int 11881 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 11882 { 11883 return test_authenticated_decryption(&ccm_test_case_128_3); 11884 } 11885 11886 static int 11887 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 11888 { 11889 return test_authenticated_encryption(&ccm_test_case_192_1); 11890 } 11891 11892 static int 11893 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 11894 { 11895 return test_authenticated_encryption(&ccm_test_case_192_2); 11896 } 11897 11898 static int 11899 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 11900 { 11901 return test_authenticated_encryption(&ccm_test_case_192_3); 11902 } 11903 11904 static int 11905 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 11906 { 11907 return test_authenticated_decryption(&ccm_test_case_192_1); 11908 } 11909 11910 static int 11911 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 11912 { 11913 return test_authenticated_decryption(&ccm_test_case_192_2); 11914 } 11915 11916 static int 11917 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 11918 { 11919 return test_authenticated_decryption(&ccm_test_case_192_3); 11920 } 11921 11922 static int 11923 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11924 { 11925 return test_authenticated_encryption(&ccm_test_case_256_1); 11926 } 11927 11928 static int 11929 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11930 { 11931 return test_authenticated_encryption(&ccm_test_case_256_2); 11932 } 11933 11934 static int 11935 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11936 { 11937 return test_authenticated_encryption(&ccm_test_case_256_3); 11938 } 11939 11940 static int 11941 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11942 { 11943 return test_authenticated_decryption(&ccm_test_case_256_1); 11944 } 11945 11946 static int 11947 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11948 { 11949 return test_authenticated_decryption(&ccm_test_case_256_2); 11950 } 11951 11952 static int 11953 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11954 { 11955 return test_authenticated_decryption(&ccm_test_case_256_3); 11956 } 11957 11958 static int 11959 test_stats(void) 11960 { 11961 struct crypto_testsuite_params *ts_params = &testsuite_params; 11962 struct rte_cryptodev_stats stats; 11963 11964 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11965 return TEST_SKIPPED; 11966 11967 /* Verify the capabilities */ 11968 struct rte_cryptodev_sym_capability_idx cap_idx; 11969 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11970 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11971 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11972 &cap_idx) == NULL) 11973 return TEST_SKIPPED; 11974 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11975 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11976 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11977 &cap_idx) == NULL) 11978 return TEST_SKIPPED; 11979 11980 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11981 == -ENOTSUP) 11982 return TEST_SKIPPED; 11983 11984 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11985 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11986 &stats) == -ENODEV), 11987 "rte_cryptodev_stats_get invalid dev failed"); 11988 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11989 "rte_cryptodev_stats_get invalid Param failed"); 11990 11991 /* Test expected values */ 11992 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11993 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11994 &stats), 11995 "rte_cryptodev_stats_get failed"); 11996 TEST_ASSERT((stats.enqueued_count == 1), 11997 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11998 TEST_ASSERT((stats.dequeued_count == 1), 11999 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12000 TEST_ASSERT((stats.enqueue_err_count == 0), 12001 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12002 TEST_ASSERT((stats.dequeue_err_count == 0), 12003 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12004 12005 /* invalid device but should ignore and not reset device stats*/ 12006 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 12007 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12008 &stats), 12009 "rte_cryptodev_stats_get failed"); 12010 TEST_ASSERT((stats.enqueued_count == 1), 12011 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12012 12013 /* check that a valid reset clears stats */ 12014 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 12015 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12016 &stats), 12017 "rte_cryptodev_stats_get failed"); 12018 TEST_ASSERT((stats.enqueued_count == 0), 12019 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12020 TEST_ASSERT((stats.dequeued_count == 0), 12021 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12022 12023 return TEST_SUCCESS; 12024 } 12025 12026 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 12027 struct crypto_unittest_params *ut_params, 12028 enum rte_crypto_auth_operation op, 12029 const struct HMAC_MD5_vector *test_case) 12030 { 12031 uint8_t key[64]; 12032 int status; 12033 12034 memcpy(key, test_case->key.data, test_case->key.len); 12035 12036 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12037 ut_params->auth_xform.next = NULL; 12038 ut_params->auth_xform.auth.op = op; 12039 12040 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 12041 12042 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 12043 ut_params->auth_xform.auth.key.length = test_case->key.len; 12044 ut_params->auth_xform.auth.key.data = key; 12045 12046 ut_params->sess = rte_cryptodev_sym_session_create( 12047 ts_params->session_mpool); 12048 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12049 if (ut_params->sess == NULL) 12050 return TEST_FAILED; 12051 12052 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12053 ut_params->sess, &ut_params->auth_xform, 12054 ts_params->session_priv_mpool); 12055 if (status == -ENOTSUP) 12056 return TEST_SKIPPED; 12057 12058 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12059 12060 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12061 rte_pktmbuf_tailroom(ut_params->ibuf)); 12062 12063 return 0; 12064 } 12065 12066 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 12067 const struct HMAC_MD5_vector *test_case, 12068 uint8_t **plaintext) 12069 { 12070 uint16_t plaintext_pad_len; 12071 12072 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12073 12074 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 12075 16); 12076 12077 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12078 plaintext_pad_len); 12079 memcpy(*plaintext, test_case->plaintext.data, 12080 test_case->plaintext.len); 12081 12082 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12083 ut_params->ibuf, MD5_DIGEST_LEN); 12084 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12085 "no room to append digest"); 12086 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12087 ut_params->ibuf, plaintext_pad_len); 12088 12089 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12090 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 12091 test_case->auth_tag.len); 12092 } 12093 12094 sym_op->auth.data.offset = 0; 12095 sym_op->auth.data.length = test_case->plaintext.len; 12096 12097 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12098 ut_params->op->sym->m_src = ut_params->ibuf; 12099 12100 return 0; 12101 } 12102 12103 static int 12104 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 12105 { 12106 uint16_t plaintext_pad_len; 12107 uint8_t *plaintext, *auth_tag; 12108 12109 struct crypto_testsuite_params *ts_params = &testsuite_params; 12110 struct crypto_unittest_params *ut_params = &unittest_params; 12111 struct rte_cryptodev_info dev_info; 12112 12113 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12114 uint64_t feat_flags = dev_info.feature_flags; 12115 12116 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12117 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12118 printf("Device doesn't support RAW data-path APIs.\n"); 12119 return TEST_SKIPPED; 12120 } 12121 12122 /* Verify the capabilities */ 12123 struct rte_cryptodev_sym_capability_idx cap_idx; 12124 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12125 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 12126 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12127 &cap_idx) == NULL) 12128 return TEST_SKIPPED; 12129 12130 if (MD5_HMAC_create_session(ts_params, ut_params, 12131 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 12132 return TEST_FAILED; 12133 12134 /* Generate Crypto op data structure */ 12135 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12136 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12137 TEST_ASSERT_NOT_NULL(ut_params->op, 12138 "Failed to allocate symmetric crypto operation struct"); 12139 12140 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 12141 16); 12142 12143 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 12144 return TEST_FAILED; 12145 12146 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12147 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12148 ut_params->op); 12149 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12150 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12151 ut_params->op, 0, 1, 0, 0); 12152 else 12153 TEST_ASSERT_NOT_NULL( 12154 process_crypto_request(ts_params->valid_devs[0], 12155 ut_params->op), 12156 "failed to process sym crypto op"); 12157 12158 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12159 "crypto op processing failed"); 12160 12161 if (ut_params->op->sym->m_dst) { 12162 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12163 uint8_t *, plaintext_pad_len); 12164 } else { 12165 auth_tag = plaintext + plaintext_pad_len; 12166 } 12167 12168 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12169 auth_tag, 12170 test_case->auth_tag.data, 12171 test_case->auth_tag.len, 12172 "HMAC_MD5 generated tag not as expected"); 12173 12174 return TEST_SUCCESS; 12175 } 12176 12177 static int 12178 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 12179 { 12180 uint8_t *plaintext; 12181 12182 struct crypto_testsuite_params *ts_params = &testsuite_params; 12183 struct crypto_unittest_params *ut_params = &unittest_params; 12184 struct rte_cryptodev_info dev_info; 12185 12186 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12187 uint64_t feat_flags = dev_info.feature_flags; 12188 12189 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12190 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12191 printf("Device doesn't support RAW data-path APIs.\n"); 12192 return TEST_SKIPPED; 12193 } 12194 12195 /* Verify the capabilities */ 12196 struct rte_cryptodev_sym_capability_idx cap_idx; 12197 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12198 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 12199 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12200 &cap_idx) == NULL) 12201 return TEST_SKIPPED; 12202 12203 if (MD5_HMAC_create_session(ts_params, ut_params, 12204 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 12205 return TEST_FAILED; 12206 } 12207 12208 /* Generate Crypto op data structure */ 12209 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12210 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12211 TEST_ASSERT_NOT_NULL(ut_params->op, 12212 "Failed to allocate symmetric crypto operation struct"); 12213 12214 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 12215 return TEST_FAILED; 12216 12217 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12218 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12219 ut_params->op); 12220 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12221 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12222 ut_params->op, 0, 1, 0, 0); 12223 else 12224 TEST_ASSERT_NOT_NULL( 12225 process_crypto_request(ts_params->valid_devs[0], 12226 ut_params->op), 12227 "failed to process sym crypto op"); 12228 12229 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12230 "HMAC_MD5 crypto op processing failed"); 12231 12232 return TEST_SUCCESS; 12233 } 12234 12235 static int 12236 test_MD5_HMAC_generate_case_1(void) 12237 { 12238 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 12239 } 12240 12241 static int 12242 test_MD5_HMAC_verify_case_1(void) 12243 { 12244 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 12245 } 12246 12247 static int 12248 test_MD5_HMAC_generate_case_2(void) 12249 { 12250 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 12251 } 12252 12253 static int 12254 test_MD5_HMAC_verify_case_2(void) 12255 { 12256 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 12257 } 12258 12259 static int 12260 test_multi_session(void) 12261 { 12262 struct crypto_testsuite_params *ts_params = &testsuite_params; 12263 struct crypto_unittest_params *ut_params = &unittest_params; 12264 12265 struct rte_cryptodev_info dev_info; 12266 struct rte_cryptodev_sym_session **sessions; 12267 12268 uint16_t i; 12269 int status; 12270 12271 /* Verify the capabilities */ 12272 struct rte_cryptodev_sym_capability_idx cap_idx; 12273 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12274 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12275 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12276 &cap_idx) == NULL) 12277 return TEST_SKIPPED; 12278 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12279 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12280 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12281 &cap_idx) == NULL) 12282 return TEST_SKIPPED; 12283 12284 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 12285 aes_cbc_key, hmac_sha512_key); 12286 12287 12288 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12289 12290 sessions = rte_malloc(NULL, 12291 sizeof(struct rte_cryptodev_sym_session *) * 12292 (MAX_NB_SESSIONS + 1), 0); 12293 12294 /* Create multiple crypto sessions*/ 12295 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12296 12297 sessions[i] = rte_cryptodev_sym_session_create( 12298 ts_params->session_mpool); 12299 TEST_ASSERT_NOT_NULL(sessions[i], 12300 "Session creation failed at session number %u", 12301 i); 12302 12303 status = rte_cryptodev_sym_session_init( 12304 ts_params->valid_devs[0], 12305 sessions[i], &ut_params->auth_xform, 12306 ts_params->session_priv_mpool); 12307 if (status == -ENOTSUP) 12308 return TEST_SKIPPED; 12309 12310 /* Attempt to send a request on each session */ 12311 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 12312 sessions[i], 12313 ut_params, 12314 ts_params, 12315 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 12316 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 12317 aes_cbc_iv), 12318 "Failed to perform decrypt on request number %u.", i); 12319 /* free crypto operation structure */ 12320 rte_crypto_op_free(ut_params->op); 12321 12322 /* 12323 * free mbuf - both obuf and ibuf are usually the same, 12324 * so check if they point at the same address is necessary, 12325 * to avoid freeing the mbuf twice. 12326 */ 12327 if (ut_params->obuf) { 12328 rte_pktmbuf_free(ut_params->obuf); 12329 if (ut_params->ibuf == ut_params->obuf) 12330 ut_params->ibuf = 0; 12331 ut_params->obuf = 0; 12332 } 12333 if (ut_params->ibuf) { 12334 rte_pktmbuf_free(ut_params->ibuf); 12335 ut_params->ibuf = 0; 12336 } 12337 } 12338 12339 sessions[i] = NULL; 12340 /* Next session create should fail */ 12341 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12342 sessions[i], &ut_params->auth_xform, 12343 ts_params->session_priv_mpool); 12344 TEST_ASSERT_NULL(sessions[i], 12345 "Session creation succeeded unexpectedly!"); 12346 12347 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12348 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12349 sessions[i]); 12350 rte_cryptodev_sym_session_free(sessions[i]); 12351 } 12352 12353 rte_free(sessions); 12354 12355 return TEST_SUCCESS; 12356 } 12357 12358 struct multi_session_params { 12359 struct crypto_unittest_params ut_params; 12360 uint8_t *cipher_key; 12361 uint8_t *hmac_key; 12362 const uint8_t *cipher; 12363 const uint8_t *digest; 12364 uint8_t *iv; 12365 }; 12366 12367 #define MB_SESSION_NUMBER 3 12368 12369 static int 12370 test_multi_session_random_usage(void) 12371 { 12372 struct crypto_testsuite_params *ts_params = &testsuite_params; 12373 struct rte_cryptodev_info dev_info; 12374 struct rte_cryptodev_sym_session **sessions; 12375 uint32_t i, j; 12376 struct multi_session_params ut_paramz[] = { 12377 12378 { 12379 .cipher_key = ms_aes_cbc_key0, 12380 .hmac_key = ms_hmac_key0, 12381 .cipher = ms_aes_cbc_cipher0, 12382 .digest = ms_hmac_digest0, 12383 .iv = ms_aes_cbc_iv0 12384 }, 12385 { 12386 .cipher_key = ms_aes_cbc_key1, 12387 .hmac_key = ms_hmac_key1, 12388 .cipher = ms_aes_cbc_cipher1, 12389 .digest = ms_hmac_digest1, 12390 .iv = ms_aes_cbc_iv1 12391 }, 12392 { 12393 .cipher_key = ms_aes_cbc_key2, 12394 .hmac_key = ms_hmac_key2, 12395 .cipher = ms_aes_cbc_cipher2, 12396 .digest = ms_hmac_digest2, 12397 .iv = ms_aes_cbc_iv2 12398 }, 12399 12400 }; 12401 int status; 12402 12403 /* Verify the capabilities */ 12404 struct rte_cryptodev_sym_capability_idx cap_idx; 12405 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12406 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12407 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12408 &cap_idx) == NULL) 12409 return TEST_SKIPPED; 12410 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12411 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12412 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12413 &cap_idx) == NULL) 12414 return TEST_SKIPPED; 12415 12416 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12417 12418 sessions = rte_malloc(NULL, 12419 (sizeof(struct rte_cryptodev_sym_session *) 12420 * MAX_NB_SESSIONS) + 1, 0); 12421 12422 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12423 sessions[i] = rte_cryptodev_sym_session_create( 12424 ts_params->session_mpool); 12425 TEST_ASSERT_NOT_NULL(sessions[i], 12426 "Session creation failed at session number %u", 12427 i); 12428 12429 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 12430 sizeof(struct crypto_unittest_params)); 12431 12432 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 12433 &ut_paramz[i].ut_params, 12434 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 12435 12436 /* Create multiple crypto sessions*/ 12437 status = rte_cryptodev_sym_session_init( 12438 ts_params->valid_devs[0], 12439 sessions[i], 12440 &ut_paramz[i].ut_params.auth_xform, 12441 ts_params->session_priv_mpool); 12442 12443 if (status == -ENOTSUP) 12444 return TEST_SKIPPED; 12445 12446 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12447 } 12448 12449 srand(time(NULL)); 12450 for (i = 0; i < 40000; i++) { 12451 12452 j = rand() % MB_SESSION_NUMBER; 12453 12454 TEST_ASSERT_SUCCESS( 12455 test_AES_CBC_HMAC_SHA512_decrypt_perform( 12456 sessions[j], 12457 &ut_paramz[j].ut_params, 12458 ts_params, ut_paramz[j].cipher, 12459 ut_paramz[j].digest, 12460 ut_paramz[j].iv), 12461 "Failed to perform decrypt on request number %u.", i); 12462 12463 rte_crypto_op_free(ut_paramz[j].ut_params.op); 12464 12465 /* 12466 * free mbuf - both obuf and ibuf are usually the same, 12467 * so check if they point at the same address is necessary, 12468 * to avoid freeing the mbuf twice. 12469 */ 12470 if (ut_paramz[j].ut_params.obuf) { 12471 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 12472 if (ut_paramz[j].ut_params.ibuf 12473 == ut_paramz[j].ut_params.obuf) 12474 ut_paramz[j].ut_params.ibuf = 0; 12475 ut_paramz[j].ut_params.obuf = 0; 12476 } 12477 if (ut_paramz[j].ut_params.ibuf) { 12478 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 12479 ut_paramz[j].ut_params.ibuf = 0; 12480 } 12481 } 12482 12483 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12484 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12485 sessions[i]); 12486 rte_cryptodev_sym_session_free(sessions[i]); 12487 } 12488 12489 rte_free(sessions); 12490 12491 return TEST_SUCCESS; 12492 } 12493 12494 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 12495 0xab, 0xab, 0xab, 0xab, 12496 0xab, 0xab, 0xab, 0xab, 12497 0xab, 0xab, 0xab, 0xab}; 12498 12499 static int 12500 test_null_invalid_operation(void) 12501 { 12502 struct crypto_testsuite_params *ts_params = &testsuite_params; 12503 struct crypto_unittest_params *ut_params = &unittest_params; 12504 int ret; 12505 12506 /* This test is for NULL PMD only */ 12507 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12508 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12509 return TEST_SKIPPED; 12510 12511 /* Setup Cipher Parameters */ 12512 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12513 ut_params->cipher_xform.next = NULL; 12514 12515 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 12516 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12517 12518 ut_params->sess = rte_cryptodev_sym_session_create( 12519 ts_params->session_mpool); 12520 12521 /* Create Crypto session*/ 12522 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12523 ut_params->sess, &ut_params->cipher_xform, 12524 ts_params->session_priv_mpool); 12525 TEST_ASSERT(ret < 0, 12526 "Session creation succeeded unexpectedly"); 12527 12528 12529 /* Setup HMAC Parameters */ 12530 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12531 ut_params->auth_xform.next = NULL; 12532 12533 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 12534 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12535 12536 ut_params->sess = rte_cryptodev_sym_session_create( 12537 ts_params->session_mpool); 12538 12539 /* Create Crypto session*/ 12540 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12541 ut_params->sess, &ut_params->auth_xform, 12542 ts_params->session_priv_mpool); 12543 TEST_ASSERT(ret < 0, 12544 "Session creation succeeded unexpectedly"); 12545 12546 return TEST_SUCCESS; 12547 } 12548 12549 12550 #define NULL_BURST_LENGTH (32) 12551 12552 static int 12553 test_null_burst_operation(void) 12554 { 12555 struct crypto_testsuite_params *ts_params = &testsuite_params; 12556 struct crypto_unittest_params *ut_params = &unittest_params; 12557 int status; 12558 12559 unsigned i, burst_len = NULL_BURST_LENGTH; 12560 12561 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 12562 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 12563 12564 /* This test is for NULL PMD only */ 12565 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12566 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12567 return TEST_SKIPPED; 12568 12569 /* Setup Cipher Parameters */ 12570 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12571 ut_params->cipher_xform.next = &ut_params->auth_xform; 12572 12573 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 12574 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12575 12576 /* Setup HMAC Parameters */ 12577 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12578 ut_params->auth_xform.next = NULL; 12579 12580 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 12581 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12582 12583 ut_params->sess = rte_cryptodev_sym_session_create( 12584 ts_params->session_mpool); 12585 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12586 12587 /* Create Crypto session*/ 12588 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12589 ut_params->sess, &ut_params->cipher_xform, 12590 ts_params->session_priv_mpool); 12591 12592 if (status == -ENOTSUP) 12593 return TEST_SKIPPED; 12594 12595 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12596 12597 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 12598 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 12599 burst_len, "failed to generate burst of crypto ops"); 12600 12601 /* Generate an operation for each mbuf in burst */ 12602 for (i = 0; i < burst_len; i++) { 12603 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12604 12605 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 12606 12607 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 12608 sizeof(unsigned)); 12609 *data = i; 12610 12611 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 12612 12613 burst[i]->sym->m_src = m; 12614 } 12615 12616 /* Process crypto operation */ 12617 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 12618 0, burst, burst_len), 12619 burst_len, 12620 "Error enqueuing burst"); 12621 12622 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 12623 0, burst_dequeued, burst_len), 12624 burst_len, 12625 "Error dequeuing burst"); 12626 12627 12628 for (i = 0; i < burst_len; i++) { 12629 TEST_ASSERT_EQUAL( 12630 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 12631 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 12632 uint32_t *), 12633 "data not as expected"); 12634 12635 rte_pktmbuf_free(burst[i]->sym->m_src); 12636 rte_crypto_op_free(burst[i]); 12637 } 12638 12639 return TEST_SUCCESS; 12640 } 12641 12642 static uint16_t 12643 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12644 uint16_t nb_ops, void *user_param) 12645 { 12646 RTE_SET_USED(dev_id); 12647 RTE_SET_USED(qp_id); 12648 RTE_SET_USED(ops); 12649 RTE_SET_USED(user_param); 12650 12651 printf("crypto enqueue callback called\n"); 12652 return nb_ops; 12653 } 12654 12655 static uint16_t 12656 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12657 uint16_t nb_ops, void *user_param) 12658 { 12659 RTE_SET_USED(dev_id); 12660 RTE_SET_USED(qp_id); 12661 RTE_SET_USED(ops); 12662 RTE_SET_USED(user_param); 12663 12664 printf("crypto dequeue callback called\n"); 12665 return nb_ops; 12666 } 12667 12668 /* 12669 * Thread using enqueue/dequeue callback with RCU. 12670 */ 12671 static int 12672 test_enqdeq_callback_thread(void *arg) 12673 { 12674 RTE_SET_USED(arg); 12675 /* DP thread calls rte_cryptodev_enqueue_burst()/ 12676 * rte_cryptodev_dequeue_burst() and invokes callback. 12677 */ 12678 test_null_burst_operation(); 12679 return 0; 12680 } 12681 12682 static int 12683 test_enq_callback_setup(void) 12684 { 12685 struct crypto_testsuite_params *ts_params = &testsuite_params; 12686 struct rte_cryptodev_info dev_info; 12687 struct rte_cryptodev_qp_conf qp_conf = { 12688 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12689 }; 12690 12691 struct rte_cryptodev_cb *cb; 12692 uint16_t qp_id = 0; 12693 12694 /* Stop the device in case it's started so it can be configured */ 12695 rte_cryptodev_stop(ts_params->valid_devs[0]); 12696 12697 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12698 12699 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12700 &ts_params->conf), 12701 "Failed to configure cryptodev %u", 12702 ts_params->valid_devs[0]); 12703 12704 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12705 qp_conf.mp_session = ts_params->session_mpool; 12706 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12707 12708 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12709 ts_params->valid_devs[0], qp_id, &qp_conf, 12710 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12711 "Failed test for " 12712 "rte_cryptodev_queue_pair_setup: num_inflights " 12713 "%u on qp %u on cryptodev %u", 12714 qp_conf.nb_descriptors, qp_id, 12715 ts_params->valid_devs[0]); 12716 12717 /* Test with invalid crypto device */ 12718 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 12719 qp_id, test_enq_callback, NULL); 12720 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12721 "cryptodev %u did not fail", 12722 qp_id, RTE_CRYPTO_MAX_DEVS); 12723 12724 /* Test with invalid queue pair */ 12725 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12726 dev_info.max_nb_queue_pairs + 1, 12727 test_enq_callback, NULL); 12728 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12729 "cryptodev %u did not fail", 12730 dev_info.max_nb_queue_pairs + 1, 12731 ts_params->valid_devs[0]); 12732 12733 /* Test with NULL callback */ 12734 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12735 qp_id, NULL, NULL); 12736 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12737 "cryptodev %u did not fail", 12738 qp_id, ts_params->valid_devs[0]); 12739 12740 /* Test with valid configuration */ 12741 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12742 qp_id, test_enq_callback, NULL); 12743 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12744 "qp %u on cryptodev %u", 12745 qp_id, ts_params->valid_devs[0]); 12746 12747 rte_cryptodev_start(ts_params->valid_devs[0]); 12748 12749 /* Launch a thread */ 12750 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12751 rte_get_next_lcore(-1, 1, 0)); 12752 12753 /* Wait until reader exited. */ 12754 rte_eal_mp_wait_lcore(); 12755 12756 /* Test with invalid crypto device */ 12757 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12758 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12759 "Expected call to fail as crypto device is invalid"); 12760 12761 /* Test with invalid queue pair */ 12762 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12763 ts_params->valid_devs[0], 12764 dev_info.max_nb_queue_pairs + 1, cb), 12765 "Expected call to fail as queue pair is invalid"); 12766 12767 /* Test with NULL callback */ 12768 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12769 ts_params->valid_devs[0], qp_id, NULL), 12770 "Expected call to fail as callback is NULL"); 12771 12772 /* Test with valid configuration */ 12773 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 12774 ts_params->valid_devs[0], qp_id, cb), 12775 "Failed test to remove callback on " 12776 "qp %u on cryptodev %u", 12777 qp_id, ts_params->valid_devs[0]); 12778 12779 return TEST_SUCCESS; 12780 } 12781 12782 static int 12783 test_deq_callback_setup(void) 12784 { 12785 struct crypto_testsuite_params *ts_params = &testsuite_params; 12786 struct rte_cryptodev_info dev_info; 12787 struct rte_cryptodev_qp_conf qp_conf = { 12788 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12789 }; 12790 12791 struct rte_cryptodev_cb *cb; 12792 uint16_t qp_id = 0; 12793 12794 /* Stop the device in case it's started so it can be configured */ 12795 rte_cryptodev_stop(ts_params->valid_devs[0]); 12796 12797 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12798 12799 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12800 &ts_params->conf), 12801 "Failed to configure cryptodev %u", 12802 ts_params->valid_devs[0]); 12803 12804 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12805 qp_conf.mp_session = ts_params->session_mpool; 12806 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12807 12808 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12809 ts_params->valid_devs[0], qp_id, &qp_conf, 12810 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12811 "Failed test for " 12812 "rte_cryptodev_queue_pair_setup: num_inflights " 12813 "%u on qp %u on cryptodev %u", 12814 qp_conf.nb_descriptors, qp_id, 12815 ts_params->valid_devs[0]); 12816 12817 /* Test with invalid crypto device */ 12818 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 12819 qp_id, test_deq_callback, NULL); 12820 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12821 "cryptodev %u did not fail", 12822 qp_id, RTE_CRYPTO_MAX_DEVS); 12823 12824 /* Test with invalid queue pair */ 12825 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12826 dev_info.max_nb_queue_pairs + 1, 12827 test_deq_callback, NULL); 12828 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12829 "cryptodev %u did not fail", 12830 dev_info.max_nb_queue_pairs + 1, 12831 ts_params->valid_devs[0]); 12832 12833 /* Test with NULL callback */ 12834 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12835 qp_id, NULL, NULL); 12836 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12837 "cryptodev %u did not fail", 12838 qp_id, ts_params->valid_devs[0]); 12839 12840 /* Test with valid configuration */ 12841 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12842 qp_id, test_deq_callback, NULL); 12843 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12844 "qp %u on cryptodev %u", 12845 qp_id, ts_params->valid_devs[0]); 12846 12847 rte_cryptodev_start(ts_params->valid_devs[0]); 12848 12849 /* Launch a thread */ 12850 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12851 rte_get_next_lcore(-1, 1, 0)); 12852 12853 /* Wait until reader exited. */ 12854 rte_eal_mp_wait_lcore(); 12855 12856 /* Test with invalid crypto device */ 12857 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12858 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12859 "Expected call to fail as crypto device is invalid"); 12860 12861 /* Test with invalid queue pair */ 12862 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12863 ts_params->valid_devs[0], 12864 dev_info.max_nb_queue_pairs + 1, cb), 12865 "Expected call to fail as queue pair is invalid"); 12866 12867 /* Test with NULL callback */ 12868 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12869 ts_params->valid_devs[0], qp_id, NULL), 12870 "Expected call to fail as callback is NULL"); 12871 12872 /* Test with valid configuration */ 12873 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 12874 ts_params->valid_devs[0], qp_id, cb), 12875 "Failed test to remove callback on " 12876 "qp %u on cryptodev %u", 12877 qp_id, ts_params->valid_devs[0]); 12878 12879 return TEST_SUCCESS; 12880 } 12881 12882 static void 12883 generate_gmac_large_plaintext(uint8_t *data) 12884 { 12885 uint16_t i; 12886 12887 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 12888 memcpy(&data[i], &data[0], 32); 12889 } 12890 12891 static int 12892 create_gmac_operation(enum rte_crypto_auth_operation op, 12893 const struct gmac_test_data *tdata) 12894 { 12895 struct crypto_testsuite_params *ts_params = &testsuite_params; 12896 struct crypto_unittest_params *ut_params = &unittest_params; 12897 struct rte_crypto_sym_op *sym_op; 12898 12899 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12900 12901 /* Generate Crypto op data structure */ 12902 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12903 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12904 TEST_ASSERT_NOT_NULL(ut_params->op, 12905 "Failed to allocate symmetric crypto operation struct"); 12906 12907 sym_op = ut_params->op->sym; 12908 12909 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12910 ut_params->ibuf, tdata->gmac_tag.len); 12911 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12912 "no room to append digest"); 12913 12914 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12915 ut_params->ibuf, plaintext_pad_len); 12916 12917 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12918 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12919 tdata->gmac_tag.len); 12920 debug_hexdump(stdout, "digest:", 12921 sym_op->auth.digest.data, 12922 tdata->gmac_tag.len); 12923 } 12924 12925 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12926 uint8_t *, IV_OFFSET); 12927 12928 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12929 12930 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12931 12932 sym_op->cipher.data.length = 0; 12933 sym_op->cipher.data.offset = 0; 12934 12935 sym_op->auth.data.offset = 0; 12936 sym_op->auth.data.length = tdata->plaintext.len; 12937 12938 return 0; 12939 } 12940 12941 static int 12942 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12943 const struct gmac_test_data *tdata, 12944 void *digest_mem, uint64_t digest_phys) 12945 { 12946 struct crypto_testsuite_params *ts_params = &testsuite_params; 12947 struct crypto_unittest_params *ut_params = &unittest_params; 12948 struct rte_crypto_sym_op *sym_op; 12949 12950 /* Generate Crypto op data structure */ 12951 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12952 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12953 TEST_ASSERT_NOT_NULL(ut_params->op, 12954 "Failed to allocate symmetric crypto operation struct"); 12955 12956 sym_op = ut_params->op->sym; 12957 12958 sym_op->auth.digest.data = digest_mem; 12959 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12960 "no room to append digest"); 12961 12962 sym_op->auth.digest.phys_addr = digest_phys; 12963 12964 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12965 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12966 tdata->gmac_tag.len); 12967 debug_hexdump(stdout, "digest:", 12968 sym_op->auth.digest.data, 12969 tdata->gmac_tag.len); 12970 } 12971 12972 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12973 uint8_t *, IV_OFFSET); 12974 12975 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12976 12977 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12978 12979 sym_op->cipher.data.length = 0; 12980 sym_op->cipher.data.offset = 0; 12981 12982 sym_op->auth.data.offset = 0; 12983 sym_op->auth.data.length = tdata->plaintext.len; 12984 12985 return 0; 12986 } 12987 12988 static int create_gmac_session(uint8_t dev_id, 12989 const struct gmac_test_data *tdata, 12990 enum rte_crypto_auth_operation auth_op) 12991 { 12992 uint8_t auth_key[tdata->key.len]; 12993 int status; 12994 12995 struct crypto_testsuite_params *ts_params = &testsuite_params; 12996 struct crypto_unittest_params *ut_params = &unittest_params; 12997 12998 memcpy(auth_key, tdata->key.data, tdata->key.len); 12999 13000 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13001 ut_params->auth_xform.next = NULL; 13002 13003 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 13004 ut_params->auth_xform.auth.op = auth_op; 13005 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 13006 ut_params->auth_xform.auth.key.length = tdata->key.len; 13007 ut_params->auth_xform.auth.key.data = auth_key; 13008 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13009 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 13010 13011 13012 ut_params->sess = rte_cryptodev_sym_session_create( 13013 ts_params->session_mpool); 13014 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13015 13016 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13017 &ut_params->auth_xform, 13018 ts_params->session_priv_mpool); 13019 13020 return status; 13021 } 13022 13023 static int 13024 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 13025 { 13026 struct crypto_testsuite_params *ts_params = &testsuite_params; 13027 struct crypto_unittest_params *ut_params = &unittest_params; 13028 struct rte_cryptodev_info dev_info; 13029 13030 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13031 uint64_t feat_flags = dev_info.feature_flags; 13032 13033 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13034 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13035 printf("Device doesn't support RAW data-path APIs.\n"); 13036 return TEST_SKIPPED; 13037 } 13038 13039 int retval; 13040 13041 uint8_t *auth_tag, *plaintext; 13042 uint16_t plaintext_pad_len; 13043 13044 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13045 "No GMAC length in the source data"); 13046 13047 /* Verify the capabilities */ 13048 struct rte_cryptodev_sym_capability_idx cap_idx; 13049 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13050 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13051 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13052 &cap_idx) == NULL) 13053 return TEST_SKIPPED; 13054 13055 retval = create_gmac_session(ts_params->valid_devs[0], 13056 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13057 13058 if (retval == -ENOTSUP) 13059 return TEST_SKIPPED; 13060 if (retval < 0) 13061 return retval; 13062 13063 if (tdata->plaintext.len > MBUF_SIZE) 13064 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 13065 else 13066 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13067 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13068 "Failed to allocate input buffer in mempool"); 13069 13070 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13071 rte_pktmbuf_tailroom(ut_params->ibuf)); 13072 13073 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13074 /* 13075 * Runtime generate the large plain text instead of use hard code 13076 * plain text vector. It is done to avoid create huge source file 13077 * with the test vector. 13078 */ 13079 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 13080 generate_gmac_large_plaintext(tdata->plaintext.data); 13081 13082 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13083 plaintext_pad_len); 13084 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13085 13086 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13087 debug_hexdump(stdout, "plaintext:", plaintext, 13088 tdata->plaintext.len); 13089 13090 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 13091 tdata); 13092 13093 if (retval < 0) 13094 return retval; 13095 13096 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13097 13098 ut_params->op->sym->m_src = ut_params->ibuf; 13099 13100 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13101 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13102 ut_params->op); 13103 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13104 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13105 ut_params->op, 0, 1, 0, 0); 13106 else 13107 TEST_ASSERT_NOT_NULL( 13108 process_crypto_request(ts_params->valid_devs[0], 13109 ut_params->op), "failed to process sym crypto op"); 13110 13111 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13112 "crypto op processing failed"); 13113 13114 if (ut_params->op->sym->m_dst) { 13115 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13116 uint8_t *, plaintext_pad_len); 13117 } else { 13118 auth_tag = plaintext + plaintext_pad_len; 13119 } 13120 13121 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13122 13123 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13124 auth_tag, 13125 tdata->gmac_tag.data, 13126 tdata->gmac_tag.len, 13127 "GMAC Generated auth tag not as expected"); 13128 13129 return 0; 13130 } 13131 13132 static int 13133 test_AES_GMAC_authentication_test_case_1(void) 13134 { 13135 return test_AES_GMAC_authentication(&gmac_test_case_1); 13136 } 13137 13138 static int 13139 test_AES_GMAC_authentication_test_case_2(void) 13140 { 13141 return test_AES_GMAC_authentication(&gmac_test_case_2); 13142 } 13143 13144 static int 13145 test_AES_GMAC_authentication_test_case_3(void) 13146 { 13147 return test_AES_GMAC_authentication(&gmac_test_case_3); 13148 } 13149 13150 static int 13151 test_AES_GMAC_authentication_test_case_4(void) 13152 { 13153 return test_AES_GMAC_authentication(&gmac_test_case_4); 13154 } 13155 13156 static int 13157 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 13158 { 13159 struct crypto_testsuite_params *ts_params = &testsuite_params; 13160 struct crypto_unittest_params *ut_params = &unittest_params; 13161 int retval; 13162 uint32_t plaintext_pad_len; 13163 uint8_t *plaintext; 13164 struct rte_cryptodev_info dev_info; 13165 13166 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13167 uint64_t feat_flags = dev_info.feature_flags; 13168 13169 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13170 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13171 printf("Device doesn't support RAW data-path APIs.\n"); 13172 return TEST_SKIPPED; 13173 } 13174 13175 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13176 "No GMAC length in the source data"); 13177 13178 /* Verify the capabilities */ 13179 struct rte_cryptodev_sym_capability_idx cap_idx; 13180 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13181 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13182 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13183 &cap_idx) == NULL) 13184 return TEST_SKIPPED; 13185 13186 retval = create_gmac_session(ts_params->valid_devs[0], 13187 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 13188 13189 if (retval == -ENOTSUP) 13190 return TEST_SKIPPED; 13191 if (retval < 0) 13192 return retval; 13193 13194 if (tdata->plaintext.len > MBUF_SIZE) 13195 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 13196 else 13197 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13198 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13199 "Failed to allocate input buffer in mempool"); 13200 13201 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13202 rte_pktmbuf_tailroom(ut_params->ibuf)); 13203 13204 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13205 13206 /* 13207 * Runtime generate the large plain text instead of use hard code 13208 * plain text vector. It is done to avoid create huge source file 13209 * with the test vector. 13210 */ 13211 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 13212 generate_gmac_large_plaintext(tdata->plaintext.data); 13213 13214 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13215 plaintext_pad_len); 13216 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13217 13218 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13219 debug_hexdump(stdout, "plaintext:", plaintext, 13220 tdata->plaintext.len); 13221 13222 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 13223 tdata); 13224 13225 if (retval < 0) 13226 return retval; 13227 13228 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13229 13230 ut_params->op->sym->m_src = ut_params->ibuf; 13231 13232 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13233 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13234 ut_params->op); 13235 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13236 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13237 ut_params->op, 0, 1, 0, 0); 13238 else 13239 TEST_ASSERT_NOT_NULL( 13240 process_crypto_request(ts_params->valid_devs[0], 13241 ut_params->op), "failed to process sym crypto op"); 13242 13243 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13244 "crypto op processing failed"); 13245 13246 return 0; 13247 13248 } 13249 13250 static int 13251 test_AES_GMAC_authentication_verify_test_case_1(void) 13252 { 13253 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 13254 } 13255 13256 static int 13257 test_AES_GMAC_authentication_verify_test_case_2(void) 13258 { 13259 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 13260 } 13261 13262 static int 13263 test_AES_GMAC_authentication_verify_test_case_3(void) 13264 { 13265 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 13266 } 13267 13268 static int 13269 test_AES_GMAC_authentication_verify_test_case_4(void) 13270 { 13271 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 13272 } 13273 13274 static int 13275 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 13276 uint32_t fragsz) 13277 { 13278 struct crypto_testsuite_params *ts_params = &testsuite_params; 13279 struct crypto_unittest_params *ut_params = &unittest_params; 13280 struct rte_cryptodev_info dev_info; 13281 uint64_t feature_flags; 13282 unsigned int trn_data = 0; 13283 void *digest_mem = NULL; 13284 uint32_t segs = 1; 13285 unsigned int to_trn = 0; 13286 struct rte_mbuf *buf = NULL; 13287 uint8_t *auth_tag, *plaintext; 13288 int retval; 13289 13290 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13291 "No GMAC length in the source data"); 13292 13293 /* Verify the capabilities */ 13294 struct rte_cryptodev_sym_capability_idx cap_idx; 13295 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13296 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13297 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13298 &cap_idx) == NULL) 13299 return TEST_SKIPPED; 13300 13301 /* Check for any input SGL support */ 13302 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13303 feature_flags = dev_info.feature_flags; 13304 13305 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 13306 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 13307 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 13308 return TEST_SKIPPED; 13309 13310 if (fragsz > tdata->plaintext.len) 13311 fragsz = tdata->plaintext.len; 13312 13313 uint16_t plaintext_len = fragsz; 13314 13315 retval = create_gmac_session(ts_params->valid_devs[0], 13316 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13317 13318 if (retval == -ENOTSUP) 13319 return TEST_SKIPPED; 13320 if (retval < 0) 13321 return retval; 13322 13323 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13324 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13325 "Failed to allocate input buffer in mempool"); 13326 13327 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13328 rte_pktmbuf_tailroom(ut_params->ibuf)); 13329 13330 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13331 plaintext_len); 13332 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13333 13334 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13335 13336 trn_data += plaintext_len; 13337 13338 buf = ut_params->ibuf; 13339 13340 /* 13341 * Loop until no more fragments 13342 */ 13343 13344 while (trn_data < tdata->plaintext.len) { 13345 ++segs; 13346 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13347 (tdata->plaintext.len - trn_data) : fragsz; 13348 13349 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13350 buf = buf->next; 13351 13352 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13353 rte_pktmbuf_tailroom(buf)); 13354 13355 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13356 to_trn); 13357 13358 memcpy(plaintext, tdata->plaintext.data + trn_data, 13359 to_trn); 13360 trn_data += to_trn; 13361 if (trn_data == tdata->plaintext.len) 13362 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13363 tdata->gmac_tag.len); 13364 } 13365 ut_params->ibuf->nb_segs = segs; 13366 13367 /* 13368 * Place digest at the end of the last buffer 13369 */ 13370 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13371 13372 if (!digest_mem) { 13373 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13374 + tdata->gmac_tag.len); 13375 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13376 tdata->plaintext.len); 13377 } 13378 13379 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 13380 tdata, digest_mem, digest_phys); 13381 13382 if (retval < 0) 13383 return retval; 13384 13385 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13386 13387 ut_params->op->sym->m_src = ut_params->ibuf; 13388 13389 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13390 return TEST_SKIPPED; 13391 13392 TEST_ASSERT_NOT_NULL( 13393 process_crypto_request(ts_params->valid_devs[0], 13394 ut_params->op), "failed to process sym crypto op"); 13395 13396 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13397 "crypto op processing failed"); 13398 13399 auth_tag = digest_mem; 13400 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13401 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13402 auth_tag, 13403 tdata->gmac_tag.data, 13404 tdata->gmac_tag.len, 13405 "GMAC Generated auth tag not as expected"); 13406 13407 return 0; 13408 } 13409 13410 /* Segment size not multiple of block size (16B) */ 13411 static int 13412 test_AES_GMAC_authentication_SGL_40B(void) 13413 { 13414 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 13415 } 13416 13417 static int 13418 test_AES_GMAC_authentication_SGL_80B(void) 13419 { 13420 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 13421 } 13422 13423 static int 13424 test_AES_GMAC_authentication_SGL_2048B(void) 13425 { 13426 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 13427 } 13428 13429 /* Segment size not multiple of block size (16B) */ 13430 static int 13431 test_AES_GMAC_authentication_SGL_2047B(void) 13432 { 13433 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 13434 } 13435 13436 struct test_crypto_vector { 13437 enum rte_crypto_cipher_algorithm crypto_algo; 13438 unsigned int cipher_offset; 13439 unsigned int cipher_len; 13440 13441 struct { 13442 uint8_t data[64]; 13443 unsigned int len; 13444 } cipher_key; 13445 13446 struct { 13447 uint8_t data[64]; 13448 unsigned int len; 13449 } iv; 13450 13451 struct { 13452 const uint8_t *data; 13453 unsigned int len; 13454 } plaintext; 13455 13456 struct { 13457 const uint8_t *data; 13458 unsigned int len; 13459 } ciphertext; 13460 13461 enum rte_crypto_auth_algorithm auth_algo; 13462 unsigned int auth_offset; 13463 13464 struct { 13465 uint8_t data[128]; 13466 unsigned int len; 13467 } auth_key; 13468 13469 struct { 13470 const uint8_t *data; 13471 unsigned int len; 13472 } aad; 13473 13474 struct { 13475 uint8_t data[128]; 13476 unsigned int len; 13477 } digest; 13478 }; 13479 13480 static const struct test_crypto_vector 13481 hmac_sha1_test_crypto_vector = { 13482 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13483 .plaintext = { 13484 .data = plaintext_hash, 13485 .len = 512 13486 }, 13487 .auth_key = { 13488 .data = { 13489 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13490 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13491 0xDE, 0xF4, 0xDE, 0xAD 13492 }, 13493 .len = 20 13494 }, 13495 .digest = { 13496 .data = { 13497 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 13498 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 13499 0x3F, 0x91, 0x64, 0x59 13500 }, 13501 .len = 20 13502 } 13503 }; 13504 13505 static const struct test_crypto_vector 13506 aes128_gmac_test_vector = { 13507 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 13508 .plaintext = { 13509 .data = plaintext_hash, 13510 .len = 512 13511 }, 13512 .iv = { 13513 .data = { 13514 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13515 0x08, 0x09, 0x0A, 0x0B 13516 }, 13517 .len = 12 13518 }, 13519 .auth_key = { 13520 .data = { 13521 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13522 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 13523 }, 13524 .len = 16 13525 }, 13526 .digest = { 13527 .data = { 13528 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 13529 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 13530 }, 13531 .len = 16 13532 } 13533 }; 13534 13535 static const struct test_crypto_vector 13536 aes128cbc_hmac_sha1_test_vector = { 13537 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13538 .cipher_offset = 0, 13539 .cipher_len = 512, 13540 .cipher_key = { 13541 .data = { 13542 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13543 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13544 }, 13545 .len = 16 13546 }, 13547 .iv = { 13548 .data = { 13549 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13550 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13551 }, 13552 .len = 16 13553 }, 13554 .plaintext = { 13555 .data = plaintext_hash, 13556 .len = 512 13557 }, 13558 .ciphertext = { 13559 .data = ciphertext512_aes128cbc, 13560 .len = 512 13561 }, 13562 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13563 .auth_offset = 0, 13564 .auth_key = { 13565 .data = { 13566 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13567 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13568 0xDE, 0xF4, 0xDE, 0xAD 13569 }, 13570 .len = 20 13571 }, 13572 .digest = { 13573 .data = { 13574 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 13575 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13576 0x18, 0x8C, 0x1D, 0x32 13577 }, 13578 .len = 20 13579 } 13580 }; 13581 13582 static const struct test_crypto_vector 13583 aes128cbc_hmac_sha1_aad_test_vector = { 13584 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13585 .cipher_offset = 8, 13586 .cipher_len = 496, 13587 .cipher_key = { 13588 .data = { 13589 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13590 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13591 }, 13592 .len = 16 13593 }, 13594 .iv = { 13595 .data = { 13596 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13597 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13598 }, 13599 .len = 16 13600 }, 13601 .plaintext = { 13602 .data = plaintext_hash, 13603 .len = 512 13604 }, 13605 .ciphertext = { 13606 .data = ciphertext512_aes128cbc_aad, 13607 .len = 512 13608 }, 13609 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13610 .auth_offset = 0, 13611 .auth_key = { 13612 .data = { 13613 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13614 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13615 0xDE, 0xF4, 0xDE, 0xAD 13616 }, 13617 .len = 20 13618 }, 13619 .digest = { 13620 .data = { 13621 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 13622 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 13623 0x62, 0x0F, 0xFB, 0x10 13624 }, 13625 .len = 20 13626 } 13627 }; 13628 13629 static void 13630 data_corruption(uint8_t *data) 13631 { 13632 data[0] += 1; 13633 } 13634 13635 static void 13636 tag_corruption(uint8_t *data, unsigned int tag_offset) 13637 { 13638 data[tag_offset] += 1; 13639 } 13640 13641 static int 13642 create_auth_session(struct crypto_unittest_params *ut_params, 13643 uint8_t dev_id, 13644 const struct test_crypto_vector *reference, 13645 enum rte_crypto_auth_operation auth_op) 13646 { 13647 struct crypto_testsuite_params *ts_params = &testsuite_params; 13648 uint8_t auth_key[reference->auth_key.len + 1]; 13649 int status; 13650 13651 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13652 13653 /* Setup Authentication Parameters */ 13654 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13655 ut_params->auth_xform.auth.op = auth_op; 13656 ut_params->auth_xform.next = NULL; 13657 ut_params->auth_xform.auth.algo = reference->auth_algo; 13658 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13659 ut_params->auth_xform.auth.key.data = auth_key; 13660 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13661 13662 /* Create Crypto session*/ 13663 ut_params->sess = rte_cryptodev_sym_session_create( 13664 ts_params->session_mpool); 13665 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13666 13667 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13668 &ut_params->auth_xform, 13669 ts_params->session_priv_mpool); 13670 13671 return status; 13672 } 13673 13674 static int 13675 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 13676 uint8_t dev_id, 13677 const struct test_crypto_vector *reference, 13678 enum rte_crypto_auth_operation auth_op, 13679 enum rte_crypto_cipher_operation cipher_op) 13680 { 13681 struct crypto_testsuite_params *ts_params = &testsuite_params; 13682 uint8_t cipher_key[reference->cipher_key.len + 1]; 13683 uint8_t auth_key[reference->auth_key.len + 1]; 13684 int status; 13685 13686 memcpy(cipher_key, reference->cipher_key.data, 13687 reference->cipher_key.len); 13688 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13689 13690 /* Setup Authentication Parameters */ 13691 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13692 ut_params->auth_xform.auth.op = auth_op; 13693 ut_params->auth_xform.auth.algo = reference->auth_algo; 13694 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13695 ut_params->auth_xform.auth.key.data = auth_key; 13696 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13697 13698 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 13699 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13700 ut_params->auth_xform.auth.iv.length = reference->iv.len; 13701 } else { 13702 ut_params->auth_xform.next = &ut_params->cipher_xform; 13703 13704 /* Setup Cipher Parameters */ 13705 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13706 ut_params->cipher_xform.next = NULL; 13707 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13708 ut_params->cipher_xform.cipher.op = cipher_op; 13709 ut_params->cipher_xform.cipher.key.data = cipher_key; 13710 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13711 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13712 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13713 } 13714 13715 /* Create Crypto session*/ 13716 ut_params->sess = rte_cryptodev_sym_session_create( 13717 ts_params->session_mpool); 13718 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13719 13720 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13721 &ut_params->auth_xform, 13722 ts_params->session_priv_mpool); 13723 13724 return status; 13725 } 13726 13727 static int 13728 create_auth_operation(struct crypto_testsuite_params *ts_params, 13729 struct crypto_unittest_params *ut_params, 13730 const struct test_crypto_vector *reference, 13731 unsigned int auth_generate) 13732 { 13733 /* Generate Crypto op data structure */ 13734 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13735 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13736 TEST_ASSERT_NOT_NULL(ut_params->op, 13737 "Failed to allocate pktmbuf offload"); 13738 13739 /* Set crypto operation data parameters */ 13740 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13741 13742 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13743 13744 /* set crypto operation source mbuf */ 13745 sym_op->m_src = ut_params->ibuf; 13746 13747 /* digest */ 13748 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13749 ut_params->ibuf, reference->digest.len); 13750 13751 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13752 "no room to append auth tag"); 13753 13754 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13755 ut_params->ibuf, reference->plaintext.len); 13756 13757 if (auth_generate) 13758 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13759 else 13760 memcpy(sym_op->auth.digest.data, 13761 reference->digest.data, 13762 reference->digest.len); 13763 13764 debug_hexdump(stdout, "digest:", 13765 sym_op->auth.digest.data, 13766 reference->digest.len); 13767 13768 sym_op->auth.data.length = reference->plaintext.len; 13769 sym_op->auth.data.offset = 0; 13770 13771 return 0; 13772 } 13773 13774 static int 13775 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 13776 struct crypto_unittest_params *ut_params, 13777 const struct test_crypto_vector *reference, 13778 unsigned int auth_generate) 13779 { 13780 /* Generate Crypto op data structure */ 13781 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13782 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13783 TEST_ASSERT_NOT_NULL(ut_params->op, 13784 "Failed to allocate pktmbuf offload"); 13785 13786 /* Set crypto operation data parameters */ 13787 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13788 13789 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13790 13791 /* set crypto operation source mbuf */ 13792 sym_op->m_src = ut_params->ibuf; 13793 13794 /* digest */ 13795 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13796 ut_params->ibuf, reference->digest.len); 13797 13798 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13799 "no room to append auth tag"); 13800 13801 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13802 ut_params->ibuf, reference->ciphertext.len); 13803 13804 if (auth_generate) 13805 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13806 else 13807 memcpy(sym_op->auth.digest.data, 13808 reference->digest.data, 13809 reference->digest.len); 13810 13811 debug_hexdump(stdout, "digest:", 13812 sym_op->auth.digest.data, 13813 reference->digest.len); 13814 13815 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13816 reference->iv.data, reference->iv.len); 13817 13818 sym_op->cipher.data.length = 0; 13819 sym_op->cipher.data.offset = 0; 13820 13821 sym_op->auth.data.length = reference->plaintext.len; 13822 sym_op->auth.data.offset = 0; 13823 13824 return 0; 13825 } 13826 13827 static int 13828 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 13829 struct crypto_unittest_params *ut_params, 13830 const struct test_crypto_vector *reference, 13831 unsigned int auth_generate) 13832 { 13833 /* Generate Crypto op data structure */ 13834 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13835 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13836 TEST_ASSERT_NOT_NULL(ut_params->op, 13837 "Failed to allocate pktmbuf offload"); 13838 13839 /* Set crypto operation data parameters */ 13840 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13841 13842 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13843 13844 /* set crypto operation source mbuf */ 13845 sym_op->m_src = ut_params->ibuf; 13846 13847 /* digest */ 13848 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13849 ut_params->ibuf, reference->digest.len); 13850 13851 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13852 "no room to append auth tag"); 13853 13854 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13855 ut_params->ibuf, reference->ciphertext.len); 13856 13857 if (auth_generate) 13858 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13859 else 13860 memcpy(sym_op->auth.digest.data, 13861 reference->digest.data, 13862 reference->digest.len); 13863 13864 debug_hexdump(stdout, "digest:", 13865 sym_op->auth.digest.data, 13866 reference->digest.len); 13867 13868 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13869 reference->iv.data, reference->iv.len); 13870 13871 sym_op->cipher.data.length = reference->cipher_len; 13872 sym_op->cipher.data.offset = reference->cipher_offset; 13873 13874 sym_op->auth.data.length = reference->plaintext.len; 13875 sym_op->auth.data.offset = reference->auth_offset; 13876 13877 return 0; 13878 } 13879 13880 static int 13881 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13882 struct crypto_unittest_params *ut_params, 13883 const struct test_crypto_vector *reference) 13884 { 13885 return create_auth_operation(ts_params, ut_params, reference, 0); 13886 } 13887 13888 static int 13889 create_auth_verify_GMAC_operation( 13890 struct crypto_testsuite_params *ts_params, 13891 struct crypto_unittest_params *ut_params, 13892 const struct test_crypto_vector *reference) 13893 { 13894 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 13895 } 13896 13897 static int 13898 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13899 struct crypto_unittest_params *ut_params, 13900 const struct test_crypto_vector *reference) 13901 { 13902 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 13903 } 13904 13905 static int 13906 test_authentication_verify_fail_when_data_corruption( 13907 struct crypto_testsuite_params *ts_params, 13908 struct crypto_unittest_params *ut_params, 13909 const struct test_crypto_vector *reference, 13910 unsigned int data_corrupted) 13911 { 13912 int retval; 13913 13914 uint8_t *plaintext; 13915 struct rte_cryptodev_info dev_info; 13916 13917 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13918 uint64_t feat_flags = dev_info.feature_flags; 13919 13920 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13921 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13922 printf("Device doesn't support RAW data-path APIs.\n"); 13923 return TEST_SKIPPED; 13924 } 13925 13926 /* Verify the capabilities */ 13927 struct rte_cryptodev_sym_capability_idx cap_idx; 13928 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13929 cap_idx.algo.auth = reference->auth_algo; 13930 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13931 &cap_idx) == NULL) 13932 return TEST_SKIPPED; 13933 13934 13935 /* Create session */ 13936 retval = create_auth_session(ut_params, 13937 ts_params->valid_devs[0], 13938 reference, 13939 RTE_CRYPTO_AUTH_OP_VERIFY); 13940 13941 if (retval == -ENOTSUP) 13942 return TEST_SKIPPED; 13943 if (retval < 0) 13944 return retval; 13945 13946 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13947 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13948 "Failed to allocate input buffer in mempool"); 13949 13950 /* clear mbuf payload */ 13951 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13952 rte_pktmbuf_tailroom(ut_params->ibuf)); 13953 13954 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13955 reference->plaintext.len); 13956 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13957 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13958 13959 debug_hexdump(stdout, "plaintext:", plaintext, 13960 reference->plaintext.len); 13961 13962 /* Create operation */ 13963 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13964 13965 if (retval < 0) 13966 return retval; 13967 13968 if (data_corrupted) 13969 data_corruption(plaintext); 13970 else 13971 tag_corruption(plaintext, reference->plaintext.len); 13972 13973 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13974 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13975 ut_params->op); 13976 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13977 RTE_CRYPTO_OP_STATUS_SUCCESS, 13978 "authentication not failed"); 13979 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13980 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13981 ut_params->op, 0, 1, 0, 0); 13982 else { 13983 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13984 ut_params->op); 13985 } 13986 if (ut_params->op == NULL) 13987 return 0; 13988 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13989 return 0; 13990 13991 return -1; 13992 } 13993 13994 static int 13995 test_authentication_verify_GMAC_fail_when_corruption( 13996 struct crypto_testsuite_params *ts_params, 13997 struct crypto_unittest_params *ut_params, 13998 const struct test_crypto_vector *reference, 13999 unsigned int data_corrupted) 14000 { 14001 int retval; 14002 uint8_t *plaintext; 14003 struct rte_cryptodev_info dev_info; 14004 14005 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14006 uint64_t feat_flags = dev_info.feature_flags; 14007 14008 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14009 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14010 printf("Device doesn't support RAW data-path APIs.\n"); 14011 return TEST_SKIPPED; 14012 } 14013 14014 /* Verify the capabilities */ 14015 struct rte_cryptodev_sym_capability_idx cap_idx; 14016 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14017 cap_idx.algo.auth = reference->auth_algo; 14018 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14019 &cap_idx) == NULL) 14020 return TEST_SKIPPED; 14021 14022 /* Create session */ 14023 retval = create_auth_cipher_session(ut_params, 14024 ts_params->valid_devs[0], 14025 reference, 14026 RTE_CRYPTO_AUTH_OP_VERIFY, 14027 RTE_CRYPTO_CIPHER_OP_DECRYPT); 14028 if (retval < 0) 14029 return retval; 14030 14031 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14032 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14033 "Failed to allocate input buffer in mempool"); 14034 14035 /* clear mbuf payload */ 14036 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14037 rte_pktmbuf_tailroom(ut_params->ibuf)); 14038 14039 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14040 reference->plaintext.len); 14041 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14042 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14043 14044 debug_hexdump(stdout, "plaintext:", plaintext, 14045 reference->plaintext.len); 14046 14047 /* Create operation */ 14048 retval = create_auth_verify_GMAC_operation(ts_params, 14049 ut_params, 14050 reference); 14051 14052 if (retval < 0) 14053 return retval; 14054 14055 if (data_corrupted) 14056 data_corruption(plaintext); 14057 else 14058 tag_corruption(plaintext, reference->aad.len); 14059 14060 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14061 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14062 ut_params->op); 14063 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14064 RTE_CRYPTO_OP_STATUS_SUCCESS, 14065 "authentication not failed"); 14066 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14067 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14068 ut_params->op, 0, 1, 0, 0); 14069 else { 14070 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14071 ut_params->op); 14072 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 14073 } 14074 14075 return 0; 14076 } 14077 14078 static int 14079 test_authenticated_decryption_fail_when_corruption( 14080 struct crypto_testsuite_params *ts_params, 14081 struct crypto_unittest_params *ut_params, 14082 const struct test_crypto_vector *reference, 14083 unsigned int data_corrupted) 14084 { 14085 int retval; 14086 14087 uint8_t *ciphertext; 14088 struct rte_cryptodev_info dev_info; 14089 14090 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14091 uint64_t feat_flags = dev_info.feature_flags; 14092 14093 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14094 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14095 printf("Device doesn't support RAW data-path APIs.\n"); 14096 return TEST_SKIPPED; 14097 } 14098 14099 /* Verify the capabilities */ 14100 struct rte_cryptodev_sym_capability_idx cap_idx; 14101 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14102 cap_idx.algo.auth = reference->auth_algo; 14103 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14104 &cap_idx) == NULL) 14105 return TEST_SKIPPED; 14106 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14107 cap_idx.algo.cipher = reference->crypto_algo; 14108 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14109 &cap_idx) == NULL) 14110 return TEST_SKIPPED; 14111 14112 /* Create session */ 14113 retval = create_auth_cipher_session(ut_params, 14114 ts_params->valid_devs[0], 14115 reference, 14116 RTE_CRYPTO_AUTH_OP_VERIFY, 14117 RTE_CRYPTO_CIPHER_OP_DECRYPT); 14118 14119 if (retval == -ENOTSUP) 14120 return TEST_SKIPPED; 14121 if (retval < 0) 14122 return retval; 14123 14124 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14125 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14126 "Failed to allocate input buffer in mempool"); 14127 14128 /* clear mbuf payload */ 14129 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14130 rte_pktmbuf_tailroom(ut_params->ibuf)); 14131 14132 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14133 reference->ciphertext.len); 14134 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14135 memcpy(ciphertext, reference->ciphertext.data, 14136 reference->ciphertext.len); 14137 14138 /* Create operation */ 14139 retval = create_cipher_auth_verify_operation(ts_params, 14140 ut_params, 14141 reference); 14142 14143 if (retval < 0) 14144 return retval; 14145 14146 if (data_corrupted) 14147 data_corruption(ciphertext); 14148 else 14149 tag_corruption(ciphertext, reference->ciphertext.len); 14150 14151 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14152 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14153 ut_params->op); 14154 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14155 RTE_CRYPTO_OP_STATUS_SUCCESS, 14156 "authentication not failed"); 14157 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14158 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14159 ut_params->op, 1, 1, 0, 0); 14160 else { 14161 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14162 ut_params->op); 14163 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 14164 } 14165 14166 return 0; 14167 } 14168 14169 static int 14170 test_authenticated_encrypt_with_esn( 14171 struct crypto_testsuite_params *ts_params, 14172 struct crypto_unittest_params *ut_params, 14173 const struct test_crypto_vector *reference) 14174 { 14175 int retval; 14176 14177 uint8_t *authciphertext, *plaintext, *auth_tag; 14178 uint16_t plaintext_pad_len; 14179 uint8_t cipher_key[reference->cipher_key.len + 1]; 14180 uint8_t auth_key[reference->auth_key.len + 1]; 14181 struct rte_cryptodev_info dev_info; 14182 int status; 14183 14184 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14185 uint64_t feat_flags = dev_info.feature_flags; 14186 14187 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14188 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14189 printf("Device doesn't support RAW data-path APIs.\n"); 14190 return TEST_SKIPPED; 14191 } 14192 14193 /* Verify the capabilities */ 14194 struct rte_cryptodev_sym_capability_idx cap_idx; 14195 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14196 cap_idx.algo.auth = reference->auth_algo; 14197 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14198 &cap_idx) == NULL) 14199 return TEST_SKIPPED; 14200 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14201 cap_idx.algo.cipher = reference->crypto_algo; 14202 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14203 &cap_idx) == NULL) 14204 return TEST_SKIPPED; 14205 14206 /* Create session */ 14207 memcpy(cipher_key, reference->cipher_key.data, 14208 reference->cipher_key.len); 14209 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14210 14211 /* Setup Cipher Parameters */ 14212 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14213 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14214 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 14215 ut_params->cipher_xform.cipher.key.data = cipher_key; 14216 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14217 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14218 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14219 14220 ut_params->cipher_xform.next = &ut_params->auth_xform; 14221 14222 /* Setup Authentication Parameters */ 14223 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14224 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14225 ut_params->auth_xform.auth.algo = reference->auth_algo; 14226 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14227 ut_params->auth_xform.auth.key.data = auth_key; 14228 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14229 ut_params->auth_xform.next = NULL; 14230 14231 /* Create Crypto session*/ 14232 ut_params->sess = rte_cryptodev_sym_session_create( 14233 ts_params->session_mpool); 14234 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14235 14236 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14237 ut_params->sess, 14238 &ut_params->cipher_xform, 14239 ts_params->session_priv_mpool); 14240 14241 if (status == -ENOTSUP) 14242 return TEST_SKIPPED; 14243 14244 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 14245 14246 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14247 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14248 "Failed to allocate input buffer in mempool"); 14249 14250 /* clear mbuf payload */ 14251 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14252 rte_pktmbuf_tailroom(ut_params->ibuf)); 14253 14254 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14255 reference->plaintext.len); 14256 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14257 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14258 14259 /* Create operation */ 14260 retval = create_cipher_auth_operation(ts_params, 14261 ut_params, 14262 reference, 0); 14263 14264 if (retval < 0) 14265 return retval; 14266 14267 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14268 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14269 ut_params->op); 14270 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14271 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14272 ut_params->op, 1, 1, 0, 0); 14273 else 14274 ut_params->op = process_crypto_request( 14275 ts_params->valid_devs[0], ut_params->op); 14276 14277 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 14278 14279 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14280 "crypto op processing failed"); 14281 14282 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 14283 14284 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 14285 ut_params->op->sym->auth.data.offset); 14286 auth_tag = authciphertext + plaintext_pad_len; 14287 debug_hexdump(stdout, "ciphertext:", authciphertext, 14288 reference->ciphertext.len); 14289 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 14290 14291 /* Validate obuf */ 14292 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14293 authciphertext, 14294 reference->ciphertext.data, 14295 reference->ciphertext.len, 14296 "Ciphertext data not as expected"); 14297 14298 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14299 auth_tag, 14300 reference->digest.data, 14301 reference->digest.len, 14302 "Generated digest not as expected"); 14303 14304 return TEST_SUCCESS; 14305 14306 } 14307 14308 static int 14309 test_authenticated_decrypt_with_esn( 14310 struct crypto_testsuite_params *ts_params, 14311 struct crypto_unittest_params *ut_params, 14312 const struct test_crypto_vector *reference) 14313 { 14314 int retval; 14315 14316 uint8_t *ciphertext; 14317 uint8_t cipher_key[reference->cipher_key.len + 1]; 14318 uint8_t auth_key[reference->auth_key.len + 1]; 14319 struct rte_cryptodev_info dev_info; 14320 14321 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14322 uint64_t feat_flags = dev_info.feature_flags; 14323 14324 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14325 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14326 printf("Device doesn't support RAW data-path APIs.\n"); 14327 return TEST_SKIPPED; 14328 } 14329 14330 /* Verify the capabilities */ 14331 struct rte_cryptodev_sym_capability_idx cap_idx; 14332 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14333 cap_idx.algo.auth = reference->auth_algo; 14334 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14335 &cap_idx) == NULL) 14336 return TEST_SKIPPED; 14337 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14338 cap_idx.algo.cipher = reference->crypto_algo; 14339 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14340 &cap_idx) == NULL) 14341 return TEST_SKIPPED; 14342 14343 /* Create session */ 14344 memcpy(cipher_key, reference->cipher_key.data, 14345 reference->cipher_key.len); 14346 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14347 14348 /* Setup Authentication Parameters */ 14349 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14350 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 14351 ut_params->auth_xform.auth.algo = reference->auth_algo; 14352 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14353 ut_params->auth_xform.auth.key.data = auth_key; 14354 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14355 ut_params->auth_xform.next = &ut_params->cipher_xform; 14356 14357 /* Setup Cipher Parameters */ 14358 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14359 ut_params->cipher_xform.next = NULL; 14360 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14361 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 14362 ut_params->cipher_xform.cipher.key.data = cipher_key; 14363 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14364 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14365 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14366 14367 /* Create Crypto session*/ 14368 ut_params->sess = rte_cryptodev_sym_session_create( 14369 ts_params->session_mpool); 14370 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14371 14372 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14373 ut_params->sess, 14374 &ut_params->auth_xform, 14375 ts_params->session_priv_mpool); 14376 14377 if (retval == -ENOTSUP) 14378 return TEST_SKIPPED; 14379 14380 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 14381 14382 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14383 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14384 "Failed to allocate input buffer in mempool"); 14385 14386 /* clear mbuf payload */ 14387 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14388 rte_pktmbuf_tailroom(ut_params->ibuf)); 14389 14390 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14391 reference->ciphertext.len); 14392 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14393 memcpy(ciphertext, reference->ciphertext.data, 14394 reference->ciphertext.len); 14395 14396 /* Create operation */ 14397 retval = create_cipher_auth_verify_operation(ts_params, 14398 ut_params, 14399 reference); 14400 14401 if (retval < 0) 14402 return retval; 14403 14404 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14405 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14406 ut_params->op); 14407 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14408 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14409 ut_params->op, 1, 1, 0, 0); 14410 else 14411 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14412 ut_params->op); 14413 14414 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 14415 TEST_ASSERT_EQUAL(ut_params->op->status, 14416 RTE_CRYPTO_OP_STATUS_SUCCESS, 14417 "crypto op processing passed"); 14418 14419 ut_params->obuf = ut_params->op->sym->m_src; 14420 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 14421 14422 return 0; 14423 } 14424 14425 static int 14426 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 14427 const struct aead_test_data *tdata, 14428 void *digest_mem, uint64_t digest_phys) 14429 { 14430 struct crypto_testsuite_params *ts_params = &testsuite_params; 14431 struct crypto_unittest_params *ut_params = &unittest_params; 14432 14433 const unsigned int auth_tag_len = tdata->auth_tag.len; 14434 const unsigned int iv_len = tdata->iv.len; 14435 unsigned int aad_len = tdata->aad.len; 14436 unsigned int aad_len_pad = 0; 14437 14438 /* Generate Crypto op data structure */ 14439 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14440 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14441 TEST_ASSERT_NOT_NULL(ut_params->op, 14442 "Failed to allocate symmetric crypto operation struct"); 14443 14444 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14445 14446 sym_op->aead.digest.data = digest_mem; 14447 14448 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 14449 "no room to append digest"); 14450 14451 sym_op->aead.digest.phys_addr = digest_phys; 14452 14453 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 14454 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 14455 auth_tag_len); 14456 debug_hexdump(stdout, "digest:", 14457 sym_op->aead.digest.data, 14458 auth_tag_len); 14459 } 14460 14461 /* Append aad data */ 14462 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 14463 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14464 uint8_t *, IV_OFFSET); 14465 14466 /* Copy IV 1 byte after the IV pointer, according to the API */ 14467 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 14468 14469 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 14470 14471 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14472 ut_params->ibuf, aad_len); 14473 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14474 "no room to prepend aad"); 14475 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14476 ut_params->ibuf); 14477 14478 memset(sym_op->aead.aad.data, 0, aad_len); 14479 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 14480 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14481 14482 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14483 debug_hexdump(stdout, "aad:", 14484 sym_op->aead.aad.data, aad_len); 14485 } else { 14486 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14487 uint8_t *, IV_OFFSET); 14488 14489 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 14490 14491 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 14492 14493 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14494 ut_params->ibuf, aad_len_pad); 14495 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14496 "no room to prepend aad"); 14497 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14498 ut_params->ibuf); 14499 14500 memset(sym_op->aead.aad.data, 0, aad_len); 14501 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14502 14503 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14504 debug_hexdump(stdout, "aad:", 14505 sym_op->aead.aad.data, aad_len); 14506 } 14507 14508 sym_op->aead.data.length = tdata->plaintext.len; 14509 sym_op->aead.data.offset = aad_len_pad; 14510 14511 return 0; 14512 } 14513 14514 #define SGL_MAX_NO 16 14515 14516 static int 14517 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 14518 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 14519 { 14520 struct crypto_testsuite_params *ts_params = &testsuite_params; 14521 struct crypto_unittest_params *ut_params = &unittest_params; 14522 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 14523 int retval; 14524 int to_trn = 0; 14525 int to_trn_tbl[SGL_MAX_NO]; 14526 int segs = 1; 14527 unsigned int trn_data = 0; 14528 uint8_t *plaintext, *ciphertext, *auth_tag; 14529 struct rte_cryptodev_info dev_info; 14530 14531 /* Verify the capabilities */ 14532 struct rte_cryptodev_sym_capability_idx cap_idx; 14533 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 14534 cap_idx.algo.aead = tdata->algo; 14535 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14536 &cap_idx) == NULL) 14537 return TEST_SKIPPED; 14538 14539 /* OOP not supported with CPU crypto */ 14540 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14541 return TEST_SKIPPED; 14542 14543 /* Detailed check for the particular SGL support flag */ 14544 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14545 if (!oop) { 14546 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14547 if (sgl_in && (!(dev_info.feature_flags & 14548 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 14549 return TEST_SKIPPED; 14550 14551 uint64_t feat_flags = dev_info.feature_flags; 14552 14553 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14554 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14555 printf("Device doesn't support RAW data-path APIs.\n"); 14556 return TEST_SKIPPED; 14557 } 14558 } else { 14559 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14560 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 14561 tdata->plaintext.len; 14562 /* Raw data path API does not support OOP */ 14563 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14564 return TEST_SKIPPED; 14565 if (sgl_in && !sgl_out) { 14566 if (!(dev_info.feature_flags & 14567 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 14568 return TEST_SKIPPED; 14569 } else if (!sgl_in && sgl_out) { 14570 if (!(dev_info.feature_flags & 14571 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 14572 return TEST_SKIPPED; 14573 } else if (sgl_in && sgl_out) { 14574 if (!(dev_info.feature_flags & 14575 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 14576 return TEST_SKIPPED; 14577 } 14578 } 14579 14580 if (fragsz > tdata->plaintext.len) 14581 fragsz = tdata->plaintext.len; 14582 14583 uint16_t plaintext_len = fragsz; 14584 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 14585 14586 if (fragsz_oop > tdata->plaintext.len) 14587 frag_size_oop = tdata->plaintext.len; 14588 14589 int ecx = 0; 14590 void *digest_mem = NULL; 14591 14592 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 14593 14594 if (tdata->plaintext.len % fragsz != 0) { 14595 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 14596 return 1; 14597 } else { 14598 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 14599 return 1; 14600 } 14601 14602 /* 14603 * For out-op-place we need to alloc another mbuf 14604 */ 14605 if (oop) { 14606 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14607 rte_pktmbuf_append(ut_params->obuf, 14608 frag_size_oop + prepend_len); 14609 buf_oop = ut_params->obuf; 14610 } 14611 14612 /* Create AEAD session */ 14613 retval = create_aead_session(ts_params->valid_devs[0], 14614 tdata->algo, 14615 RTE_CRYPTO_AEAD_OP_ENCRYPT, 14616 tdata->key.data, tdata->key.len, 14617 tdata->aad.len, tdata->auth_tag.len, 14618 tdata->iv.len); 14619 if (retval < 0) 14620 return retval; 14621 14622 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14623 14624 /* clear mbuf payload */ 14625 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14626 rte_pktmbuf_tailroom(ut_params->ibuf)); 14627 14628 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14629 plaintext_len); 14630 14631 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14632 14633 trn_data += plaintext_len; 14634 14635 buf = ut_params->ibuf; 14636 14637 /* 14638 * Loop until no more fragments 14639 */ 14640 14641 while (trn_data < tdata->plaintext.len) { 14642 ++segs; 14643 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14644 (tdata->plaintext.len - trn_data) : fragsz; 14645 14646 to_trn_tbl[ecx++] = to_trn; 14647 14648 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14649 buf = buf->next; 14650 14651 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14652 rte_pktmbuf_tailroom(buf)); 14653 14654 /* OOP */ 14655 if (oop && !fragsz_oop) { 14656 buf_last_oop = buf_oop->next = 14657 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14658 buf_oop = buf_oop->next; 14659 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14660 0, rte_pktmbuf_tailroom(buf_oop)); 14661 rte_pktmbuf_append(buf_oop, to_trn); 14662 } 14663 14664 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14665 to_trn); 14666 14667 memcpy(plaintext, tdata->plaintext.data + trn_data, 14668 to_trn); 14669 trn_data += to_trn; 14670 if (trn_data == tdata->plaintext.len) { 14671 if (oop) { 14672 if (!fragsz_oop) 14673 digest_mem = rte_pktmbuf_append(buf_oop, 14674 tdata->auth_tag.len); 14675 } else 14676 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14677 tdata->auth_tag.len); 14678 } 14679 } 14680 14681 uint64_t digest_phys = 0; 14682 14683 ut_params->ibuf->nb_segs = segs; 14684 14685 segs = 1; 14686 if (fragsz_oop && oop) { 14687 to_trn = 0; 14688 ecx = 0; 14689 14690 if (frag_size_oop == tdata->plaintext.len) { 14691 digest_mem = rte_pktmbuf_append(ut_params->obuf, 14692 tdata->auth_tag.len); 14693 14694 digest_phys = rte_pktmbuf_iova_offset( 14695 ut_params->obuf, 14696 tdata->plaintext.len + prepend_len); 14697 } 14698 14699 trn_data = frag_size_oop; 14700 while (trn_data < tdata->plaintext.len) { 14701 ++segs; 14702 to_trn = 14703 (tdata->plaintext.len - trn_data < 14704 frag_size_oop) ? 14705 (tdata->plaintext.len - trn_data) : 14706 frag_size_oop; 14707 14708 to_trn_tbl[ecx++] = to_trn; 14709 14710 buf_last_oop = buf_oop->next = 14711 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14712 buf_oop = buf_oop->next; 14713 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14714 0, rte_pktmbuf_tailroom(buf_oop)); 14715 rte_pktmbuf_append(buf_oop, to_trn); 14716 14717 trn_data += to_trn; 14718 14719 if (trn_data == tdata->plaintext.len) { 14720 digest_mem = rte_pktmbuf_append(buf_oop, 14721 tdata->auth_tag.len); 14722 } 14723 } 14724 14725 ut_params->obuf->nb_segs = segs; 14726 } 14727 14728 /* 14729 * Place digest at the end of the last buffer 14730 */ 14731 if (!digest_phys) 14732 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14733 if (oop && buf_last_oop) 14734 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 14735 14736 if (!digest_mem && !oop) { 14737 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14738 + tdata->auth_tag.len); 14739 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14740 tdata->plaintext.len); 14741 } 14742 14743 /* Create AEAD operation */ 14744 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 14745 tdata, digest_mem, digest_phys); 14746 14747 if (retval < 0) 14748 return retval; 14749 14750 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14751 14752 ut_params->op->sym->m_src = ut_params->ibuf; 14753 if (oop) 14754 ut_params->op->sym->m_dst = ut_params->obuf; 14755 14756 /* Process crypto operation */ 14757 if (oop == IN_PLACE && 14758 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14759 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 14760 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14761 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14762 ut_params->op, 0, 0, 0, 0); 14763 else 14764 TEST_ASSERT_NOT_NULL( 14765 process_crypto_request(ts_params->valid_devs[0], 14766 ut_params->op), "failed to process sym crypto op"); 14767 14768 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14769 "crypto op processing failed"); 14770 14771 14772 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 14773 uint8_t *, prepend_len); 14774 if (oop) { 14775 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14776 uint8_t *, prepend_len); 14777 } 14778 14779 if (fragsz_oop) 14780 fragsz = fragsz_oop; 14781 14782 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14783 ciphertext, 14784 tdata->ciphertext.data, 14785 fragsz, 14786 "Ciphertext data not as expected"); 14787 14788 buf = ut_params->op->sym->m_src->next; 14789 if (oop) 14790 buf = ut_params->op->sym->m_dst->next; 14791 14792 unsigned int off = fragsz; 14793 14794 ecx = 0; 14795 while (buf) { 14796 ciphertext = rte_pktmbuf_mtod(buf, 14797 uint8_t *); 14798 14799 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14800 ciphertext, 14801 tdata->ciphertext.data + off, 14802 to_trn_tbl[ecx], 14803 "Ciphertext data not as expected"); 14804 14805 off += to_trn_tbl[ecx++]; 14806 buf = buf->next; 14807 } 14808 14809 auth_tag = digest_mem; 14810 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14811 auth_tag, 14812 tdata->auth_tag.data, 14813 tdata->auth_tag.len, 14814 "Generated auth tag not as expected"); 14815 14816 return 0; 14817 } 14818 14819 static int 14820 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 14821 { 14822 return test_authenticated_encryption_SGL( 14823 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 14824 } 14825 14826 static int 14827 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 14828 { 14829 return test_authenticated_encryption_SGL( 14830 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 14831 } 14832 14833 static int 14834 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 14835 { 14836 return test_authenticated_encryption_SGL( 14837 &gcm_test_case_8, OUT_OF_PLACE, 400, 14838 gcm_test_case_8.plaintext.len); 14839 } 14840 14841 static int 14842 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 14843 { 14844 /* This test is not for OPENSSL PMD */ 14845 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14846 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 14847 return TEST_SKIPPED; 14848 14849 return test_authenticated_encryption_SGL( 14850 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 14851 } 14852 14853 static int 14854 test_authentication_verify_fail_when_data_corrupted( 14855 struct crypto_testsuite_params *ts_params, 14856 struct crypto_unittest_params *ut_params, 14857 const struct test_crypto_vector *reference) 14858 { 14859 return test_authentication_verify_fail_when_data_corruption( 14860 ts_params, ut_params, reference, 1); 14861 } 14862 14863 static int 14864 test_authentication_verify_fail_when_tag_corrupted( 14865 struct crypto_testsuite_params *ts_params, 14866 struct crypto_unittest_params *ut_params, 14867 const struct test_crypto_vector *reference) 14868 { 14869 return test_authentication_verify_fail_when_data_corruption( 14870 ts_params, ut_params, reference, 0); 14871 } 14872 14873 static int 14874 test_authentication_verify_GMAC_fail_when_data_corrupted( 14875 struct crypto_testsuite_params *ts_params, 14876 struct crypto_unittest_params *ut_params, 14877 const struct test_crypto_vector *reference) 14878 { 14879 return test_authentication_verify_GMAC_fail_when_corruption( 14880 ts_params, ut_params, reference, 1); 14881 } 14882 14883 static int 14884 test_authentication_verify_GMAC_fail_when_tag_corrupted( 14885 struct crypto_testsuite_params *ts_params, 14886 struct crypto_unittest_params *ut_params, 14887 const struct test_crypto_vector *reference) 14888 { 14889 return test_authentication_verify_GMAC_fail_when_corruption( 14890 ts_params, ut_params, reference, 0); 14891 } 14892 14893 static int 14894 test_authenticated_decryption_fail_when_data_corrupted( 14895 struct crypto_testsuite_params *ts_params, 14896 struct crypto_unittest_params *ut_params, 14897 const struct test_crypto_vector *reference) 14898 { 14899 return test_authenticated_decryption_fail_when_corruption( 14900 ts_params, ut_params, reference, 1); 14901 } 14902 14903 static int 14904 test_authenticated_decryption_fail_when_tag_corrupted( 14905 struct crypto_testsuite_params *ts_params, 14906 struct crypto_unittest_params *ut_params, 14907 const struct test_crypto_vector *reference) 14908 { 14909 return test_authenticated_decryption_fail_when_corruption( 14910 ts_params, ut_params, reference, 0); 14911 } 14912 14913 static int 14914 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 14915 { 14916 return test_authentication_verify_fail_when_data_corrupted( 14917 &testsuite_params, &unittest_params, 14918 &hmac_sha1_test_crypto_vector); 14919 } 14920 14921 static int 14922 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14923 { 14924 return test_authentication_verify_fail_when_tag_corrupted( 14925 &testsuite_params, &unittest_params, 14926 &hmac_sha1_test_crypto_vector); 14927 } 14928 14929 static int 14930 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14931 { 14932 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14933 &testsuite_params, &unittest_params, 14934 &aes128_gmac_test_vector); 14935 } 14936 14937 static int 14938 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14939 { 14940 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14941 &testsuite_params, &unittest_params, 14942 &aes128_gmac_test_vector); 14943 } 14944 14945 static int 14946 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14947 { 14948 return test_authenticated_decryption_fail_when_data_corrupted( 14949 &testsuite_params, 14950 &unittest_params, 14951 &aes128cbc_hmac_sha1_test_vector); 14952 } 14953 14954 static int 14955 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14956 { 14957 return test_authenticated_decryption_fail_when_tag_corrupted( 14958 &testsuite_params, 14959 &unittest_params, 14960 &aes128cbc_hmac_sha1_test_vector); 14961 } 14962 14963 static int 14964 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14965 { 14966 return test_authenticated_encrypt_with_esn( 14967 &testsuite_params, 14968 &unittest_params, 14969 &aes128cbc_hmac_sha1_aad_test_vector); 14970 } 14971 14972 static int 14973 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14974 { 14975 return test_authenticated_decrypt_with_esn( 14976 &testsuite_params, 14977 &unittest_params, 14978 &aes128cbc_hmac_sha1_aad_test_vector); 14979 } 14980 14981 static int 14982 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14983 { 14984 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14985 } 14986 14987 static int 14988 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14989 { 14990 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14991 } 14992 14993 static int 14994 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14995 { 14996 return test_authenticated_encryption_SGL( 14997 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14998 chacha20_poly1305_case_2.plaintext.len); 14999 } 15000 15001 #ifdef RTE_CRYPTO_SCHEDULER 15002 15003 /* global AESNI worker IDs for the scheduler test */ 15004 uint8_t aesni_ids[2]; 15005 15006 static int 15007 scheduler_testsuite_setup(void) 15008 { 15009 uint32_t i = 0; 15010 int32_t nb_devs, ret; 15011 char vdev_args[VDEV_ARGS_SIZE] = {""}; 15012 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 15013 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 15014 uint16_t worker_core_count = 0; 15015 uint16_t socket_id = 0; 15016 15017 if (gbl_driver_id == rte_cryptodev_driver_id_get( 15018 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 15019 15020 /* Identify the Worker Cores 15021 * Use 2 worker cores for the device args 15022 */ 15023 RTE_LCORE_FOREACH_WORKER(i) { 15024 if (worker_core_count > 1) 15025 break; 15026 snprintf(vdev_args, sizeof(vdev_args), 15027 "%s%d", temp_str, i); 15028 strcpy(temp_str, vdev_args); 15029 strlcat(temp_str, ";", sizeof(temp_str)); 15030 worker_core_count++; 15031 socket_id = rte_lcore_to_socket_id(i); 15032 } 15033 if (worker_core_count != 2) { 15034 RTE_LOG(ERR, USER1, 15035 "Cryptodev scheduler test require at least " 15036 "two worker cores to run. " 15037 "Please use the correct coremask.\n"); 15038 return TEST_FAILED; 15039 } 15040 strcpy(temp_str, vdev_args); 15041 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 15042 temp_str, socket_id); 15043 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 15044 nb_devs = rte_cryptodev_device_count_by_driver( 15045 rte_cryptodev_driver_id_get( 15046 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 15047 if (nb_devs < 1) { 15048 ret = rte_vdev_init( 15049 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 15050 vdev_args); 15051 TEST_ASSERT(ret == 0, 15052 "Failed to create instance %u of pmd : %s", 15053 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15054 } 15055 } 15056 return testsuite_setup(); 15057 } 15058 15059 static int 15060 test_scheduler_attach_worker_op(void) 15061 { 15062 struct crypto_testsuite_params *ts_params = &testsuite_params; 15063 uint8_t sched_id = ts_params->valid_devs[0]; 15064 uint32_t i, nb_devs_attached = 0; 15065 int ret; 15066 char vdev_name[32]; 15067 unsigned int count = rte_cryptodev_count(); 15068 15069 /* create 2 AESNI_MB vdevs on top of existing devices */ 15070 for (i = count; i < count + 2; i++) { 15071 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 15072 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 15073 i); 15074 ret = rte_vdev_init(vdev_name, NULL); 15075 15076 TEST_ASSERT(ret == 0, 15077 "Failed to create instance %u of" 15078 " pmd : %s", 15079 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15080 15081 if (ret < 0) { 15082 RTE_LOG(ERR, USER1, 15083 "Failed to create 2 AESNI MB PMDs.\n"); 15084 return TEST_SKIPPED; 15085 } 15086 } 15087 15088 /* attach 2 AESNI_MB cdevs */ 15089 for (i = count; i < count + 2; i++) { 15090 struct rte_cryptodev_info info; 15091 unsigned int session_size; 15092 15093 rte_cryptodev_info_get(i, &info); 15094 if (info.driver_id != rte_cryptodev_driver_id_get( 15095 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 15096 continue; 15097 15098 session_size = rte_cryptodev_sym_get_private_session_size(i); 15099 /* 15100 * Create the session mempool again, since now there are new devices 15101 * to use the mempool. 15102 */ 15103 if (ts_params->session_mpool) { 15104 rte_mempool_free(ts_params->session_mpool); 15105 ts_params->session_mpool = NULL; 15106 } 15107 if (ts_params->session_priv_mpool) { 15108 rte_mempool_free(ts_params->session_priv_mpool); 15109 ts_params->session_priv_mpool = NULL; 15110 } 15111 15112 if (info.sym.max_nb_sessions != 0 && 15113 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 15114 RTE_LOG(ERR, USER1, 15115 "Device does not support " 15116 "at least %u sessions\n", 15117 MAX_NB_SESSIONS); 15118 return TEST_FAILED; 15119 } 15120 /* 15121 * Create mempool with maximum number of sessions, 15122 * to include the session headers 15123 */ 15124 if (ts_params->session_mpool == NULL) { 15125 ts_params->session_mpool = 15126 rte_cryptodev_sym_session_pool_create( 15127 "test_sess_mp", 15128 MAX_NB_SESSIONS, 0, 0, 0, 15129 SOCKET_ID_ANY); 15130 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 15131 "session mempool allocation failed"); 15132 } 15133 15134 /* 15135 * Create mempool with maximum number of sessions, 15136 * to include device specific session private data 15137 */ 15138 if (ts_params->session_priv_mpool == NULL) { 15139 ts_params->session_priv_mpool = rte_mempool_create( 15140 "test_sess_mp_priv", 15141 MAX_NB_SESSIONS, 15142 session_size, 15143 0, 0, NULL, NULL, NULL, 15144 NULL, SOCKET_ID_ANY, 15145 0); 15146 15147 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 15148 "session mempool allocation failed"); 15149 } 15150 15151 ts_params->qp_conf.mp_session = ts_params->session_mpool; 15152 ts_params->qp_conf.mp_session_private = 15153 ts_params->session_priv_mpool; 15154 15155 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 15156 (uint8_t)i); 15157 15158 TEST_ASSERT(ret == 0, 15159 "Failed to attach device %u of pmd : %s", i, 15160 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15161 15162 aesni_ids[nb_devs_attached] = (uint8_t)i; 15163 15164 nb_devs_attached++; 15165 } 15166 15167 return 0; 15168 } 15169 15170 static int 15171 test_scheduler_detach_worker_op(void) 15172 { 15173 struct crypto_testsuite_params *ts_params = &testsuite_params; 15174 uint8_t sched_id = ts_params->valid_devs[0]; 15175 uint32_t i; 15176 int ret; 15177 15178 for (i = 0; i < 2; i++) { 15179 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 15180 aesni_ids[i]); 15181 TEST_ASSERT(ret == 0, 15182 "Failed to detach device %u", aesni_ids[i]); 15183 } 15184 15185 return 0; 15186 } 15187 15188 static int 15189 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 15190 { 15191 struct crypto_testsuite_params *ts_params = &testsuite_params; 15192 uint8_t sched_id = ts_params->valid_devs[0]; 15193 /* set mode */ 15194 return rte_cryptodev_scheduler_mode_set(sched_id, 15195 scheduler_mode); 15196 } 15197 15198 static int 15199 test_scheduler_mode_roundrobin_op(void) 15200 { 15201 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 15202 0, "Failed to set roundrobin mode"); 15203 return 0; 15204 15205 } 15206 15207 static int 15208 test_scheduler_mode_multicore_op(void) 15209 { 15210 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 15211 0, "Failed to set multicore mode"); 15212 15213 return 0; 15214 } 15215 15216 static int 15217 test_scheduler_mode_failover_op(void) 15218 { 15219 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 15220 0, "Failed to set failover mode"); 15221 15222 return 0; 15223 } 15224 15225 static int 15226 test_scheduler_mode_pkt_size_distr_op(void) 15227 { 15228 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 15229 0, "Failed to set pktsize mode"); 15230 15231 return 0; 15232 } 15233 15234 static int 15235 scheduler_multicore_testsuite_setup(void) 15236 { 15237 if (test_scheduler_attach_worker_op() < 0) 15238 return TEST_SKIPPED; 15239 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 15240 return TEST_SKIPPED; 15241 return 0; 15242 } 15243 15244 static int 15245 scheduler_roundrobin_testsuite_setup(void) 15246 { 15247 if (test_scheduler_attach_worker_op() < 0) 15248 return TEST_SKIPPED; 15249 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 15250 return TEST_SKIPPED; 15251 return 0; 15252 } 15253 15254 static int 15255 scheduler_failover_testsuite_setup(void) 15256 { 15257 if (test_scheduler_attach_worker_op() < 0) 15258 return TEST_SKIPPED; 15259 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 15260 return TEST_SKIPPED; 15261 return 0; 15262 } 15263 15264 static int 15265 scheduler_pkt_size_distr_testsuite_setup(void) 15266 { 15267 if (test_scheduler_attach_worker_op() < 0) 15268 return TEST_SKIPPED; 15269 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 15270 return TEST_SKIPPED; 15271 return 0; 15272 } 15273 15274 static void 15275 scheduler_mode_testsuite_teardown(void) 15276 { 15277 test_scheduler_detach_worker_op(); 15278 } 15279 15280 #endif /* RTE_CRYPTO_SCHEDULER */ 15281 15282 static struct unit_test_suite end_testsuite = { 15283 .suite_name = NULL, 15284 .setup = NULL, 15285 .teardown = NULL, 15286 .unit_test_suites = NULL 15287 }; 15288 15289 #ifdef RTE_LIB_SECURITY 15290 static struct unit_test_suite ipsec_proto_testsuite = { 15291 .suite_name = "IPsec Proto Unit Test Suite", 15292 .setup = ipsec_proto_testsuite_setup, 15293 .unit_test_cases = { 15294 TEST_CASE_NAMED_WITH_DATA( 15295 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15296 ut_setup_security, ut_teardown, 15297 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 15298 TEST_CASE_NAMED_WITH_DATA( 15299 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15300 ut_setup_security, ut_teardown, 15301 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 15302 TEST_CASE_NAMED_WITH_DATA( 15303 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15304 ut_setup_security, ut_teardown, 15305 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 15306 TEST_CASE_NAMED_WITH_DATA( 15307 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 15308 ut_setup_security, ut_teardown, 15309 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 15310 TEST_CASE_NAMED_WITH_DATA( 15311 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15312 ut_setup_security, ut_teardown, 15313 test_ipsec_proto_known_vec, 15314 &pkt_aes_128_cbc_hmac_sha256), 15315 TEST_CASE_NAMED_WITH_DATA( 15316 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15317 ut_setup_security, ut_teardown, 15318 test_ipsec_proto_known_vec, 15319 &pkt_aes_128_cbc_hmac_sha384), 15320 TEST_CASE_NAMED_WITH_DATA( 15321 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15322 ut_setup_security, ut_teardown, 15323 test_ipsec_proto_known_vec, 15324 &pkt_aes_128_cbc_hmac_sha512), 15325 TEST_CASE_NAMED_WITH_DATA( 15326 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15327 ut_setup_security, ut_teardown, 15328 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 15329 TEST_CASE_NAMED_WITH_DATA( 15330 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15331 ut_setup_security, ut_teardown, 15332 test_ipsec_proto_known_vec, 15333 &pkt_aes_128_cbc_hmac_sha256_v6), 15334 TEST_CASE_NAMED_WITH_DATA( 15335 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15336 ut_setup_security, ut_teardown, 15337 test_ipsec_proto_known_vec, 15338 &pkt_null_aes_xcbc), 15339 TEST_CASE_NAMED_WITH_DATA( 15340 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15341 ut_setup_security, ut_teardown, 15342 test_ipsec_proto_known_vec, 15343 &pkt_ah_tunnel_sha256), 15344 TEST_CASE_NAMED_WITH_DATA( 15345 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15346 ut_setup_security, ut_teardown, 15347 test_ipsec_proto_known_vec, 15348 &pkt_ah_transport_sha256), 15349 TEST_CASE_NAMED_WITH_DATA( 15350 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15351 ut_setup_security, ut_teardown, 15352 test_ipsec_proto_known_vec, 15353 &pkt_ah_ipv4_aes_gmac_128), 15354 TEST_CASE_NAMED_WITH_DATA( 15355 "Outbound fragmented packet", 15356 ut_setup_security, ut_teardown, 15357 test_ipsec_proto_known_vec_fragmented, 15358 &pkt_aes_128_gcm_frag), 15359 TEST_CASE_NAMED_WITH_DATA( 15360 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15361 ut_setup_security, ut_teardown, 15362 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 15363 TEST_CASE_NAMED_WITH_DATA( 15364 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15365 ut_setup_security, ut_teardown, 15366 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 15367 TEST_CASE_NAMED_WITH_DATA( 15368 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15369 ut_setup_security, ut_teardown, 15370 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 15371 TEST_CASE_NAMED_WITH_DATA( 15372 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 15373 ut_setup_security, ut_teardown, 15374 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 15375 TEST_CASE_NAMED_WITH_DATA( 15376 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 15377 ut_setup_security, ut_teardown, 15378 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 15379 TEST_CASE_NAMED_WITH_DATA( 15380 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15381 ut_setup_security, ut_teardown, 15382 test_ipsec_proto_known_vec_inb, 15383 &pkt_aes_128_cbc_hmac_sha256), 15384 TEST_CASE_NAMED_WITH_DATA( 15385 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15386 ut_setup_security, ut_teardown, 15387 test_ipsec_proto_known_vec_inb, 15388 &pkt_aes_128_cbc_hmac_sha384), 15389 TEST_CASE_NAMED_WITH_DATA( 15390 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15391 ut_setup_security, ut_teardown, 15392 test_ipsec_proto_known_vec_inb, 15393 &pkt_aes_128_cbc_hmac_sha512), 15394 TEST_CASE_NAMED_WITH_DATA( 15395 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15396 ut_setup_security, ut_teardown, 15397 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 15398 TEST_CASE_NAMED_WITH_DATA( 15399 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15400 ut_setup_security, ut_teardown, 15401 test_ipsec_proto_known_vec_inb, 15402 &pkt_aes_128_cbc_hmac_sha256_v6), 15403 TEST_CASE_NAMED_WITH_DATA( 15404 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15405 ut_setup_security, ut_teardown, 15406 test_ipsec_proto_known_vec_inb, 15407 &pkt_null_aes_xcbc), 15408 TEST_CASE_NAMED_WITH_DATA( 15409 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15410 ut_setup_security, ut_teardown, 15411 test_ipsec_proto_known_vec_inb, 15412 &pkt_ah_tunnel_sha256), 15413 TEST_CASE_NAMED_WITH_DATA( 15414 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15415 ut_setup_security, ut_teardown, 15416 test_ipsec_proto_known_vec_inb, 15417 &pkt_ah_transport_sha256), 15418 TEST_CASE_NAMED_WITH_DATA( 15419 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15420 ut_setup_security, ut_teardown, 15421 test_ipsec_proto_known_vec_inb, 15422 &pkt_ah_ipv4_aes_gmac_128), 15423 TEST_CASE_NAMED_ST( 15424 "Combined test alg list", 15425 ut_setup_security, ut_teardown, 15426 test_ipsec_proto_display_list), 15427 TEST_CASE_NAMED_ST( 15428 "Combined test alg list (AH)", 15429 ut_setup_security, ut_teardown, 15430 test_ipsec_proto_ah_tunnel_ipv4), 15431 TEST_CASE_NAMED_ST( 15432 "IV generation", 15433 ut_setup_security, ut_teardown, 15434 test_ipsec_proto_iv_gen), 15435 TEST_CASE_NAMED_ST( 15436 "UDP encapsulation", 15437 ut_setup_security, ut_teardown, 15438 test_ipsec_proto_udp_encap), 15439 TEST_CASE_NAMED_ST( 15440 "UDP encapsulation ports verification test", 15441 ut_setup_security, ut_teardown, 15442 test_ipsec_proto_udp_ports_verify), 15443 TEST_CASE_NAMED_ST( 15444 "SA expiry packets soft", 15445 ut_setup_security, ut_teardown, 15446 test_ipsec_proto_sa_exp_pkts_soft), 15447 TEST_CASE_NAMED_ST( 15448 "SA expiry packets hard", 15449 ut_setup_security, ut_teardown, 15450 test_ipsec_proto_sa_exp_pkts_hard), 15451 TEST_CASE_NAMED_ST( 15452 "Negative test: ICV corruption", 15453 ut_setup_security, ut_teardown, 15454 test_ipsec_proto_err_icv_corrupt), 15455 TEST_CASE_NAMED_ST( 15456 "Tunnel dst addr verification", 15457 ut_setup_security, ut_teardown, 15458 test_ipsec_proto_tunnel_dst_addr_verify), 15459 TEST_CASE_NAMED_ST( 15460 "Tunnel src and dst addr verification", 15461 ut_setup_security, ut_teardown, 15462 test_ipsec_proto_tunnel_src_dst_addr_verify), 15463 TEST_CASE_NAMED_ST( 15464 "Inner IP checksum", 15465 ut_setup_security, ut_teardown, 15466 test_ipsec_proto_inner_ip_csum), 15467 TEST_CASE_NAMED_ST( 15468 "Inner L4 checksum", 15469 ut_setup_security, ut_teardown, 15470 test_ipsec_proto_inner_l4_csum), 15471 TEST_CASE_NAMED_ST( 15472 "Tunnel IPv4 in IPv4", 15473 ut_setup_security, ut_teardown, 15474 test_ipsec_proto_tunnel_v4_in_v4), 15475 TEST_CASE_NAMED_ST( 15476 "Tunnel IPv6 in IPv6", 15477 ut_setup_security, ut_teardown, 15478 test_ipsec_proto_tunnel_v6_in_v6), 15479 TEST_CASE_NAMED_ST( 15480 "Tunnel IPv4 in IPv6", 15481 ut_setup_security, ut_teardown, 15482 test_ipsec_proto_tunnel_v4_in_v6), 15483 TEST_CASE_NAMED_ST( 15484 "Tunnel IPv6 in IPv4", 15485 ut_setup_security, ut_teardown, 15486 test_ipsec_proto_tunnel_v6_in_v4), 15487 TEST_CASE_NAMED_ST( 15488 "Transport IPv4", 15489 ut_setup_security, ut_teardown, 15490 test_ipsec_proto_transport_v4), 15491 TEST_CASE_NAMED_ST( 15492 "AH transport IPv4", 15493 ut_setup_security, ut_teardown, 15494 test_ipsec_proto_ah_transport_ipv4), 15495 TEST_CASE_NAMED_ST( 15496 "Transport l4 checksum", 15497 ut_setup_security, ut_teardown, 15498 test_ipsec_proto_transport_l4_csum), 15499 TEST_CASE_NAMED_ST( 15500 "Statistics: success", 15501 ut_setup_security, ut_teardown, 15502 test_ipsec_proto_stats), 15503 TEST_CASE_NAMED_ST( 15504 "Fragmented packet", 15505 ut_setup_security, ut_teardown, 15506 test_ipsec_proto_pkt_fragment), 15507 TEST_CASE_NAMED_ST( 15508 "Tunnel header copy DF (inner 0)", 15509 ut_setup_security, ut_teardown, 15510 test_ipsec_proto_copy_df_inner_0), 15511 TEST_CASE_NAMED_ST( 15512 "Tunnel header copy DF (inner 1)", 15513 ut_setup_security, ut_teardown, 15514 test_ipsec_proto_copy_df_inner_1), 15515 TEST_CASE_NAMED_ST( 15516 "Tunnel header set DF 0 (inner 1)", 15517 ut_setup_security, ut_teardown, 15518 test_ipsec_proto_set_df_0_inner_1), 15519 TEST_CASE_NAMED_ST( 15520 "Tunnel header set DF 1 (inner 0)", 15521 ut_setup_security, ut_teardown, 15522 test_ipsec_proto_set_df_1_inner_0), 15523 TEST_CASE_NAMED_ST( 15524 "Tunnel header IPv4 copy DSCP (inner 0)", 15525 ut_setup_security, ut_teardown, 15526 test_ipsec_proto_ipv4_copy_dscp_inner_0), 15527 TEST_CASE_NAMED_ST( 15528 "Tunnel header IPv4 copy DSCP (inner 1)", 15529 ut_setup_security, ut_teardown, 15530 test_ipsec_proto_ipv4_copy_dscp_inner_1), 15531 TEST_CASE_NAMED_ST( 15532 "Tunnel header IPv4 set DSCP 0 (inner 1)", 15533 ut_setup_security, ut_teardown, 15534 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 15535 TEST_CASE_NAMED_ST( 15536 "Tunnel header IPv4 set DSCP 1 (inner 0)", 15537 ut_setup_security, ut_teardown, 15538 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 15539 TEST_CASE_NAMED_ST( 15540 "Tunnel header IPv6 copy DSCP (inner 0)", 15541 ut_setup_security, ut_teardown, 15542 test_ipsec_proto_ipv6_copy_dscp_inner_0), 15543 TEST_CASE_NAMED_ST( 15544 "Tunnel header IPv6 copy DSCP (inner 1)", 15545 ut_setup_security, ut_teardown, 15546 test_ipsec_proto_ipv6_copy_dscp_inner_1), 15547 TEST_CASE_NAMED_ST( 15548 "Tunnel header IPv6 set DSCP 0 (inner 1)", 15549 ut_setup_security, ut_teardown, 15550 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 15551 TEST_CASE_NAMED_ST( 15552 "Tunnel header IPv6 set DSCP 1 (inner 0)", 15553 ut_setup_security, ut_teardown, 15554 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 15555 TEST_CASE_NAMED_WITH_DATA( 15556 "Antireplay with window size 1024", 15557 ut_setup_security, ut_teardown, 15558 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 15559 TEST_CASE_NAMED_WITH_DATA( 15560 "Antireplay with window size 2048", 15561 ut_setup_security, ut_teardown, 15562 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 15563 TEST_CASE_NAMED_WITH_DATA( 15564 "Antireplay with window size 4096", 15565 ut_setup_security, ut_teardown, 15566 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 15567 TEST_CASE_NAMED_WITH_DATA( 15568 "ESN and Antireplay with window size 1024", 15569 ut_setup_security, ut_teardown, 15570 test_ipsec_proto_pkt_esn_antireplay1024, 15571 &pkt_aes_128_gcm), 15572 TEST_CASE_NAMED_WITH_DATA( 15573 "ESN and Antireplay with window size 2048", 15574 ut_setup_security, ut_teardown, 15575 test_ipsec_proto_pkt_esn_antireplay2048, 15576 &pkt_aes_128_gcm), 15577 TEST_CASE_NAMED_WITH_DATA( 15578 "ESN and Antireplay with window size 4096", 15579 ut_setup_security, ut_teardown, 15580 test_ipsec_proto_pkt_esn_antireplay4096, 15581 &pkt_aes_128_gcm), 15582 TEST_CASE_NAMED_ST( 15583 "Tunnel header IPv4 decrement inner TTL", 15584 ut_setup_security, ut_teardown, 15585 test_ipsec_proto_ipv4_ttl_decrement), 15586 TEST_CASE_NAMED_ST( 15587 "Tunnel header IPv6 decrement inner hop limit", 15588 ut_setup_security, ut_teardown, 15589 test_ipsec_proto_ipv6_hop_limit_decrement), 15590 TEST_CASES_END() /**< NULL terminate unit test array */ 15591 } 15592 }; 15593 15594 static struct unit_test_suite pdcp_proto_testsuite = { 15595 .suite_name = "PDCP Proto Unit Test Suite", 15596 .setup = pdcp_proto_testsuite_setup, 15597 .unit_test_cases = { 15598 TEST_CASE_ST(ut_setup_security, ut_teardown, 15599 test_PDCP_PROTO_all), 15600 TEST_CASES_END() /**< NULL terminate unit test array */ 15601 } 15602 }; 15603 15604 #define ADD_UPLINK_TESTCASE(data) \ 15605 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 15606 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 15607 15608 #define ADD_DOWNLINK_TESTCASE(data) \ 15609 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 15610 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 15611 15612 static struct unit_test_suite docsis_proto_testsuite = { 15613 .suite_name = "DOCSIS Proto Unit Test Suite", 15614 .setup = docsis_proto_testsuite_setup, 15615 .unit_test_cases = { 15616 /* Uplink */ 15617 ADD_UPLINK_TESTCASE(docsis_test_case_1) 15618 ADD_UPLINK_TESTCASE(docsis_test_case_2) 15619 ADD_UPLINK_TESTCASE(docsis_test_case_3) 15620 ADD_UPLINK_TESTCASE(docsis_test_case_4) 15621 ADD_UPLINK_TESTCASE(docsis_test_case_5) 15622 ADD_UPLINK_TESTCASE(docsis_test_case_6) 15623 ADD_UPLINK_TESTCASE(docsis_test_case_7) 15624 ADD_UPLINK_TESTCASE(docsis_test_case_8) 15625 ADD_UPLINK_TESTCASE(docsis_test_case_9) 15626 ADD_UPLINK_TESTCASE(docsis_test_case_10) 15627 ADD_UPLINK_TESTCASE(docsis_test_case_11) 15628 ADD_UPLINK_TESTCASE(docsis_test_case_12) 15629 ADD_UPLINK_TESTCASE(docsis_test_case_13) 15630 ADD_UPLINK_TESTCASE(docsis_test_case_14) 15631 ADD_UPLINK_TESTCASE(docsis_test_case_15) 15632 ADD_UPLINK_TESTCASE(docsis_test_case_16) 15633 ADD_UPLINK_TESTCASE(docsis_test_case_17) 15634 ADD_UPLINK_TESTCASE(docsis_test_case_18) 15635 ADD_UPLINK_TESTCASE(docsis_test_case_19) 15636 ADD_UPLINK_TESTCASE(docsis_test_case_20) 15637 ADD_UPLINK_TESTCASE(docsis_test_case_21) 15638 ADD_UPLINK_TESTCASE(docsis_test_case_22) 15639 ADD_UPLINK_TESTCASE(docsis_test_case_23) 15640 ADD_UPLINK_TESTCASE(docsis_test_case_24) 15641 ADD_UPLINK_TESTCASE(docsis_test_case_25) 15642 ADD_UPLINK_TESTCASE(docsis_test_case_26) 15643 /* Downlink */ 15644 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 15645 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 15646 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 15647 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 15648 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 15649 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 15650 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 15651 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 15652 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 15653 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 15654 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 15655 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 15656 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 15657 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 15658 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 15659 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 15660 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 15661 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 15662 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 15663 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 15664 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 15665 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 15666 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 15667 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 15668 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 15669 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 15670 TEST_CASES_END() /**< NULL terminate unit test array */ 15671 } 15672 }; 15673 #endif 15674 15675 static struct unit_test_suite cryptodev_gen_testsuite = { 15676 .suite_name = "Crypto General Unit Test Suite", 15677 .setup = crypto_gen_testsuite_setup, 15678 .unit_test_cases = { 15679 TEST_CASE_ST(ut_setup, ut_teardown, 15680 test_device_configure_invalid_dev_id), 15681 TEST_CASE_ST(ut_setup, ut_teardown, 15682 test_queue_pair_descriptor_setup), 15683 TEST_CASE_ST(ut_setup, ut_teardown, 15684 test_device_configure_invalid_queue_pair_ids), 15685 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 15686 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 15687 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 15688 TEST_CASES_END() /**< NULL terminate unit test array */ 15689 } 15690 }; 15691 15692 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 15693 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 15694 .setup = negative_hmac_sha1_testsuite_setup, 15695 .unit_test_cases = { 15696 /** Negative tests */ 15697 TEST_CASE_ST(ut_setup, ut_teardown, 15698 authentication_verify_HMAC_SHA1_fail_data_corrupt), 15699 TEST_CASE_ST(ut_setup, ut_teardown, 15700 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 15701 TEST_CASE_ST(ut_setup, ut_teardown, 15702 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 15703 TEST_CASE_ST(ut_setup, ut_teardown, 15704 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 15705 15706 TEST_CASES_END() /**< NULL terminate unit test array */ 15707 } 15708 }; 15709 15710 static struct unit_test_suite cryptodev_multi_session_testsuite = { 15711 .suite_name = "Multi Session Unit Test Suite", 15712 .setup = multi_session_testsuite_setup, 15713 .unit_test_cases = { 15714 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 15715 TEST_CASE_ST(ut_setup, ut_teardown, 15716 test_multi_session_random_usage), 15717 15718 TEST_CASES_END() /**< NULL terminate unit test array */ 15719 } 15720 }; 15721 15722 static struct unit_test_suite cryptodev_null_testsuite = { 15723 .suite_name = "NULL Test Suite", 15724 .setup = null_testsuite_setup, 15725 .unit_test_cases = { 15726 TEST_CASE_ST(ut_setup, ut_teardown, 15727 test_null_invalid_operation), 15728 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 15729 TEST_CASES_END() 15730 } 15731 }; 15732 15733 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 15734 .suite_name = "AES CCM Authenticated Test Suite", 15735 .setup = aes_ccm_auth_testsuite_setup, 15736 .unit_test_cases = { 15737 /** AES CCM Authenticated Encryption 128 bits key*/ 15738 TEST_CASE_ST(ut_setup, ut_teardown, 15739 test_AES_CCM_authenticated_encryption_test_case_128_1), 15740 TEST_CASE_ST(ut_setup, ut_teardown, 15741 test_AES_CCM_authenticated_encryption_test_case_128_2), 15742 TEST_CASE_ST(ut_setup, ut_teardown, 15743 test_AES_CCM_authenticated_encryption_test_case_128_3), 15744 15745 /** AES CCM Authenticated Decryption 128 bits key*/ 15746 TEST_CASE_ST(ut_setup, ut_teardown, 15747 test_AES_CCM_authenticated_decryption_test_case_128_1), 15748 TEST_CASE_ST(ut_setup, ut_teardown, 15749 test_AES_CCM_authenticated_decryption_test_case_128_2), 15750 TEST_CASE_ST(ut_setup, ut_teardown, 15751 test_AES_CCM_authenticated_decryption_test_case_128_3), 15752 15753 /** AES CCM Authenticated Encryption 192 bits key */ 15754 TEST_CASE_ST(ut_setup, ut_teardown, 15755 test_AES_CCM_authenticated_encryption_test_case_192_1), 15756 TEST_CASE_ST(ut_setup, ut_teardown, 15757 test_AES_CCM_authenticated_encryption_test_case_192_2), 15758 TEST_CASE_ST(ut_setup, ut_teardown, 15759 test_AES_CCM_authenticated_encryption_test_case_192_3), 15760 15761 /** AES CCM Authenticated Decryption 192 bits key*/ 15762 TEST_CASE_ST(ut_setup, ut_teardown, 15763 test_AES_CCM_authenticated_decryption_test_case_192_1), 15764 TEST_CASE_ST(ut_setup, ut_teardown, 15765 test_AES_CCM_authenticated_decryption_test_case_192_2), 15766 TEST_CASE_ST(ut_setup, ut_teardown, 15767 test_AES_CCM_authenticated_decryption_test_case_192_3), 15768 15769 /** AES CCM Authenticated Encryption 256 bits key */ 15770 TEST_CASE_ST(ut_setup, ut_teardown, 15771 test_AES_CCM_authenticated_encryption_test_case_256_1), 15772 TEST_CASE_ST(ut_setup, ut_teardown, 15773 test_AES_CCM_authenticated_encryption_test_case_256_2), 15774 TEST_CASE_ST(ut_setup, ut_teardown, 15775 test_AES_CCM_authenticated_encryption_test_case_256_3), 15776 15777 /** AES CCM Authenticated Decryption 256 bits key*/ 15778 TEST_CASE_ST(ut_setup, ut_teardown, 15779 test_AES_CCM_authenticated_decryption_test_case_256_1), 15780 TEST_CASE_ST(ut_setup, ut_teardown, 15781 test_AES_CCM_authenticated_decryption_test_case_256_2), 15782 TEST_CASE_ST(ut_setup, ut_teardown, 15783 test_AES_CCM_authenticated_decryption_test_case_256_3), 15784 TEST_CASES_END() 15785 } 15786 }; 15787 15788 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 15789 .suite_name = "AES GCM Authenticated Test Suite", 15790 .setup = aes_gcm_auth_testsuite_setup, 15791 .unit_test_cases = { 15792 /** AES GCM Authenticated Encryption */ 15793 TEST_CASE_ST(ut_setup, ut_teardown, 15794 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 15795 TEST_CASE_ST(ut_setup, ut_teardown, 15796 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 15797 TEST_CASE_ST(ut_setup, ut_teardown, 15798 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 15799 TEST_CASE_ST(ut_setup, ut_teardown, 15800 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 15801 TEST_CASE_ST(ut_setup, ut_teardown, 15802 test_AES_GCM_authenticated_encryption_test_case_1), 15803 TEST_CASE_ST(ut_setup, ut_teardown, 15804 test_AES_GCM_authenticated_encryption_test_case_2), 15805 TEST_CASE_ST(ut_setup, ut_teardown, 15806 test_AES_GCM_authenticated_encryption_test_case_3), 15807 TEST_CASE_ST(ut_setup, ut_teardown, 15808 test_AES_GCM_authenticated_encryption_test_case_4), 15809 TEST_CASE_ST(ut_setup, ut_teardown, 15810 test_AES_GCM_authenticated_encryption_test_case_5), 15811 TEST_CASE_ST(ut_setup, ut_teardown, 15812 test_AES_GCM_authenticated_encryption_test_case_6), 15813 TEST_CASE_ST(ut_setup, ut_teardown, 15814 test_AES_GCM_authenticated_encryption_test_case_7), 15815 TEST_CASE_ST(ut_setup, ut_teardown, 15816 test_AES_GCM_authenticated_encryption_test_case_8), 15817 TEST_CASE_ST(ut_setup, ut_teardown, 15818 test_AES_GCM_J0_authenticated_encryption_test_case_1), 15819 15820 /** AES GCM Authenticated Decryption */ 15821 TEST_CASE_ST(ut_setup, ut_teardown, 15822 test_AES_GCM_authenticated_decryption_test_case_1), 15823 TEST_CASE_ST(ut_setup, ut_teardown, 15824 test_AES_GCM_authenticated_decryption_test_case_2), 15825 TEST_CASE_ST(ut_setup, ut_teardown, 15826 test_AES_GCM_authenticated_decryption_test_case_3), 15827 TEST_CASE_ST(ut_setup, ut_teardown, 15828 test_AES_GCM_authenticated_decryption_test_case_4), 15829 TEST_CASE_ST(ut_setup, ut_teardown, 15830 test_AES_GCM_authenticated_decryption_test_case_5), 15831 TEST_CASE_ST(ut_setup, ut_teardown, 15832 test_AES_GCM_authenticated_decryption_test_case_6), 15833 TEST_CASE_ST(ut_setup, ut_teardown, 15834 test_AES_GCM_authenticated_decryption_test_case_7), 15835 TEST_CASE_ST(ut_setup, ut_teardown, 15836 test_AES_GCM_authenticated_decryption_test_case_8), 15837 TEST_CASE_ST(ut_setup, ut_teardown, 15838 test_AES_GCM_J0_authenticated_decryption_test_case_1), 15839 15840 /** AES GCM Authenticated Encryption 192 bits key */ 15841 TEST_CASE_ST(ut_setup, ut_teardown, 15842 test_AES_GCM_auth_encryption_test_case_192_1), 15843 TEST_CASE_ST(ut_setup, ut_teardown, 15844 test_AES_GCM_auth_encryption_test_case_192_2), 15845 TEST_CASE_ST(ut_setup, ut_teardown, 15846 test_AES_GCM_auth_encryption_test_case_192_3), 15847 TEST_CASE_ST(ut_setup, ut_teardown, 15848 test_AES_GCM_auth_encryption_test_case_192_4), 15849 TEST_CASE_ST(ut_setup, ut_teardown, 15850 test_AES_GCM_auth_encryption_test_case_192_5), 15851 TEST_CASE_ST(ut_setup, ut_teardown, 15852 test_AES_GCM_auth_encryption_test_case_192_6), 15853 TEST_CASE_ST(ut_setup, ut_teardown, 15854 test_AES_GCM_auth_encryption_test_case_192_7), 15855 15856 /** AES GCM Authenticated Decryption 192 bits key */ 15857 TEST_CASE_ST(ut_setup, ut_teardown, 15858 test_AES_GCM_auth_decryption_test_case_192_1), 15859 TEST_CASE_ST(ut_setup, ut_teardown, 15860 test_AES_GCM_auth_decryption_test_case_192_2), 15861 TEST_CASE_ST(ut_setup, ut_teardown, 15862 test_AES_GCM_auth_decryption_test_case_192_3), 15863 TEST_CASE_ST(ut_setup, ut_teardown, 15864 test_AES_GCM_auth_decryption_test_case_192_4), 15865 TEST_CASE_ST(ut_setup, ut_teardown, 15866 test_AES_GCM_auth_decryption_test_case_192_5), 15867 TEST_CASE_ST(ut_setup, ut_teardown, 15868 test_AES_GCM_auth_decryption_test_case_192_6), 15869 TEST_CASE_ST(ut_setup, ut_teardown, 15870 test_AES_GCM_auth_decryption_test_case_192_7), 15871 15872 /** AES GCM Authenticated Encryption 256 bits key */ 15873 TEST_CASE_ST(ut_setup, ut_teardown, 15874 test_AES_GCM_auth_encryption_test_case_256_1), 15875 TEST_CASE_ST(ut_setup, ut_teardown, 15876 test_AES_GCM_auth_encryption_test_case_256_2), 15877 TEST_CASE_ST(ut_setup, ut_teardown, 15878 test_AES_GCM_auth_encryption_test_case_256_3), 15879 TEST_CASE_ST(ut_setup, ut_teardown, 15880 test_AES_GCM_auth_encryption_test_case_256_4), 15881 TEST_CASE_ST(ut_setup, ut_teardown, 15882 test_AES_GCM_auth_encryption_test_case_256_5), 15883 TEST_CASE_ST(ut_setup, ut_teardown, 15884 test_AES_GCM_auth_encryption_test_case_256_6), 15885 TEST_CASE_ST(ut_setup, ut_teardown, 15886 test_AES_GCM_auth_encryption_test_case_256_7), 15887 15888 /** AES GCM Authenticated Decryption 256 bits key */ 15889 TEST_CASE_ST(ut_setup, ut_teardown, 15890 test_AES_GCM_auth_decryption_test_case_256_1), 15891 TEST_CASE_ST(ut_setup, ut_teardown, 15892 test_AES_GCM_auth_decryption_test_case_256_2), 15893 TEST_CASE_ST(ut_setup, ut_teardown, 15894 test_AES_GCM_auth_decryption_test_case_256_3), 15895 TEST_CASE_ST(ut_setup, ut_teardown, 15896 test_AES_GCM_auth_decryption_test_case_256_4), 15897 TEST_CASE_ST(ut_setup, ut_teardown, 15898 test_AES_GCM_auth_decryption_test_case_256_5), 15899 TEST_CASE_ST(ut_setup, ut_teardown, 15900 test_AES_GCM_auth_decryption_test_case_256_6), 15901 TEST_CASE_ST(ut_setup, ut_teardown, 15902 test_AES_GCM_auth_decryption_test_case_256_7), 15903 15904 /** AES GCM Authenticated Encryption big aad size */ 15905 TEST_CASE_ST(ut_setup, ut_teardown, 15906 test_AES_GCM_auth_encryption_test_case_aad_1), 15907 TEST_CASE_ST(ut_setup, ut_teardown, 15908 test_AES_GCM_auth_encryption_test_case_aad_2), 15909 15910 /** AES GCM Authenticated Decryption big aad size */ 15911 TEST_CASE_ST(ut_setup, ut_teardown, 15912 test_AES_GCM_auth_decryption_test_case_aad_1), 15913 TEST_CASE_ST(ut_setup, ut_teardown, 15914 test_AES_GCM_auth_decryption_test_case_aad_2), 15915 15916 /** Out of place tests */ 15917 TEST_CASE_ST(ut_setup, ut_teardown, 15918 test_AES_GCM_authenticated_encryption_oop_test_case_1), 15919 TEST_CASE_ST(ut_setup, ut_teardown, 15920 test_AES_GCM_authenticated_decryption_oop_test_case_1), 15921 15922 /** Session-less tests */ 15923 TEST_CASE_ST(ut_setup, ut_teardown, 15924 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 15925 TEST_CASE_ST(ut_setup, ut_teardown, 15926 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 15927 15928 TEST_CASES_END() 15929 } 15930 }; 15931 15932 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 15933 .suite_name = "AES GMAC Authentication Test Suite", 15934 .setup = aes_gmac_auth_testsuite_setup, 15935 .unit_test_cases = { 15936 TEST_CASE_ST(ut_setup, ut_teardown, 15937 test_AES_GMAC_authentication_test_case_1), 15938 TEST_CASE_ST(ut_setup, ut_teardown, 15939 test_AES_GMAC_authentication_verify_test_case_1), 15940 TEST_CASE_ST(ut_setup, ut_teardown, 15941 test_AES_GMAC_authentication_test_case_2), 15942 TEST_CASE_ST(ut_setup, ut_teardown, 15943 test_AES_GMAC_authentication_verify_test_case_2), 15944 TEST_CASE_ST(ut_setup, ut_teardown, 15945 test_AES_GMAC_authentication_test_case_3), 15946 TEST_CASE_ST(ut_setup, ut_teardown, 15947 test_AES_GMAC_authentication_verify_test_case_3), 15948 TEST_CASE_ST(ut_setup, ut_teardown, 15949 test_AES_GMAC_authentication_test_case_4), 15950 TEST_CASE_ST(ut_setup, ut_teardown, 15951 test_AES_GMAC_authentication_verify_test_case_4), 15952 TEST_CASE_ST(ut_setup, ut_teardown, 15953 test_AES_GMAC_authentication_SGL_40B), 15954 TEST_CASE_ST(ut_setup, ut_teardown, 15955 test_AES_GMAC_authentication_SGL_80B), 15956 TEST_CASE_ST(ut_setup, ut_teardown, 15957 test_AES_GMAC_authentication_SGL_2048B), 15958 TEST_CASE_ST(ut_setup, ut_teardown, 15959 test_AES_GMAC_authentication_SGL_2047B), 15960 15961 TEST_CASES_END() 15962 } 15963 }; 15964 15965 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 15966 .suite_name = "Chacha20-Poly1305 Test Suite", 15967 .setup = chacha20_poly1305_testsuite_setup, 15968 .unit_test_cases = { 15969 TEST_CASE_ST(ut_setup, ut_teardown, 15970 test_chacha20_poly1305_encrypt_test_case_rfc8439), 15971 TEST_CASE_ST(ut_setup, ut_teardown, 15972 test_chacha20_poly1305_decrypt_test_case_rfc8439), 15973 TEST_CASE_ST(ut_setup, ut_teardown, 15974 test_chacha20_poly1305_encrypt_SGL_out_of_place), 15975 TEST_CASES_END() 15976 } 15977 }; 15978 15979 static struct unit_test_suite cryptodev_snow3g_testsuite = { 15980 .suite_name = "SNOW 3G Test Suite", 15981 .setup = snow3g_testsuite_setup, 15982 .unit_test_cases = { 15983 /** SNOW 3G encrypt only (UEA2) */ 15984 TEST_CASE_ST(ut_setup, ut_teardown, 15985 test_snow3g_encryption_test_case_1), 15986 TEST_CASE_ST(ut_setup, ut_teardown, 15987 test_snow3g_encryption_test_case_2), 15988 TEST_CASE_ST(ut_setup, ut_teardown, 15989 test_snow3g_encryption_test_case_3), 15990 TEST_CASE_ST(ut_setup, ut_teardown, 15991 test_snow3g_encryption_test_case_4), 15992 TEST_CASE_ST(ut_setup, ut_teardown, 15993 test_snow3g_encryption_test_case_5), 15994 15995 TEST_CASE_ST(ut_setup, ut_teardown, 15996 test_snow3g_encryption_test_case_1_oop), 15997 TEST_CASE_ST(ut_setup, ut_teardown, 15998 test_snow3g_encryption_test_case_1_oop_sgl), 15999 TEST_CASE_ST(ut_setup, ut_teardown, 16000 test_snow3g_encryption_test_case_1_offset_oop), 16001 TEST_CASE_ST(ut_setup, ut_teardown, 16002 test_snow3g_decryption_test_case_1_oop), 16003 16004 /** SNOW 3G generate auth, then encrypt (UEA2) */ 16005 TEST_CASE_ST(ut_setup, ut_teardown, 16006 test_snow3g_auth_cipher_test_case_1), 16007 TEST_CASE_ST(ut_setup, ut_teardown, 16008 test_snow3g_auth_cipher_test_case_2), 16009 TEST_CASE_ST(ut_setup, ut_teardown, 16010 test_snow3g_auth_cipher_test_case_2_oop), 16011 TEST_CASE_ST(ut_setup, ut_teardown, 16012 test_snow3g_auth_cipher_part_digest_enc), 16013 TEST_CASE_ST(ut_setup, ut_teardown, 16014 test_snow3g_auth_cipher_part_digest_enc_oop), 16015 TEST_CASE_ST(ut_setup, ut_teardown, 16016 test_snow3g_auth_cipher_test_case_3_sgl), 16017 TEST_CASE_ST(ut_setup, ut_teardown, 16018 test_snow3g_auth_cipher_test_case_3_oop_sgl), 16019 TEST_CASE_ST(ut_setup, ut_teardown, 16020 test_snow3g_auth_cipher_part_digest_enc_sgl), 16021 TEST_CASE_ST(ut_setup, ut_teardown, 16022 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 16023 TEST_CASE_ST(ut_setup, ut_teardown, 16024 test_snow3g_auth_cipher_total_digest_enc_1), 16025 TEST_CASE_ST(ut_setup, ut_teardown, 16026 test_snow3g_auth_cipher_total_digest_enc_1_oop), 16027 TEST_CASE_ST(ut_setup, ut_teardown, 16028 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 16029 TEST_CASE_ST(ut_setup, ut_teardown, 16030 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 16031 16032 /** SNOW 3G decrypt (UEA2), then verify auth */ 16033 TEST_CASE_ST(ut_setup, ut_teardown, 16034 test_snow3g_auth_cipher_verify_test_case_1), 16035 TEST_CASE_ST(ut_setup, ut_teardown, 16036 test_snow3g_auth_cipher_verify_test_case_2), 16037 TEST_CASE_ST(ut_setup, ut_teardown, 16038 test_snow3g_auth_cipher_verify_test_case_2_oop), 16039 TEST_CASE_ST(ut_setup, ut_teardown, 16040 test_snow3g_auth_cipher_verify_part_digest_enc), 16041 TEST_CASE_ST(ut_setup, ut_teardown, 16042 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 16043 TEST_CASE_ST(ut_setup, ut_teardown, 16044 test_snow3g_auth_cipher_verify_test_case_3_sgl), 16045 TEST_CASE_ST(ut_setup, ut_teardown, 16046 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 16047 TEST_CASE_ST(ut_setup, ut_teardown, 16048 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 16049 TEST_CASE_ST(ut_setup, ut_teardown, 16050 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 16051 TEST_CASE_ST(ut_setup, ut_teardown, 16052 test_snow3g_auth_cipher_verify_total_digest_enc_1), 16053 TEST_CASE_ST(ut_setup, ut_teardown, 16054 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 16055 TEST_CASE_ST(ut_setup, ut_teardown, 16056 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 16057 TEST_CASE_ST(ut_setup, ut_teardown, 16058 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 16059 16060 /** SNOW 3G decrypt only (UEA2) */ 16061 TEST_CASE_ST(ut_setup, ut_teardown, 16062 test_snow3g_decryption_test_case_1), 16063 TEST_CASE_ST(ut_setup, ut_teardown, 16064 test_snow3g_decryption_test_case_2), 16065 TEST_CASE_ST(ut_setup, ut_teardown, 16066 test_snow3g_decryption_test_case_3), 16067 TEST_CASE_ST(ut_setup, ut_teardown, 16068 test_snow3g_decryption_test_case_4), 16069 TEST_CASE_ST(ut_setup, ut_teardown, 16070 test_snow3g_decryption_test_case_5), 16071 TEST_CASE_ST(ut_setup, ut_teardown, 16072 test_snow3g_decryption_with_digest_test_case_1), 16073 TEST_CASE_ST(ut_setup, ut_teardown, 16074 test_snow3g_hash_generate_test_case_1), 16075 TEST_CASE_ST(ut_setup, ut_teardown, 16076 test_snow3g_hash_generate_test_case_2), 16077 TEST_CASE_ST(ut_setup, ut_teardown, 16078 test_snow3g_hash_generate_test_case_3), 16079 16080 /* Tests with buffers which length is not byte-aligned */ 16081 TEST_CASE_ST(ut_setup, ut_teardown, 16082 test_snow3g_hash_generate_test_case_4), 16083 TEST_CASE_ST(ut_setup, ut_teardown, 16084 test_snow3g_hash_generate_test_case_5), 16085 TEST_CASE_ST(ut_setup, ut_teardown, 16086 test_snow3g_hash_generate_test_case_6), 16087 TEST_CASE_ST(ut_setup, ut_teardown, 16088 test_snow3g_hash_verify_test_case_1), 16089 TEST_CASE_ST(ut_setup, ut_teardown, 16090 test_snow3g_hash_verify_test_case_2), 16091 TEST_CASE_ST(ut_setup, ut_teardown, 16092 test_snow3g_hash_verify_test_case_3), 16093 16094 /* Tests with buffers which length is not byte-aligned */ 16095 TEST_CASE_ST(ut_setup, ut_teardown, 16096 test_snow3g_hash_verify_test_case_4), 16097 TEST_CASE_ST(ut_setup, ut_teardown, 16098 test_snow3g_hash_verify_test_case_5), 16099 TEST_CASE_ST(ut_setup, ut_teardown, 16100 test_snow3g_hash_verify_test_case_6), 16101 TEST_CASE_ST(ut_setup, ut_teardown, 16102 test_snow3g_cipher_auth_test_case_1), 16103 TEST_CASE_ST(ut_setup, ut_teardown, 16104 test_snow3g_auth_cipher_with_digest_test_case_1), 16105 TEST_CASES_END() 16106 } 16107 }; 16108 16109 static struct unit_test_suite cryptodev_zuc_testsuite = { 16110 .suite_name = "ZUC Test Suite", 16111 .setup = zuc_testsuite_setup, 16112 .unit_test_cases = { 16113 /** ZUC encrypt only (EEA3) */ 16114 TEST_CASE_ST(ut_setup, ut_teardown, 16115 test_zuc_encryption_test_case_1), 16116 TEST_CASE_ST(ut_setup, ut_teardown, 16117 test_zuc_encryption_test_case_2), 16118 TEST_CASE_ST(ut_setup, ut_teardown, 16119 test_zuc_encryption_test_case_3), 16120 TEST_CASE_ST(ut_setup, ut_teardown, 16121 test_zuc_encryption_test_case_4), 16122 TEST_CASE_ST(ut_setup, ut_teardown, 16123 test_zuc_encryption_test_case_5), 16124 TEST_CASE_ST(ut_setup, ut_teardown, 16125 test_zuc_encryption_test_case_6_sgl), 16126 16127 /** ZUC authenticate (EIA3) */ 16128 TEST_CASE_ST(ut_setup, ut_teardown, 16129 test_zuc_hash_generate_test_case_1), 16130 TEST_CASE_ST(ut_setup, ut_teardown, 16131 test_zuc_hash_generate_test_case_2), 16132 TEST_CASE_ST(ut_setup, ut_teardown, 16133 test_zuc_hash_generate_test_case_3), 16134 TEST_CASE_ST(ut_setup, ut_teardown, 16135 test_zuc_hash_generate_test_case_4), 16136 TEST_CASE_ST(ut_setup, ut_teardown, 16137 test_zuc_hash_generate_test_case_5), 16138 TEST_CASE_ST(ut_setup, ut_teardown, 16139 test_zuc_hash_generate_test_case_6), 16140 TEST_CASE_ST(ut_setup, ut_teardown, 16141 test_zuc_hash_generate_test_case_7), 16142 TEST_CASE_ST(ut_setup, ut_teardown, 16143 test_zuc_hash_generate_test_case_8), 16144 TEST_CASE_ST(ut_setup, ut_teardown, 16145 test_zuc_hash_generate_test_case_9), 16146 TEST_CASE_ST(ut_setup, ut_teardown, 16147 test_zuc_hash_generate_test_case_10), 16148 TEST_CASE_ST(ut_setup, ut_teardown, 16149 test_zuc_hash_generate_test_case_11), 16150 16151 16152 /** ZUC alg-chain (EEA3/EIA3) */ 16153 TEST_CASE_ST(ut_setup, ut_teardown, 16154 test_zuc_cipher_auth_test_case_1), 16155 TEST_CASE_ST(ut_setup, ut_teardown, 16156 test_zuc_cipher_auth_test_case_2), 16157 16158 /** ZUC generate auth, then encrypt (EEA3) */ 16159 TEST_CASE_ST(ut_setup, ut_teardown, 16160 test_zuc_auth_cipher_test_case_1), 16161 TEST_CASE_ST(ut_setup, ut_teardown, 16162 test_zuc_auth_cipher_test_case_1_oop), 16163 TEST_CASE_ST(ut_setup, ut_teardown, 16164 test_zuc_auth_cipher_test_case_1_sgl), 16165 TEST_CASE_ST(ut_setup, ut_teardown, 16166 test_zuc_auth_cipher_test_case_1_oop_sgl), 16167 TEST_CASE_ST(ut_setup, ut_teardown, 16168 test_zuc_auth_cipher_test_case_2), 16169 TEST_CASE_ST(ut_setup, ut_teardown, 16170 test_zuc_auth_cipher_test_case_2_oop), 16171 16172 /** ZUC decrypt (EEA3), then verify auth */ 16173 TEST_CASE_ST(ut_setup, ut_teardown, 16174 test_zuc_auth_cipher_verify_test_case_1), 16175 TEST_CASE_ST(ut_setup, ut_teardown, 16176 test_zuc_auth_cipher_verify_test_case_1_oop), 16177 TEST_CASE_ST(ut_setup, ut_teardown, 16178 test_zuc_auth_cipher_verify_test_case_1_sgl), 16179 TEST_CASE_ST(ut_setup, ut_teardown, 16180 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 16181 TEST_CASE_ST(ut_setup, ut_teardown, 16182 test_zuc_auth_cipher_verify_test_case_2), 16183 TEST_CASE_ST(ut_setup, ut_teardown, 16184 test_zuc_auth_cipher_verify_test_case_2_oop), 16185 16186 /** ZUC-256 encrypt only **/ 16187 TEST_CASE_ST(ut_setup, ut_teardown, 16188 test_zuc256_encryption_test_case_1), 16189 TEST_CASE_ST(ut_setup, ut_teardown, 16190 test_zuc256_encryption_test_case_2), 16191 16192 /** ZUC-256 authentication only **/ 16193 TEST_CASE_ST(ut_setup, ut_teardown, 16194 test_zuc256_authentication_test_case_1), 16195 TEST_CASE_ST(ut_setup, ut_teardown, 16196 test_zuc256_authentication_test_case_2), 16197 16198 TEST_CASES_END() 16199 } 16200 }; 16201 16202 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 16203 .suite_name = "HMAC_MD5 Authentication Test Suite", 16204 .setup = hmac_md5_auth_testsuite_setup, 16205 .unit_test_cases = { 16206 TEST_CASE_ST(ut_setup, ut_teardown, 16207 test_MD5_HMAC_generate_case_1), 16208 TEST_CASE_ST(ut_setup, ut_teardown, 16209 test_MD5_HMAC_verify_case_1), 16210 TEST_CASE_ST(ut_setup, ut_teardown, 16211 test_MD5_HMAC_generate_case_2), 16212 TEST_CASE_ST(ut_setup, ut_teardown, 16213 test_MD5_HMAC_verify_case_2), 16214 TEST_CASES_END() 16215 } 16216 }; 16217 16218 static struct unit_test_suite cryptodev_kasumi_testsuite = { 16219 .suite_name = "Kasumi Test Suite", 16220 .setup = kasumi_testsuite_setup, 16221 .unit_test_cases = { 16222 /** KASUMI hash only (UIA1) */ 16223 TEST_CASE_ST(ut_setup, ut_teardown, 16224 test_kasumi_hash_generate_test_case_1), 16225 TEST_CASE_ST(ut_setup, ut_teardown, 16226 test_kasumi_hash_generate_test_case_2), 16227 TEST_CASE_ST(ut_setup, ut_teardown, 16228 test_kasumi_hash_generate_test_case_3), 16229 TEST_CASE_ST(ut_setup, ut_teardown, 16230 test_kasumi_hash_generate_test_case_4), 16231 TEST_CASE_ST(ut_setup, ut_teardown, 16232 test_kasumi_hash_generate_test_case_5), 16233 TEST_CASE_ST(ut_setup, ut_teardown, 16234 test_kasumi_hash_generate_test_case_6), 16235 16236 TEST_CASE_ST(ut_setup, ut_teardown, 16237 test_kasumi_hash_verify_test_case_1), 16238 TEST_CASE_ST(ut_setup, ut_teardown, 16239 test_kasumi_hash_verify_test_case_2), 16240 TEST_CASE_ST(ut_setup, ut_teardown, 16241 test_kasumi_hash_verify_test_case_3), 16242 TEST_CASE_ST(ut_setup, ut_teardown, 16243 test_kasumi_hash_verify_test_case_4), 16244 TEST_CASE_ST(ut_setup, ut_teardown, 16245 test_kasumi_hash_verify_test_case_5), 16246 16247 /** KASUMI encrypt only (UEA1) */ 16248 TEST_CASE_ST(ut_setup, ut_teardown, 16249 test_kasumi_encryption_test_case_1), 16250 TEST_CASE_ST(ut_setup, ut_teardown, 16251 test_kasumi_encryption_test_case_1_sgl), 16252 TEST_CASE_ST(ut_setup, ut_teardown, 16253 test_kasumi_encryption_test_case_1_oop), 16254 TEST_CASE_ST(ut_setup, ut_teardown, 16255 test_kasumi_encryption_test_case_1_oop_sgl), 16256 TEST_CASE_ST(ut_setup, ut_teardown, 16257 test_kasumi_encryption_test_case_2), 16258 TEST_CASE_ST(ut_setup, ut_teardown, 16259 test_kasumi_encryption_test_case_3), 16260 TEST_CASE_ST(ut_setup, ut_teardown, 16261 test_kasumi_encryption_test_case_4), 16262 TEST_CASE_ST(ut_setup, ut_teardown, 16263 test_kasumi_encryption_test_case_5), 16264 16265 /** KASUMI decrypt only (UEA1) */ 16266 TEST_CASE_ST(ut_setup, ut_teardown, 16267 test_kasumi_decryption_test_case_1), 16268 TEST_CASE_ST(ut_setup, ut_teardown, 16269 test_kasumi_decryption_test_case_2), 16270 TEST_CASE_ST(ut_setup, ut_teardown, 16271 test_kasumi_decryption_test_case_3), 16272 TEST_CASE_ST(ut_setup, ut_teardown, 16273 test_kasumi_decryption_test_case_4), 16274 TEST_CASE_ST(ut_setup, ut_teardown, 16275 test_kasumi_decryption_test_case_5), 16276 TEST_CASE_ST(ut_setup, ut_teardown, 16277 test_kasumi_decryption_test_case_1_oop), 16278 TEST_CASE_ST(ut_setup, ut_teardown, 16279 test_kasumi_cipher_auth_test_case_1), 16280 16281 /** KASUMI generate auth, then encrypt (F8) */ 16282 TEST_CASE_ST(ut_setup, ut_teardown, 16283 test_kasumi_auth_cipher_test_case_1), 16284 TEST_CASE_ST(ut_setup, ut_teardown, 16285 test_kasumi_auth_cipher_test_case_2), 16286 TEST_CASE_ST(ut_setup, ut_teardown, 16287 test_kasumi_auth_cipher_test_case_2_oop), 16288 TEST_CASE_ST(ut_setup, ut_teardown, 16289 test_kasumi_auth_cipher_test_case_2_sgl), 16290 TEST_CASE_ST(ut_setup, ut_teardown, 16291 test_kasumi_auth_cipher_test_case_2_oop_sgl), 16292 16293 /** KASUMI decrypt (F8), then verify auth */ 16294 TEST_CASE_ST(ut_setup, ut_teardown, 16295 test_kasumi_auth_cipher_verify_test_case_1), 16296 TEST_CASE_ST(ut_setup, ut_teardown, 16297 test_kasumi_auth_cipher_verify_test_case_2), 16298 TEST_CASE_ST(ut_setup, ut_teardown, 16299 test_kasumi_auth_cipher_verify_test_case_2_oop), 16300 TEST_CASE_ST(ut_setup, ut_teardown, 16301 test_kasumi_auth_cipher_verify_test_case_2_sgl), 16302 TEST_CASE_ST(ut_setup, ut_teardown, 16303 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 16304 16305 TEST_CASES_END() 16306 } 16307 }; 16308 16309 static struct unit_test_suite cryptodev_esn_testsuite = { 16310 .suite_name = "ESN Test Suite", 16311 .setup = esn_testsuite_setup, 16312 .unit_test_cases = { 16313 TEST_CASE_ST(ut_setup, ut_teardown, 16314 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 16315 TEST_CASE_ST(ut_setup, ut_teardown, 16316 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 16317 TEST_CASES_END() 16318 } 16319 }; 16320 16321 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 16322 .suite_name = "Negative AES GCM Test Suite", 16323 .setup = negative_aes_gcm_testsuite_setup, 16324 .unit_test_cases = { 16325 TEST_CASE_ST(ut_setup, ut_teardown, 16326 test_AES_GCM_auth_encryption_fail_iv_corrupt), 16327 TEST_CASE_ST(ut_setup, ut_teardown, 16328 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 16329 TEST_CASE_ST(ut_setup, ut_teardown, 16330 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 16331 TEST_CASE_ST(ut_setup, ut_teardown, 16332 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 16333 TEST_CASE_ST(ut_setup, ut_teardown, 16334 test_AES_GCM_auth_encryption_fail_aad_corrupt), 16335 TEST_CASE_ST(ut_setup, ut_teardown, 16336 test_AES_GCM_auth_encryption_fail_tag_corrupt), 16337 TEST_CASE_ST(ut_setup, ut_teardown, 16338 test_AES_GCM_auth_decryption_fail_iv_corrupt), 16339 TEST_CASE_ST(ut_setup, ut_teardown, 16340 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 16341 TEST_CASE_ST(ut_setup, ut_teardown, 16342 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 16343 TEST_CASE_ST(ut_setup, ut_teardown, 16344 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 16345 TEST_CASE_ST(ut_setup, ut_teardown, 16346 test_AES_GCM_auth_decryption_fail_aad_corrupt), 16347 TEST_CASE_ST(ut_setup, ut_teardown, 16348 test_AES_GCM_auth_decryption_fail_tag_corrupt), 16349 16350 TEST_CASES_END() 16351 } 16352 }; 16353 16354 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 16355 .suite_name = "Negative AES GMAC Test Suite", 16356 .setup = negative_aes_gmac_testsuite_setup, 16357 .unit_test_cases = { 16358 TEST_CASE_ST(ut_setup, ut_teardown, 16359 authentication_verify_AES128_GMAC_fail_data_corrupt), 16360 TEST_CASE_ST(ut_setup, ut_teardown, 16361 authentication_verify_AES128_GMAC_fail_tag_corrupt), 16362 16363 TEST_CASES_END() 16364 } 16365 }; 16366 16367 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 16368 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 16369 .setup = mixed_cipher_hash_testsuite_setup, 16370 .unit_test_cases = { 16371 /** AUTH AES CMAC + CIPHER AES CTR */ 16372 TEST_CASE_ST(ut_setup, ut_teardown, 16373 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 16374 TEST_CASE_ST(ut_setup, ut_teardown, 16375 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16376 TEST_CASE_ST(ut_setup, ut_teardown, 16377 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16378 TEST_CASE_ST(ut_setup, ut_teardown, 16379 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16380 TEST_CASE_ST(ut_setup, ut_teardown, 16381 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 16382 TEST_CASE_ST(ut_setup, ut_teardown, 16383 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16384 TEST_CASE_ST(ut_setup, ut_teardown, 16385 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16386 TEST_CASE_ST(ut_setup, ut_teardown, 16387 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16388 TEST_CASE_ST(ut_setup, ut_teardown, 16389 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 16390 TEST_CASE_ST(ut_setup, ut_teardown, 16391 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 16392 TEST_CASE_ST(ut_setup, ut_teardown, 16393 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 16394 TEST_CASE_ST(ut_setup, ut_teardown, 16395 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 16396 16397 /** AUTH ZUC + CIPHER SNOW3G */ 16398 TEST_CASE_ST(ut_setup, ut_teardown, 16399 test_auth_zuc_cipher_snow_test_case_1), 16400 TEST_CASE_ST(ut_setup, ut_teardown, 16401 test_verify_auth_zuc_cipher_snow_test_case_1), 16402 TEST_CASE_ST(ut_setup, ut_teardown, 16403 test_auth_zuc_cipher_snow_test_case_1_inplace), 16404 TEST_CASE_ST(ut_setup, ut_teardown, 16405 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 16406 /** AUTH AES CMAC + CIPHER SNOW3G */ 16407 TEST_CASE_ST(ut_setup, ut_teardown, 16408 test_auth_aes_cmac_cipher_snow_test_case_1), 16409 TEST_CASE_ST(ut_setup, ut_teardown, 16410 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 16411 TEST_CASE_ST(ut_setup, ut_teardown, 16412 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 16413 TEST_CASE_ST(ut_setup, ut_teardown, 16414 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 16415 /** AUTH ZUC + CIPHER AES CTR */ 16416 TEST_CASE_ST(ut_setup, ut_teardown, 16417 test_auth_zuc_cipher_aes_ctr_test_case_1), 16418 TEST_CASE_ST(ut_setup, ut_teardown, 16419 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 16420 TEST_CASE_ST(ut_setup, ut_teardown, 16421 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 16422 TEST_CASE_ST(ut_setup, ut_teardown, 16423 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 16424 /** AUTH SNOW3G + CIPHER AES CTR */ 16425 TEST_CASE_ST(ut_setup, ut_teardown, 16426 test_auth_snow_cipher_aes_ctr_test_case_1), 16427 TEST_CASE_ST(ut_setup, ut_teardown, 16428 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 16429 TEST_CASE_ST(ut_setup, ut_teardown, 16430 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 16431 TEST_CASE_ST(ut_setup, ut_teardown, 16432 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 16433 TEST_CASE_ST(ut_setup, ut_teardown, 16434 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 16435 TEST_CASE_ST(ut_setup, ut_teardown, 16436 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 16437 /** AUTH SNOW3G + CIPHER ZUC */ 16438 TEST_CASE_ST(ut_setup, ut_teardown, 16439 test_auth_snow_cipher_zuc_test_case_1), 16440 TEST_CASE_ST(ut_setup, ut_teardown, 16441 test_verify_auth_snow_cipher_zuc_test_case_1), 16442 TEST_CASE_ST(ut_setup, ut_teardown, 16443 test_auth_snow_cipher_zuc_test_case_1_inplace), 16444 TEST_CASE_ST(ut_setup, ut_teardown, 16445 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 16446 /** AUTH AES CMAC + CIPHER ZUC */ 16447 TEST_CASE_ST(ut_setup, ut_teardown, 16448 test_auth_aes_cmac_cipher_zuc_test_case_1), 16449 TEST_CASE_ST(ut_setup, ut_teardown, 16450 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 16451 TEST_CASE_ST(ut_setup, ut_teardown, 16452 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 16453 TEST_CASE_ST(ut_setup, ut_teardown, 16454 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 16455 16456 /** AUTH NULL + CIPHER SNOW3G */ 16457 TEST_CASE_ST(ut_setup, ut_teardown, 16458 test_auth_null_cipher_snow_test_case_1), 16459 TEST_CASE_ST(ut_setup, ut_teardown, 16460 test_verify_auth_null_cipher_snow_test_case_1), 16461 /** AUTH NULL + CIPHER ZUC */ 16462 TEST_CASE_ST(ut_setup, ut_teardown, 16463 test_auth_null_cipher_zuc_test_case_1), 16464 TEST_CASE_ST(ut_setup, ut_teardown, 16465 test_verify_auth_null_cipher_zuc_test_case_1), 16466 /** AUTH SNOW3G + CIPHER NULL */ 16467 TEST_CASE_ST(ut_setup, ut_teardown, 16468 test_auth_snow_cipher_null_test_case_1), 16469 TEST_CASE_ST(ut_setup, ut_teardown, 16470 test_verify_auth_snow_cipher_null_test_case_1), 16471 /** AUTH ZUC + CIPHER NULL */ 16472 TEST_CASE_ST(ut_setup, ut_teardown, 16473 test_auth_zuc_cipher_null_test_case_1), 16474 TEST_CASE_ST(ut_setup, ut_teardown, 16475 test_verify_auth_zuc_cipher_null_test_case_1), 16476 /** AUTH NULL + CIPHER AES CTR */ 16477 TEST_CASE_ST(ut_setup, ut_teardown, 16478 test_auth_null_cipher_aes_ctr_test_case_1), 16479 TEST_CASE_ST(ut_setup, ut_teardown, 16480 test_verify_auth_null_cipher_aes_ctr_test_case_1), 16481 /** AUTH AES CMAC + CIPHER NULL */ 16482 TEST_CASE_ST(ut_setup, ut_teardown, 16483 test_auth_aes_cmac_cipher_null_test_case_1), 16484 TEST_CASE_ST(ut_setup, ut_teardown, 16485 test_verify_auth_aes_cmac_cipher_null_test_case_1), 16486 TEST_CASES_END() 16487 } 16488 }; 16489 16490 static int 16491 run_cryptodev_testsuite(const char *pmd_name) 16492 { 16493 uint8_t ret, j, i = 0, blk_start_idx = 0; 16494 const enum blockcipher_test_type blk_suites[] = { 16495 BLKCIPHER_AES_CHAIN_TYPE, 16496 BLKCIPHER_AES_CIPHERONLY_TYPE, 16497 BLKCIPHER_AES_DOCSIS_TYPE, 16498 BLKCIPHER_3DES_CHAIN_TYPE, 16499 BLKCIPHER_3DES_CIPHERONLY_TYPE, 16500 BLKCIPHER_DES_CIPHERONLY_TYPE, 16501 BLKCIPHER_DES_DOCSIS_TYPE, 16502 BLKCIPHER_AUTHONLY_TYPE}; 16503 struct unit_test_suite *static_suites[] = { 16504 &cryptodev_multi_session_testsuite, 16505 &cryptodev_null_testsuite, 16506 &cryptodev_aes_ccm_auth_testsuite, 16507 &cryptodev_aes_gcm_auth_testsuite, 16508 &cryptodev_aes_gmac_auth_testsuite, 16509 &cryptodev_snow3g_testsuite, 16510 &cryptodev_chacha20_poly1305_testsuite, 16511 &cryptodev_zuc_testsuite, 16512 &cryptodev_hmac_md5_auth_testsuite, 16513 &cryptodev_kasumi_testsuite, 16514 &cryptodev_esn_testsuite, 16515 &cryptodev_negative_aes_gcm_testsuite, 16516 &cryptodev_negative_aes_gmac_testsuite, 16517 &cryptodev_mixed_cipher_hash_testsuite, 16518 &cryptodev_negative_hmac_sha1_testsuite, 16519 &cryptodev_gen_testsuite, 16520 #ifdef RTE_LIB_SECURITY 16521 &ipsec_proto_testsuite, 16522 &pdcp_proto_testsuite, 16523 &docsis_proto_testsuite, 16524 #endif 16525 &end_testsuite 16526 }; 16527 static struct unit_test_suite ts = { 16528 .suite_name = "Cryptodev Unit Test Suite", 16529 .setup = testsuite_setup, 16530 .teardown = testsuite_teardown, 16531 .unit_test_cases = {TEST_CASES_END()} 16532 }; 16533 16534 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 16535 16536 if (gbl_driver_id == -1) { 16537 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 16538 return TEST_SKIPPED; 16539 } 16540 16541 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16542 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 16543 16544 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 16545 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16546 ret = unit_test_suite_runner(&ts); 16547 16548 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 16549 free(ts.unit_test_suites); 16550 return ret; 16551 } 16552 16553 static int 16554 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 16555 { 16556 struct rte_cryptodev_info dev_info; 16557 uint8_t i, nb_devs; 16558 int driver_id; 16559 16560 driver_id = rte_cryptodev_driver_id_get(pmd_name); 16561 if (driver_id == -1) { 16562 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 16563 return TEST_SKIPPED; 16564 } 16565 16566 nb_devs = rte_cryptodev_count(); 16567 if (nb_devs < 1) { 16568 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 16569 return TEST_SKIPPED; 16570 } 16571 16572 for (i = 0; i < nb_devs; i++) { 16573 rte_cryptodev_info_get(i, &dev_info); 16574 if (dev_info.driver_id == driver_id) { 16575 if (!(dev_info.feature_flags & flag)) { 16576 RTE_LOG(INFO, USER1, "%s not supported\n", 16577 flag_name); 16578 return TEST_SKIPPED; 16579 } 16580 return 0; /* found */ 16581 } 16582 } 16583 16584 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 16585 return TEST_SKIPPED; 16586 } 16587 16588 static int 16589 test_cryptodev_qat(void) 16590 { 16591 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 16592 } 16593 16594 static int 16595 test_cryptodev_virtio(void) 16596 { 16597 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 16598 } 16599 16600 static int 16601 test_cryptodev_aesni_mb(void) 16602 { 16603 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16604 } 16605 16606 static int 16607 test_cryptodev_cpu_aesni_mb(void) 16608 { 16609 int32_t rc; 16610 enum rte_security_session_action_type at = gbl_action_type; 16611 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16612 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16613 gbl_action_type = at; 16614 return rc; 16615 } 16616 16617 static int 16618 test_cryptodev_chacha_poly_mb(void) 16619 { 16620 int32_t rc; 16621 enum rte_security_session_action_type at = gbl_action_type; 16622 rc = run_cryptodev_testsuite( 16623 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 16624 gbl_action_type = at; 16625 return rc; 16626 } 16627 16628 static int 16629 test_cryptodev_openssl(void) 16630 { 16631 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 16632 } 16633 16634 static int 16635 test_cryptodev_aesni_gcm(void) 16636 { 16637 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16638 } 16639 16640 static int 16641 test_cryptodev_cpu_aesni_gcm(void) 16642 { 16643 int32_t rc; 16644 enum rte_security_session_action_type at = gbl_action_type; 16645 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16646 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16647 gbl_action_type = at; 16648 return rc; 16649 } 16650 16651 static int 16652 test_cryptodev_mlx5(void) 16653 { 16654 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 16655 } 16656 16657 static int 16658 test_cryptodev_null(void) 16659 { 16660 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 16661 } 16662 16663 static int 16664 test_cryptodev_sw_snow3g(void) 16665 { 16666 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 16667 } 16668 16669 static int 16670 test_cryptodev_sw_kasumi(void) 16671 { 16672 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 16673 } 16674 16675 static int 16676 test_cryptodev_sw_zuc(void) 16677 { 16678 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 16679 } 16680 16681 static int 16682 test_cryptodev_armv8(void) 16683 { 16684 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 16685 } 16686 16687 static int 16688 test_cryptodev_mrvl(void) 16689 { 16690 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 16691 } 16692 16693 #ifdef RTE_CRYPTO_SCHEDULER 16694 16695 static int 16696 test_cryptodev_scheduler(void) 16697 { 16698 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 16699 const enum blockcipher_test_type blk_suites[] = { 16700 BLKCIPHER_AES_CHAIN_TYPE, 16701 BLKCIPHER_AES_CIPHERONLY_TYPE, 16702 BLKCIPHER_AUTHONLY_TYPE 16703 }; 16704 static struct unit_test_suite scheduler_multicore = { 16705 .suite_name = "Scheduler Multicore Unit Test Suite", 16706 .setup = scheduler_multicore_testsuite_setup, 16707 .teardown = scheduler_mode_testsuite_teardown, 16708 .unit_test_cases = {TEST_CASES_END()} 16709 }; 16710 static struct unit_test_suite scheduler_round_robin = { 16711 .suite_name = "Scheduler Round Robin Unit Test Suite", 16712 .setup = scheduler_roundrobin_testsuite_setup, 16713 .teardown = scheduler_mode_testsuite_teardown, 16714 .unit_test_cases = {TEST_CASES_END()} 16715 }; 16716 static struct unit_test_suite scheduler_failover = { 16717 .suite_name = "Scheduler Failover Unit Test Suite", 16718 .setup = scheduler_failover_testsuite_setup, 16719 .teardown = scheduler_mode_testsuite_teardown, 16720 .unit_test_cases = {TEST_CASES_END()} 16721 }; 16722 static struct unit_test_suite scheduler_pkt_size_distr = { 16723 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 16724 .setup = scheduler_pkt_size_distr_testsuite_setup, 16725 .teardown = scheduler_mode_testsuite_teardown, 16726 .unit_test_cases = {TEST_CASES_END()} 16727 }; 16728 struct unit_test_suite *sched_mode_suites[] = { 16729 &scheduler_multicore, 16730 &scheduler_round_robin, 16731 &scheduler_failover, 16732 &scheduler_pkt_size_distr 16733 }; 16734 static struct unit_test_suite scheduler_config = { 16735 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 16736 .unit_test_cases = { 16737 TEST_CASE(test_scheduler_attach_worker_op), 16738 TEST_CASE(test_scheduler_mode_multicore_op), 16739 TEST_CASE(test_scheduler_mode_roundrobin_op), 16740 TEST_CASE(test_scheduler_mode_failover_op), 16741 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 16742 TEST_CASE(test_scheduler_detach_worker_op), 16743 16744 TEST_CASES_END() /**< NULL terminate array */ 16745 } 16746 }; 16747 struct unit_test_suite *static_suites[] = { 16748 &scheduler_config, 16749 &end_testsuite 16750 }; 16751 static struct unit_test_suite ts = { 16752 .suite_name = "Scheduler Unit Test Suite", 16753 .setup = scheduler_testsuite_setup, 16754 .teardown = testsuite_teardown, 16755 .unit_test_cases = {TEST_CASES_END()} 16756 }; 16757 16758 gbl_driver_id = rte_cryptodev_driver_id_get( 16759 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16760 16761 if (gbl_driver_id == -1) { 16762 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 16763 return TEST_SKIPPED; 16764 } 16765 16766 if (rte_cryptodev_driver_id_get( 16767 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 16768 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 16769 return TEST_SKIPPED; 16770 } 16771 16772 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16773 uint8_t blk_i = 0; 16774 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 16775 (struct unit_test_suite *) * 16776 (RTE_DIM(blk_suites) + 1)); 16777 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 16778 blk_suites, RTE_DIM(blk_suites)); 16779 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 16780 } 16781 16782 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16783 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 16784 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 16785 RTE_DIM(sched_mode_suites)); 16786 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16787 ret = unit_test_suite_runner(&ts); 16788 16789 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16790 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 16791 (*sched_mode_suites[sched_i]), 16792 RTE_DIM(blk_suites)); 16793 free(sched_mode_suites[sched_i]->unit_test_suites); 16794 } 16795 free(ts.unit_test_suites); 16796 return ret; 16797 } 16798 16799 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 16800 16801 #endif 16802 16803 static int 16804 test_cryptodev_dpaa2_sec(void) 16805 { 16806 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 16807 } 16808 16809 static int 16810 test_cryptodev_dpaa_sec(void) 16811 { 16812 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 16813 } 16814 16815 static int 16816 test_cryptodev_ccp(void) 16817 { 16818 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 16819 } 16820 16821 static int 16822 test_cryptodev_octeontx(void) 16823 { 16824 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 16825 } 16826 16827 static int 16828 test_cryptodev_caam_jr(void) 16829 { 16830 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 16831 } 16832 16833 static int 16834 test_cryptodev_nitrox(void) 16835 { 16836 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 16837 } 16838 16839 static int 16840 test_cryptodev_bcmfs(void) 16841 { 16842 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 16843 } 16844 16845 static int 16846 test_cryptodev_qat_raw_api(void) 16847 { 16848 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 16849 int ret; 16850 16851 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16852 "RAW API"); 16853 if (ret) 16854 return ret; 16855 16856 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16857 ret = run_cryptodev_testsuite(pmd_name); 16858 global_api_test_type = CRYPTODEV_API_TEST; 16859 16860 return ret; 16861 } 16862 16863 static int 16864 test_cryptodev_cn9k(void) 16865 { 16866 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 16867 } 16868 16869 static int 16870 test_cryptodev_cn10k(void) 16871 { 16872 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 16873 } 16874 16875 static int 16876 test_cryptodev_dpaa2_sec_raw_api(void) 16877 { 16878 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 16879 int ret; 16880 16881 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16882 "RAW API"); 16883 if (ret) 16884 return ret; 16885 16886 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16887 ret = run_cryptodev_testsuite(pmd_name); 16888 global_api_test_type = CRYPTODEV_API_TEST; 16889 16890 return ret; 16891 } 16892 16893 static int 16894 test_cryptodev_dpaa_sec_raw_api(void) 16895 { 16896 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD); 16897 int ret; 16898 16899 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16900 "RAW API"); 16901 if (ret) 16902 return ret; 16903 16904 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16905 ret = run_cryptodev_testsuite(pmd_name); 16906 global_api_test_type = CRYPTODEV_API_TEST; 16907 16908 return ret; 16909 } 16910 16911 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 16912 test_cryptodev_dpaa2_sec_raw_api); 16913 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 16914 test_cryptodev_dpaa_sec_raw_api); 16915 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 16916 test_cryptodev_qat_raw_api); 16917 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 16918 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 16919 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 16920 test_cryptodev_cpu_aesni_mb); 16921 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 16922 test_cryptodev_chacha_poly_mb); 16923 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 16924 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 16925 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 16926 test_cryptodev_cpu_aesni_gcm); 16927 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 16928 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 16929 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 16930 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 16931 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 16932 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 16933 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 16934 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 16935 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 16936 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 16937 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 16938 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 16939 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 16940 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 16941 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 16942 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 16943 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 16944