1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2017 Intel Corporation 3 */ 4 5 #include <rte_common.h> 6 #include <rte_hexdump.h> 7 #include <rte_mbuf.h> 8 #include <rte_malloc.h> 9 #include <rte_memcpy.h> 10 #include <rte_pause.h> 11 12 #include <rte_crypto.h> 13 #include <rte_cryptodev.h> 14 15 #include "test.h" 16 #include "test_cryptodev.h" 17 #include "test_cryptodev_blockcipher.h" 18 #include "test_cryptodev_aes_test_vectors.h" 19 #include "test_cryptodev_des_test_vectors.h" 20 #include "test_cryptodev_hash_test_vectors.h" 21 22 static int 23 verify_algo_support(const struct blockcipher_test_case *t, 24 const uint8_t dev_id, const uint32_t digest_len) 25 { 26 int ret = 0; 27 const struct blockcipher_test_data *tdata = t->test_data; 28 struct rte_cryptodev_sym_capability_idx cap_idx; 29 const struct rte_cryptodev_symmetric_capability *capability; 30 31 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 32 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 33 cap_idx.algo.cipher = tdata->crypto_algo; 34 capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx); 35 if (capability == NULL) 36 return -1; 37 38 if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL && 39 !(t->test_data->wrapped_key)) 40 ret = rte_cryptodev_sym_capability_check_cipher(capability, 41 tdata->cipher_key.len, 42 tdata->iv.len); 43 if (ret != 0) 44 return -1; 45 } 46 47 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { 48 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 49 cap_idx.algo.auth = tdata->auth_algo; 50 capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx); 51 if (capability == NULL) 52 return -1; 53 54 if (cap_idx.algo.auth != RTE_CRYPTO_AUTH_NULL) 55 ret = rte_cryptodev_sym_capability_check_auth(capability, 56 tdata->auth_key.len, 57 digest_len, 58 0); 59 if (ret != 0) 60 return -1; 61 } 62 63 return 0; 64 } 65 66 static int 67 test_blockcipher_one_case(const struct blockcipher_test_case *t, 68 struct rte_mempool *mbuf_pool, 69 struct rte_mempool *op_mpool, 70 struct rte_mempool *sess_mpool, 71 struct rte_mempool *sess_priv_mpool, 72 uint8_t dev_id, 73 char *test_msg) 74 { 75 struct rte_mbuf *ibuf = NULL; 76 struct rte_mbuf *obuf = NULL; 77 struct rte_mbuf *iobuf; 78 struct rte_crypto_sym_xform *cipher_xform = NULL; 79 struct rte_crypto_sym_xform *auth_xform = NULL; 80 struct rte_crypto_sym_xform *init_xform = NULL; 81 struct rte_crypto_sym_op *sym_op = NULL; 82 struct rte_crypto_op *op = NULL; 83 struct rte_cryptodev_info dev_info; 84 struct rte_cryptodev_sym_session *sess = NULL; 85 86 int status = TEST_SUCCESS; 87 const struct blockcipher_test_data *tdata = t->test_data; 88 uint8_t cipher_key[tdata->cipher_key.len]; 89 uint8_t auth_key[tdata->auth_key.len]; 90 uint32_t buf_len = tdata->ciphertext.len; 91 uint32_t digest_len = tdata->digest.len; 92 char *buf_p = NULL; 93 uint8_t src_pattern = 0xa5; 94 uint8_t dst_pattern = 0xb6; 95 uint8_t tmp_src_buf[MBUF_SIZE]; 96 uint8_t tmp_dst_buf[MBUF_SIZE]; 97 uint32_t pad_len; 98 99 int nb_segs = 1; 100 uint32_t nb_iterates = 0; 101 102 rte_cryptodev_info_get(dev_id, &dev_info); 103 uint64_t feat_flags = dev_info.feature_flags; 104 105 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 106 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 107 printf("Device doesn't support sessionless operations " 108 "Test Skipped.\n"); 109 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 110 "SKIPPED"); 111 return TEST_SKIPPED; 112 } 113 } 114 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_DIGEST_ENCRYPTED) { 115 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 116 printf("Device doesn't support encrypted digest " 117 "Test Skipped.\n"); 118 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 119 "SKIPPED"); 120 return TEST_SKIPPED; 121 } 122 } 123 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) { 124 uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT; 125 126 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 127 if (!(feat_flags & oop_flag)) { 128 printf("Device doesn't support out-of-place " 129 "scatter-gather in input mbuf. " 130 "Test Skipped.\n"); 131 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 132 "SKIPPED"); 133 return TEST_SKIPPED; 134 } 135 } else { 136 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 137 printf("Device doesn't support in-place " 138 "scatter-gather mbufs. " 139 "Test Skipped.\n"); 140 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 141 "SKIPPED"); 142 return TEST_SKIPPED; 143 } 144 } 145 146 nb_segs = 3; 147 } 148 if (!!(feat_flags & RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY) ^ 149 tdata->wrapped_key) { 150 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 151 "SKIPPED"); 152 return TEST_SKIPPED; 153 } 154 155 if (global_api_test_type == CRYPTODEV_RAW_API_TEST && 156 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) { 157 printf("Device doesn't support raw data-path APIs. " 158 "Test Skipped.\n"); 159 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); 160 return TEST_SKIPPED; 161 } 162 163 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 164 uint64_t oop_flags = RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | 165 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT | 166 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT | 167 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT; 168 if (!(feat_flags & oop_flags)) { 169 printf("Device doesn't support out-of-place operations." 170 "Test Skipped.\n"); 171 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 172 "SKIPPED"); 173 return TEST_SKIPPED; 174 } 175 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 176 printf("Raw Data Path APIs do not support OOP, " 177 "Test Skipped.\n"); 178 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); 179 status = TEST_SKIPPED; 180 goto error_exit; 181 } 182 } 183 184 if (tdata->cipher_key.len) 185 memcpy(cipher_key, tdata->cipher_key.data, 186 tdata->cipher_key.len); 187 if (tdata->auth_key.len) 188 memcpy(auth_key, tdata->auth_key.data, 189 tdata->auth_key.len); 190 191 /* Check if PMD is capable of performing that test */ 192 if (verify_algo_support(t, dev_id, digest_len) < 0) { 193 RTE_LOG(DEBUG, USER1, 194 "Device does not support this algorithm." 195 "Test Skipped.\n"); 196 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); 197 return TEST_SKIPPED; 198 } 199 200 /* preparing data */ 201 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) 202 buf_len += digest_len; 203 204 pad_len = RTE_ALIGN(buf_len, 16) - buf_len; 205 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 206 buf_len += pad_len; 207 208 /* for contiguous mbuf, nb_segs is 1 */ 209 ibuf = create_segmented_mbuf(mbuf_pool, 210 tdata->ciphertext.len, nb_segs, src_pattern); 211 if (ibuf == NULL) { 212 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 213 "line %u FAILED: %s", 214 __LINE__, "Cannot create source mbuf"); 215 status = TEST_FAILED; 216 goto error_exit; 217 } 218 219 /* only encryption requires plaintext.data input, 220 * decryption/(digest gen)/(digest verify) use ciphertext.data 221 * to be computed 222 */ 223 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) 224 pktmbuf_write(ibuf, 0, tdata->plaintext.len, 225 tdata->plaintext.data); 226 else 227 pktmbuf_write(ibuf, 0, tdata->ciphertext.len, 228 tdata->ciphertext.data); 229 230 buf_p = rte_pktmbuf_append(ibuf, digest_len); 231 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 232 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 233 rte_memcpy(buf_p, 234 tdata->ciphertext.data + tdata->ciphertext.len, 235 digest_len); 236 else 237 rte_memcpy(buf_p, tdata->digest.data, digest_len); 238 else 239 memset(buf_p, 0, digest_len); 240 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) { 241 buf_p = rte_pktmbuf_append(ibuf, pad_len); 242 if (!buf_p) { 243 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 244 "FAILED: %s", __LINE__, 245 "No room to append mbuf"); 246 status = TEST_FAILED; 247 goto error_exit; 248 } 249 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { 250 const uint8_t *temp_p = tdata->ciphertext.data + 251 tdata->ciphertext.len + 252 digest_len; 253 rte_memcpy(buf_p, temp_p, pad_len); 254 } else 255 memset(buf_p, 0xa5, pad_len); 256 } 257 258 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 259 obuf = rte_pktmbuf_alloc(mbuf_pool); 260 if (!obuf) { 261 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 262 "FAILED: %s", __LINE__, 263 "Allocation of rte_mbuf failed"); 264 status = TEST_FAILED; 265 goto error_exit; 266 } 267 memset(obuf->buf_addr, dst_pattern, obuf->buf_len); 268 269 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 270 buf_p = rte_pktmbuf_append(obuf, buf_len + pad_len); 271 else 272 buf_p = rte_pktmbuf_append(obuf, buf_len); 273 if (!buf_p) { 274 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 275 "FAILED: %s", __LINE__, 276 "No room to append mbuf"); 277 status = TEST_FAILED; 278 goto error_exit; 279 } 280 memset(buf_p, 0, buf_len); 281 } 282 283 /* Generate Crypto op data structure */ 284 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC); 285 if (!op) { 286 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 287 "line %u FAILED: %s", 288 __LINE__, "Failed to allocate symmetric crypto " 289 "operation struct"); 290 status = TEST_FAILED; 291 goto error_exit; 292 } 293 294 sym_op = op->sym; 295 296 iterate: 297 if (nb_iterates) { 298 struct rte_mbuf *tmp_buf = ibuf; 299 300 ibuf = obuf; 301 obuf = tmp_buf; 302 303 rte_pktmbuf_reset(ibuf); 304 rte_pktmbuf_reset(obuf); 305 306 rte_pktmbuf_append(ibuf, tdata->ciphertext.len); 307 308 /* only encryption requires plaintext.data input, 309 * decryption/(digest gen)/(digest verify) use ciphertext.data 310 * to be computed 311 */ 312 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) 313 pktmbuf_write(ibuf, 0, tdata->plaintext.len, 314 tdata->plaintext.data); 315 else 316 pktmbuf_write(ibuf, 0, tdata->ciphertext.len, 317 tdata->ciphertext.data); 318 319 buf_p = rte_pktmbuf_append(ibuf, digest_len); 320 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 321 rte_memcpy(buf_p, tdata->digest.data, digest_len); 322 else 323 memset(buf_p, 0, digest_len); 324 325 memset(obuf->buf_addr, dst_pattern, obuf->buf_len); 326 327 buf_p = rte_pktmbuf_append(obuf, buf_len); 328 if (!buf_p) { 329 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 330 "FAILED: %s", __LINE__, 331 "No room to append mbuf"); 332 status = TEST_FAILED; 333 goto error_exit; 334 } 335 memset(buf_p, 0, buf_len); 336 } 337 338 sym_op->m_src = ibuf; 339 340 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 341 sym_op->m_dst = obuf; 342 iobuf = obuf; 343 } else { 344 sym_op->m_dst = NULL; 345 iobuf = ibuf; 346 } 347 348 /* sessionless op requires allocate xform using 349 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc() 350 * is used 351 */ 352 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 353 uint32_t n_xforms = 0; 354 355 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) 356 n_xforms++; 357 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) 358 n_xforms++; 359 360 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms) 361 == NULL) { 362 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 363 "FAILED: %s", __LINE__, "Failed to " 364 "allocate space for crypto transforms"); 365 status = TEST_FAILED; 366 goto error_exit; 367 } 368 } else { 369 cipher_xform = rte_zmalloc(NULL, 370 sizeof(struct rte_crypto_sym_xform), 0); 371 372 auth_xform = rte_zmalloc(NULL, 373 sizeof(struct rte_crypto_sym_xform), 0); 374 375 if (!cipher_xform || !auth_xform) { 376 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 377 "FAILED: %s", __LINE__, "Failed to " 378 "allocate memory for crypto transforms"); 379 status = TEST_FAILED; 380 goto error_exit; 381 } 382 } 383 384 /* preparing xform, for sessioned op, init_xform is initialized 385 * here and later as param in rte_cryptodev_sym_session_create() call 386 */ 387 if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) { 388 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 389 cipher_xform = op->sym->xform; 390 auth_xform = cipher_xform->next; 391 auth_xform->next = NULL; 392 } else { 393 cipher_xform->next = auth_xform; 394 auth_xform->next = NULL; 395 init_xform = cipher_xform; 396 } 397 } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) { 398 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 399 auth_xform = op->sym->xform; 400 cipher_xform = auth_xform->next; 401 cipher_xform->next = NULL; 402 } else { 403 auth_xform->next = cipher_xform; 404 cipher_xform->next = NULL; 405 init_xform = auth_xform; 406 } 407 } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN_ENC) { 408 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 409 auth_xform = op->sym->xform; 410 cipher_xform = auth_xform->next; 411 cipher_xform->next = NULL; 412 } else { 413 auth_xform->next = cipher_xform; 414 cipher_xform->next = NULL; 415 init_xform = auth_xform; 416 } 417 } else if (t->op_mask == BLOCKCIPHER_TEST_OP_DEC_AUTH_VERIFY) { 418 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 419 cipher_xform = op->sym->xform; 420 auth_xform = cipher_xform->next; 421 auth_xform->next = NULL; 422 } else { 423 cipher_xform->next = auth_xform; 424 auth_xform->next = NULL; 425 init_xform = cipher_xform; 426 } 427 } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) || 428 (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) { 429 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) 430 cipher_xform = op->sym->xform; 431 else 432 init_xform = cipher_xform; 433 cipher_xform->next = NULL; 434 } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) || 435 (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) { 436 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) 437 auth_xform = op->sym->xform; 438 else 439 init_xform = auth_xform; 440 auth_xform->next = NULL; 441 } else { 442 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 443 "line %u FAILED: %s", 444 __LINE__, "Unrecognized operation"); 445 status = TEST_FAILED; 446 goto error_exit; 447 } 448 449 /*configure xforms & sym_op cipher and auth data*/ 450 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 451 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; 452 cipher_xform->cipher.algo = tdata->crypto_algo; 453 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) 454 cipher_xform->cipher.op = 455 RTE_CRYPTO_CIPHER_OP_ENCRYPT; 456 else 457 cipher_xform->cipher.op = 458 RTE_CRYPTO_CIPHER_OP_DECRYPT; 459 cipher_xform->cipher.key.data = cipher_key; 460 cipher_xform->cipher.key.length = tdata->cipher_key.len; 461 cipher_xform->cipher.iv.offset = IV_OFFSET; 462 cipher_xform->cipher.dataunit_len = tdata->xts_dataunit_len; 463 464 if (tdata->crypto_algo == RTE_CRYPTO_CIPHER_NULL) 465 cipher_xform->cipher.iv.length = 0; 466 else 467 cipher_xform->cipher.iv.length = tdata->iv.len; 468 469 sym_op->cipher.data.offset = tdata->cipher_offset; 470 sym_op->cipher.data.length = tdata->ciphertext.len - 471 tdata->cipher_offset; 472 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) { 473 sym_op->cipher.data.length += tdata->digest.len; 474 sym_op->cipher.data.length += pad_len; 475 } 476 rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET), 477 tdata->iv.data, 478 tdata->iv.len); 479 } 480 481 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { 482 uint32_t digest_offset = tdata->ciphertext.len; 483 484 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH; 485 auth_xform->auth.algo = tdata->auth_algo; 486 auth_xform->auth.key.length = tdata->auth_key.len; 487 auth_xform->auth.key.data = auth_key; 488 auth_xform->auth.digest_length = digest_len; 489 490 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { 491 auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 492 sym_op->auth.digest.data = pktmbuf_mtod_offset 493 (iobuf, digest_offset); 494 sym_op->auth.digest.phys_addr = 495 pktmbuf_iova_offset(iobuf, 496 digest_offset); 497 } else { 498 auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 499 sym_op->auth.digest.data = pktmbuf_mtod_offset 500 (sym_op->m_src, digest_offset); 501 sym_op->auth.digest.phys_addr = 502 pktmbuf_iova_offset(sym_op->m_src, 503 digest_offset); 504 } 505 506 sym_op->auth.data.offset = tdata->auth_offset; 507 sym_op->auth.data.length = tdata->ciphertext.len - 508 tdata->auth_offset; 509 } 510 511 /** 512 * Create session for sessioned op. For mbuf iteration test, 513 * skip the session creation for the second iteration. 514 */ 515 if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) && 516 nb_iterates == 0) { 517 sess = rte_cryptodev_sym_session_create(sess_mpool); 518 519 status = rte_cryptodev_sym_session_init(dev_id, sess, 520 init_xform, sess_priv_mpool); 521 if (status == -ENOTSUP) { 522 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "UNSUPPORTED"); 523 status = TEST_SKIPPED; 524 goto error_exit; 525 } 526 if (!sess || status < 0) { 527 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 528 "FAILED: %s", __LINE__, 529 "Session creation failed"); 530 status = TEST_FAILED; 531 goto error_exit; 532 } 533 534 /* attach symmetric crypto session to crypto operations */ 535 rte_crypto_op_attach_sym_session(op, sess); 536 } 537 538 debug_hexdump(stdout, "m_src(before):", 539 sym_op->m_src->buf_addr, sym_op->m_src->buf_len); 540 rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr, 541 sym_op->m_src->buf_len); 542 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 543 debug_hexdump(stdout, "m_dst(before):", 544 sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); 545 rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr, 546 sym_op->m_dst->buf_len); 547 } 548 549 /* Process crypto operation */ 550 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 551 uint8_t is_cipher = 0, is_auth = 0; 552 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) 553 is_cipher = 1; 554 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) 555 is_auth = 1; 556 557 process_sym_raw_dp_op(dev_id, 0, op, is_cipher, is_auth, 0, 558 tdata->iv.len); 559 } else { 560 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 561 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 562 "line %u FAILED: %s", 563 __LINE__, "Error sending packet for encryption"); 564 status = TEST_FAILED; 565 goto error_exit; 566 } 567 568 op = NULL; 569 570 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 571 rte_pause(); 572 573 if (!op) { 574 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 575 "line %u FAILED: %s", 576 __LINE__, "Failed to process sym crypto op"); 577 status = TEST_FAILED; 578 goto error_exit; 579 } 580 } 581 582 debug_hexdump(stdout, "m_src(after):", 583 sym_op->m_src->buf_addr, sym_op->m_src->buf_len); 584 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) 585 debug_hexdump(stdout, "m_dst(after):", 586 sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); 587 588 /* Verify results */ 589 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 590 if ((t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) && 591 (op->status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED)) 592 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 593 "FAILED: Digest verification failed " 594 "(0x%X)", __LINE__, op->status); 595 else 596 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 597 "FAILED: Operation failed " 598 "(0x%X)", __LINE__, op->status); 599 status = TEST_FAILED; 600 goto error_exit; 601 } 602 603 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 604 uint8_t buffer[2048]; 605 const uint8_t *compare_ref; 606 uint32_t compare_len; 607 608 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) { 609 compare_ref = tdata->ciphertext.data + 610 tdata->cipher_offset; 611 compare_len = tdata->ciphertext.len - 612 tdata->cipher_offset; 613 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 614 compare_len += tdata->digest.len; 615 } else { 616 compare_ref = tdata->plaintext.data + 617 tdata->cipher_offset; 618 compare_len = tdata->plaintext.len - 619 tdata->cipher_offset; 620 } 621 622 if (memcmp(rte_pktmbuf_read(iobuf, tdata->cipher_offset, 623 compare_len, buffer), compare_ref, 624 compare_len)) { 625 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 626 "FAILED: %s", __LINE__, 627 "Crypto data not as expected"); 628 status = TEST_FAILED; 629 goto error_exit; 630 } 631 } 632 633 /* Check digest data only in enc-then-auth_gen case. 634 * In auth_gen-then-enc case, cipher text contains both encrypted 635 * plain text and encrypted digest value. If cipher text is correct, 636 * it implies digest is also generated properly. 637 */ 638 if (!(t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)) 639 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { 640 uint8_t *auth_res = pktmbuf_mtod_offset(iobuf, 641 tdata->ciphertext.len); 642 643 if (memcmp(auth_res, tdata->digest.data, digest_len)) { 644 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 645 "FAILED: %s", __LINE__, "Generated " 646 "digest data not as expected"); 647 status = TEST_FAILED; 648 goto error_exit; 649 } 650 } 651 652 /* The only parts that should have changed in the buffer are 653 * plaintext/ciphertext and digest. 654 * In OOP only the dest buffer should change. 655 */ 656 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 657 struct rte_mbuf *mbuf; 658 uint8_t value; 659 uint32_t head_unchanged_len, changed_len = 0; 660 uint32_t i; 661 uint32_t hdroom_used = 0, tlroom_used = 0; 662 uint32_t hdroom = 0; 663 664 mbuf = sym_op->m_src; 665 /* 666 * Crypto PMDs specify the headroom & tailroom it would use 667 * when processing the crypto operation. PMD is free to modify 668 * this space, and so the verification check should skip that 669 * block. 670 */ 671 hdroom_used = dev_info.min_mbuf_headroom_req; 672 tlroom_used = dev_info.min_mbuf_tailroom_req; 673 674 /* Get headroom */ 675 hdroom = rte_pktmbuf_headroom(mbuf); 676 677 head_unchanged_len = mbuf->buf_len; 678 679 for (i = 0; i < mbuf->buf_len; i++) { 680 681 /* Skip headroom used by PMD */ 682 if (i == hdroom - hdroom_used) 683 i += hdroom_used; 684 685 /* Skip tailroom used by PMD */ 686 if (i == (hdroom + mbuf->data_len)) 687 i += tlroom_used; 688 689 value = *((uint8_t *)(mbuf->buf_addr)+i); 690 if (value != tmp_src_buf[i]) { 691 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 692 "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)", 693 __LINE__, value, tmp_src_buf[i]); 694 status = TEST_FAILED; 695 goto error_exit; 696 } 697 } 698 699 mbuf = sym_op->m_dst; 700 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { 701 head_unchanged_len = hdroom + sym_op->auth.data.offset; 702 changed_len = sym_op->auth.data.length; 703 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) 704 changed_len += digest_len; 705 } else { 706 /* cipher-only */ 707 head_unchanged_len = hdroom + 708 sym_op->cipher.data.offset; 709 changed_len = sym_op->cipher.data.length; 710 } 711 712 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 713 changed_len = sym_op->cipher.data.length + 714 digest_len + pad_len; 715 716 for (i = 0; i < mbuf->buf_len; i++) { 717 if (i == head_unchanged_len) 718 i += changed_len; 719 value = *((uint8_t *)(mbuf->buf_addr)+i); 720 if (value != tmp_dst_buf[i]) { 721 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 722 "line %u FAILED: OOP dst outer mbuf data " 723 "(0x%x) not as expected (0x%x)", 724 __LINE__, value, tmp_dst_buf[i]); 725 status = TEST_FAILED; 726 goto error_exit; 727 } 728 } 729 730 if (!nb_iterates) { 731 nb_iterates++; 732 goto iterate; 733 } 734 } else { 735 /* In-place operation */ 736 struct rte_mbuf *mbuf; 737 uint8_t value; 738 uint32_t head_unchanged_len = 0, changed_len = 0; 739 uint32_t i; 740 uint32_t hdroom_used = 0, tlroom_used = 0; 741 uint32_t hdroom = 0; 742 743 /* 744 * Crypto PMDs specify the headroom & tailroom it would use 745 * when processing the crypto operation. PMD is free to modify 746 * this space, and so the verification check should skip that 747 * block. 748 */ 749 hdroom_used = dev_info.min_mbuf_headroom_req; 750 tlroom_used = dev_info.min_mbuf_tailroom_req; 751 752 mbuf = sym_op->m_src; 753 754 /* Get headroom */ 755 hdroom = rte_pktmbuf_headroom(mbuf); 756 757 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 758 head_unchanged_len = hdroom + 759 sym_op->cipher.data.offset; 760 changed_len = sym_op->cipher.data.length; 761 } else { 762 /* auth-only */ 763 head_unchanged_len = hdroom + 764 sym_op->auth.data.offset + 765 sym_op->auth.data.length; 766 changed_len = 0; 767 } 768 769 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) 770 changed_len += digest_len; 771 772 if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 773 changed_len = sym_op->cipher.data.length; 774 775 for (i = 0; i < mbuf->buf_len; i++) { 776 777 /* Skip headroom used by PMD */ 778 if (i == hdroom - hdroom_used) 779 i += hdroom_used; 780 781 if (i == head_unchanged_len) 782 i += changed_len; 783 784 /* Skip tailroom used by PMD */ 785 if (i == (hdroom + mbuf->data_len)) 786 i += tlroom_used; 787 788 value = *((uint8_t *)(mbuf->buf_addr)+i); 789 if (value != tmp_src_buf[i]) { 790 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 791 "line %u FAILED: outer mbuf data (0x%x) " 792 "not as expected (0x%x)", 793 __LINE__, value, tmp_src_buf[i]); 794 status = TEST_FAILED; 795 goto error_exit; 796 } 797 } 798 } 799 800 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS"); 801 802 error_exit: 803 if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) { 804 if (sess) { 805 rte_cryptodev_sym_session_clear(dev_id, sess); 806 rte_cryptodev_sym_session_free(sess); 807 } 808 rte_free(cipher_xform); 809 rte_free(auth_xform); 810 } 811 812 rte_crypto_op_free(op); 813 814 rte_pktmbuf_free(obuf); 815 816 rte_pktmbuf_free(ibuf); 817 818 return status; 819 } 820 821 static int 822 blockcipher_test_case_run(const void *data) 823 { 824 const struct blockcipher_test_case *tc_data = data; 825 int status; 826 char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1]; 827 828 status = test_blockcipher_one_case(tc_data, 829 p_testsuite_params->mbuf_pool, 830 p_testsuite_params->op_mpool, 831 p_testsuite_params->session_mpool, 832 p_testsuite_params->session_priv_mpool, 833 p_testsuite_params->valid_devs[0], 834 test_msg); 835 return status; 836 } 837 838 static int 839 aes_chain_setup(void) 840 { 841 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 842 struct rte_cryptodev_info dev_info; 843 uint64_t feat_flags; 844 const enum rte_crypto_cipher_algorithm ciphers[] = { 845 RTE_CRYPTO_CIPHER_NULL, 846 RTE_CRYPTO_CIPHER_AES_CTR, 847 RTE_CRYPTO_CIPHER_AES_CBC 848 }; 849 const enum rte_crypto_auth_algorithm auths[] = { 850 RTE_CRYPTO_AUTH_NULL, 851 RTE_CRYPTO_AUTH_SHA1_HMAC, 852 RTE_CRYPTO_AUTH_AES_XCBC_MAC, 853 RTE_CRYPTO_AUTH_SHA256_HMAC, 854 RTE_CRYPTO_AUTH_SHA512_HMAC, 855 RTE_CRYPTO_AUTH_SHA224_HMAC, 856 RTE_CRYPTO_AUTH_SHA384_HMAC 857 }; 858 859 rte_cryptodev_info_get(dev_id, &dev_info); 860 feat_flags = dev_info.feature_flags; 861 862 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 863 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 864 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 865 RTE_LOG(INFO, USER1, "Feature flag requirements for AES Chain " 866 "testsuite not met\n"); 867 return TEST_SKIPPED; 868 } 869 870 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 871 && check_auth_capabilities_supported(auths, 872 RTE_DIM(auths)) != 0) { 873 RTE_LOG(INFO, USER1, "Capability requirements for AES Chain " 874 "testsuite not met\n"); 875 return TEST_SKIPPED; 876 } 877 878 return 0; 879 } 880 881 static int 882 aes_cipheronly_setup(void) 883 { 884 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 885 struct rte_cryptodev_info dev_info; 886 uint64_t feat_flags; 887 const enum rte_crypto_cipher_algorithm ciphers[] = { 888 RTE_CRYPTO_CIPHER_NULL, 889 RTE_CRYPTO_CIPHER_AES_CTR, 890 RTE_CRYPTO_CIPHER_AES_CBC, 891 RTE_CRYPTO_CIPHER_AES_ECB, 892 RTE_CRYPTO_CIPHER_AES_XTS 893 }; 894 const enum rte_crypto_auth_algorithm auths[] = { 895 RTE_CRYPTO_AUTH_NULL, 896 RTE_CRYPTO_AUTH_SHA1_HMAC, 897 RTE_CRYPTO_AUTH_AES_XCBC_MAC 898 }; 899 900 rte_cryptodev_info_get(dev_id, &dev_info); 901 feat_flags = dev_info.feature_flags; 902 903 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 904 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 905 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 906 RTE_LOG(INFO, USER1, "Feature flag requirements for AES Cipheronly " 907 "testsuite not met\n"); 908 return TEST_SKIPPED; 909 } 910 911 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 912 && check_auth_capabilities_supported(auths, 913 RTE_DIM(auths)) != 0) { 914 RTE_LOG(INFO, USER1, "Capability requirements for AES Cipheronly " 915 "testsuite not met\n"); 916 return TEST_SKIPPED; 917 } 918 919 return 0; 920 } 921 922 static int 923 aes_docsis_setup(void) 924 { 925 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 926 struct rte_cryptodev_info dev_info; 927 uint64_t feat_flags; 928 const enum rte_crypto_cipher_algorithm ciphers[] = { 929 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 930 }; 931 932 rte_cryptodev_info_get(dev_id, &dev_info); 933 feat_flags = dev_info.feature_flags; 934 935 /* Data-path service does not support DOCSIS yet */ 936 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 937 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 938 RTE_LOG(INFO, USER1, "Feature flag requirements for AES Docsis " 939 "testsuite not met\n"); 940 return TEST_SKIPPED; 941 } 942 943 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 944 RTE_LOG(INFO, USER1, "Capability requirements for AES Docsis " 945 "testsuite not met\n"); 946 return TEST_SKIPPED; 947 } 948 949 return 0; 950 } 951 952 static int 953 triple_des_chain_setup(void) 954 { 955 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 956 struct rte_cryptodev_info dev_info; 957 uint64_t feat_flags; 958 const enum rte_crypto_cipher_algorithm ciphers[] = { 959 RTE_CRYPTO_CIPHER_3DES_CTR, 960 RTE_CRYPTO_CIPHER_3DES_CBC 961 }; 962 const enum rte_crypto_auth_algorithm auths[] = { 963 RTE_CRYPTO_AUTH_SHA1_HMAC, 964 RTE_CRYPTO_AUTH_SHA1 965 }; 966 967 rte_cryptodev_info_get(dev_id, &dev_info); 968 feat_flags = dev_info.feature_flags; 969 970 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 971 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 972 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 973 RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES Chain " 974 "testsuite not met\n"); 975 return TEST_SKIPPED; 976 } 977 978 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 979 && check_auth_capabilities_supported(auths, 980 RTE_DIM(auths)) != 0) { 981 RTE_LOG(INFO, USER1, "Capability requirements for 3DES Chain " 982 "testsuite not met\n"); 983 return TEST_SKIPPED; 984 } 985 986 return 0; 987 } 988 989 static int 990 triple_des_cipheronly_setup(void) 991 { 992 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 993 struct rte_cryptodev_info dev_info; 994 uint64_t feat_flags; 995 const enum rte_crypto_cipher_algorithm ciphers[] = { 996 RTE_CRYPTO_CIPHER_3DES_CTR, 997 RTE_CRYPTO_CIPHER_3DES_CBC 998 }; 999 1000 rte_cryptodev_info_get(dev_id, &dev_info); 1001 feat_flags = dev_info.feature_flags; 1002 1003 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1004 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1005 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1006 RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES " 1007 "Cipheronly testsuite not met\n"); 1008 return TEST_SKIPPED; 1009 } 1010 1011 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 1012 RTE_LOG(INFO, USER1, "Capability requirements for 3DES " 1013 "Cipheronly testsuite not met\n"); 1014 return TEST_SKIPPED; 1015 } 1016 1017 return 0; 1018 } 1019 1020 static int 1021 des_cipheronly_setup(void) 1022 { 1023 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 1024 struct rte_cryptodev_info dev_info; 1025 uint64_t feat_flags; 1026 const enum rte_crypto_cipher_algorithm ciphers[] = { 1027 RTE_CRYPTO_CIPHER_DES_CBC 1028 }; 1029 1030 rte_cryptodev_info_get(dev_id, &dev_info); 1031 feat_flags = dev_info.feature_flags; 1032 1033 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1034 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1035 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1036 RTE_LOG(INFO, USER1, "Feature flag requirements for DES " 1037 "Cipheronly testsuite not met\n"); 1038 return TEST_SKIPPED; 1039 } 1040 1041 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 1042 RTE_LOG(INFO, USER1, "Capability requirements for DES " 1043 "Cipheronly testsuite not met\n"); 1044 return TEST_SKIPPED; 1045 } 1046 1047 return 0; 1048 } 1049 1050 static int 1051 des_docsis_setup(void) 1052 { 1053 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 1054 struct rte_cryptodev_info dev_info; 1055 uint64_t feat_flags; 1056 const enum rte_crypto_cipher_algorithm ciphers[] = { 1057 RTE_CRYPTO_CIPHER_DES_DOCSISBPI 1058 }; 1059 1060 rte_cryptodev_info_get(dev_id, &dev_info); 1061 feat_flags = dev_info.feature_flags; 1062 1063 /* Data-path service does not support DOCSIS yet */ 1064 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1065 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1066 RTE_LOG(INFO, USER1, "Feature flag requirements for DES Docsis " 1067 "testsuite not met\n"); 1068 return TEST_SKIPPED; 1069 } 1070 1071 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 1072 RTE_LOG(INFO, USER1, "Capability requirements for DES Docsis " 1073 "testsuite not met\n"); 1074 return TEST_SKIPPED; 1075 } 1076 1077 return 0; 1078 } 1079 1080 static int 1081 authonly_setup(void) 1082 { 1083 uint8_t dev_id = p_testsuite_params->valid_devs[0]; 1084 struct rte_cryptodev_info dev_info; 1085 uint64_t feat_flags; 1086 const enum rte_crypto_auth_algorithm auths[] = { 1087 RTE_CRYPTO_AUTH_MD5, 1088 RTE_CRYPTO_AUTH_MD5_HMAC, 1089 RTE_CRYPTO_AUTH_SHA1, 1090 RTE_CRYPTO_AUTH_SHA1_HMAC, 1091 RTE_CRYPTO_AUTH_SHA224, 1092 RTE_CRYPTO_AUTH_SHA224_HMAC, 1093 RTE_CRYPTO_AUTH_SHA256, 1094 RTE_CRYPTO_AUTH_SHA256_HMAC, 1095 RTE_CRYPTO_AUTH_SHA384, 1096 RTE_CRYPTO_AUTH_SHA384_HMAC, 1097 RTE_CRYPTO_AUTH_SHA512, 1098 RTE_CRYPTO_AUTH_SHA512_HMAC, 1099 RTE_CRYPTO_AUTH_AES_CMAC, 1100 RTE_CRYPTO_AUTH_NULL, 1101 RTE_CRYPTO_AUTH_AES_XCBC_MAC 1102 }; 1103 1104 rte_cryptodev_info_get(dev_id, &dev_info); 1105 feat_flags = dev_info.feature_flags; 1106 1107 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1108 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1109 !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1110 RTE_LOG(INFO, USER1, "Feature flag requirements for Auth Only " 1111 "testsuite not met\n"); 1112 return TEST_SKIPPED; 1113 } 1114 1115 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1116 RTE_LOG(INFO, USER1, "Capability requirements for Auth Only " 1117 "testsuite not met\n"); 1118 return TEST_SKIPPED; 1119 } 1120 1121 return 0; 1122 } 1123 1124 struct unit_test_suite * 1125 build_blockcipher_test_suite(enum blockcipher_test_type test_type) 1126 { 1127 int i, n_test_cases = 0; 1128 struct unit_test_suite *ts; 1129 const char *ts_name = NULL; 1130 const struct blockcipher_test_case *blk_tcs; 1131 struct unit_test_case *tc; 1132 int (*ts_setup)(void) = NULL; 1133 1134 switch (test_type) { 1135 case BLKCIPHER_AES_CHAIN_TYPE: 1136 n_test_cases = RTE_DIM(aes_chain_test_cases); 1137 blk_tcs = aes_chain_test_cases; 1138 ts_name = "AES Chain"; 1139 ts_setup = aes_chain_setup; 1140 break; 1141 case BLKCIPHER_AES_CIPHERONLY_TYPE: 1142 n_test_cases = RTE_DIM(aes_cipheronly_test_cases); 1143 blk_tcs = aes_cipheronly_test_cases; 1144 ts_name = "AES Cipher Only"; 1145 ts_setup = aes_cipheronly_setup; 1146 break; 1147 case BLKCIPHER_AES_DOCSIS_TYPE: 1148 n_test_cases = RTE_DIM(aes_docsis_test_cases); 1149 blk_tcs = aes_docsis_test_cases; 1150 ts_name = "AES Docsis"; 1151 ts_setup = aes_docsis_setup; 1152 break; 1153 case BLKCIPHER_3DES_CHAIN_TYPE: 1154 n_test_cases = RTE_DIM(triple_des_chain_test_cases); 1155 blk_tcs = triple_des_chain_test_cases; 1156 ts_name = "3DES Chain"; 1157 ts_setup = triple_des_chain_setup; 1158 break; 1159 case BLKCIPHER_3DES_CIPHERONLY_TYPE: 1160 n_test_cases = RTE_DIM(triple_des_cipheronly_test_cases); 1161 blk_tcs = triple_des_cipheronly_test_cases; 1162 ts_name = "3DES Cipher Only"; 1163 ts_setup = triple_des_cipheronly_setup; 1164 break; 1165 case BLKCIPHER_DES_CIPHERONLY_TYPE: 1166 n_test_cases = RTE_DIM(des_cipheronly_test_cases); 1167 blk_tcs = des_cipheronly_test_cases; 1168 ts_name = "DES Cipher Only"; 1169 ts_setup = des_cipheronly_setup; 1170 break; 1171 case BLKCIPHER_DES_DOCSIS_TYPE: 1172 n_test_cases = RTE_DIM(des_docsis_test_cases); 1173 blk_tcs = des_docsis_test_cases; 1174 ts_name = "DES Docsis"; 1175 ts_setup = des_docsis_setup; 1176 break; 1177 case BLKCIPHER_AUTHONLY_TYPE: 1178 n_test_cases = RTE_DIM(hash_test_cases); 1179 blk_tcs = hash_test_cases; 1180 ts_name = "Auth Only"; 1181 ts_setup = authonly_setup; 1182 break; 1183 default: 1184 return NULL; 1185 } 1186 1187 ts = calloc(1, sizeof(struct unit_test_suite) + 1188 (sizeof(struct unit_test_case) * (n_test_cases + 1))); 1189 ts->suite_name = ts_name; 1190 ts->setup = ts_setup; 1191 1192 for (i = 0; i < n_test_cases; i++) { 1193 tc = &ts->unit_test_cases[i]; 1194 tc->name = blk_tcs[i].test_descr; 1195 tc->enabled = 1; 1196 tc->setup = ut_setup; 1197 tc->teardown = ut_teardown; 1198 tc->testcase = NULL; 1199 tc->testcase_with_data = blockcipher_test_case_run; 1200 tc->data = &blk_tcs[i]; 1201 } 1202 tc = &ts->unit_test_cases[i]; 1203 tc->name = NULL; 1204 tc->enabled = 0; 1205 tc->setup = NULL; 1206 tc->teardown = NULL; 1207 tc->testcase = NULL; 1208 tc->testcase_with_data = NULL; 1209 tc->data = NULL; 1210 1211 return ts; 1212 } 1213 1214 void 1215 free_blockcipher_test_suite(struct unit_test_suite *ts) 1216 { 1217 free(ts); 1218 } 1219