1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * * Neither the name of Intel Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <rte_common.h> 34 #include <rte_hexdump.h> 35 #include <rte_mbuf.h> 36 #include <rte_malloc.h> 37 #include <rte_memcpy.h> 38 39 #include <rte_crypto.h> 40 #include <rte_cryptodev.h> 41 #include <rte_cryptodev_pmd.h> 42 43 #include "test.h" 44 #include "test_cryptodev.h" 45 #include "test_cryptodev_blockcipher.h" 46 #include "test_cryptodev_aes_test_vectors.h" 47 #include "test_cryptodev_des_test_vectors.h" 48 #include "test_cryptodev_hash_test_vectors.h" 49 #include "test_cryptodev.h" 50 51 static int 52 test_blockcipher_one_case(const struct blockcipher_test_case *t, 53 struct rte_mempool *mbuf_pool, 54 struct rte_mempool *op_mpool, 55 uint8_t dev_id, 56 enum rte_cryptodev_type cryptodev_type, 57 char *test_msg) 58 { 59 struct rte_mbuf *ibuf = NULL; 60 struct rte_mbuf *obuf = NULL; 61 struct rte_mbuf *iobuf; 62 struct rte_crypto_sym_xform *cipher_xform = NULL; 63 struct rte_crypto_sym_xform *auth_xform = NULL; 64 struct rte_crypto_sym_xform *init_xform = NULL; 65 struct rte_crypto_sym_op *sym_op = NULL; 66 struct rte_crypto_op *op = NULL; 67 struct rte_cryptodev_sym_session *sess = NULL; 68 struct rte_cryptodev_info dev_info; 69 70 int status = TEST_SUCCESS; 71 const struct blockcipher_test_data *tdata = t->test_data; 72 uint8_t cipher_key[tdata->cipher_key.len]; 73 uint8_t auth_key[tdata->auth_key.len]; 74 uint32_t buf_len = tdata->ciphertext.len; 75 uint32_t digest_len = 0; 76 char *buf_p = NULL; 77 uint8_t src_pattern = 0xa5; 78 uint8_t dst_pattern = 0xb6; 79 uint8_t tmp_src_buf[MBUF_SIZE]; 80 uint8_t tmp_dst_buf[MBUF_SIZE]; 81 82 int nb_segs = 1; 83 84 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) { 85 rte_cryptodev_info_get(dev_id, &dev_info); 86 if (!(dev_info.feature_flags & 87 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { 88 printf("Device doesn't support scatter-gather. " 89 "Test Skipped.\n"); 90 return 0; 91 } 92 nb_segs = 3; 93 } 94 95 if (tdata->cipher_key.len) 96 memcpy(cipher_key, tdata->cipher_key.data, 97 tdata->cipher_key.len); 98 if (tdata->auth_key.len) 99 memcpy(auth_key, tdata->auth_key.data, 100 tdata->auth_key.len); 101 102 switch (cryptodev_type) { 103 case RTE_CRYPTODEV_QAT_SYM_PMD: 104 case RTE_CRYPTODEV_OPENSSL_PMD: 105 digest_len = tdata->digest.len; 106 break; 107 case RTE_CRYPTODEV_AESNI_MB_PMD: 108 digest_len = tdata->digest.truncated_len; 109 break; 110 default: 111 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 112 "line %u FAILED: %s", 113 __LINE__, "Unsupported PMD type"); 114 status = TEST_FAILED; 115 goto error_exit; 116 } 117 118 /* preparing data */ 119 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) 120 buf_len += tdata->iv.len; 121 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) 122 buf_len += digest_len; 123 124 /* for contiguous mbuf, nb_segs is 1 */ 125 ibuf = create_segmented_mbuf(mbuf_pool, 126 tdata->ciphertext.len, nb_segs, src_pattern); 127 if (ibuf == NULL) { 128 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 129 "line %u FAILED: %s", 130 __LINE__, "Cannot create source mbuf"); 131 status = TEST_FAILED; 132 goto error_exit; 133 } 134 135 /* only encryption requires plaintext.data input, 136 * decryption/(digest gen)/(digest verify) use ciphertext.data 137 * to be computed 138 */ 139 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) 140 pktmbuf_write(ibuf, 0, tdata->plaintext.len, 141 tdata->plaintext.data); 142 else 143 pktmbuf_write(ibuf, 0, tdata->ciphertext.len, 144 tdata->ciphertext.data); 145 146 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 147 rte_memcpy(rte_pktmbuf_prepend(ibuf, tdata->iv.len), 148 tdata->iv.data, tdata->iv.len); 149 } 150 buf_p = rte_pktmbuf_append(ibuf, digest_len); 151 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 152 rte_memcpy(buf_p, tdata->digest.data, digest_len); 153 else 154 memset(buf_p, 0, digest_len); 155 156 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 157 obuf = rte_pktmbuf_alloc(mbuf_pool); 158 if (!obuf) { 159 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 160 "FAILED: %s", __LINE__, 161 "Allocation of rte_mbuf failed"); 162 status = TEST_FAILED; 163 goto error_exit; 164 } 165 memset(obuf->buf_addr, dst_pattern, obuf->buf_len); 166 167 buf_p = rte_pktmbuf_append(obuf, buf_len); 168 if (!buf_p) { 169 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 170 "FAILED: %s", __LINE__, 171 "No room to append mbuf"); 172 status = TEST_FAILED; 173 goto error_exit; 174 } 175 memset(buf_p, 0, buf_len); 176 } 177 178 /* Generate Crypto op data structure */ 179 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC); 180 if (!op) { 181 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 182 "line %u FAILED: %s", 183 __LINE__, "Failed to allocate symmetric crypto " 184 "operation struct"); 185 status = TEST_FAILED; 186 goto error_exit; 187 } 188 189 sym_op = op->sym; 190 191 sym_op->m_src = ibuf; 192 193 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 194 sym_op->m_dst = obuf; 195 iobuf = obuf; 196 } else { 197 sym_op->m_dst = NULL; 198 iobuf = ibuf; 199 } 200 201 /* sessionless op requires allocate xform using 202 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc() 203 * is used 204 */ 205 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 206 uint32_t n_xforms = 0; 207 208 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) 209 n_xforms++; 210 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) 211 n_xforms++; 212 213 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms) 214 == NULL) { 215 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 216 "FAILED: %s", __LINE__, "Failed to " 217 "allocate space for crypto transforms"); 218 status = TEST_FAILED; 219 goto error_exit; 220 } 221 } else { 222 cipher_xform = rte_zmalloc(NULL, 223 sizeof(struct rte_crypto_sym_xform), 0); 224 225 auth_xform = rte_zmalloc(NULL, 226 sizeof(struct rte_crypto_sym_xform), 0); 227 228 if (!cipher_xform || !auth_xform) { 229 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 230 "FAILED: %s", __LINE__, "Failed to " 231 "allocate memory for crypto transforms"); 232 status = TEST_FAILED; 233 goto error_exit; 234 } 235 } 236 237 /* preparing xform, for sessioned op, init_xform is initialized 238 * here and later as param in rte_cryptodev_sym_session_create() call 239 */ 240 if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) { 241 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 242 cipher_xform = op->sym->xform; 243 auth_xform = cipher_xform->next; 244 auth_xform->next = NULL; 245 } else { 246 cipher_xform->next = auth_xform; 247 auth_xform->next = NULL; 248 init_xform = cipher_xform; 249 } 250 } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) { 251 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { 252 auth_xform = op->sym->xform; 253 cipher_xform = auth_xform->next; 254 cipher_xform->next = NULL; 255 } else { 256 auth_xform->next = cipher_xform; 257 cipher_xform->next = NULL; 258 init_xform = auth_xform; 259 } 260 } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) || 261 (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) { 262 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) 263 cipher_xform = op->sym->xform; 264 else 265 init_xform = cipher_xform; 266 cipher_xform->next = NULL; 267 } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) || 268 (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) { 269 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) 270 auth_xform = op->sym->xform; 271 else 272 init_xform = auth_xform; 273 auth_xform->next = NULL; 274 } else { 275 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 276 "line %u FAILED: %s", 277 __LINE__, "Unrecognized operation"); 278 status = TEST_FAILED; 279 goto error_exit; 280 } 281 282 /*configure xforms & sym_op cipher and auth data*/ 283 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 284 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; 285 cipher_xform->cipher.algo = tdata->crypto_algo; 286 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) 287 cipher_xform->cipher.op = 288 RTE_CRYPTO_CIPHER_OP_ENCRYPT; 289 else 290 cipher_xform->cipher.op = 291 RTE_CRYPTO_CIPHER_OP_DECRYPT; 292 cipher_xform->cipher.key.data = cipher_key; 293 cipher_xform->cipher.key.length = tdata->cipher_key.len; 294 295 sym_op->cipher.data.offset = tdata->iv.len; 296 sym_op->cipher.data.length = tdata->ciphertext.len; 297 sym_op->cipher.iv.data = rte_pktmbuf_mtod(sym_op->m_src, 298 uint8_t *); 299 sym_op->cipher.iv.length = tdata->iv.len; 300 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys( 301 sym_op->m_src); 302 } 303 304 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { 305 uint32_t auth_data_offset = 0; 306 uint32_t digest_offset = tdata->ciphertext.len; 307 308 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 309 digest_offset += tdata->iv.len; 310 auth_data_offset += tdata->iv.len; 311 } 312 313 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH; 314 auth_xform->auth.algo = tdata->auth_algo; 315 auth_xform->auth.key.length = tdata->auth_key.len; 316 auth_xform->auth.key.data = auth_key; 317 auth_xform->auth.digest_length = digest_len; 318 319 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { 320 auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 321 sym_op->auth.digest.data = pktmbuf_mtod_offset 322 (iobuf, digest_offset); 323 sym_op->auth.digest.phys_addr = 324 pktmbuf_mtophys_offset(iobuf, 325 digest_offset); 326 } else { 327 auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 328 sym_op->auth.digest.data = pktmbuf_mtod_offset 329 (sym_op->m_src, digest_offset); 330 sym_op->auth.digest.phys_addr = 331 pktmbuf_mtophys_offset(sym_op->m_src, 332 digest_offset); 333 } 334 335 sym_op->auth.data.offset = auth_data_offset; 336 sym_op->auth.data.length = tdata->ciphertext.len; 337 sym_op->auth.digest.length = digest_len; 338 } 339 340 /* create session for sessioned op */ 341 if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) { 342 sess = rte_cryptodev_sym_session_create(dev_id, 343 init_xform); 344 if (!sess) { 345 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 346 "FAILED: %s", __LINE__, 347 "Session creation failed"); 348 status = TEST_FAILED; 349 goto error_exit; 350 } 351 352 /* attach symmetric crypto session to crypto operations */ 353 rte_crypto_op_attach_sym_session(op, sess); 354 } 355 356 TEST_HEXDUMP(stdout, "m_src(before):", 357 sym_op->m_src->buf_addr, sym_op->m_src->buf_len); 358 rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr, 359 sym_op->m_src->buf_len); 360 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 361 TEST_HEXDUMP(stdout, "m_dst(before):", 362 sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); 363 rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr, 364 sym_op->m_dst->buf_len); 365 } 366 367 /* Process crypto operation */ 368 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 369 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 370 "line %u FAILED: %s", 371 __LINE__, "Error sending packet for encryption"); 372 status = TEST_FAILED; 373 goto error_exit; 374 } 375 376 op = NULL; 377 378 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 379 rte_pause(); 380 381 if (!op) { 382 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 383 "line %u FAILED: %s", 384 __LINE__, "Failed to process sym crypto op"); 385 status = TEST_FAILED; 386 goto error_exit; 387 } 388 389 TEST_HEXDUMP(stdout, "m_src(after):", 390 sym_op->m_src->buf_addr, sym_op->m_src->buf_len); 391 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) 392 TEST_HEXDUMP(stdout, "m_dst(after):", 393 sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); 394 395 /* Verify results */ 396 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 397 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 398 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 399 "FAILED: Digest verification failed " 400 "(0x%X)", __LINE__, op->status); 401 else 402 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 403 "FAILED: Digest verification failed " 404 "(0x%X)", __LINE__, op->status); 405 status = TEST_FAILED; 406 goto error_exit; 407 } 408 409 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 410 uint8_t buffer[2048]; 411 const uint8_t *compare_ref; 412 uint32_t compare_len; 413 414 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) { 415 compare_ref = tdata->ciphertext.data; 416 compare_len = tdata->ciphertext.len; 417 } else { 418 compare_ref = tdata->plaintext.data; 419 compare_len = tdata->plaintext.len; 420 } 421 422 if (memcmp(rte_pktmbuf_read(iobuf, tdata->iv.len, compare_len, 423 buffer), compare_ref, compare_len)) { 424 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 425 "FAILED: %s", __LINE__, 426 "Crypto data not as expected"); 427 status = TEST_FAILED; 428 goto error_exit; 429 } 430 } 431 432 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { 433 uint8_t *auth_res; 434 435 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) 436 auth_res = pktmbuf_mtod_offset(iobuf, 437 tdata->iv.len + tdata->ciphertext.len); 438 else 439 auth_res = pktmbuf_mtod_offset(iobuf, 440 tdata->ciphertext.len); 441 442 if (memcmp(auth_res, tdata->digest.data, digest_len)) { 443 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " 444 "FAILED: %s", __LINE__, "Generated " 445 "digest data not as expected"); 446 status = TEST_FAILED; 447 goto error_exit; 448 } 449 } 450 451 /* The only parts that should have changed in the buffer are 452 * plaintext/ciphertext and digest. 453 * In OOP only the dest buffer should change. 454 */ 455 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { 456 struct rte_mbuf *mbuf; 457 uint8_t value; 458 uint32_t head_unchanged_len = 0, changed_len = 0; 459 uint32_t i; 460 461 mbuf = sym_op->m_src; 462 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { 463 /* white-box test: PMDs use some of the 464 * tailroom as temp storage in verify case 465 */ 466 head_unchanged_len = rte_pktmbuf_headroom(mbuf) 467 + rte_pktmbuf_data_len(mbuf); 468 changed_len = digest_len; 469 } else { 470 head_unchanged_len = mbuf->buf_len; 471 changed_len = 0; 472 } 473 474 for (i = 0; i < mbuf->buf_len; i++) { 475 if (i == head_unchanged_len) 476 i += changed_len; 477 value = *((uint8_t *)(mbuf->buf_addr)+i); 478 if (value != tmp_src_buf[i]) { 479 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 480 "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)", 481 __LINE__, value, tmp_src_buf[i]); 482 status = TEST_FAILED; 483 goto error_exit; 484 } 485 } 486 487 mbuf = sym_op->m_dst; 488 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { 489 head_unchanged_len = rte_pktmbuf_headroom(mbuf) + 490 sym_op->auth.data.offset; 491 changed_len = sym_op->auth.data.length; 492 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) 493 changed_len += sym_op->auth.digest.length; 494 } else { 495 /* cipher-only */ 496 head_unchanged_len = rte_pktmbuf_headroom(mbuf) + 497 sym_op->cipher.data.offset; 498 changed_len = sym_op->cipher.data.length; 499 } 500 501 for (i = 0; i < mbuf->buf_len; i++) { 502 if (i == head_unchanged_len) 503 i += changed_len; 504 value = *((uint8_t *)(mbuf->buf_addr)+i); 505 if (value != tmp_dst_buf[i]) { 506 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 507 "line %u FAILED: OOP dst outer mbuf data " 508 "(0x%x) not as expected (0x%x)", 509 __LINE__, value, tmp_dst_buf[i]); 510 status = TEST_FAILED; 511 goto error_exit; 512 } 513 } 514 } else { 515 /* In-place operation */ 516 struct rte_mbuf *mbuf; 517 uint8_t value; 518 uint32_t head_unchanged_len = 0, changed_len = 0; 519 uint32_t i; 520 521 mbuf = sym_op->m_src; 522 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 523 head_unchanged_len = rte_pktmbuf_headroom(mbuf) + 524 sym_op->cipher.data.offset; 525 changed_len = sym_op->cipher.data.length; 526 } else { 527 /* auth-only */ 528 head_unchanged_len = rte_pktmbuf_headroom(mbuf) + 529 sym_op->auth.data.offset + 530 sym_op->auth.data.length; 531 changed_len = 0; 532 } 533 534 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) 535 changed_len += sym_op->auth.digest.length; 536 537 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { 538 /* white-box test: PMDs use some of the 539 * tailroom as temp storage in verify case 540 */ 541 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { 542 /* This is simplified, not checking digest*/ 543 changed_len += digest_len*2; 544 } else { 545 head_unchanged_len += digest_len; 546 changed_len += digest_len; 547 } 548 } 549 550 for (i = 0; i < mbuf->buf_len; i++) { 551 if (i == head_unchanged_len) 552 i += changed_len; 553 value = *((uint8_t *)(mbuf->buf_addr)+i); 554 if (value != tmp_src_buf[i]) { 555 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, 556 "line %u FAILED: outer mbuf data (0x%x) " 557 "not as expected (0x%x)", 558 __LINE__, value, tmp_src_buf[i]); 559 status = TEST_FAILED; 560 goto error_exit; 561 } 562 } 563 } 564 565 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS"); 566 567 error_exit: 568 if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) { 569 if (sess) 570 rte_cryptodev_sym_session_free(dev_id, sess); 571 if (cipher_xform) 572 rte_free(cipher_xform); 573 if (auth_xform) 574 rte_free(auth_xform); 575 } 576 577 if (op) 578 rte_crypto_op_free(op); 579 580 if (obuf) 581 rte_pktmbuf_free(obuf); 582 583 if (ibuf) 584 rte_pktmbuf_free(ibuf); 585 586 return status; 587 } 588 589 int 590 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool, 591 struct rte_mempool *op_mpool, 592 uint8_t dev_id, 593 enum rte_cryptodev_type cryptodev_type, 594 enum blockcipher_test_type test_type) 595 { 596 int status, overall_status = TEST_SUCCESS; 597 uint32_t i, test_index = 0; 598 char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1]; 599 uint32_t n_test_cases = 0; 600 uint32_t target_pmd_mask = 0; 601 const struct blockcipher_test_case *tcs = NULL; 602 603 switch (test_type) { 604 case BLKCIPHER_AES_CHAIN_TYPE: 605 n_test_cases = sizeof(aes_chain_test_cases) / 606 sizeof(aes_chain_test_cases[0]); 607 tcs = aes_chain_test_cases; 608 break; 609 case BLKCIPHER_AES_CIPHERONLY_TYPE: 610 n_test_cases = sizeof(aes_cipheronly_test_cases) / 611 sizeof(aes_cipheronly_test_cases[0]); 612 tcs = aes_cipheronly_test_cases; 613 break; 614 case BLKCIPHER_3DES_CHAIN_TYPE: 615 n_test_cases = sizeof(triple_des_chain_test_cases) / 616 sizeof(triple_des_chain_test_cases[0]); 617 tcs = triple_des_chain_test_cases; 618 break; 619 case BLKCIPHER_3DES_CIPHERONLY_TYPE: 620 n_test_cases = sizeof(triple_des_cipheronly_test_cases) / 621 sizeof(triple_des_cipheronly_test_cases[0]); 622 tcs = triple_des_cipheronly_test_cases; 623 break; 624 case BLKCIPHER_DES_CIPHERONLY_TYPE: 625 n_test_cases = sizeof(des_cipheronly_test_cases) / 626 sizeof(des_cipheronly_test_cases[0]); 627 tcs = des_cipheronly_test_cases; 628 break; 629 case BLKCIPHER_AUTHONLY_TYPE: 630 n_test_cases = sizeof(hash_test_cases) / 631 sizeof(hash_test_cases[0]); 632 tcs = hash_test_cases; 633 break; 634 default: 635 break; 636 } 637 638 switch (cryptodev_type) { 639 case RTE_CRYPTODEV_AESNI_MB_PMD: 640 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB; 641 break; 642 case RTE_CRYPTODEV_QAT_SYM_PMD: 643 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT; 644 break; 645 case RTE_CRYPTODEV_OPENSSL_PMD: 646 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL; 647 break; 648 default: 649 TEST_ASSERT(0, "Unrecognized cryptodev type"); 650 break; 651 } 652 653 for (i = 0; i < n_test_cases; i++) { 654 const struct blockcipher_test_case *tc = &tcs[i]; 655 656 if (!(tc->pmd_mask & target_pmd_mask)) 657 continue; 658 659 status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool, 660 dev_id, cryptodev_type, test_msg); 661 662 printf(" %u) TestCase %s %s\n", test_index ++, 663 tc->test_descr, test_msg); 664 665 if (status != TEST_SUCCESS) { 666 if (overall_status == TEST_SUCCESS) 667 overall_status = status; 668 669 if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER) 670 break; 671 } 672 } 673 674 return overall_status; 675 } 676