1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2015-2017 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 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 44 #include <rte_cryptodev_scheduler.h> 45 #include <rte_cryptodev_scheduler_operations.h> 46 #endif 47 48 #include "test.h" 49 #include "test_cryptodev.h" 50 51 #include "test_cryptodev_blockcipher.h" 52 #include "test_cryptodev_aes_test_vectors.h" 53 #include "test_cryptodev_des_test_vectors.h" 54 #include "test_cryptodev_hash_test_vectors.h" 55 #include "test_cryptodev_kasumi_test_vectors.h" 56 #include "test_cryptodev_kasumi_hash_test_vectors.h" 57 #include "test_cryptodev_snow3g_test_vectors.h" 58 #include "test_cryptodev_snow3g_hash_test_vectors.h" 59 #include "test_cryptodev_zuc_test_vectors.h" 60 #include "test_cryptodev_zuc_hash_test_vectors.h" 61 #include "test_cryptodev_gcm_test_vectors.h" 62 #include "test_cryptodev_hmac_test_vectors.h" 63 64 static enum rte_cryptodev_type gbl_cryptodev_type; 65 66 struct crypto_testsuite_params { 67 struct rte_mempool *mbuf_pool; 68 struct rte_mempool *large_mbuf_pool; 69 struct rte_mempool *op_mpool; 70 struct rte_cryptodev_config conf; 71 struct rte_cryptodev_qp_conf qp_conf; 72 73 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 74 uint8_t valid_dev_count; 75 }; 76 77 struct crypto_unittest_params { 78 struct rte_crypto_sym_xform cipher_xform; 79 struct rte_crypto_sym_xform auth_xform; 80 81 struct rte_cryptodev_sym_session *sess; 82 83 struct rte_crypto_op *op; 84 85 struct rte_mbuf *obuf, *ibuf; 86 87 uint8_t *digest; 88 }; 89 90 #define ALIGN_POW2_ROUNDUP(num, align) \ 91 (((num) + (align) - 1) & ~((align) - 1)) 92 93 /* 94 * Forward declarations. 95 */ 96 static int 97 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 98 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 99 uint8_t *hmac_key); 100 101 static int 102 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 103 struct crypto_unittest_params *ut_params, 104 struct crypto_testsuite_params *ts_param, 105 const uint8_t *cipher, 106 const uint8_t *digest, 107 const uint8_t *iv); 108 109 static struct rte_mbuf * 110 setup_test_string(struct rte_mempool *mpool, 111 const char *string, size_t len, uint8_t blocksize) 112 { 113 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 114 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 115 116 memset(m->buf_addr, 0, m->buf_len); 117 if (m) { 118 char *dst = rte_pktmbuf_append(m, t_len); 119 120 if (!dst) { 121 rte_pktmbuf_free(m); 122 return NULL; 123 } 124 if (string != NULL) 125 rte_memcpy(dst, string, t_len); 126 else 127 memset(dst, 0, t_len); 128 } 129 130 return m; 131 } 132 133 /* Get number of bytes in X bits (rounding up) */ 134 static uint32_t 135 ceil_byte_length(uint32_t num_bits) 136 { 137 if (num_bits % 8) 138 return ((num_bits >> 3) + 1); 139 else 140 return (num_bits >> 3); 141 } 142 143 static struct rte_crypto_op * 144 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 145 { 146 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 147 printf("Error sending packet for encryption"); 148 return NULL; 149 } 150 151 op = NULL; 152 153 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 154 rte_pause(); 155 156 return op; 157 } 158 159 static struct crypto_testsuite_params testsuite_params = { NULL }; 160 static struct crypto_unittest_params unittest_params; 161 162 static int 163 testsuite_setup(void) 164 { 165 struct crypto_testsuite_params *ts_params = &testsuite_params; 166 struct rte_cryptodev_info info; 167 uint32_t i = 0, nb_devs, dev_id; 168 int ret; 169 uint16_t qp_id; 170 171 memset(ts_params, 0, sizeof(*ts_params)); 172 173 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 174 if (ts_params->mbuf_pool == NULL) { 175 /* Not already created so create */ 176 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 177 "CRYPTO_MBUFPOOL", 178 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 179 rte_socket_id()); 180 if (ts_params->mbuf_pool == NULL) { 181 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 182 return TEST_FAILED; 183 } 184 } 185 186 ts_params->large_mbuf_pool = rte_mempool_lookup( 187 "CRYPTO_LARGE_MBUFPOOL"); 188 if (ts_params->large_mbuf_pool == NULL) { 189 /* Not already created so create */ 190 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 191 "CRYPTO_LARGE_MBUFPOOL", 192 1, 0, 0, UINT16_MAX, 193 rte_socket_id()); 194 if (ts_params->large_mbuf_pool == NULL) { 195 RTE_LOG(ERR, USER1, 196 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 197 return TEST_FAILED; 198 } 199 } 200 201 ts_params->op_mpool = rte_crypto_op_pool_create( 202 "MBUF_CRYPTO_SYM_OP_POOL", 203 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 204 NUM_MBUFS, MBUF_CACHE_SIZE, 205 DEFAULT_NUM_XFORMS * 206 sizeof(struct rte_crypto_sym_xform), 207 rte_socket_id()); 208 if (ts_params->op_mpool == NULL) { 209 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 210 return TEST_FAILED; 211 } 212 213 /* Create 2 AESNI MB devices if required */ 214 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) { 215 #ifndef RTE_LIBRTE_PMD_AESNI_MB 216 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be" 217 " enabled in config file to run this testsuite.\n"); 218 return TEST_FAILED; 219 #endif 220 nb_devs = rte_cryptodev_count_devtype( 221 RTE_CRYPTODEV_AESNI_MB_PMD); 222 if (nb_devs < 2) { 223 for (i = nb_devs; i < 2; i++) { 224 ret = rte_eal_vdev_init( 225 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 226 227 TEST_ASSERT(ret == 0, 228 "Failed to create instance %u of" 229 " pmd : %s", 230 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 231 } 232 } 233 } 234 235 /* Create 2 AESNI GCM devices if required */ 236 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) { 237 #ifndef RTE_LIBRTE_PMD_AESNI_GCM 238 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be" 239 " enabled in config file to run this testsuite.\n"); 240 return TEST_FAILED; 241 #endif 242 nb_devs = rte_cryptodev_count_devtype( 243 RTE_CRYPTODEV_AESNI_GCM_PMD); 244 if (nb_devs < 2) { 245 for (i = nb_devs; i < 2; i++) { 246 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 247 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 248 "Failed to create instance %u of" 249 " pmd : %s", 250 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 251 } 252 } 253 } 254 255 /* Create 2 SNOW 3G devices if required */ 256 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) { 257 #ifndef RTE_LIBRTE_PMD_SNOW3G 258 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be" 259 " enabled in config file to run this testsuite.\n"); 260 return TEST_FAILED; 261 #endif 262 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD); 263 if (nb_devs < 2) { 264 for (i = nb_devs; i < 2; i++) { 265 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 266 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 267 "Failed to create instance %u of" 268 " pmd : %s", 269 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 270 } 271 } 272 } 273 274 /* Create 2 KASUMI devices if required */ 275 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) { 276 #ifndef RTE_LIBRTE_PMD_KASUMI 277 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be" 278 " enabled in config file to run this testsuite.\n"); 279 return TEST_FAILED; 280 #endif 281 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD); 282 if (nb_devs < 2) { 283 for (i = nb_devs; i < 2; i++) { 284 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 285 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 286 "Failed to create instance %u of" 287 " pmd : %s", 288 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 289 } 290 } 291 } 292 293 /* Create 2 ZUC devices if required */ 294 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) { 295 #ifndef RTE_LIBRTE_PMD_ZUC 296 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be" 297 " enabled in config file to run this testsuite.\n"); 298 return TEST_FAILED; 299 #endif 300 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD); 301 if (nb_devs < 2) { 302 for (i = nb_devs; i < 2; i++) { 303 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 304 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 305 "Failed to create instance %u of" 306 " pmd : %s", 307 i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 308 } 309 } 310 } 311 312 /* Create 2 NULL devices if required */ 313 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) { 314 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO 315 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be" 316 " enabled in config file to run this testsuite.\n"); 317 return TEST_FAILED; 318 #endif 319 nb_devs = rte_cryptodev_count_devtype( 320 RTE_CRYPTODEV_NULL_PMD); 321 if (nb_devs < 2) { 322 for (i = nb_devs; i < 2; i++) { 323 int dev_id = rte_eal_vdev_init( 324 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 325 326 TEST_ASSERT(dev_id >= 0, 327 "Failed to create instance %u of" 328 " pmd : %s", 329 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 330 } 331 } 332 } 333 334 /* Create 2 OPENSSL devices if required */ 335 if (gbl_cryptodev_type == RTE_CRYPTODEV_OPENSSL_PMD) { 336 #ifndef RTE_LIBRTE_PMD_OPENSSL 337 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_OPENSSL must be" 338 " enabled in config file to run this testsuite.\n"); 339 return TEST_FAILED; 340 #endif 341 nb_devs = rte_cryptodev_count_devtype( 342 RTE_CRYPTODEV_OPENSSL_PMD); 343 if (nb_devs < 2) { 344 for (i = nb_devs; i < 2; i++) { 345 ret = rte_eal_vdev_init( 346 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 347 NULL); 348 349 TEST_ASSERT(ret == 0, "Failed to create " 350 "instance %u of pmd : %s", i, 351 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 352 } 353 } 354 } 355 356 /* Create 2 ARMv8 devices if required */ 357 if (gbl_cryptodev_type == RTE_CRYPTODEV_ARMV8_PMD) { 358 #ifndef RTE_LIBRTE_PMD_ARMV8_CRYPTO 359 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO must be" 360 " enabled in config file to run this testsuite.\n"); 361 return TEST_FAILED; 362 #endif 363 nb_devs = rte_cryptodev_count_devtype( 364 RTE_CRYPTODEV_ARMV8_PMD); 365 if (nb_devs < 2) { 366 for (i = nb_devs; i < 2; i++) { 367 ret = rte_eal_vdev_init( 368 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 369 NULL); 370 371 TEST_ASSERT(ret == 0, "Failed to create " 372 "instance %u of pmd : %s", i, 373 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 374 } 375 } 376 } 377 378 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 379 if (gbl_cryptodev_type == RTE_CRYPTODEV_SCHEDULER_PMD) { 380 381 #ifndef RTE_LIBRTE_PMD_AESNI_MB 382 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be" 383 " enabled in config file to run this testsuite.\n"); 384 return TEST_FAILED; 385 #endif 386 nb_devs = rte_cryptodev_count_devtype( 387 RTE_CRYPTODEV_SCHEDULER_PMD); 388 if (nb_devs < 1) { 389 ret = rte_eal_vdev_init( 390 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 391 NULL); 392 393 TEST_ASSERT(ret == 0, 394 "Failed to create instance %u of" 395 " pmd : %s", 396 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 397 } 398 } 399 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */ 400 401 #ifndef RTE_LIBRTE_PMD_QAT 402 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) { 403 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled " 404 "in config file to run this testsuite.\n"); 405 return TEST_FAILED; 406 } 407 #endif 408 409 nb_devs = rte_cryptodev_count(); 410 if (nb_devs < 1) { 411 RTE_LOG(ERR, USER1, "No crypto devices found?\n"); 412 return TEST_FAILED; 413 } 414 415 /* Create list of valid crypto devs */ 416 for (i = 0; i < nb_devs; i++) { 417 rte_cryptodev_info_get(i, &info); 418 if (info.dev_type == gbl_cryptodev_type) 419 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 420 } 421 422 if (ts_params->valid_dev_count < 1) 423 return TEST_FAILED; 424 425 /* Set up all the qps on the first of the valid devices found */ 426 427 dev_id = ts_params->valid_devs[0]; 428 429 rte_cryptodev_info_get(dev_id, &info); 430 431 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 432 ts_params->conf.socket_id = SOCKET_ID_ANY; 433 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions; 434 435 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 436 &ts_params->conf), 437 "Failed to configure cryptodev %u with %u qps", 438 dev_id, ts_params->conf.nb_queue_pairs); 439 440 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 441 442 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 443 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 444 dev_id, qp_id, &ts_params->qp_conf, 445 rte_cryptodev_socket_id(dev_id)), 446 "Failed to setup queue pair %u on cryptodev %u", 447 qp_id, dev_id); 448 } 449 450 return TEST_SUCCESS; 451 } 452 453 static void 454 testsuite_teardown(void) 455 { 456 struct crypto_testsuite_params *ts_params = &testsuite_params; 457 458 if (ts_params->mbuf_pool != NULL) { 459 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 460 rte_mempool_avail_count(ts_params->mbuf_pool)); 461 } 462 463 if (ts_params->op_mpool != NULL) { 464 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 465 rte_mempool_avail_count(ts_params->op_mpool)); 466 } 467 468 } 469 470 static int 471 ut_setup(void) 472 { 473 struct crypto_testsuite_params *ts_params = &testsuite_params; 474 struct crypto_unittest_params *ut_params = &unittest_params; 475 476 uint16_t qp_id; 477 478 /* Clear unit test parameters before running test */ 479 memset(ut_params, 0, sizeof(*ut_params)); 480 481 /* Reconfigure device to default parameters */ 482 ts_params->conf.socket_id = SOCKET_ID_ANY; 483 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT; 484 485 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 486 &ts_params->conf), 487 "Failed to configure cryptodev %u", 488 ts_params->valid_devs[0]); 489 490 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 491 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 492 ts_params->valid_devs[0], qp_id, 493 &ts_params->qp_conf, 494 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 495 "Failed to setup queue pair %u on cryptodev %u", 496 qp_id, ts_params->valid_devs[0]); 497 } 498 499 500 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 501 502 /* Start the device */ 503 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 504 "Failed to start cryptodev %u", 505 ts_params->valid_devs[0]); 506 507 return TEST_SUCCESS; 508 } 509 510 static void 511 ut_teardown(void) 512 { 513 struct crypto_testsuite_params *ts_params = &testsuite_params; 514 struct crypto_unittest_params *ut_params = &unittest_params; 515 struct rte_cryptodev_stats stats; 516 517 /* free crypto session structure */ 518 if (ut_params->sess) { 519 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 520 ut_params->sess); 521 ut_params->sess = NULL; 522 } 523 524 /* free crypto operation structure */ 525 if (ut_params->op) 526 rte_crypto_op_free(ut_params->op); 527 528 /* 529 * free mbuf - both obuf and ibuf are usually the same, 530 * so check if they point at the same address is necessary, 531 * to avoid freeing the mbuf twice. 532 */ 533 if (ut_params->obuf) { 534 rte_pktmbuf_free(ut_params->obuf); 535 if (ut_params->ibuf == ut_params->obuf) 536 ut_params->ibuf = 0; 537 ut_params->obuf = 0; 538 } 539 if (ut_params->ibuf) { 540 rte_pktmbuf_free(ut_params->ibuf); 541 ut_params->ibuf = 0; 542 } 543 544 if (ts_params->mbuf_pool != NULL) 545 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 546 rte_mempool_avail_count(ts_params->mbuf_pool)); 547 548 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 549 550 /* Stop the device */ 551 rte_cryptodev_stop(ts_params->valid_devs[0]); 552 } 553 554 static int 555 test_device_configure_invalid_dev_id(void) 556 { 557 struct crypto_testsuite_params *ts_params = &testsuite_params; 558 uint16_t dev_id, num_devs = 0; 559 560 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 561 "Need at least %d devices for test", 1); 562 563 /* valid dev_id values */ 564 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1]; 565 566 /* Stop the device in case it's started so it can be configured */ 567 rte_cryptodev_stop(ts_params->valid_devs[dev_id]); 568 569 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 570 "Failed test for rte_cryptodev_configure: " 571 "invalid dev_num %u", dev_id); 572 573 /* invalid dev_id values */ 574 dev_id = num_devs; 575 576 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 577 "Failed test for rte_cryptodev_configure: " 578 "invalid dev_num %u", dev_id); 579 580 dev_id = 0xff; 581 582 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 583 "Failed test for rte_cryptodev_configure:" 584 "invalid dev_num %u", dev_id); 585 586 return TEST_SUCCESS; 587 } 588 589 static int 590 test_device_configure_invalid_queue_pair_ids(void) 591 { 592 struct crypto_testsuite_params *ts_params = &testsuite_params; 593 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 594 595 /* Stop the device in case it's started so it can be configured */ 596 rte_cryptodev_stop(ts_params->valid_devs[0]); 597 598 /* valid - one queue pairs */ 599 ts_params->conf.nb_queue_pairs = 1; 600 601 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 602 &ts_params->conf), 603 "Failed to configure cryptodev: dev_id %u, qp_id %u", 604 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 605 606 607 /* valid - max value queue pairs */ 608 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE; 609 610 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 611 &ts_params->conf), 612 "Failed to configure cryptodev: dev_id %u, qp_id %u", 613 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 614 615 616 /* invalid - zero queue pairs */ 617 ts_params->conf.nb_queue_pairs = 0; 618 619 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 620 &ts_params->conf), 621 "Failed test for rte_cryptodev_configure, dev_id %u," 622 " invalid qps: %u", 623 ts_params->valid_devs[0], 624 ts_params->conf.nb_queue_pairs); 625 626 627 /* invalid - max value supported by field queue pairs */ 628 ts_params->conf.nb_queue_pairs = UINT16_MAX; 629 630 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 631 &ts_params->conf), 632 "Failed test for rte_cryptodev_configure, dev_id %u," 633 " invalid qps: %u", 634 ts_params->valid_devs[0], 635 ts_params->conf.nb_queue_pairs); 636 637 638 /* invalid - max value + 1 queue pairs */ 639 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1; 640 641 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 642 &ts_params->conf), 643 "Failed test for rte_cryptodev_configure, dev_id %u," 644 " invalid qps: %u", 645 ts_params->valid_devs[0], 646 ts_params->conf.nb_queue_pairs); 647 648 /* revert to original testsuite value */ 649 ts_params->conf.nb_queue_pairs = orig_nb_qps; 650 651 return TEST_SUCCESS; 652 } 653 654 static int 655 test_queue_pair_descriptor_setup(void) 656 { 657 struct crypto_testsuite_params *ts_params = &testsuite_params; 658 struct rte_cryptodev_info dev_info; 659 struct rte_cryptodev_qp_conf qp_conf = { 660 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 661 }; 662 663 uint16_t qp_id; 664 665 /* Stop the device in case it's started so it can be configured */ 666 rte_cryptodev_stop(ts_params->valid_devs[0]); 667 668 669 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 670 671 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions; 672 673 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 674 &ts_params->conf), "Failed to configure cryptodev %u", 675 ts_params->valid_devs[0]); 676 677 678 /* 679 * Test various ring sizes on this device. memzones can't be 680 * freed so are re-used if ring is released and re-created. 681 */ 682 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 683 684 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 685 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 686 ts_params->valid_devs[0], qp_id, &qp_conf, 687 rte_cryptodev_socket_id( 688 ts_params->valid_devs[0])), 689 "Failed test for " 690 "rte_cryptodev_queue_pair_setup: num_inflights " 691 "%u on qp %u on cryptodev %u", 692 qp_conf.nb_descriptors, qp_id, 693 ts_params->valid_devs[0]); 694 } 695 696 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 697 698 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 699 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 700 ts_params->valid_devs[0], qp_id, &qp_conf, 701 rte_cryptodev_socket_id( 702 ts_params->valid_devs[0])), 703 "Failed test for" 704 " rte_cryptodev_queue_pair_setup: num_inflights" 705 " %u on qp %u on cryptodev %u", 706 qp_conf.nb_descriptors, qp_id, 707 ts_params->valid_devs[0]); 708 } 709 710 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 711 712 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 713 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 714 ts_params->valid_devs[0], qp_id, &qp_conf, 715 rte_cryptodev_socket_id( 716 ts_params->valid_devs[0])), 717 "Failed test for " 718 "rte_cryptodev_queue_pair_setup: num_inflights" 719 " %u on qp %u on cryptodev %u", 720 qp_conf.nb_descriptors, qp_id, 721 ts_params->valid_devs[0]); 722 } 723 724 /* invalid number of descriptors - max supported + 2 */ 725 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2; 726 727 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 728 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 729 ts_params->valid_devs[0], qp_id, &qp_conf, 730 rte_cryptodev_socket_id( 731 ts_params->valid_devs[0])), 732 "Unexpectedly passed test for " 733 "rte_cryptodev_queue_pair_setup:" 734 "num_inflights %u on qp %u on cryptodev %u", 735 qp_conf.nb_descriptors, qp_id, 736 ts_params->valid_devs[0]); 737 } 738 739 /* invalid number of descriptors - max value of parameter */ 740 qp_conf.nb_descriptors = UINT32_MAX-1; 741 742 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 743 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 744 ts_params->valid_devs[0], qp_id, &qp_conf, 745 rte_cryptodev_socket_id( 746 ts_params->valid_devs[0])), 747 "Unexpectedly passed test for " 748 "rte_cryptodev_queue_pair_setup:" 749 "num_inflights %u on qp %u on cryptodev %u", 750 qp_conf.nb_descriptors, qp_id, 751 ts_params->valid_devs[0]); 752 } 753 754 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 755 756 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 757 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 758 ts_params->valid_devs[0], qp_id, &qp_conf, 759 rte_cryptodev_socket_id( 760 ts_params->valid_devs[0])), 761 "Failed test for" 762 " rte_cryptodev_queue_pair_setup:" 763 "num_inflights %u on qp %u on cryptodev %u", 764 qp_conf.nb_descriptors, qp_id, 765 ts_params->valid_devs[0]); 766 } 767 768 /* invalid number of descriptors - max supported + 1 */ 769 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1; 770 771 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 772 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 773 ts_params->valid_devs[0], qp_id, &qp_conf, 774 rte_cryptodev_socket_id( 775 ts_params->valid_devs[0])), 776 "Unexpectedly passed test for " 777 "rte_cryptodev_queue_pair_setup:" 778 "num_inflights %u on qp %u on cryptodev %u", 779 qp_conf.nb_descriptors, qp_id, 780 ts_params->valid_devs[0]); 781 } 782 783 /* test invalid queue pair id */ 784 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 785 786 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */ 787 788 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 789 ts_params->valid_devs[0], 790 qp_id, &qp_conf, 791 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 792 "Failed test for rte_cryptodev_queue_pair_setup:" 793 "invalid qp %u on cryptodev %u", 794 qp_id, ts_params->valid_devs[0]); 795 796 qp_id = 0xffff; /*invalid*/ 797 798 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 799 ts_params->valid_devs[0], 800 qp_id, &qp_conf, 801 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 802 "Failed test for rte_cryptodev_queue_pair_setup:" 803 "invalid qp %u on cryptodev %u", 804 qp_id, ts_params->valid_devs[0]); 805 806 return TEST_SUCCESS; 807 } 808 809 /* ***** Plaintext data for tests ***** */ 810 811 const char catch_22_quote_1[] = 812 "There was only one catch and that was Catch-22, which " 813 "specified that a concern for one's safety in the face of " 814 "dangers that were real and immediate was the process of a " 815 "rational mind. Orr was crazy and could be grounded. All he " 816 "had to do was ask; and as soon as he did, he would no longer " 817 "be crazy and would have to fly more missions. Orr would be " 818 "crazy to fly more missions and sane if he didn't, but if he " 819 "was sane he had to fly them. If he flew them he was crazy " 820 "and didn't have to; but if he didn't want to he was sane and " 821 "had to. Yossarian was moved very deeply by the absolute " 822 "simplicity of this clause of Catch-22 and let out a " 823 "respectful whistle. \"That's some catch, that Catch-22\", he " 824 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 825 826 const char catch_22_quote[] = 827 "What a lousy earth! He wondered how many people were " 828 "destitute that same night even in his own prosperous country, " 829 "how many homes were shanties, how many husbands were drunk " 830 "and wives socked, and how many children were bullied, abused, " 831 "or abandoned. How many families hungered for food they could " 832 "not afford to buy? How many hearts were broken? How many " 833 "suicides would take place that same night, how many people " 834 "would go insane? How many cockroaches and landlords would " 835 "triumph? How many winners were losers, successes failures, " 836 "and rich men poor men? How many wise guys were stupid? How " 837 "many happy endings were unhappy endings? How many honest men " 838 "were liars, brave men cowards, loyal men traitors, how many " 839 "sainted men were corrupt, how many people in positions of " 840 "trust had sold their souls to bodyguards, how many had never " 841 "had souls? How many straight-and-narrow paths were crooked " 842 "paths? How many best families were worst families and how " 843 "many good people were bad people? When you added them all up " 844 "and then subtracted, you might be left with only the children, " 845 "and perhaps with Albert Einstein and an old violinist or " 846 "sculptor somewhere."; 847 848 #define QUOTE_480_BYTES (480) 849 #define QUOTE_512_BYTES (512) 850 #define QUOTE_768_BYTES (768) 851 #define QUOTE_1024_BYTES (1024) 852 853 854 855 /* ***** SHA1 Hash Tests ***** */ 856 857 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 858 859 static uint8_t hmac_sha1_key[] = { 860 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 861 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 862 0xDE, 0xF4, 0xDE, 0xAD }; 863 864 /* ***** SHA224 Hash Tests ***** */ 865 866 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 867 868 869 /* ***** AES-CBC Cipher Tests ***** */ 870 871 #define CIPHER_KEY_LENGTH_AES_CBC (16) 872 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 873 874 static uint8_t aes_cbc_key[] = { 875 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 876 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 877 878 static uint8_t aes_cbc_iv[] = { 879 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 880 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 881 882 883 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 884 885 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 886 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 887 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 888 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 889 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 890 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 891 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 892 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 893 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 894 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 895 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 896 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 897 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 898 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 899 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 900 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 901 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 902 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 903 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 904 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 905 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 906 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 907 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 908 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 909 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 910 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 911 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 912 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 913 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 914 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 915 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 916 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 917 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 918 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 919 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 920 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 921 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 922 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 923 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 924 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 925 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 926 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 927 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 928 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 929 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 930 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 931 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 932 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 933 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 934 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 935 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 936 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 937 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 938 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 939 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 940 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 941 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 942 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 943 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 944 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 945 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 946 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 947 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 948 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 949 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 950 }; 951 952 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 953 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 954 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 955 0x18, 0x8c, 0x1d, 0x32 956 }; 957 958 959 /* Multisession Vector context Test */ 960 /*Begin Session 0 */ 961 static uint8_t ms_aes_cbc_key0[] = { 962 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 963 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 964 }; 965 966 static uint8_t ms_aes_cbc_iv0[] = { 967 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 968 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 969 }; 970 971 static const uint8_t ms_aes_cbc_cipher0[] = { 972 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 973 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 974 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 975 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 976 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 977 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 978 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 979 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 980 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 981 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 982 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 983 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 984 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 985 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 986 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 987 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 988 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 989 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 990 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 991 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 992 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 993 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 994 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 995 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 996 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 997 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 998 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 999 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1000 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1001 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1002 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1003 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1004 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1005 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1006 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1007 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1008 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1009 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1010 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1011 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1012 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1013 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1014 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1015 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1016 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1017 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1018 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1019 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1020 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1021 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1022 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1023 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1024 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1025 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1026 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1027 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1028 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1029 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1030 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1031 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1032 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1033 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1034 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1035 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1036 }; 1037 1038 1039 static uint8_t ms_hmac_key0[] = { 1040 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1041 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1042 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1043 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1044 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1045 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1046 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1047 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1048 }; 1049 1050 static const uint8_t ms_hmac_digest0[] = { 1051 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1052 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1053 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1054 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1055 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1056 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1057 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1058 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1059 }; 1060 1061 /* End Session 0 */ 1062 /* Begin session 1 */ 1063 1064 static uint8_t ms_aes_cbc_key1[] = { 1065 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1066 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1067 }; 1068 1069 static uint8_t ms_aes_cbc_iv1[] = { 1070 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1071 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1072 }; 1073 1074 static const uint8_t ms_aes_cbc_cipher1[] = { 1075 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1076 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1077 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1078 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1079 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1080 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1081 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1082 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1083 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1084 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1085 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1086 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1087 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1088 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1089 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1090 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1091 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1092 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1093 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1094 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1095 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1096 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1097 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1098 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1099 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1100 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1101 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1102 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1103 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1104 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1105 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1106 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1107 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1108 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1109 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1110 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1111 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1112 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1113 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1114 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1115 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1116 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1117 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1118 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1119 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1120 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1121 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1122 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1123 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1124 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1125 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1126 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1127 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1128 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1129 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1130 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1131 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1132 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1133 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1134 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1135 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1136 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1137 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1138 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1139 1140 }; 1141 1142 static uint8_t ms_hmac_key1[] = { 1143 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1144 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1145 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1146 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1147 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1148 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1149 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1150 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1151 }; 1152 1153 static const uint8_t ms_hmac_digest1[] = { 1154 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1155 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1156 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1157 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1158 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1159 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1160 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1161 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1162 }; 1163 /* End Session 1 */ 1164 /* Begin Session 2 */ 1165 static uint8_t ms_aes_cbc_key2[] = { 1166 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1167 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1168 }; 1169 1170 static uint8_t ms_aes_cbc_iv2[] = { 1171 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1172 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1173 }; 1174 1175 static const uint8_t ms_aes_cbc_cipher2[] = { 1176 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1177 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1178 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1179 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1180 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1181 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1182 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1183 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1184 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1185 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1186 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1187 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1188 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1189 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1190 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1191 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1192 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1193 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1194 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1195 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1196 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1197 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1198 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1199 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1200 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1201 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1202 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1203 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1204 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1205 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1206 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1207 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1208 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1209 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1210 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1211 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1212 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1213 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1214 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1215 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1216 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1217 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1218 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1219 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1220 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1221 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1222 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1223 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1224 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1225 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1226 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1227 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1228 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1229 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1230 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1231 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1232 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1233 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1234 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1235 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1236 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1237 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1238 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1239 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1240 }; 1241 1242 static uint8_t ms_hmac_key2[] = { 1243 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1244 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1245 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1246 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1247 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1248 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1249 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1250 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1251 }; 1252 1253 static const uint8_t ms_hmac_digest2[] = { 1254 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1255 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1256 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1257 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1258 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1259 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1260 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1261 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1262 }; 1263 1264 /* End Session 2 */ 1265 1266 1267 static int 1268 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1269 { 1270 struct crypto_testsuite_params *ts_params = &testsuite_params; 1271 struct crypto_unittest_params *ut_params = &unittest_params; 1272 1273 /* Generate test mbuf data and space for digest */ 1274 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1275 catch_22_quote, QUOTE_512_BYTES, 0); 1276 1277 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1278 DIGEST_BYTE_LENGTH_SHA1); 1279 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1280 1281 /* Setup Cipher Parameters */ 1282 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1283 ut_params->cipher_xform.next = &ut_params->auth_xform; 1284 1285 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1286 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1287 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1288 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1289 1290 /* Setup HMAC Parameters */ 1291 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1292 1293 ut_params->auth_xform.next = NULL; 1294 1295 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1296 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1297 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1298 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1299 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1300 1301 /* Create crypto session*/ 1302 ut_params->sess = rte_cryptodev_sym_session_create( 1303 ts_params->valid_devs[0], 1304 &ut_params->cipher_xform); 1305 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1306 1307 /* Generate crypto op data structure */ 1308 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1309 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1310 TEST_ASSERT_NOT_NULL(ut_params->op, 1311 "Failed to allocate symmetric crypto operation struct"); 1312 1313 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1314 1315 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1316 1317 /* set crypto operation source mbuf */ 1318 sym_op->m_src = ut_params->ibuf; 1319 1320 /* Set crypto operation authentication parameters */ 1321 sym_op->auth.digest.data = ut_params->digest; 1322 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1323 ut_params->ibuf, QUOTE_512_BYTES); 1324 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1; 1325 1326 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1327 sym_op->auth.data.length = QUOTE_512_BYTES; 1328 1329 /* Set crypto operation cipher parameters */ 1330 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf, 1331 CIPHER_IV_LENGTH_AES_CBC); 1332 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1333 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1334 1335 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv, 1336 CIPHER_IV_LENGTH_AES_CBC); 1337 1338 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1339 sym_op->cipher.data.length = QUOTE_512_BYTES; 1340 1341 /* Process crypto operation */ 1342 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 1343 ut_params->op), "failed to process sym crypto op"); 1344 1345 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1346 "crypto op processing failed"); 1347 1348 /* Validate obuf */ 1349 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 1350 uint8_t *, CIPHER_IV_LENGTH_AES_CBC); 1351 1352 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1353 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1354 QUOTE_512_BYTES, 1355 "ciphertext data not as expected"); 1356 1357 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1358 1359 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1360 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1361 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ? 1362 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1363 DIGEST_BYTE_LENGTH_SHA1, 1364 "Generated digest data not as expected"); 1365 1366 return TEST_SUCCESS; 1367 } 1368 1369 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1370 1371 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1372 1373 static uint8_t hmac_sha512_key[] = { 1374 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1375 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1376 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1377 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1378 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1379 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1380 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1381 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1382 1383 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1384 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1385 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1386 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1387 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1388 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1389 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1390 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1391 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1392 1393 1394 1395 static int 1396 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1397 struct crypto_unittest_params *ut_params, 1398 uint8_t *cipher_key, 1399 uint8_t *hmac_key); 1400 1401 static int 1402 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1403 struct crypto_unittest_params *ut_params, 1404 struct crypto_testsuite_params *ts_params, 1405 const uint8_t *cipher, 1406 const uint8_t *digest, 1407 const uint8_t *iv); 1408 1409 1410 static int 1411 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1412 struct crypto_unittest_params *ut_params, 1413 uint8_t *cipher_key, 1414 uint8_t *hmac_key) 1415 { 1416 1417 /* Setup Cipher Parameters */ 1418 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1419 ut_params->cipher_xform.next = NULL; 1420 1421 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1422 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1423 ut_params->cipher_xform.cipher.key.data = cipher_key; 1424 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1425 1426 /* Setup HMAC Parameters */ 1427 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1428 ut_params->auth_xform.next = &ut_params->cipher_xform; 1429 1430 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1431 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1432 ut_params->auth_xform.auth.key.data = hmac_key; 1433 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1434 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1435 1436 return TEST_SUCCESS; 1437 } 1438 1439 1440 static int 1441 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1442 struct crypto_unittest_params *ut_params, 1443 struct crypto_testsuite_params *ts_params, 1444 const uint8_t *cipher, 1445 const uint8_t *digest, 1446 const uint8_t *iv) 1447 { 1448 /* Generate test mbuf data and digest */ 1449 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1450 (const char *) 1451 cipher, 1452 QUOTE_512_BYTES, 0); 1453 1454 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1455 DIGEST_BYTE_LENGTH_SHA512); 1456 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1457 1458 rte_memcpy(ut_params->digest, 1459 digest, 1460 DIGEST_BYTE_LENGTH_SHA512); 1461 1462 /* Generate Crypto op data structure */ 1463 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1464 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1465 TEST_ASSERT_NOT_NULL(ut_params->op, 1466 "Failed to allocate symmetric crypto operation struct"); 1467 1468 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1469 1470 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1471 1472 /* set crypto operation source mbuf */ 1473 sym_op->m_src = ut_params->ibuf; 1474 1475 sym_op->auth.digest.data = ut_params->digest; 1476 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1477 ut_params->ibuf, QUOTE_512_BYTES); 1478 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512; 1479 1480 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1481 sym_op->auth.data.length = QUOTE_512_BYTES; 1482 1483 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 1484 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC); 1485 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset( 1486 ut_params->ibuf, 0); 1487 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1488 1489 rte_memcpy(sym_op->cipher.iv.data, iv, 1490 CIPHER_IV_LENGTH_AES_CBC); 1491 1492 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1493 sym_op->cipher.data.length = QUOTE_512_BYTES; 1494 1495 /* Process crypto operation */ 1496 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 1497 ut_params->op), "failed to process sym crypto op"); 1498 1499 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1500 "crypto op processing failed"); 1501 1502 ut_params->obuf = ut_params->op->sym->m_src; 1503 1504 /* Validate obuf */ 1505 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1506 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + 1507 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote, 1508 QUOTE_512_BYTES, 1509 "Plaintext data not as expected"); 1510 1511 /* Validate obuf */ 1512 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1513 "Digest verification failed"); 1514 1515 return TEST_SUCCESS; 1516 } 1517 1518 static int 1519 test_AES_cipheronly_mb_all(void) 1520 { 1521 struct crypto_testsuite_params *ts_params = &testsuite_params; 1522 int status; 1523 1524 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1525 ts_params->op_mpool, ts_params->valid_devs[0], 1526 RTE_CRYPTODEV_AESNI_MB_PMD, 1527 BLKCIPHER_AES_CIPHERONLY_TYPE); 1528 1529 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1530 1531 return TEST_SUCCESS; 1532 } 1533 1534 static int 1535 test_authonly_mb_all(void) 1536 { 1537 struct crypto_testsuite_params *ts_params = &testsuite_params; 1538 int status; 1539 1540 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1541 ts_params->op_mpool, ts_params->valid_devs[0], 1542 RTE_CRYPTODEV_AESNI_MB_PMD, 1543 BLKCIPHER_AUTHONLY_TYPE); 1544 1545 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1546 1547 return TEST_SUCCESS; 1548 } 1549 1550 static int 1551 test_AES_chain_mb_all(void) 1552 { 1553 struct crypto_testsuite_params *ts_params = &testsuite_params; 1554 int status; 1555 1556 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1557 ts_params->op_mpool, ts_params->valid_devs[0], 1558 RTE_CRYPTODEV_AESNI_MB_PMD, 1559 BLKCIPHER_AES_CHAIN_TYPE); 1560 1561 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1562 1563 return TEST_SUCCESS; 1564 } 1565 1566 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 1567 1568 static int 1569 test_AES_cipheronly_scheduler_all(void) 1570 { 1571 struct crypto_testsuite_params *ts_params = &testsuite_params; 1572 int status; 1573 1574 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1575 ts_params->op_mpool, ts_params->valid_devs[0], 1576 RTE_CRYPTODEV_SCHEDULER_PMD, 1577 BLKCIPHER_AES_CIPHERONLY_TYPE); 1578 1579 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1580 1581 return TEST_SUCCESS; 1582 } 1583 1584 static int 1585 test_AES_chain_scheduler_all(void) 1586 { 1587 struct crypto_testsuite_params *ts_params = &testsuite_params; 1588 int status; 1589 1590 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1591 ts_params->op_mpool, ts_params->valid_devs[0], 1592 RTE_CRYPTODEV_SCHEDULER_PMD, 1593 BLKCIPHER_AES_CHAIN_TYPE); 1594 1595 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1596 1597 return TEST_SUCCESS; 1598 } 1599 1600 static int 1601 test_authonly_scheduler_all(void) 1602 { 1603 struct crypto_testsuite_params *ts_params = &testsuite_params; 1604 int status; 1605 1606 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1607 ts_params->op_mpool, ts_params->valid_devs[0], 1608 RTE_CRYPTODEV_SCHEDULER_PMD, 1609 BLKCIPHER_AUTHONLY_TYPE); 1610 1611 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1612 1613 return TEST_SUCCESS; 1614 } 1615 1616 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */ 1617 1618 static int 1619 test_AES_chain_openssl_all(void) 1620 { 1621 struct crypto_testsuite_params *ts_params = &testsuite_params; 1622 int status; 1623 1624 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1625 ts_params->op_mpool, ts_params->valid_devs[0], 1626 RTE_CRYPTODEV_OPENSSL_PMD, 1627 BLKCIPHER_AES_CHAIN_TYPE); 1628 1629 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1630 1631 return TEST_SUCCESS; 1632 } 1633 1634 static int 1635 test_AES_cipheronly_openssl_all(void) 1636 { 1637 struct crypto_testsuite_params *ts_params = &testsuite_params; 1638 int status; 1639 1640 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1641 ts_params->op_mpool, ts_params->valid_devs[0], 1642 RTE_CRYPTODEV_OPENSSL_PMD, 1643 BLKCIPHER_AES_CIPHERONLY_TYPE); 1644 1645 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1646 1647 return TEST_SUCCESS; 1648 } 1649 1650 static int 1651 test_AES_chain_qat_all(void) 1652 { 1653 struct crypto_testsuite_params *ts_params = &testsuite_params; 1654 int status; 1655 1656 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1657 ts_params->op_mpool, ts_params->valid_devs[0], 1658 RTE_CRYPTODEV_QAT_SYM_PMD, 1659 BLKCIPHER_AES_CHAIN_TYPE); 1660 1661 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1662 1663 return TEST_SUCCESS; 1664 } 1665 1666 static int 1667 test_AES_cipheronly_qat_all(void) 1668 { 1669 struct crypto_testsuite_params *ts_params = &testsuite_params; 1670 int status; 1671 1672 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1673 ts_params->op_mpool, ts_params->valid_devs[0], 1674 RTE_CRYPTODEV_QAT_SYM_PMD, 1675 BLKCIPHER_AES_CIPHERONLY_TYPE); 1676 1677 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1678 1679 return TEST_SUCCESS; 1680 } 1681 1682 static int 1683 test_authonly_openssl_all(void) 1684 { 1685 struct crypto_testsuite_params *ts_params = &testsuite_params; 1686 int status; 1687 1688 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1689 ts_params->op_mpool, ts_params->valid_devs[0], 1690 RTE_CRYPTODEV_OPENSSL_PMD, 1691 BLKCIPHER_AUTHONLY_TYPE); 1692 1693 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1694 1695 return TEST_SUCCESS; 1696 } 1697 1698 static int 1699 test_AES_chain_armv8_all(void) 1700 { 1701 struct crypto_testsuite_params *ts_params = &testsuite_params; 1702 int status; 1703 1704 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1705 ts_params->op_mpool, ts_params->valid_devs[0], 1706 RTE_CRYPTODEV_ARMV8_PMD, 1707 BLKCIPHER_AES_CHAIN_TYPE); 1708 1709 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1710 1711 return TEST_SUCCESS; 1712 } 1713 1714 /* ***** SNOW 3G Tests ***** */ 1715 static int 1716 create_wireless_algo_hash_session(uint8_t dev_id, 1717 const uint8_t *key, const uint8_t key_len, 1718 const uint8_t aad_len, const uint8_t auth_len, 1719 enum rte_crypto_auth_operation op, 1720 enum rte_crypto_auth_algorithm algo) 1721 { 1722 uint8_t hash_key[key_len]; 1723 1724 struct crypto_unittest_params *ut_params = &unittest_params; 1725 1726 memcpy(hash_key, key, key_len); 1727 1728 TEST_HEXDUMP(stdout, "key:", key, key_len); 1729 1730 /* Setup Authentication Parameters */ 1731 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1732 ut_params->auth_xform.next = NULL; 1733 1734 ut_params->auth_xform.auth.op = op; 1735 ut_params->auth_xform.auth.algo = algo; 1736 ut_params->auth_xform.auth.key.length = key_len; 1737 ut_params->auth_xform.auth.key.data = hash_key; 1738 ut_params->auth_xform.auth.digest_length = auth_len; 1739 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1740 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1741 &ut_params->auth_xform); 1742 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1743 return 0; 1744 } 1745 1746 static int 1747 create_wireless_algo_cipher_session(uint8_t dev_id, 1748 enum rte_crypto_cipher_operation op, 1749 enum rte_crypto_cipher_algorithm algo, 1750 const uint8_t *key, const uint8_t key_len) 1751 { 1752 uint8_t cipher_key[key_len]; 1753 1754 struct crypto_unittest_params *ut_params = &unittest_params; 1755 1756 memcpy(cipher_key, key, key_len); 1757 1758 /* Setup Cipher Parameters */ 1759 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1760 ut_params->cipher_xform.next = NULL; 1761 1762 ut_params->cipher_xform.cipher.algo = algo; 1763 ut_params->cipher_xform.cipher.op = op; 1764 ut_params->cipher_xform.cipher.key.data = cipher_key; 1765 ut_params->cipher_xform.cipher.key.length = key_len; 1766 1767 TEST_HEXDUMP(stdout, "key:", key, key_len); 1768 1769 /* Create Crypto session */ 1770 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1771 &ut_params-> 1772 cipher_xform); 1773 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1774 return 0; 1775 } 1776 1777 static int 1778 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len, 1779 const unsigned cipher_len, 1780 const unsigned cipher_offset, 1781 enum rte_crypto_cipher_algorithm algo) 1782 { 1783 struct crypto_testsuite_params *ts_params = &testsuite_params; 1784 struct crypto_unittest_params *ut_params = &unittest_params; 1785 unsigned iv_pad_len = 0; 1786 1787 /* Generate Crypto op data structure */ 1788 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1789 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1790 TEST_ASSERT_NOT_NULL(ut_params->op, 1791 "Failed to allocate pktmbuf offload"); 1792 1793 /* Set crypto operation data parameters */ 1794 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1795 1796 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1797 1798 /* set crypto operation source mbuf */ 1799 sym_op->m_src = ut_params->ibuf; 1800 1801 /* iv */ 1802 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 1803 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 1804 else 1805 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 1806 1807 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf 1808 , iv_pad_len); 1809 1810 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 1811 1812 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 1813 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1814 sym_op->cipher.iv.length = iv_pad_len; 1815 1816 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 1817 sym_op->cipher.data.length = cipher_len; 1818 sym_op->cipher.data.offset = cipher_offset; 1819 return 0; 1820 } 1821 1822 static int 1823 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len, 1824 const unsigned cipher_len, 1825 const unsigned cipher_offset, 1826 enum rte_crypto_cipher_algorithm algo) 1827 { 1828 struct crypto_testsuite_params *ts_params = &testsuite_params; 1829 struct crypto_unittest_params *ut_params = &unittest_params; 1830 unsigned iv_pad_len = 0; 1831 1832 /* Generate Crypto op data structure */ 1833 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1834 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1835 TEST_ASSERT_NOT_NULL(ut_params->op, 1836 "Failed to allocate pktmbuf offload"); 1837 1838 /* Set crypto operation data parameters */ 1839 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1840 1841 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1842 1843 /* set crypto operation source mbuf */ 1844 sym_op->m_src = ut_params->ibuf; 1845 sym_op->m_dst = ut_params->obuf; 1846 1847 /* iv */ 1848 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 1849 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 1850 else 1851 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 1852 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf, 1853 iv_pad_len); 1854 1855 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 1856 1857 /* For OOP operation both buffers must have the same size */ 1858 if (ut_params->obuf) 1859 rte_pktmbuf_prepend(ut_params->obuf, iv_pad_len); 1860 1861 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 1862 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1863 sym_op->cipher.iv.length = iv_pad_len; 1864 1865 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 1866 sym_op->cipher.data.length = cipher_len; 1867 sym_op->cipher.data.offset = cipher_offset; 1868 return 0; 1869 } 1870 1871 static int 1872 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 1873 enum rte_crypto_cipher_operation cipher_op, 1874 enum rte_crypto_auth_operation auth_op, 1875 enum rte_crypto_auth_algorithm auth_algo, 1876 enum rte_crypto_cipher_algorithm cipher_algo, 1877 const uint8_t *key, const uint8_t key_len, 1878 const uint8_t aad_len, const uint8_t auth_len) 1879 1880 { 1881 uint8_t cipher_auth_key[key_len]; 1882 1883 struct crypto_unittest_params *ut_params = &unittest_params; 1884 1885 memcpy(cipher_auth_key, key, key_len); 1886 1887 /* Setup Authentication Parameters */ 1888 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1889 ut_params->auth_xform.next = NULL; 1890 1891 ut_params->auth_xform.auth.op = auth_op; 1892 ut_params->auth_xform.auth.algo = auth_algo; 1893 ut_params->auth_xform.auth.key.length = key_len; 1894 /* Hash key = cipher key */ 1895 ut_params->auth_xform.auth.key.data = cipher_auth_key; 1896 ut_params->auth_xform.auth.digest_length = auth_len; 1897 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1898 1899 /* Setup Cipher Parameters */ 1900 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1901 ut_params->cipher_xform.next = &ut_params->auth_xform; 1902 1903 ut_params->cipher_xform.cipher.algo = cipher_algo; 1904 ut_params->cipher_xform.cipher.op = cipher_op; 1905 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 1906 ut_params->cipher_xform.cipher.key.length = key_len; 1907 1908 TEST_HEXDUMP(stdout, "key:", key, key_len); 1909 1910 /* Create Crypto session*/ 1911 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1912 &ut_params->cipher_xform); 1913 1914 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1915 return 0; 1916 } 1917 1918 static int 1919 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 1920 enum rte_crypto_cipher_operation cipher_op, 1921 enum rte_crypto_auth_operation auth_op, 1922 enum rte_crypto_auth_algorithm auth_algo, 1923 enum rte_crypto_cipher_algorithm cipher_algo, 1924 const uint8_t *key, const uint8_t key_len, 1925 const uint8_t aad_len, const uint8_t auth_len) 1926 { 1927 uint8_t auth_cipher_key[key_len]; 1928 1929 struct crypto_unittest_params *ut_params = &unittest_params; 1930 1931 memcpy(auth_cipher_key, key, key_len); 1932 1933 /* Setup Authentication Parameters */ 1934 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1935 ut_params->auth_xform.auth.op = auth_op; 1936 ut_params->auth_xform.next = &ut_params->cipher_xform; 1937 ut_params->auth_xform.auth.algo = auth_algo; 1938 ut_params->auth_xform.auth.key.length = key_len; 1939 ut_params->auth_xform.auth.key.data = auth_cipher_key; 1940 ut_params->auth_xform.auth.digest_length = auth_len; 1941 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1942 1943 /* Setup Cipher Parameters */ 1944 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1945 ut_params->cipher_xform.next = NULL; 1946 ut_params->cipher_xform.cipher.algo = cipher_algo; 1947 ut_params->cipher_xform.cipher.op = cipher_op; 1948 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 1949 ut_params->cipher_xform.cipher.key.length = key_len; 1950 1951 TEST_HEXDUMP(stdout, "key:", key, key_len); 1952 1953 /* Create Crypto session*/ 1954 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1955 &ut_params->auth_xform); 1956 1957 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1958 1959 return 0; 1960 } 1961 1962 static int 1963 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 1964 const unsigned auth_tag_len, 1965 const uint8_t *aad, const unsigned aad_len, 1966 unsigned data_pad_len, 1967 enum rte_crypto_auth_operation op, 1968 enum rte_crypto_auth_algorithm algo, 1969 const unsigned auth_len, const unsigned auth_offset) 1970 { 1971 struct crypto_testsuite_params *ts_params = &testsuite_params; 1972 1973 struct crypto_unittest_params *ut_params = &unittest_params; 1974 1975 unsigned aad_buffer_len; 1976 1977 /* Generate Crypto op data structure */ 1978 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1979 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1980 TEST_ASSERT_NOT_NULL(ut_params->op, 1981 "Failed to allocate pktmbuf offload"); 1982 1983 /* Set crypto operation data parameters */ 1984 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1985 1986 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1987 1988 /* set crypto operation source mbuf */ 1989 sym_op->m_src = ut_params->ibuf; 1990 1991 /* aad */ 1992 /* 1993 * Always allocate the aad up to the block size. 1994 * The cryptodev API calls out - 1995 * - the array must be big enough to hold the AAD, plus any 1996 * space to round this up to the nearest multiple of the 1997 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G). 1998 */ 1999 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9) 2000 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 2001 else 2002 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 2003 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 2004 ut_params->ibuf, aad_buffer_len); 2005 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 2006 "no room to prepend aad"); 2007 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 2008 ut_params->ibuf); 2009 sym_op->auth.aad.length = aad_len; 2010 2011 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 2012 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 2013 2014 TEST_HEXDUMP(stdout, "aad:", 2015 sym_op->auth.aad.data, aad_len); 2016 2017 /* digest */ 2018 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2019 ut_params->ibuf, auth_tag_len); 2020 2021 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2022 "no room to append auth tag"); 2023 ut_params->digest = sym_op->auth.digest.data; 2024 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 2025 ut_params->ibuf, data_pad_len + aad_len); 2026 sym_op->auth.digest.length = auth_tag_len; 2027 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2028 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2029 else 2030 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2031 2032 TEST_HEXDUMP(stdout, "digest:", 2033 sym_op->auth.digest.data, 2034 sym_op->auth.digest.length); 2035 2036 sym_op->auth.data.length = auth_len; 2037 sym_op->auth.data.offset = auth_offset; 2038 2039 return 0; 2040 } 2041 2042 static int 2043 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2044 const unsigned auth_tag_len, 2045 const uint8_t *aad, const uint8_t aad_len, 2046 unsigned data_pad_len, 2047 enum rte_crypto_auth_operation op, 2048 enum rte_crypto_auth_algorithm auth_algo, 2049 enum rte_crypto_cipher_algorithm cipher_algo, 2050 const uint8_t *iv, const uint8_t iv_len, 2051 const unsigned cipher_len, const unsigned cipher_offset, 2052 const unsigned auth_len, const unsigned auth_offset) 2053 { 2054 struct crypto_testsuite_params *ts_params = &testsuite_params; 2055 struct crypto_unittest_params *ut_params = &unittest_params; 2056 2057 unsigned iv_pad_len = 0; 2058 unsigned aad_buffer_len; 2059 2060 /* Generate Crypto op data structure */ 2061 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2062 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2063 TEST_ASSERT_NOT_NULL(ut_params->op, 2064 "Failed to allocate pktmbuf offload"); 2065 /* Set crypto operation data parameters */ 2066 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2067 2068 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2069 2070 /* set crypto operation source mbuf */ 2071 sym_op->m_src = ut_params->ibuf; 2072 2073 /* digest */ 2074 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2075 ut_params->ibuf, auth_tag_len); 2076 2077 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2078 "no room to append auth tag"); 2079 ut_params->digest = sym_op->auth.digest.data; 2080 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 2081 ut_params->ibuf, data_pad_len); 2082 sym_op->auth.digest.length = auth_tag_len; 2083 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2084 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2085 else 2086 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2087 2088 TEST_HEXDUMP(stdout, "digest:", 2089 sym_op->auth.digest.data, 2090 sym_op->auth.digest.length); 2091 2092 /* aad */ 2093 /* 2094 * Always allocate the aad up to the block size. 2095 * The cryptodev API calls out - 2096 * - the array must be big enough to hold the AAD, plus any 2097 * space to round this up to the nearest multiple of the 2098 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G). 2099 */ 2100 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9) 2101 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 2102 else 2103 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 2104 sym_op->auth.aad.data = 2105 (uint8_t *)rte_pktmbuf_prepend( 2106 ut_params->ibuf, aad_buffer_len); 2107 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 2108 "no room to prepend aad"); 2109 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 2110 ut_params->ibuf); 2111 sym_op->auth.aad.length = aad_len; 2112 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 2113 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 2114 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len); 2115 2116 /* iv */ 2117 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 2118 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 2119 else 2120 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 2121 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 2122 ut_params->ibuf, iv_pad_len); 2123 2124 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 2125 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 2126 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 2127 sym_op->cipher.iv.length = iv_pad_len; 2128 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 2129 sym_op->cipher.data.length = cipher_len; 2130 sym_op->cipher.data.offset = cipher_offset + auth_offset; 2131 sym_op->auth.data.length = auth_len; 2132 sym_op->auth.data.offset = auth_offset + cipher_offset; 2133 2134 return 0; 2135 } 2136 2137 static int 2138 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len, 2139 const uint8_t *iv, const uint8_t iv_len, 2140 const uint8_t *aad, const uint8_t aad_len, 2141 unsigned data_pad_len, 2142 const unsigned cipher_len, const unsigned cipher_offset, 2143 const unsigned auth_len, const unsigned auth_offset, 2144 enum rte_crypto_auth_algorithm auth_algo, 2145 enum rte_crypto_cipher_algorithm cipher_algo) 2146 { 2147 struct crypto_testsuite_params *ts_params = &testsuite_params; 2148 struct crypto_unittest_params *ut_params = &unittest_params; 2149 2150 unsigned iv_pad_len = 0; 2151 unsigned aad_buffer_len = 0; 2152 2153 /* Generate Crypto op data structure */ 2154 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2155 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2156 TEST_ASSERT_NOT_NULL(ut_params->op, 2157 "Failed to allocate pktmbuf offload"); 2158 2159 /* Set crypto operation data parameters */ 2160 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2161 2162 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2163 2164 /* set crypto operation source mbuf */ 2165 sym_op->m_src = ut_params->ibuf; 2166 2167 /* digest */ 2168 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2169 ut_params->ibuf, auth_tag_len); 2170 2171 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2172 "no room to append auth tag"); 2173 2174 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 2175 ut_params->ibuf, data_pad_len); 2176 sym_op->auth.digest.length = auth_tag_len; 2177 2178 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2179 2180 TEST_HEXDUMP(stdout, "digest:", 2181 sym_op->auth.digest.data, 2182 sym_op->auth.digest.length); 2183 2184 /* aad */ 2185 /* 2186 * Always allocate the aad up to the block size. 2187 * The cryptodev API calls out - 2188 * - the array must be big enough to hold the AAD, plus any 2189 * space to round this up to the nearest multiple of the 2190 * block size (8 bytes for KASUMI 16 bytes). 2191 */ 2192 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9) 2193 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 2194 else 2195 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 2196 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 2197 ut_params->ibuf, aad_buffer_len); 2198 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 2199 "no room to prepend aad"); 2200 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 2201 ut_params->ibuf); 2202 sym_op->auth.aad.length = aad_len; 2203 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 2204 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 2205 TEST_HEXDUMP(stdout, "aad:", 2206 sym_op->auth.aad.data, aad_len); 2207 2208 /* iv */ 2209 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 2210 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 2211 else 2212 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 2213 2214 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 2215 ut_params->ibuf, iv_pad_len); 2216 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 2217 2218 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 2219 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 2220 sym_op->cipher.iv.length = iv_pad_len; 2221 2222 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 2223 2224 sym_op->cipher.data.length = cipher_len; 2225 sym_op->cipher.data.offset = auth_offset + cipher_offset; 2226 2227 sym_op->auth.data.length = auth_len; 2228 sym_op->auth.data.offset = auth_offset + cipher_offset; 2229 2230 return 0; 2231 } 2232 2233 static int 2234 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2235 { 2236 struct crypto_testsuite_params *ts_params = &testsuite_params; 2237 struct crypto_unittest_params *ut_params = &unittest_params; 2238 2239 int retval; 2240 unsigned plaintext_pad_len; 2241 unsigned plaintext_len; 2242 uint8_t *plaintext; 2243 2244 /* Create SNOW 3G session */ 2245 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2246 tdata->key.data, tdata->key.len, 2247 tdata->aad.len, tdata->digest.len, 2248 RTE_CRYPTO_AUTH_OP_GENERATE, 2249 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2250 if (retval < 0) 2251 return retval; 2252 2253 /* alloc mbuf and set payload */ 2254 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2255 2256 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2257 rte_pktmbuf_tailroom(ut_params->ibuf)); 2258 2259 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2260 /* Append data which is padded to a multiple of */ 2261 /* the algorithms block size */ 2262 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2263 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2264 plaintext_pad_len); 2265 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2266 2267 /* Create SNOW 3G operation */ 2268 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2269 tdata->aad.data, tdata->aad.len, 2270 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2271 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 2272 tdata->validAuthLenInBits.len, 2273 tdata->validAuthOffsetLenInBits.len); 2274 if (retval < 0) 2275 return retval; 2276 2277 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2278 ut_params->op); 2279 ut_params->obuf = ut_params->op->sym->m_src; 2280 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2281 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2282 + plaintext_pad_len + tdata->aad.len; 2283 2284 /* Validate obuf */ 2285 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2286 ut_params->digest, 2287 tdata->digest.data, 2288 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2289 "SNOW 3G Generated auth tag not as expected"); 2290 2291 return 0; 2292 } 2293 2294 static int 2295 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2296 { 2297 struct crypto_testsuite_params *ts_params = &testsuite_params; 2298 struct crypto_unittest_params *ut_params = &unittest_params; 2299 2300 int retval; 2301 unsigned plaintext_pad_len; 2302 unsigned plaintext_len; 2303 uint8_t *plaintext; 2304 2305 /* Create SNOW 3G session */ 2306 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2307 tdata->key.data, tdata->key.len, 2308 tdata->aad.len, tdata->digest.len, 2309 RTE_CRYPTO_AUTH_OP_VERIFY, 2310 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2311 if (retval < 0) 2312 return retval; 2313 /* alloc mbuf and set payload */ 2314 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2315 2316 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2317 rte_pktmbuf_tailroom(ut_params->ibuf)); 2318 2319 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2320 /* Append data which is padded to a multiple of */ 2321 /* the algorithms block size */ 2322 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2323 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2324 plaintext_pad_len); 2325 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2326 2327 /* Create SNOW 3G operation */ 2328 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2329 tdata->digest.len, 2330 tdata->aad.data, tdata->aad.len, 2331 plaintext_pad_len, 2332 RTE_CRYPTO_AUTH_OP_VERIFY, 2333 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 2334 tdata->validAuthLenInBits.len, 2335 tdata->validAuthOffsetLenInBits.len); 2336 if (retval < 0) 2337 return retval; 2338 2339 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2340 ut_params->op); 2341 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2342 ut_params->obuf = ut_params->op->sym->m_src; 2343 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2344 + plaintext_pad_len + tdata->aad.len; 2345 2346 /* Validate obuf */ 2347 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2348 return 0; 2349 else 2350 return -1; 2351 2352 return 0; 2353 } 2354 2355 static int 2356 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2357 { 2358 struct crypto_testsuite_params *ts_params = &testsuite_params; 2359 struct crypto_unittest_params *ut_params = &unittest_params; 2360 2361 int retval; 2362 unsigned plaintext_pad_len; 2363 unsigned plaintext_len; 2364 uint8_t *plaintext; 2365 2366 /* Create KASUMI session */ 2367 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2368 tdata->key.data, tdata->key.len, 2369 tdata->aad.len, tdata->digest.len, 2370 RTE_CRYPTO_AUTH_OP_GENERATE, 2371 RTE_CRYPTO_AUTH_KASUMI_F9); 2372 if (retval < 0) 2373 return retval; 2374 2375 /* alloc mbuf and set payload */ 2376 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2377 2378 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2379 rte_pktmbuf_tailroom(ut_params->ibuf)); 2380 2381 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2382 /* Append data which is padded to a multiple of */ 2383 /* the algorithms block size */ 2384 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2385 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2386 plaintext_pad_len); 2387 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2388 2389 /* Create KASUMI operation */ 2390 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2391 tdata->aad.data, tdata->aad.len, 2392 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2393 RTE_CRYPTO_AUTH_KASUMI_F9, 2394 tdata->validAuthLenInBits.len, 2395 tdata->validAuthOffsetLenInBits.len); 2396 if (retval < 0) 2397 return retval; 2398 2399 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2400 ut_params->op); 2401 ut_params->obuf = ut_params->op->sym->m_src; 2402 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2403 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2404 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8); 2405 2406 /* Validate obuf */ 2407 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2408 ut_params->digest, 2409 tdata->digest.data, 2410 DIGEST_BYTE_LENGTH_KASUMI_F9, 2411 "KASUMI Generated auth tag not as expected"); 2412 2413 return 0; 2414 } 2415 2416 static int 2417 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2418 { 2419 struct crypto_testsuite_params *ts_params = &testsuite_params; 2420 struct crypto_unittest_params *ut_params = &unittest_params; 2421 2422 int retval; 2423 unsigned plaintext_pad_len; 2424 unsigned plaintext_len; 2425 uint8_t *plaintext; 2426 2427 /* Create KASUMI session */ 2428 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2429 tdata->key.data, tdata->key.len, 2430 tdata->aad.len, tdata->digest.len, 2431 RTE_CRYPTO_AUTH_OP_VERIFY, 2432 RTE_CRYPTO_AUTH_KASUMI_F9); 2433 if (retval < 0) 2434 return retval; 2435 /* alloc mbuf and set payload */ 2436 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2437 2438 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2439 rte_pktmbuf_tailroom(ut_params->ibuf)); 2440 2441 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2442 /* Append data which is padded to a multiple */ 2443 /* of the algorithms block size */ 2444 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2445 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2446 plaintext_pad_len); 2447 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2448 2449 /* Create KASUMI operation */ 2450 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2451 tdata->digest.len, 2452 tdata->aad.data, tdata->aad.len, 2453 plaintext_pad_len, 2454 RTE_CRYPTO_AUTH_OP_VERIFY, 2455 RTE_CRYPTO_AUTH_KASUMI_F9, 2456 tdata->validAuthLenInBits.len, 2457 tdata->validAuthOffsetLenInBits.len); 2458 if (retval < 0) 2459 return retval; 2460 2461 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2462 ut_params->op); 2463 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2464 ut_params->obuf = ut_params->op->sym->m_src; 2465 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2466 + plaintext_pad_len + tdata->aad.len; 2467 2468 /* Validate obuf */ 2469 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2470 return 0; 2471 else 2472 return -1; 2473 2474 return 0; 2475 } 2476 2477 static int 2478 test_snow3g_hash_generate_test_case_1(void) 2479 { 2480 return test_snow3g_authentication(&snow3g_hash_test_case_1); 2481 } 2482 2483 static int 2484 test_snow3g_hash_generate_test_case_2(void) 2485 { 2486 return test_snow3g_authentication(&snow3g_hash_test_case_2); 2487 } 2488 2489 static int 2490 test_snow3g_hash_generate_test_case_3(void) 2491 { 2492 return test_snow3g_authentication(&snow3g_hash_test_case_3); 2493 } 2494 2495 static int 2496 test_snow3g_hash_generate_test_case_4(void) 2497 { 2498 return test_snow3g_authentication(&snow3g_hash_test_case_4); 2499 } 2500 2501 static int 2502 test_snow3g_hash_generate_test_case_5(void) 2503 { 2504 return test_snow3g_authentication(&snow3g_hash_test_case_5); 2505 } 2506 2507 static int 2508 test_snow3g_hash_generate_test_case_6(void) 2509 { 2510 return test_snow3g_authentication(&snow3g_hash_test_case_6); 2511 } 2512 2513 static int 2514 test_snow3g_hash_verify_test_case_1(void) 2515 { 2516 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 2517 2518 } 2519 2520 static int 2521 test_snow3g_hash_verify_test_case_2(void) 2522 { 2523 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 2524 } 2525 2526 static int 2527 test_snow3g_hash_verify_test_case_3(void) 2528 { 2529 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 2530 } 2531 2532 static int 2533 test_snow3g_hash_verify_test_case_4(void) 2534 { 2535 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 2536 } 2537 2538 static int 2539 test_snow3g_hash_verify_test_case_5(void) 2540 { 2541 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 2542 } 2543 2544 static int 2545 test_snow3g_hash_verify_test_case_6(void) 2546 { 2547 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 2548 } 2549 2550 static int 2551 test_kasumi_hash_generate_test_case_1(void) 2552 { 2553 return test_kasumi_authentication(&kasumi_hash_test_case_1); 2554 } 2555 2556 static int 2557 test_kasumi_hash_generate_test_case_2(void) 2558 { 2559 return test_kasumi_authentication(&kasumi_hash_test_case_2); 2560 } 2561 2562 static int 2563 test_kasumi_hash_generate_test_case_3(void) 2564 { 2565 return test_kasumi_authentication(&kasumi_hash_test_case_3); 2566 } 2567 2568 static int 2569 test_kasumi_hash_generate_test_case_4(void) 2570 { 2571 return test_kasumi_authentication(&kasumi_hash_test_case_4); 2572 } 2573 2574 static int 2575 test_kasumi_hash_generate_test_case_5(void) 2576 { 2577 return test_kasumi_authentication(&kasumi_hash_test_case_5); 2578 } 2579 2580 static int 2581 test_kasumi_hash_generate_test_case_6(void) 2582 { 2583 return test_kasumi_authentication(&kasumi_hash_test_case_6); 2584 } 2585 2586 static int 2587 test_kasumi_hash_verify_test_case_1(void) 2588 { 2589 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 2590 } 2591 2592 static int 2593 test_kasumi_hash_verify_test_case_2(void) 2594 { 2595 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 2596 } 2597 2598 static int 2599 test_kasumi_hash_verify_test_case_3(void) 2600 { 2601 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 2602 } 2603 2604 static int 2605 test_kasumi_hash_verify_test_case_4(void) 2606 { 2607 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 2608 } 2609 2610 static int 2611 test_kasumi_hash_verify_test_case_5(void) 2612 { 2613 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 2614 } 2615 2616 static int 2617 test_kasumi_encryption(const struct kasumi_test_data *tdata) 2618 { 2619 struct crypto_testsuite_params *ts_params = &testsuite_params; 2620 struct crypto_unittest_params *ut_params = &unittest_params; 2621 2622 int retval; 2623 uint8_t *plaintext, *ciphertext; 2624 unsigned plaintext_pad_len; 2625 unsigned plaintext_len; 2626 2627 /* Create KASUMI session */ 2628 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2629 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2630 RTE_CRYPTO_CIPHER_KASUMI_F8, 2631 tdata->key.data, tdata->key.len); 2632 if (retval < 0) 2633 return retval; 2634 2635 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2636 2637 /* Clear mbuf payload */ 2638 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2639 rte_pktmbuf_tailroom(ut_params->ibuf)); 2640 2641 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2642 /* Append data which is padded to a multiple */ 2643 /* of the algorithms block size */ 2644 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2645 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2646 plaintext_pad_len); 2647 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2648 2649 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2650 2651 /* Create KASUMI operation */ 2652 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 2653 tdata->plaintext.len, 2654 tdata->validCipherOffsetLenInBits.len, 2655 RTE_CRYPTO_CIPHER_KASUMI_F8); 2656 if (retval < 0) 2657 return retval; 2658 2659 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2660 ut_params->op); 2661 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2662 2663 ut_params->obuf = ut_params->op->sym->m_dst; 2664 if (ut_params->obuf) 2665 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2666 + tdata->iv.len; 2667 else 2668 ciphertext = plaintext; 2669 2670 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2671 2672 /* Validate obuf */ 2673 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2674 ciphertext, 2675 tdata->ciphertext.data, 2676 tdata->validCipherLenInBits.len, 2677 "KASUMI Ciphertext data not as expected"); 2678 return 0; 2679 } 2680 2681 static int 2682 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 2683 { 2684 struct crypto_testsuite_params *ts_params = &testsuite_params; 2685 struct crypto_unittest_params *ut_params = &unittest_params; 2686 2687 int retval; 2688 2689 unsigned int plaintext_pad_len; 2690 unsigned int plaintext_len; 2691 2692 uint8_t buffer[10000]; 2693 const uint8_t *ciphertext; 2694 2695 struct rte_cryptodev_info dev_info; 2696 2697 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2698 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { 2699 printf("Device doesn't support scatter-gather. " 2700 "Test Skipped.\n"); 2701 return 0; 2702 } 2703 2704 /* Create KASUMI session */ 2705 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2706 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2707 RTE_CRYPTO_CIPHER_KASUMI_F8, 2708 tdata->key.data, tdata->key.len); 2709 if (retval < 0) 2710 return retval; 2711 2712 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2713 2714 2715 /* Append data which is padded to a multiple */ 2716 /* of the algorithms block size */ 2717 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2718 2719 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 2720 plaintext_pad_len, 10, 0); 2721 2722 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 2723 2724 /* Create KASUMI operation */ 2725 retval = create_wireless_algo_cipher_operation(tdata->iv.data, 2726 tdata->iv.len, 2727 tdata->plaintext.len, 2728 tdata->validCipherOffsetLenInBits.len, 2729 RTE_CRYPTO_CIPHER_KASUMI_F8); 2730 if (retval < 0) 2731 return retval; 2732 2733 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2734 ut_params->op); 2735 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2736 2737 ut_params->obuf = ut_params->op->sym->m_dst; 2738 2739 if (ut_params->obuf) 2740 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len, 2741 plaintext_len, buffer); 2742 else 2743 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len, 2744 plaintext_len, buffer); 2745 2746 /* Validate obuf */ 2747 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2748 2749 /* Validate obuf */ 2750 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2751 ciphertext, 2752 tdata->ciphertext.data, 2753 tdata->validCipherLenInBits.len, 2754 "KASUMI Ciphertext data not as expected"); 2755 return 0; 2756 } 2757 2758 static int 2759 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 2760 { 2761 struct crypto_testsuite_params *ts_params = &testsuite_params; 2762 struct crypto_unittest_params *ut_params = &unittest_params; 2763 2764 int retval; 2765 uint8_t *plaintext, *ciphertext; 2766 unsigned plaintext_pad_len; 2767 unsigned plaintext_len; 2768 2769 /* Create KASUMI session */ 2770 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2771 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2772 RTE_CRYPTO_CIPHER_KASUMI_F8, 2773 tdata->key.data, tdata->key.len); 2774 if (retval < 0) 2775 return retval; 2776 2777 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2778 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2779 2780 /* Clear mbuf payload */ 2781 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2782 rte_pktmbuf_tailroom(ut_params->ibuf)); 2783 2784 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2785 /* Append data which is padded to a multiple */ 2786 /* of the algorithms block size */ 2787 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2788 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2789 plaintext_pad_len); 2790 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 2791 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2792 2793 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2794 2795 /* Create KASUMI operation */ 2796 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2797 tdata->iv.len, 2798 tdata->plaintext.len, 2799 tdata->validCipherOffsetLenInBits.len, 2800 RTE_CRYPTO_CIPHER_KASUMI_F8); 2801 if (retval < 0) 2802 return retval; 2803 2804 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2805 ut_params->op); 2806 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2807 2808 ut_params->obuf = ut_params->op->sym->m_dst; 2809 if (ut_params->obuf) 2810 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2811 + tdata->iv.len; 2812 else 2813 ciphertext = plaintext; 2814 2815 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2816 2817 /* Validate obuf */ 2818 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2819 ciphertext, 2820 tdata->ciphertext.data, 2821 tdata->validCipherLenInBits.len, 2822 "KASUMI Ciphertext data not as expected"); 2823 return 0; 2824 } 2825 2826 static int 2827 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 2828 { 2829 struct crypto_testsuite_params *ts_params = &testsuite_params; 2830 struct crypto_unittest_params *ut_params = &unittest_params; 2831 2832 int retval; 2833 unsigned int plaintext_pad_len; 2834 unsigned int plaintext_len; 2835 2836 const uint8_t *ciphertext; 2837 uint8_t buffer[2048]; 2838 2839 struct rte_cryptodev_info dev_info; 2840 2841 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2842 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { 2843 printf("Device doesn't support scatter-gather. " 2844 "Test Skipped.\n"); 2845 return 0; 2846 } 2847 2848 /* Create KASUMI session */ 2849 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2850 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2851 RTE_CRYPTO_CIPHER_KASUMI_F8, 2852 tdata->key.data, tdata->key.len); 2853 if (retval < 0) 2854 return retval; 2855 2856 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2857 /* Append data which is padded to a multiple */ 2858 /* of the algorithms block size */ 2859 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2860 2861 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 2862 plaintext_pad_len, 10, 0); 2863 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 2864 plaintext_pad_len, 3, 0); 2865 2866 /* Append data which is padded to a multiple */ 2867 /* of the algorithms block size */ 2868 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 2869 2870 /* Create KASUMI operation */ 2871 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2872 tdata->iv.len, 2873 tdata->plaintext.len, 2874 tdata->validCipherOffsetLenInBits.len, 2875 RTE_CRYPTO_CIPHER_KASUMI_F8); 2876 if (retval < 0) 2877 return retval; 2878 2879 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2880 ut_params->op); 2881 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2882 2883 ut_params->obuf = ut_params->op->sym->m_dst; 2884 if (ut_params->obuf) 2885 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len, 2886 plaintext_pad_len, buffer); 2887 else 2888 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len, 2889 plaintext_pad_len, buffer); 2890 2891 /* Validate obuf */ 2892 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2893 ciphertext, 2894 tdata->ciphertext.data, 2895 tdata->validCipherLenInBits.len, 2896 "KASUMI Ciphertext data not as expected"); 2897 return 0; 2898 } 2899 2900 2901 static int 2902 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 2903 { 2904 struct crypto_testsuite_params *ts_params = &testsuite_params; 2905 struct crypto_unittest_params *ut_params = &unittest_params; 2906 2907 int retval; 2908 uint8_t *ciphertext, *plaintext; 2909 unsigned ciphertext_pad_len; 2910 unsigned ciphertext_len; 2911 2912 /* Create KASUMI session */ 2913 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2914 RTE_CRYPTO_CIPHER_OP_DECRYPT, 2915 RTE_CRYPTO_CIPHER_KASUMI_F8, 2916 tdata->key.data, tdata->key.len); 2917 if (retval < 0) 2918 return retval; 2919 2920 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2921 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2922 2923 /* Clear mbuf payload */ 2924 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2925 rte_pktmbuf_tailroom(ut_params->ibuf)); 2926 2927 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 2928 /* Append data which is padded to a multiple */ 2929 /* of the algorithms block size */ 2930 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 2931 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2932 ciphertext_pad_len); 2933 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 2934 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 2935 2936 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 2937 2938 /* Create KASUMI operation */ 2939 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2940 tdata->iv.len, 2941 tdata->ciphertext.len, 2942 tdata->validCipherOffsetLenInBits.len, 2943 RTE_CRYPTO_CIPHER_KASUMI_F8); 2944 if (retval < 0) 2945 return retval; 2946 2947 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2948 ut_params->op); 2949 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2950 2951 ut_params->obuf = ut_params->op->sym->m_dst; 2952 if (ut_params->obuf) 2953 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2954 + tdata->iv.len; 2955 else 2956 plaintext = ciphertext; 2957 2958 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 2959 2960 /* Validate obuf */ 2961 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2962 plaintext, 2963 tdata->plaintext.data, 2964 tdata->validCipherLenInBits.len, 2965 "KASUMI Plaintext data not as expected"); 2966 return 0; 2967 } 2968 2969 static int 2970 test_kasumi_decryption(const struct kasumi_test_data *tdata) 2971 { 2972 struct crypto_testsuite_params *ts_params = &testsuite_params; 2973 struct crypto_unittest_params *ut_params = &unittest_params; 2974 2975 int retval; 2976 uint8_t *ciphertext, *plaintext; 2977 unsigned ciphertext_pad_len; 2978 unsigned ciphertext_len; 2979 2980 /* Create KASUMI session */ 2981 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2982 RTE_CRYPTO_CIPHER_OP_DECRYPT, 2983 RTE_CRYPTO_CIPHER_KASUMI_F8, 2984 tdata->key.data, tdata->key.len); 2985 if (retval < 0) 2986 return retval; 2987 2988 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2989 2990 /* Clear mbuf payload */ 2991 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2992 rte_pktmbuf_tailroom(ut_params->ibuf)); 2993 2994 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 2995 /* Append data which is padded to a multiple */ 2996 /* of the algorithms block size */ 2997 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 2998 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2999 ciphertext_pad_len); 3000 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3001 3002 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 3003 3004 /* Create KASUMI operation */ 3005 retval = create_wireless_algo_cipher_operation(tdata->iv.data, 3006 tdata->iv.len, 3007 tdata->ciphertext.len, 3008 tdata->validCipherOffsetLenInBits.len, 3009 RTE_CRYPTO_CIPHER_KASUMI_F8); 3010 if (retval < 0) 3011 return retval; 3012 3013 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3014 ut_params->op); 3015 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3016 3017 ut_params->obuf = ut_params->op->sym->m_dst; 3018 if (ut_params->obuf) 3019 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3020 + tdata->iv.len; 3021 else 3022 plaintext = ciphertext; 3023 3024 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 3025 3026 /* Validate obuf */ 3027 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3028 plaintext, 3029 tdata->plaintext.data, 3030 tdata->validCipherLenInBits.len, 3031 "KASUMI Plaintext data not as expected"); 3032 return 0; 3033 } 3034 3035 static int 3036 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3037 { 3038 struct crypto_testsuite_params *ts_params = &testsuite_params; 3039 struct crypto_unittest_params *ut_params = &unittest_params; 3040 3041 int retval; 3042 uint8_t *plaintext, *ciphertext; 3043 unsigned plaintext_pad_len; 3044 unsigned plaintext_len; 3045 3046 /* Create SNOW 3G session */ 3047 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3048 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3049 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3050 tdata->key.data, tdata->key.len); 3051 if (retval < 0) 3052 return retval; 3053 3054 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3055 3056 /* Clear mbuf payload */ 3057 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3058 rte_pktmbuf_tailroom(ut_params->ibuf)); 3059 3060 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3061 /* Append data which is padded to a multiple of */ 3062 /* the algorithms block size */ 3063 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3064 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3065 plaintext_pad_len); 3066 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3067 3068 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3069 3070 /* Create SNOW 3G operation */ 3071 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 3072 tdata->validCipherLenInBits.len, 3073 tdata->validCipherOffsetLenInBits.len, 3074 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3075 if (retval < 0) 3076 return retval; 3077 3078 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3079 ut_params->op); 3080 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3081 3082 ut_params->obuf = ut_params->op->sym->m_dst; 3083 if (ut_params->obuf) 3084 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3085 + tdata->iv.len; 3086 else 3087 ciphertext = plaintext; 3088 3089 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3090 3091 /* Validate obuf */ 3092 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3093 ciphertext, 3094 tdata->ciphertext.data, 3095 tdata->validDataLenInBits.len, 3096 "SNOW 3G Ciphertext data not as expected"); 3097 return 0; 3098 } 3099 3100 3101 static int 3102 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3103 { 3104 struct crypto_testsuite_params *ts_params = &testsuite_params; 3105 struct crypto_unittest_params *ut_params = &unittest_params; 3106 uint8_t *plaintext, *ciphertext; 3107 3108 int retval; 3109 unsigned plaintext_pad_len; 3110 unsigned plaintext_len; 3111 3112 /* Create SNOW 3G session */ 3113 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3114 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3115 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3116 tdata->key.data, tdata->key.len); 3117 if (retval < 0) 3118 return retval; 3119 3120 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3121 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3122 3123 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3124 "Failed to allocate input buffer in mempool"); 3125 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3126 "Failed to allocate output buffer in mempool"); 3127 3128 /* Clear mbuf payload */ 3129 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3130 rte_pktmbuf_tailroom(ut_params->ibuf)); 3131 3132 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3133 /* Append data which is padded to a multiple of */ 3134 /* the algorithms block size */ 3135 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3136 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3137 plaintext_pad_len); 3138 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3139 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3140 3141 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3142 3143 /* Create SNOW 3G operation */ 3144 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 3145 tdata->iv.len, 3146 tdata->validCipherLenInBits.len, 3147 tdata->validCipherOffsetLenInBits.len, 3148 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3149 if (retval < 0) 3150 return retval; 3151 3152 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3153 ut_params->op); 3154 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3155 3156 ut_params->obuf = ut_params->op->sym->m_dst; 3157 if (ut_params->obuf) 3158 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3159 + tdata->iv.len; 3160 else 3161 ciphertext = plaintext; 3162 3163 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3164 3165 /* Validate obuf */ 3166 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3167 ciphertext, 3168 tdata->ciphertext.data, 3169 tdata->validDataLenInBits.len, 3170 "SNOW 3G Ciphertext data not as expected"); 3171 return 0; 3172 } 3173 3174 static int 3175 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3176 { 3177 struct crypto_testsuite_params *ts_params = &testsuite_params; 3178 struct crypto_unittest_params *ut_params = &unittest_params; 3179 3180 int retval; 3181 unsigned int plaintext_pad_len; 3182 unsigned int plaintext_len; 3183 uint8_t buffer[10000]; 3184 const uint8_t *ciphertext; 3185 3186 struct rte_cryptodev_info dev_info; 3187 3188 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3189 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { 3190 printf("Device doesn't support scatter-gather. " 3191 "Test Skipped.\n"); 3192 return 0; 3193 } 3194 3195 /* Create SNOW 3G session */ 3196 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3197 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3198 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3199 tdata->key.data, tdata->key.len); 3200 if (retval < 0) 3201 return retval; 3202 3203 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3204 /* Append data which is padded to a multiple of */ 3205 /* the algorithms block size */ 3206 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3207 3208 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3209 plaintext_pad_len, 10, 0); 3210 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3211 plaintext_pad_len, 3, 0); 3212 3213 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3214 "Failed to allocate input buffer in mempool"); 3215 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3216 "Failed to allocate output buffer in mempool"); 3217 3218 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3219 3220 /* Create SNOW 3G operation */ 3221 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 3222 tdata->iv.len, 3223 tdata->validCipherLenInBits.len, 3224 tdata->validCipherOffsetLenInBits.len, 3225 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3226 if (retval < 0) 3227 return retval; 3228 3229 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3230 ut_params->op); 3231 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3232 3233 ut_params->obuf = ut_params->op->sym->m_dst; 3234 if (ut_params->obuf) 3235 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len, 3236 plaintext_len, buffer); 3237 else 3238 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len, 3239 plaintext_len, buffer); 3240 3241 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3242 3243 /* Validate obuf */ 3244 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3245 ciphertext, 3246 tdata->ciphertext.data, 3247 tdata->validDataLenInBits.len, 3248 "SNOW 3G Ciphertext data not as expected"); 3249 3250 return 0; 3251 } 3252 3253 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3254 static void 3255 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3256 { 3257 uint8_t curr_byte, prev_byte; 3258 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3259 uint8_t lower_byte_mask = (1 << offset) - 1; 3260 unsigned i; 3261 3262 prev_byte = buffer[0]; 3263 buffer[0] >>= offset; 3264 3265 for (i = 1; i < length_in_bytes; i++) { 3266 curr_byte = buffer[i]; 3267 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 3268 (curr_byte >> offset); 3269 prev_byte = curr_byte; 3270 } 3271 } 3272 3273 static int 3274 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 3275 { 3276 struct crypto_testsuite_params *ts_params = &testsuite_params; 3277 struct crypto_unittest_params *ut_params = &unittest_params; 3278 uint8_t *plaintext, *ciphertext; 3279 int retval; 3280 uint32_t plaintext_len; 3281 uint32_t plaintext_pad_len; 3282 uint8_t extra_offset = 4; 3283 uint8_t *expected_ciphertext_shifted; 3284 3285 /* Create SNOW 3G session */ 3286 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3287 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3288 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3289 tdata->key.data, tdata->key.len); 3290 if (retval < 0) 3291 return retval; 3292 3293 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3294 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3295 3296 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3297 "Failed to allocate input buffer in mempool"); 3298 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3299 "Failed to allocate output buffer in mempool"); 3300 3301 /* Clear mbuf payload */ 3302 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3303 rte_pktmbuf_tailroom(ut_params->ibuf)); 3304 3305 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 3306 /* 3307 * Append data which is padded to a 3308 * multiple of the algorithms block size 3309 */ 3310 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3311 3312 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 3313 plaintext_pad_len); 3314 3315 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3316 3317 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 3318 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 3319 3320 #ifdef RTE_APP_TEST_DEBUG 3321 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 3322 #endif 3323 /* Create SNOW 3G operation */ 3324 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 3325 tdata->iv.len, 3326 tdata->validCipherLenInBits.len, 3327 tdata->validCipherOffsetLenInBits.len + 3328 extra_offset, 3329 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3330 if (retval < 0) 3331 return retval; 3332 3333 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3334 ut_params->op); 3335 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3336 3337 ut_params->obuf = ut_params->op->sym->m_dst; 3338 if (ut_params->obuf) 3339 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3340 + tdata->iv.len; 3341 else 3342 ciphertext = plaintext; 3343 3344 #ifdef RTE_APP_TEST_DEBUG 3345 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3346 #endif 3347 3348 expected_ciphertext_shifted = rte_malloc(NULL, 3349 ceil_byte_length(plaintext_len + extra_offset), 0); 3350 3351 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 3352 "failed to reserve memory for ciphertext shifted\n"); 3353 3354 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 3355 ceil_byte_length(tdata->ciphertext.len)); 3356 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 3357 extra_offset); 3358 /* Validate obuf */ 3359 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 3360 ciphertext, 3361 expected_ciphertext_shifted, 3362 tdata->validDataLenInBits.len, 3363 extra_offset, 3364 "SNOW 3G Ciphertext data not as expected"); 3365 return 0; 3366 } 3367 3368 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 3369 { 3370 struct crypto_testsuite_params *ts_params = &testsuite_params; 3371 struct crypto_unittest_params *ut_params = &unittest_params; 3372 3373 int retval; 3374 3375 uint8_t *plaintext, *ciphertext; 3376 unsigned ciphertext_pad_len; 3377 unsigned ciphertext_len; 3378 3379 /* Create SNOW 3G session */ 3380 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3381 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3382 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3383 tdata->key.data, tdata->key.len); 3384 if (retval < 0) 3385 return retval; 3386 3387 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3388 3389 /* Clear mbuf payload */ 3390 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3391 rte_pktmbuf_tailroom(ut_params->ibuf)); 3392 3393 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3394 /* Append data which is padded to a multiple of */ 3395 /* the algorithms block size */ 3396 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 3397 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3398 ciphertext_pad_len); 3399 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3400 3401 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 3402 3403 /* Create SNOW 3G operation */ 3404 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 3405 tdata->validCipherLenInBits.len, 3406 tdata->validCipherOffsetLenInBits.len, 3407 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3408 if (retval < 0) 3409 return retval; 3410 3411 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3412 ut_params->op); 3413 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3414 ut_params->obuf = ut_params->op->sym->m_dst; 3415 if (ut_params->obuf) 3416 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3417 + tdata->iv.len; 3418 else 3419 plaintext = ciphertext; 3420 3421 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 3422 3423 /* Validate obuf */ 3424 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3425 tdata->plaintext.data, 3426 tdata->validDataLenInBits.len, 3427 "SNOW 3G Plaintext data not as expected"); 3428 return 0; 3429 } 3430 3431 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 3432 { 3433 struct crypto_testsuite_params *ts_params = &testsuite_params; 3434 struct crypto_unittest_params *ut_params = &unittest_params; 3435 3436 int retval; 3437 3438 uint8_t *plaintext, *ciphertext; 3439 unsigned ciphertext_pad_len; 3440 unsigned ciphertext_len; 3441 3442 /* Create SNOW 3G session */ 3443 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3444 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3445 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3446 tdata->key.data, tdata->key.len); 3447 if (retval < 0) 3448 return retval; 3449 3450 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3451 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3452 3453 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3454 "Failed to allocate input buffer"); 3455 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3456 "Failed to allocate output buffer"); 3457 3458 /* Clear mbuf payload */ 3459 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3460 rte_pktmbuf_tailroom(ut_params->ibuf)); 3461 3462 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 3463 rte_pktmbuf_tailroom(ut_params->obuf)); 3464 3465 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3466 /* Append data which is padded to a multiple of */ 3467 /* the algorithms block size */ 3468 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 3469 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3470 ciphertext_pad_len); 3471 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3472 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3473 3474 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 3475 3476 /* Create SNOW 3G operation */ 3477 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 3478 tdata->iv.len, 3479 tdata->validCipherLenInBits.len, 3480 tdata->validCipherOffsetLenInBits.len, 3481 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3482 if (retval < 0) 3483 return retval; 3484 3485 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3486 ut_params->op); 3487 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3488 ut_params->obuf = ut_params->op->sym->m_dst; 3489 if (ut_params->obuf) 3490 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3491 + tdata->iv.len; 3492 else 3493 plaintext = ciphertext; 3494 3495 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 3496 3497 /* Validate obuf */ 3498 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3499 tdata->plaintext.data, 3500 tdata->validDataLenInBits.len, 3501 "SNOW 3G Plaintext data not as expected"); 3502 return 0; 3503 } 3504 3505 static int 3506 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 3507 { 3508 struct crypto_testsuite_params *ts_params = &testsuite_params; 3509 struct crypto_unittest_params *ut_params = &unittest_params; 3510 3511 int retval; 3512 3513 uint8_t *plaintext, *ciphertext; 3514 unsigned plaintext_pad_len; 3515 unsigned plaintext_len; 3516 3517 /* Create SNOW 3G session */ 3518 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 3519 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3520 RTE_CRYPTO_AUTH_OP_GENERATE, 3521 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3522 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3523 tdata->key.data, tdata->key.len, 3524 tdata->aad.len, tdata->digest.len); 3525 if (retval < 0) 3526 return retval; 3527 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3528 3529 /* clear mbuf payload */ 3530 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3531 rte_pktmbuf_tailroom(ut_params->ibuf)); 3532 3533 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3534 /* Append data which is padded to a multiple of */ 3535 /* the algorithms block size */ 3536 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3537 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3538 plaintext_pad_len); 3539 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3540 3541 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3542 3543 /* Create SNOW 3G operation */ 3544 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 3545 tdata->digest.len, tdata->aad.data, 3546 tdata->aad.len, /*tdata->plaintext.len,*/ 3547 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3548 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3549 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3550 tdata->iv.data, tdata->iv.len, 3551 tdata->validCipherLenInBits.len, 3552 tdata->validCipherOffsetLenInBits.len, 3553 tdata->validAuthLenInBits.len, 3554 tdata->validAuthOffsetLenInBits.len 3555 ); 3556 if (retval < 0) 3557 return retval; 3558 3559 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3560 ut_params->op); 3561 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3562 ut_params->obuf = ut_params->op->sym->m_src; 3563 if (ut_params->obuf) 3564 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3565 + tdata->iv.len + tdata->aad.len; 3566 else 3567 ciphertext = plaintext; 3568 3569 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3570 /* Validate obuf */ 3571 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3572 ciphertext, 3573 tdata->ciphertext.data, 3574 tdata->validDataLenInBits.len, 3575 "SNOW 3G Ciphertext data not as expected"); 3576 3577 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3578 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3579 3580 /* Validate obuf */ 3581 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3582 ut_params->digest, 3583 tdata->digest.data, 3584 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3585 "SNOW 3G Generated auth tag not as expected"); 3586 return 0; 3587 } 3588 static int 3589 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata) 3590 { 3591 struct crypto_testsuite_params *ts_params = &testsuite_params; 3592 struct crypto_unittest_params *ut_params = &unittest_params; 3593 3594 int retval; 3595 3596 uint8_t *plaintext, *ciphertext; 3597 unsigned plaintext_pad_len; 3598 unsigned plaintext_len; 3599 3600 /* Create SNOW 3G session */ 3601 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0], 3602 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3603 RTE_CRYPTO_AUTH_OP_GENERATE, 3604 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3605 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3606 tdata->key.data, tdata->key.len, 3607 tdata->aad.len, tdata->digest.len); 3608 if (retval < 0) 3609 return retval; 3610 3611 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3612 3613 /* clear mbuf payload */ 3614 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3615 rte_pktmbuf_tailroom(ut_params->ibuf)); 3616 3617 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3618 /* Append data which is padded to a multiple of */ 3619 /* the algorithms block size */ 3620 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3621 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3622 plaintext_pad_len); 3623 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3624 3625 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3626 3627 /* Create SNOW 3G operation */ 3628 retval = create_wireless_algo_auth_cipher_operation( 3629 tdata->digest.len, 3630 tdata->iv.data, tdata->iv.len, 3631 tdata->aad.data, tdata->aad.len, 3632 plaintext_pad_len, 3633 tdata->validCipherLenInBits.len, 3634 tdata->validCipherOffsetLenInBits.len, 3635 tdata->validAuthLenInBits.len, 3636 tdata->validAuthOffsetLenInBits.len, 3637 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3638 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 3639 ); 3640 3641 if (retval < 0) 3642 return retval; 3643 3644 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3645 ut_params->op); 3646 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3647 ut_params->obuf = ut_params->op->sym->m_src; 3648 if (ut_params->obuf) 3649 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3650 + tdata->aad.len + tdata->iv.len; 3651 else 3652 ciphertext = plaintext; 3653 3654 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3655 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3656 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3657 3658 /* Validate obuf */ 3659 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3660 ciphertext, 3661 tdata->ciphertext.data, 3662 tdata->validDataLenInBits.len, 3663 "SNOW 3G Ciphertext data not as expected"); 3664 3665 /* Validate obuf */ 3666 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3667 ut_params->digest, 3668 tdata->digest.data, 3669 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3670 "SNOW 3G Generated auth tag not as expected"); 3671 return 0; 3672 } 3673 3674 static int 3675 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata) 3676 { 3677 struct crypto_testsuite_params *ts_params = &testsuite_params; 3678 struct crypto_unittest_params *ut_params = &unittest_params; 3679 3680 int retval; 3681 3682 uint8_t *plaintext, *ciphertext; 3683 unsigned plaintext_pad_len; 3684 unsigned plaintext_len; 3685 3686 /* Create KASUMI session */ 3687 retval = create_wireless_algo_auth_cipher_session( 3688 ts_params->valid_devs[0], 3689 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3690 RTE_CRYPTO_AUTH_OP_GENERATE, 3691 RTE_CRYPTO_AUTH_KASUMI_F9, 3692 RTE_CRYPTO_CIPHER_KASUMI_F8, 3693 tdata->key.data, tdata->key.len, 3694 tdata->aad.len, tdata->digest.len); 3695 if (retval < 0) 3696 return retval; 3697 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3698 3699 /* clear mbuf payload */ 3700 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3701 rte_pktmbuf_tailroom(ut_params->ibuf)); 3702 3703 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3704 /* Append data which is padded to a multiple of */ 3705 /* the algorithms block size */ 3706 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3707 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3708 plaintext_pad_len); 3709 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3710 3711 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3712 3713 /* Create KASUMI operation */ 3714 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len, 3715 tdata->iv.data, tdata->iv.len, 3716 tdata->aad.data, tdata->aad.len, 3717 plaintext_pad_len, 3718 tdata->validCipherLenInBits.len, 3719 tdata->validCipherOffsetLenInBits.len, 3720 tdata->validAuthLenInBits.len, 3721 tdata->validAuthOffsetLenInBits.len, 3722 RTE_CRYPTO_AUTH_KASUMI_F9, 3723 RTE_CRYPTO_CIPHER_KASUMI_F8 3724 ); 3725 3726 if (retval < 0) 3727 return retval; 3728 3729 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3730 ut_params->op); 3731 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3732 ut_params->obuf = ut_params->op->sym->m_src; 3733 if (ut_params->obuf) 3734 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3735 + tdata->iv.len + tdata->aad.len; 3736 else 3737 ciphertext = plaintext; 3738 3739 /* Validate obuf */ 3740 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3741 ciphertext, 3742 tdata->ciphertext.data, 3743 tdata->validCipherLenInBits.len, 3744 "KASUMI Ciphertext data not as expected"); 3745 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3746 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3747 3748 /* Validate obuf */ 3749 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3750 ut_params->digest, 3751 tdata->digest.data, 3752 DIGEST_BYTE_LENGTH_KASUMI_F9, 3753 "KASUMI Generated auth tag not as expected"); 3754 return 0; 3755 } 3756 3757 static int 3758 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 3759 { 3760 struct crypto_testsuite_params *ts_params = &testsuite_params; 3761 struct crypto_unittest_params *ut_params = &unittest_params; 3762 3763 int retval; 3764 3765 uint8_t *plaintext, *ciphertext; 3766 unsigned plaintext_pad_len; 3767 unsigned plaintext_len; 3768 3769 /* Create KASUMI session */ 3770 retval = create_wireless_algo_cipher_auth_session( 3771 ts_params->valid_devs[0], 3772 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3773 RTE_CRYPTO_AUTH_OP_GENERATE, 3774 RTE_CRYPTO_AUTH_KASUMI_F9, 3775 RTE_CRYPTO_CIPHER_KASUMI_F8, 3776 tdata->key.data, tdata->key.len, 3777 tdata->aad.len, tdata->digest.len); 3778 if (retval < 0) 3779 return retval; 3780 3781 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3782 3783 /* clear mbuf payload */ 3784 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3785 rte_pktmbuf_tailroom(ut_params->ibuf)); 3786 3787 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3788 /* Append data which is padded to a multiple of */ 3789 /* the algorithms block size */ 3790 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3791 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3792 plaintext_pad_len); 3793 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3794 3795 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3796 3797 /* Create KASUMI operation */ 3798 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 3799 tdata->digest.len, tdata->aad.data, 3800 tdata->aad.len, 3801 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3802 RTE_CRYPTO_AUTH_KASUMI_F9, 3803 RTE_CRYPTO_CIPHER_KASUMI_F8, 3804 tdata->iv.data, tdata->iv.len, 3805 tdata->validCipherLenInBits.len, 3806 tdata->validCipherOffsetLenInBits.len, 3807 tdata->validAuthLenInBits.len, 3808 tdata->validAuthOffsetLenInBits.len 3809 ); 3810 if (retval < 0) 3811 return retval; 3812 3813 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3814 ut_params->op); 3815 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3816 ut_params->obuf = ut_params->op->sym->m_src; 3817 if (ut_params->obuf) 3818 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3819 + tdata->aad.len + tdata->iv.len; 3820 else 3821 ciphertext = plaintext; 3822 3823 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3824 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3825 3826 /* Validate obuf */ 3827 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3828 ciphertext, 3829 tdata->ciphertext.data, 3830 tdata->validCipherLenInBits.len, 3831 "KASUMI Ciphertext data not as expected"); 3832 3833 /* Validate obuf */ 3834 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3835 ut_params->digest, 3836 tdata->digest.data, 3837 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3838 "KASUMI Generated auth tag not as expected"); 3839 return 0; 3840 } 3841 3842 static int 3843 test_zuc_encryption(const struct zuc_test_data *tdata) 3844 { 3845 struct crypto_testsuite_params *ts_params = &testsuite_params; 3846 struct crypto_unittest_params *ut_params = &unittest_params; 3847 3848 int retval; 3849 uint8_t *plaintext, *ciphertext; 3850 unsigned plaintext_pad_len; 3851 unsigned plaintext_len; 3852 3853 /* Create ZUC session */ 3854 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3855 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3856 RTE_CRYPTO_CIPHER_ZUC_EEA3, 3857 tdata->key.data, tdata->key.len); 3858 if (retval < 0) 3859 return retval; 3860 3861 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3862 3863 /* Clear mbuf payload */ 3864 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3865 rte_pktmbuf_tailroom(ut_params->ibuf)); 3866 3867 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3868 /* Append data which is padded to a multiple */ 3869 /* of the algorithms block size */ 3870 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3871 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3872 plaintext_pad_len); 3873 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3874 3875 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3876 3877 /* Create ZUC operation */ 3878 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 3879 tdata->plaintext.len, 3880 tdata->validCipherOffsetLenInBits.len, 3881 RTE_CRYPTO_CIPHER_ZUC_EEA3); 3882 if (retval < 0) 3883 return retval; 3884 3885 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3886 ut_params->op); 3887 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3888 3889 ut_params->obuf = ut_params->op->sym->m_dst; 3890 if (ut_params->obuf) 3891 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3892 + tdata->iv.len; 3893 else 3894 ciphertext = plaintext; 3895 3896 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3897 3898 /* Validate obuf */ 3899 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3900 ciphertext, 3901 tdata->ciphertext.data, 3902 tdata->validCipherLenInBits.len, 3903 "ZUC Ciphertext data not as expected"); 3904 return 0; 3905 } 3906 3907 static int 3908 test_zuc_encryption_sgl(const struct zuc_test_data *tdata) 3909 { 3910 struct crypto_testsuite_params *ts_params = &testsuite_params; 3911 struct crypto_unittest_params *ut_params = &unittest_params; 3912 3913 int retval; 3914 3915 unsigned int plaintext_pad_len; 3916 unsigned int plaintext_len; 3917 const uint8_t *ciphertext; 3918 uint8_t ciphertext_buffer[2048]; 3919 struct rte_cryptodev_info dev_info; 3920 3921 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3922 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { 3923 printf("Device doesn't support scatter-gather. " 3924 "Test Skipped.\n"); 3925 return 0; 3926 } 3927 3928 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3929 3930 /* Append data which is padded to a multiple */ 3931 /* of the algorithms block size */ 3932 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3933 3934 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3935 plaintext_pad_len, 10, 0); 3936 3937 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 3938 tdata->plaintext.data); 3939 3940 /* Create ZUC session */ 3941 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3942 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3943 RTE_CRYPTO_CIPHER_ZUC_EEA3, 3944 tdata->key.data, tdata->key.len); 3945 if (retval < 0) 3946 return retval; 3947 3948 /* Clear mbuf payload */ 3949 3950 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3951 3952 /* Create ZUC operation */ 3953 retval = create_wireless_algo_cipher_operation(tdata->iv.data, 3954 tdata->iv.len, tdata->plaintext.len, 3955 tdata->validCipherOffsetLenInBits.len, 3956 RTE_CRYPTO_CIPHER_ZUC_EEA3); 3957 if (retval < 0) 3958 return retval; 3959 3960 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3961 ut_params->op); 3962 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3963 3964 ut_params->obuf = ut_params->op->sym->m_dst; 3965 if (ut_params->obuf) 3966 ciphertext = rte_pktmbuf_read(ut_params->obuf, 3967 tdata->iv.len, plaintext_len, ciphertext_buffer); 3968 else 3969 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3970 tdata->iv.len, plaintext_len, ciphertext_buffer); 3971 3972 /* Validate obuf */ 3973 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3974 3975 /* Validate obuf */ 3976 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3977 ciphertext, 3978 tdata->ciphertext.data, 3979 tdata->validCipherLenInBits.len, 3980 "ZUC Ciphertext data not as expected"); 3981 3982 return 0; 3983 } 3984 3985 static int 3986 test_zuc_authentication(const struct zuc_hash_test_data *tdata) 3987 { 3988 struct crypto_testsuite_params *ts_params = &testsuite_params; 3989 struct crypto_unittest_params *ut_params = &unittest_params; 3990 3991 int retval; 3992 unsigned plaintext_pad_len; 3993 unsigned plaintext_len; 3994 uint8_t *plaintext; 3995 3996 /* Create ZUC session */ 3997 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3998 tdata->key.data, tdata->key.len, 3999 tdata->aad.len, tdata->digest.len, 4000 RTE_CRYPTO_AUTH_OP_GENERATE, 4001 RTE_CRYPTO_AUTH_ZUC_EIA3); 4002 if (retval < 0) 4003 return retval; 4004 4005 /* alloc mbuf and set payload */ 4006 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4007 4008 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4009 rte_pktmbuf_tailroom(ut_params->ibuf)); 4010 4011 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4012 /* Append data which is padded to a multiple of */ 4013 /* the algorithms block size */ 4014 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4015 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4016 plaintext_pad_len); 4017 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4018 4019 /* Create ZUC operation */ 4020 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 4021 tdata->aad.data, tdata->aad.len, 4022 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4023 RTE_CRYPTO_AUTH_ZUC_EIA3, 4024 tdata->validAuthLenInBits.len, 4025 tdata->validAuthOffsetLenInBits.len); 4026 if (retval < 0) 4027 return retval; 4028 4029 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4030 ut_params->op); 4031 ut_params->obuf = ut_params->op->sym->m_src; 4032 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4033 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4034 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8); 4035 4036 /* Validate obuf */ 4037 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4038 ut_params->digest, 4039 tdata->digest.data, 4040 DIGEST_BYTE_LENGTH_KASUMI_F9, 4041 "ZUC Generated auth tag not as expected"); 4042 4043 return 0; 4044 } 4045 4046 static int 4047 test_kasumi_encryption_test_case_1(void) 4048 { 4049 return test_kasumi_encryption(&kasumi_test_case_1); 4050 } 4051 4052 static int 4053 test_kasumi_encryption_test_case_1_sgl(void) 4054 { 4055 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 4056 } 4057 4058 static int 4059 test_kasumi_encryption_test_case_1_oop(void) 4060 { 4061 return test_kasumi_encryption_oop(&kasumi_test_case_1); 4062 } 4063 4064 static int 4065 test_kasumi_encryption_test_case_1_oop_sgl(void) 4066 { 4067 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 4068 } 4069 4070 static int 4071 test_kasumi_encryption_test_case_2(void) 4072 { 4073 return test_kasumi_encryption(&kasumi_test_case_2); 4074 } 4075 4076 static int 4077 test_kasumi_encryption_test_case_3(void) 4078 { 4079 return test_kasumi_encryption(&kasumi_test_case_3); 4080 } 4081 4082 static int 4083 test_kasumi_encryption_test_case_4(void) 4084 { 4085 return test_kasumi_encryption(&kasumi_test_case_4); 4086 } 4087 4088 static int 4089 test_kasumi_encryption_test_case_5(void) 4090 { 4091 return test_kasumi_encryption(&kasumi_test_case_5); 4092 } 4093 4094 static int 4095 test_kasumi_decryption_test_case_1(void) 4096 { 4097 return test_kasumi_decryption(&kasumi_test_case_1); 4098 } 4099 4100 static int 4101 test_kasumi_decryption_test_case_1_oop(void) 4102 { 4103 return test_kasumi_decryption_oop(&kasumi_test_case_1); 4104 } 4105 4106 static int 4107 test_kasumi_decryption_test_case_2(void) 4108 { 4109 return test_kasumi_decryption(&kasumi_test_case_2); 4110 } 4111 4112 static int 4113 test_kasumi_decryption_test_case_3(void) 4114 { 4115 return test_kasumi_decryption(&kasumi_test_case_3); 4116 } 4117 4118 static int 4119 test_kasumi_decryption_test_case_4(void) 4120 { 4121 return test_kasumi_decryption(&kasumi_test_case_4); 4122 } 4123 4124 static int 4125 test_kasumi_decryption_test_case_5(void) 4126 { 4127 return test_kasumi_decryption(&kasumi_test_case_5); 4128 } 4129 static int 4130 test_snow3g_encryption_test_case_1(void) 4131 { 4132 return test_snow3g_encryption(&snow3g_test_case_1); 4133 } 4134 4135 static int 4136 test_snow3g_encryption_test_case_1_oop(void) 4137 { 4138 return test_snow3g_encryption_oop(&snow3g_test_case_1); 4139 } 4140 4141 static int 4142 test_snow3g_encryption_test_case_1_oop_sgl(void) 4143 { 4144 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 4145 } 4146 4147 4148 static int 4149 test_snow3g_encryption_test_case_1_offset_oop(void) 4150 { 4151 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 4152 } 4153 4154 static int 4155 test_snow3g_encryption_test_case_2(void) 4156 { 4157 return test_snow3g_encryption(&snow3g_test_case_2); 4158 } 4159 4160 static int 4161 test_snow3g_encryption_test_case_3(void) 4162 { 4163 return test_snow3g_encryption(&snow3g_test_case_3); 4164 } 4165 4166 static int 4167 test_snow3g_encryption_test_case_4(void) 4168 { 4169 return test_snow3g_encryption(&snow3g_test_case_4); 4170 } 4171 4172 static int 4173 test_snow3g_encryption_test_case_5(void) 4174 { 4175 return test_snow3g_encryption(&snow3g_test_case_5); 4176 } 4177 4178 static int 4179 test_snow3g_decryption_test_case_1(void) 4180 { 4181 return test_snow3g_decryption(&snow3g_test_case_1); 4182 } 4183 4184 static int 4185 test_snow3g_decryption_test_case_1_oop(void) 4186 { 4187 return test_snow3g_decryption_oop(&snow3g_test_case_1); 4188 } 4189 4190 static int 4191 test_snow3g_decryption_test_case_2(void) 4192 { 4193 return test_snow3g_decryption(&snow3g_test_case_2); 4194 } 4195 4196 static int 4197 test_snow3g_decryption_test_case_3(void) 4198 { 4199 return test_snow3g_decryption(&snow3g_test_case_3); 4200 } 4201 4202 static int 4203 test_snow3g_decryption_test_case_4(void) 4204 { 4205 return test_snow3g_decryption(&snow3g_test_case_4); 4206 } 4207 4208 static int 4209 test_snow3g_decryption_test_case_5(void) 4210 { 4211 return test_snow3g_decryption(&snow3g_test_case_5); 4212 } 4213 static int 4214 test_snow3g_cipher_auth_test_case_1(void) 4215 { 4216 return test_snow3g_cipher_auth(&snow3g_test_case_3); 4217 } 4218 4219 static int 4220 test_snow3g_auth_cipher_test_case_1(void) 4221 { 4222 return test_snow3g_auth_cipher(&snow3g_test_case_6); 4223 } 4224 4225 static int 4226 test_kasumi_auth_cipher_test_case_1(void) 4227 { 4228 return test_kasumi_auth_cipher(&kasumi_test_case_3); 4229 } 4230 4231 static int 4232 test_kasumi_cipher_auth_test_case_1(void) 4233 { 4234 return test_kasumi_cipher_auth(&kasumi_test_case_6); 4235 } 4236 4237 static int 4238 test_zuc_encryption_test_case_1(void) 4239 { 4240 return test_zuc_encryption(&zuc_test_case_1); 4241 } 4242 4243 static int 4244 test_zuc_encryption_test_case_2(void) 4245 { 4246 return test_zuc_encryption(&zuc_test_case_2); 4247 } 4248 4249 static int 4250 test_zuc_encryption_test_case_3(void) 4251 { 4252 return test_zuc_encryption(&zuc_test_case_3); 4253 } 4254 4255 static int 4256 test_zuc_encryption_test_case_4(void) 4257 { 4258 return test_zuc_encryption(&zuc_test_case_4); 4259 } 4260 4261 static int 4262 test_zuc_encryption_test_case_5(void) 4263 { 4264 return test_zuc_encryption(&zuc_test_case_5); 4265 } 4266 4267 static int 4268 test_zuc_encryption_test_case_6_sgl(void) 4269 { 4270 return test_zuc_encryption_sgl(&zuc_test_case_1); 4271 } 4272 4273 static int 4274 test_zuc_hash_generate_test_case_1(void) 4275 { 4276 return test_zuc_authentication(&zuc_hash_test_case_1); 4277 } 4278 4279 static int 4280 test_zuc_hash_generate_test_case_2(void) 4281 { 4282 return test_zuc_authentication(&zuc_hash_test_case_2); 4283 } 4284 4285 static int 4286 test_zuc_hash_generate_test_case_3(void) 4287 { 4288 return test_zuc_authentication(&zuc_hash_test_case_3); 4289 } 4290 4291 static int 4292 test_zuc_hash_generate_test_case_4(void) 4293 { 4294 return test_zuc_authentication(&zuc_hash_test_case_4); 4295 } 4296 4297 static int 4298 test_zuc_hash_generate_test_case_5(void) 4299 { 4300 return test_zuc_authentication(&zuc_hash_test_case_5); 4301 } 4302 4303 static int 4304 test_3DES_chain_qat_all(void) 4305 { 4306 struct crypto_testsuite_params *ts_params = &testsuite_params; 4307 int status; 4308 4309 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 4310 ts_params->op_mpool, ts_params->valid_devs[0], 4311 RTE_CRYPTODEV_QAT_SYM_PMD, 4312 BLKCIPHER_3DES_CHAIN_TYPE); 4313 4314 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 4315 4316 return TEST_SUCCESS; 4317 } 4318 4319 static int 4320 test_DES_cipheronly_qat_all(void) 4321 { 4322 struct crypto_testsuite_params *ts_params = &testsuite_params; 4323 int status; 4324 4325 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 4326 ts_params->op_mpool, ts_params->valid_devs[0], 4327 RTE_CRYPTODEV_QAT_SYM_PMD, 4328 BLKCIPHER_DES_CIPHERONLY_TYPE); 4329 4330 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 4331 4332 return TEST_SUCCESS; 4333 } 4334 4335 static int 4336 test_3DES_cipheronly_qat_all(void) 4337 { 4338 struct crypto_testsuite_params *ts_params = &testsuite_params; 4339 int status; 4340 4341 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 4342 ts_params->op_mpool, ts_params->valid_devs[0], 4343 RTE_CRYPTODEV_QAT_SYM_PMD, 4344 BLKCIPHER_3DES_CIPHERONLY_TYPE); 4345 4346 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 4347 4348 return TEST_SUCCESS; 4349 } 4350 4351 static int 4352 test_3DES_chain_openssl_all(void) 4353 { 4354 struct crypto_testsuite_params *ts_params = &testsuite_params; 4355 int status; 4356 4357 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 4358 ts_params->op_mpool, ts_params->valid_devs[0], 4359 RTE_CRYPTODEV_OPENSSL_PMD, 4360 BLKCIPHER_3DES_CHAIN_TYPE); 4361 4362 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 4363 4364 return TEST_SUCCESS; 4365 } 4366 4367 static int 4368 test_3DES_cipheronly_openssl_all(void) 4369 { 4370 struct crypto_testsuite_params *ts_params = &testsuite_params; 4371 int status; 4372 4373 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 4374 ts_params->op_mpool, ts_params->valid_devs[0], 4375 RTE_CRYPTODEV_OPENSSL_PMD, 4376 BLKCIPHER_3DES_CIPHERONLY_TYPE); 4377 4378 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 4379 4380 return TEST_SUCCESS; 4381 } 4382 4383 /* ***** AES-GCM Tests ***** */ 4384 4385 static int 4386 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op, 4387 const uint8_t *key, const uint8_t key_len, 4388 const uint8_t aad_len, const uint8_t auth_len, 4389 enum rte_crypto_auth_operation auth_op) 4390 { 4391 uint8_t cipher_key[key_len]; 4392 4393 struct crypto_unittest_params *ut_params = &unittest_params; 4394 4395 memcpy(cipher_key, key, key_len); 4396 4397 /* Setup Cipher Parameters */ 4398 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4399 ut_params->cipher_xform.next = NULL; 4400 4401 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM; 4402 ut_params->auth_xform.auth.op = auth_op; 4403 ut_params->cipher_xform.cipher.op = op; 4404 ut_params->cipher_xform.cipher.key.data = cipher_key; 4405 ut_params->cipher_xform.cipher.key.length = key_len; 4406 4407 TEST_HEXDUMP(stdout, "key:", key, key_len); 4408 4409 /* Setup Authentication Parameters */ 4410 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4411 ut_params->auth_xform.next = NULL; 4412 4413 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM; 4414 4415 ut_params->auth_xform.auth.digest_length = auth_len; 4416 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 4417 ut_params->auth_xform.auth.key.length = 0; 4418 ut_params->auth_xform.auth.key.data = NULL; 4419 4420 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 4421 ut_params->cipher_xform.next = &ut_params->auth_xform; 4422 4423 /* Create Crypto session*/ 4424 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 4425 &ut_params->cipher_xform); 4426 } else {/* Create Crypto session*/ 4427 ut_params->auth_xform.next = &ut_params->cipher_xform; 4428 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 4429 &ut_params->auth_xform); 4430 } 4431 4432 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4433 4434 return 0; 4435 } 4436 4437 static int 4438 create_gcm_xforms(struct rte_crypto_op *op, 4439 enum rte_crypto_cipher_operation cipher_op, 4440 uint8_t *key, const uint8_t key_len, 4441 const uint8_t aad_len, const uint8_t auth_len, 4442 enum rte_crypto_auth_operation auth_op) 4443 { 4444 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 2), 4445 "failed to allocate space for crypto transforms"); 4446 4447 struct rte_crypto_sym_op *sym_op = op->sym; 4448 4449 /* Setup Cipher Parameters */ 4450 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4451 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM; 4452 sym_op->xform->cipher.op = cipher_op; 4453 sym_op->xform->cipher.key.data = key; 4454 sym_op->xform->cipher.key.length = key_len; 4455 4456 TEST_HEXDUMP(stdout, "key:", key, key_len); 4457 4458 /* Setup Authentication Parameters */ 4459 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH; 4460 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_AES_GCM; 4461 sym_op->xform->next->auth.op = auth_op; 4462 sym_op->xform->next->auth.digest_length = auth_len; 4463 sym_op->xform->next->auth.add_auth_data_length = aad_len; 4464 sym_op->xform->next->auth.key.length = 0; 4465 sym_op->xform->next->auth.key.data = NULL; 4466 sym_op->xform->next->next = NULL; 4467 4468 return 0; 4469 } 4470 4471 static int 4472 create_gcm_operation(enum rte_crypto_cipher_operation op, 4473 const struct gcm_test_data *tdata) 4474 { 4475 struct crypto_testsuite_params *ts_params = &testsuite_params; 4476 struct crypto_unittest_params *ut_params = &unittest_params; 4477 4478 uint8_t *plaintext, *ciphertext; 4479 unsigned int iv_pad_len, aad_pad_len, plaintext_pad_len; 4480 4481 /* Generate Crypto op data structure */ 4482 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4483 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4484 TEST_ASSERT_NOT_NULL(ut_params->op, 4485 "Failed to allocate symmetric crypto operation struct"); 4486 4487 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4488 4489 /* Append aad data */ 4490 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 4491 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4492 aad_pad_len); 4493 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 4494 "no room to append aad"); 4495 4496 sym_op->auth.aad.length = tdata->aad.len; 4497 sym_op->auth.aad.phys_addr = 4498 rte_pktmbuf_mtophys(ut_params->ibuf); 4499 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len); 4500 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, 4501 sym_op->auth.aad.length); 4502 4503 /* Prepend iv */ 4504 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16); 4505 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 4506 ut_params->ibuf, iv_pad_len); 4507 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 4508 4509 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 4510 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 4511 sym_op->cipher.iv.length = tdata->iv.len; 4512 4513 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len); 4514 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, 4515 sym_op->cipher.iv.length); 4516 4517 /* Append plaintext/ciphertext */ 4518 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 4519 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 4520 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4521 plaintext_pad_len); 4522 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 4523 4524 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 4525 TEST_HEXDUMP(stdout, "plaintext:", plaintext, 4526 tdata->plaintext.len); 4527 4528 if (ut_params->obuf) { 4529 ciphertext = (uint8_t *)rte_pktmbuf_append( 4530 ut_params->obuf, 4531 plaintext_pad_len + aad_pad_len + 4532 iv_pad_len); 4533 TEST_ASSERT_NOT_NULL(ciphertext, 4534 "no room to append ciphertext"); 4535 4536 memset(ciphertext + aad_pad_len + iv_pad_len, 0, 4537 tdata->ciphertext.len); 4538 } 4539 } else { 4540 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 4541 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4542 plaintext_pad_len); 4543 TEST_ASSERT_NOT_NULL(ciphertext, 4544 "no room to append ciphertext"); 4545 4546 memcpy(ciphertext, tdata->ciphertext.data, 4547 tdata->ciphertext.len); 4548 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, 4549 tdata->ciphertext.len); 4550 4551 if (ut_params->obuf) { 4552 plaintext = (uint8_t *)rte_pktmbuf_append( 4553 ut_params->obuf, 4554 plaintext_pad_len + aad_pad_len + 4555 iv_pad_len); 4556 TEST_ASSERT_NOT_NULL(plaintext, 4557 "no room to append plaintext"); 4558 4559 memset(plaintext + aad_pad_len + iv_pad_len, 0, 4560 tdata->plaintext.len); 4561 } 4562 } 4563 4564 /* Append digest data */ 4565 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 4566 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 4567 ut_params->obuf ? ut_params->obuf : 4568 ut_params->ibuf, 4569 tdata->auth_tag.len); 4570 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 4571 "no room to append digest"); 4572 memset(sym_op->auth.digest.data, 0, tdata->auth_tag.len); 4573 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 4574 ut_params->obuf ? ut_params->obuf : 4575 ut_params->ibuf, 4576 plaintext_pad_len + 4577 aad_pad_len + iv_pad_len); 4578 sym_op->auth.digest.length = tdata->auth_tag.len; 4579 } else { 4580 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 4581 ut_params->ibuf, tdata->auth_tag.len); 4582 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 4583 "no room to append digest"); 4584 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 4585 ut_params->ibuf, 4586 plaintext_pad_len + aad_pad_len + iv_pad_len); 4587 sym_op->auth.digest.length = tdata->auth_tag.len; 4588 4589 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data, 4590 tdata->auth_tag.len); 4591 TEST_HEXDUMP(stdout, "digest:", 4592 sym_op->auth.digest.data, 4593 sym_op->auth.digest.length); 4594 } 4595 4596 sym_op->cipher.data.length = tdata->plaintext.len; 4597 sym_op->cipher.data.offset = aad_pad_len + iv_pad_len; 4598 4599 sym_op->auth.data.length = tdata->plaintext.len; 4600 sym_op->auth.data.offset = aad_pad_len + iv_pad_len; 4601 4602 return 0; 4603 } 4604 4605 static int 4606 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata) 4607 { 4608 struct crypto_testsuite_params *ts_params = &testsuite_params; 4609 struct crypto_unittest_params *ut_params = &unittest_params; 4610 4611 int retval; 4612 uint8_t *ciphertext, *auth_tag; 4613 uint16_t plaintext_pad_len; 4614 uint32_t i; 4615 4616 /* Create GCM session */ 4617 retval = create_gcm_session(ts_params->valid_devs[0], 4618 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4619 tdata->key.data, tdata->key.len, 4620 tdata->aad.len, tdata->auth_tag.len, 4621 RTE_CRYPTO_AUTH_OP_GENERATE); 4622 if (retval < 0) 4623 return retval; 4624 4625 if (tdata->aad.len > MBUF_SIZE) { 4626 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 4627 /* Populate full size of add data */ 4628 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32) 4629 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 4630 } else 4631 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4632 4633 /* clear mbuf payload */ 4634 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4635 rte_pktmbuf_tailroom(ut_params->ibuf)); 4636 4637 /* Create GCM operation */ 4638 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata); 4639 if (retval < 0) 4640 return retval; 4641 4642 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4643 4644 ut_params->op->sym->m_src = ut_params->ibuf; 4645 4646 /* Process crypto operation */ 4647 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4648 ut_params->op), "failed to process sym crypto op"); 4649 4650 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4651 "crypto op processing failed"); 4652 4653 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 4654 4655 if (ut_params->op->sym->m_dst) { 4656 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 4657 uint8_t *); 4658 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 4659 uint8_t *, plaintext_pad_len); 4660 } else { 4661 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 4662 uint8_t *, 4663 ut_params->op->sym->cipher.data.offset); 4664 auth_tag = ciphertext + plaintext_pad_len; 4665 } 4666 4667 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 4668 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 4669 4670 /* Validate obuf */ 4671 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4672 ciphertext, 4673 tdata->ciphertext.data, 4674 tdata->ciphertext.len, 4675 "GCM Ciphertext data not as expected"); 4676 4677 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4678 auth_tag, 4679 tdata->auth_tag.data, 4680 tdata->auth_tag.len, 4681 "GCM Generated auth tag not as expected"); 4682 4683 return 0; 4684 4685 } 4686 4687 static int 4688 test_mb_AES_GCM_authenticated_encryption_test_case_1(void) 4689 { 4690 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1); 4691 } 4692 4693 static int 4694 test_mb_AES_GCM_authenticated_encryption_test_case_2(void) 4695 { 4696 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2); 4697 } 4698 4699 static int 4700 test_mb_AES_GCM_authenticated_encryption_test_case_3(void) 4701 { 4702 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3); 4703 } 4704 4705 static int 4706 test_mb_AES_GCM_authenticated_encryption_test_case_4(void) 4707 { 4708 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4); 4709 } 4710 4711 static int 4712 test_mb_AES_GCM_authenticated_encryption_test_case_5(void) 4713 { 4714 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5); 4715 } 4716 4717 static int 4718 test_mb_AES_GCM_authenticated_encryption_test_case_6(void) 4719 { 4720 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6); 4721 } 4722 4723 static int 4724 test_mb_AES_GCM_authenticated_encryption_test_case_7(void) 4725 { 4726 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7); 4727 } 4728 4729 static int 4730 test_mb_AES_GCM_auth_encryption_test_case_256_1(void) 4731 { 4732 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_1); 4733 } 4734 4735 static int 4736 test_mb_AES_GCM_auth_encryption_test_case_256_2(void) 4737 { 4738 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_2); 4739 } 4740 4741 static int 4742 test_mb_AES_GCM_auth_encryption_test_case_256_3(void) 4743 { 4744 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_3); 4745 } 4746 4747 static int 4748 test_mb_AES_GCM_auth_encryption_test_case_256_4(void) 4749 { 4750 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_4); 4751 } 4752 4753 static int 4754 test_mb_AES_GCM_auth_encryption_test_case_256_5(void) 4755 { 4756 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_5); 4757 } 4758 4759 static int 4760 test_mb_AES_GCM_auth_encryption_test_case_256_6(void) 4761 { 4762 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_6); 4763 } 4764 4765 static int 4766 test_mb_AES_GCM_auth_encryption_test_case_256_7(void) 4767 { 4768 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_7); 4769 } 4770 4771 static int 4772 test_mb_AES_GCM_auth_encryption_test_case_aad_1(void) 4773 { 4774 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1); 4775 } 4776 4777 static int 4778 test_mb_AES_GCM_auth_encryption_test_case_aad_2(void) 4779 { 4780 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2); 4781 } 4782 4783 static int 4784 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata) 4785 { 4786 struct crypto_testsuite_params *ts_params = &testsuite_params; 4787 struct crypto_unittest_params *ut_params = &unittest_params; 4788 4789 int retval; 4790 uint8_t *plaintext; 4791 uint32_t i; 4792 4793 /* Create GCM session */ 4794 retval = create_gcm_session(ts_params->valid_devs[0], 4795 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4796 tdata->key.data, tdata->key.len, 4797 tdata->aad.len, tdata->auth_tag.len, 4798 RTE_CRYPTO_AUTH_OP_VERIFY); 4799 if (retval < 0) 4800 return retval; 4801 4802 /* alloc mbuf and set payload */ 4803 if (tdata->aad.len > MBUF_SIZE) { 4804 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 4805 /* Populate full size of add data */ 4806 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32) 4807 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 4808 } else 4809 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4810 4811 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4812 rte_pktmbuf_tailroom(ut_params->ibuf)); 4813 4814 /* Create GCM operation */ 4815 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata); 4816 if (retval < 0) 4817 return retval; 4818 4819 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4820 4821 ut_params->op->sym->m_src = ut_params->ibuf; 4822 4823 /* Process crypto operation */ 4824 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4825 ut_params->op), "failed to process sym crypto op"); 4826 4827 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4828 "crypto op processing failed"); 4829 4830 if (ut_params->op->sym->m_dst) 4831 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 4832 uint8_t *); 4833 else 4834 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 4835 uint8_t *, 4836 ut_params->op->sym->cipher.data.offset); 4837 4838 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 4839 4840 /* Validate obuf */ 4841 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4842 plaintext, 4843 tdata->plaintext.data, 4844 tdata->plaintext.len, 4845 "GCM plaintext data not as expected"); 4846 4847 TEST_ASSERT_EQUAL(ut_params->op->status, 4848 RTE_CRYPTO_OP_STATUS_SUCCESS, 4849 "GCM authentication failed"); 4850 return 0; 4851 } 4852 4853 static int 4854 test_mb_AES_GCM_authenticated_decryption_test_case_1(void) 4855 { 4856 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1); 4857 } 4858 4859 static int 4860 test_mb_AES_GCM_authenticated_decryption_test_case_2(void) 4861 { 4862 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2); 4863 } 4864 4865 static int 4866 test_mb_AES_GCM_authenticated_decryption_test_case_3(void) 4867 { 4868 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3); 4869 } 4870 4871 static int 4872 test_mb_AES_GCM_authenticated_decryption_test_case_4(void) 4873 { 4874 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4); 4875 } 4876 4877 static int 4878 test_mb_AES_GCM_authenticated_decryption_test_case_5(void) 4879 { 4880 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5); 4881 } 4882 4883 static int 4884 test_mb_AES_GCM_authenticated_decryption_test_case_6(void) 4885 { 4886 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6); 4887 } 4888 4889 static int 4890 test_mb_AES_GCM_authenticated_decryption_test_case_7(void) 4891 { 4892 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7); 4893 } 4894 4895 static int 4896 test_mb_AES_GCM_auth_decryption_test_case_256_1(void) 4897 { 4898 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_1); 4899 } 4900 4901 static int 4902 test_mb_AES_GCM_auth_decryption_test_case_256_2(void) 4903 { 4904 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_2); 4905 } 4906 4907 static int 4908 test_mb_AES_GCM_auth_decryption_test_case_256_3(void) 4909 { 4910 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_3); 4911 } 4912 4913 static int 4914 test_mb_AES_GCM_auth_decryption_test_case_256_4(void) 4915 { 4916 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_4); 4917 } 4918 4919 static int 4920 test_mb_AES_GCM_auth_decryption_test_case_256_5(void) 4921 { 4922 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_5); 4923 } 4924 4925 static int 4926 test_mb_AES_GCM_auth_decryption_test_case_256_6(void) 4927 { 4928 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_6); 4929 } 4930 4931 static int 4932 test_mb_AES_GCM_auth_decryption_test_case_256_7(void) 4933 { 4934 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_7); 4935 } 4936 4937 static int 4938 test_mb_AES_GCM_auth_decryption_test_case_aad_1(void) 4939 { 4940 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1); 4941 } 4942 4943 static int 4944 test_mb_AES_GCM_auth_decryption_test_case_aad_2(void) 4945 { 4946 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2); 4947 } 4948 4949 static int 4950 test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata) 4951 { 4952 struct crypto_testsuite_params *ts_params = &testsuite_params; 4953 struct crypto_unittest_params *ut_params = &unittest_params; 4954 4955 int retval; 4956 uint8_t *ciphertext, *auth_tag; 4957 uint16_t plaintext_pad_len; 4958 4959 /* Create GCM session */ 4960 retval = create_gcm_session(ts_params->valid_devs[0], 4961 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4962 tdata->key.data, tdata->key.len, 4963 tdata->aad.len, tdata->auth_tag.len, 4964 RTE_CRYPTO_AUTH_OP_GENERATE); 4965 if (retval < 0) 4966 return retval; 4967 4968 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4969 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4970 4971 /* clear mbuf payload */ 4972 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4973 rte_pktmbuf_tailroom(ut_params->ibuf)); 4974 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4975 rte_pktmbuf_tailroom(ut_params->obuf)); 4976 4977 /* Create GCM operation */ 4978 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata); 4979 if (retval < 0) 4980 return retval; 4981 4982 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4983 4984 ut_params->op->sym->m_src = ut_params->ibuf; 4985 ut_params->op->sym->m_dst = ut_params->obuf; 4986 4987 /* Process crypto operation */ 4988 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4989 ut_params->op), "failed to process sym crypto op"); 4990 4991 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4992 "crypto op processing failed"); 4993 4994 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 4995 4996 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 4997 ut_params->op->sym->cipher.data.offset); 4998 auth_tag = ciphertext + plaintext_pad_len; 4999 5000 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 5001 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 5002 5003 /* Validate obuf */ 5004 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5005 ciphertext, 5006 tdata->ciphertext.data, 5007 tdata->ciphertext.len, 5008 "GCM Ciphertext data not as expected"); 5009 5010 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5011 auth_tag, 5012 tdata->auth_tag.data, 5013 tdata->auth_tag.len, 5014 "GCM Generated auth tag not as expected"); 5015 5016 return 0; 5017 5018 } 5019 5020 static int 5021 test_mb_AES_GCM_authenticated_encryption_oop(void) 5022 { 5023 return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5); 5024 } 5025 5026 static int 5027 test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata) 5028 { 5029 struct crypto_testsuite_params *ts_params = &testsuite_params; 5030 struct crypto_unittest_params *ut_params = &unittest_params; 5031 5032 int retval; 5033 uint8_t *plaintext; 5034 5035 /* Create GCM session */ 5036 retval = create_gcm_session(ts_params->valid_devs[0], 5037 RTE_CRYPTO_CIPHER_OP_DECRYPT, 5038 tdata->key.data, tdata->key.len, 5039 tdata->aad.len, tdata->auth_tag.len, 5040 RTE_CRYPTO_AUTH_OP_VERIFY); 5041 if (retval < 0) 5042 return retval; 5043 5044 /* alloc mbuf and set payload */ 5045 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5046 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5047 5048 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5049 rte_pktmbuf_tailroom(ut_params->ibuf)); 5050 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5051 rte_pktmbuf_tailroom(ut_params->obuf)); 5052 5053 /* Create GCM operation */ 5054 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata); 5055 if (retval < 0) 5056 return retval; 5057 5058 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5059 5060 ut_params->op->sym->m_src = ut_params->ibuf; 5061 ut_params->op->sym->m_dst = ut_params->obuf; 5062 5063 /* Process crypto operation */ 5064 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5065 ut_params->op), "failed to process sym crypto op"); 5066 5067 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5068 "crypto op processing failed"); 5069 5070 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5071 ut_params->op->sym->cipher.data.offset); 5072 5073 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 5074 5075 /* Validate obuf */ 5076 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5077 plaintext, 5078 tdata->plaintext.data, 5079 tdata->plaintext.len, 5080 "GCM plaintext data not as expected"); 5081 5082 TEST_ASSERT_EQUAL(ut_params->op->status, 5083 RTE_CRYPTO_OP_STATUS_SUCCESS, 5084 "GCM authentication failed"); 5085 return 0; 5086 } 5087 5088 static int 5089 test_mb_AES_GCM_authenticated_decryption_oop(void) 5090 { 5091 return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5); 5092 } 5093 5094 static int 5095 test_AES_GCM_authenticated_encryption_sessionless( 5096 const struct gcm_test_data *tdata) 5097 { 5098 struct crypto_testsuite_params *ts_params = &testsuite_params; 5099 struct crypto_unittest_params *ut_params = &unittest_params; 5100 5101 int retval; 5102 uint8_t *ciphertext, *auth_tag; 5103 uint16_t plaintext_pad_len; 5104 uint8_t key[tdata->key.len + 1]; 5105 5106 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5107 5108 /* clear mbuf payload */ 5109 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5110 rte_pktmbuf_tailroom(ut_params->ibuf)); 5111 5112 /* Create GCM operation */ 5113 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata); 5114 if (retval < 0) 5115 return retval; 5116 5117 /* Create GCM xforms */ 5118 memcpy(key, tdata->key.data, tdata->key.len); 5119 retval = create_gcm_xforms(ut_params->op, 5120 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5121 key, tdata->key.len, 5122 tdata->aad.len, tdata->auth_tag.len, 5123 RTE_CRYPTO_AUTH_OP_GENERATE); 5124 if (retval < 0) 5125 return retval; 5126 5127 ut_params->op->sym->m_src = ut_params->ibuf; 5128 5129 TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type, 5130 RTE_CRYPTO_SYM_OP_SESSIONLESS, 5131 "crypto op session type not sessionless"); 5132 5133 /* Process crypto operation */ 5134 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5135 ut_params->op), "failed to process sym crypto op"); 5136 5137 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 5138 5139 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5140 "crypto op status not success"); 5141 5142 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 5143 5144 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 5145 ut_params->op->sym->cipher.data.offset); 5146 auth_tag = ciphertext + plaintext_pad_len; 5147 5148 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 5149 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 5150 5151 /* Validate obuf */ 5152 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5153 ciphertext, 5154 tdata->ciphertext.data, 5155 tdata->ciphertext.len, 5156 "GCM Ciphertext data not as expected"); 5157 5158 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5159 auth_tag, 5160 tdata->auth_tag.data, 5161 tdata->auth_tag.len, 5162 "GCM Generated auth tag not as expected"); 5163 5164 return 0; 5165 5166 } 5167 5168 static int 5169 test_mb_AES_GCM_authenticated_encryption_sessionless(void) 5170 { 5171 return test_AES_GCM_authenticated_encryption_sessionless( 5172 &gcm_test_case_5); 5173 } 5174 5175 static int 5176 test_AES_GCM_authenticated_decryption_sessionless( 5177 const struct gcm_test_data *tdata) 5178 { 5179 struct crypto_testsuite_params *ts_params = &testsuite_params; 5180 struct crypto_unittest_params *ut_params = &unittest_params; 5181 5182 int retval; 5183 uint8_t *plaintext; 5184 uint8_t key[tdata->key.len + 1]; 5185 5186 /* alloc mbuf and set payload */ 5187 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5188 5189 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5190 rte_pktmbuf_tailroom(ut_params->ibuf)); 5191 5192 /* Create GCM operation */ 5193 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata); 5194 if (retval < 0) 5195 return retval; 5196 5197 /* Create GCM xforms */ 5198 memcpy(key, tdata->key.data, tdata->key.len); 5199 retval = create_gcm_xforms(ut_params->op, 5200 RTE_CRYPTO_CIPHER_OP_DECRYPT, 5201 key, tdata->key.len, 5202 tdata->aad.len, tdata->auth_tag.len, 5203 RTE_CRYPTO_AUTH_OP_VERIFY); 5204 if (retval < 0) 5205 return retval; 5206 5207 ut_params->op->sym->m_src = ut_params->ibuf; 5208 5209 TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type, 5210 RTE_CRYPTO_SYM_OP_SESSIONLESS, 5211 "crypto op session type not sessionless"); 5212 5213 /* Process crypto operation */ 5214 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5215 ut_params->op), "failed to process sym crypto op"); 5216 5217 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 5218 5219 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5220 "crypto op status not success"); 5221 5222 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 5223 ut_params->op->sym->cipher.data.offset); 5224 5225 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 5226 5227 /* Validate obuf */ 5228 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5229 plaintext, 5230 tdata->plaintext.data, 5231 tdata->plaintext.len, 5232 "GCM plaintext data not as expected"); 5233 5234 TEST_ASSERT_EQUAL(ut_params->op->status, 5235 RTE_CRYPTO_OP_STATUS_SUCCESS, 5236 "GCM authentication failed"); 5237 return 0; 5238 } 5239 5240 static int 5241 test_mb_AES_GCM_authenticated_decryption_sessionless(void) 5242 { 5243 return test_AES_GCM_authenticated_decryption_sessionless( 5244 &gcm_test_case_5); 5245 } 5246 5247 static int 5248 test_stats(void) 5249 { 5250 struct crypto_testsuite_params *ts_params = &testsuite_params; 5251 struct rte_cryptodev_stats stats; 5252 struct rte_cryptodev *dev; 5253 cryptodev_stats_get_t temp_pfn; 5254 5255 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 5256 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 5257 &stats) == -ENODEV), 5258 "rte_cryptodev_stats_get invalid dev failed"); 5259 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 5260 "rte_cryptodev_stats_get invalid Param failed"); 5261 dev = &rte_cryptodevs[ts_params->valid_devs[0]]; 5262 temp_pfn = dev->dev_ops->stats_get; 5263 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0; 5264 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 5265 == -ENOTSUP), 5266 "rte_cryptodev_stats_get invalid Param failed"); 5267 dev->dev_ops->stats_get = temp_pfn; 5268 5269 /* Test expected values */ 5270 ut_setup(); 5271 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 5272 ut_teardown(); 5273 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 5274 &stats), 5275 "rte_cryptodev_stats_get failed"); 5276 TEST_ASSERT((stats.enqueued_count == 1), 5277 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5278 TEST_ASSERT((stats.dequeued_count == 1), 5279 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5280 TEST_ASSERT((stats.enqueue_err_count == 0), 5281 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5282 TEST_ASSERT((stats.dequeue_err_count == 0), 5283 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5284 5285 /* invalid device but should ignore and not reset device stats*/ 5286 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 5287 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 5288 &stats), 5289 "rte_cryptodev_stats_get failed"); 5290 TEST_ASSERT((stats.enqueued_count == 1), 5291 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5292 5293 /* check that a valid reset clears stats */ 5294 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 5295 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 5296 &stats), 5297 "rte_cryptodev_stats_get failed"); 5298 TEST_ASSERT((stats.enqueued_count == 0), 5299 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5300 TEST_ASSERT((stats.dequeued_count == 0), 5301 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 5302 5303 return TEST_SUCCESS; 5304 } 5305 5306 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 5307 struct crypto_unittest_params *ut_params, 5308 enum rte_crypto_auth_operation op, 5309 const struct HMAC_MD5_vector *test_case) 5310 { 5311 uint8_t key[64]; 5312 5313 memcpy(key, test_case->key.data, test_case->key.len); 5314 5315 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5316 ut_params->auth_xform.next = NULL; 5317 ut_params->auth_xform.auth.op = op; 5318 5319 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 5320 5321 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 5322 ut_params->auth_xform.auth.add_auth_data_length = 0; 5323 ut_params->auth_xform.auth.key.length = test_case->key.len; 5324 ut_params->auth_xform.auth.key.data = key; 5325 5326 ut_params->sess = rte_cryptodev_sym_session_create( 5327 ts_params->valid_devs[0], &ut_params->auth_xform); 5328 5329 if (ut_params->sess == NULL) 5330 return TEST_FAILED; 5331 5332 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5333 5334 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5335 rte_pktmbuf_tailroom(ut_params->ibuf)); 5336 5337 return 0; 5338 } 5339 5340 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 5341 const struct HMAC_MD5_vector *test_case, 5342 uint8_t **plaintext) 5343 { 5344 uint16_t plaintext_pad_len; 5345 5346 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5347 5348 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 5349 16); 5350 5351 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5352 plaintext_pad_len); 5353 memcpy(*plaintext, test_case->plaintext.data, 5354 test_case->plaintext.len); 5355 5356 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 5357 ut_params->ibuf, MD5_DIGEST_LEN); 5358 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 5359 "no room to append digest"); 5360 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 5361 ut_params->ibuf, plaintext_pad_len); 5362 sym_op->auth.digest.length = MD5_DIGEST_LEN; 5363 5364 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 5365 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 5366 test_case->auth_tag.len); 5367 } 5368 5369 sym_op->auth.data.offset = 0; 5370 sym_op->auth.data.length = test_case->plaintext.len; 5371 5372 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5373 ut_params->op->sym->m_src = ut_params->ibuf; 5374 5375 return 0; 5376 } 5377 5378 static int 5379 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 5380 { 5381 uint16_t plaintext_pad_len; 5382 uint8_t *plaintext, *auth_tag; 5383 5384 struct crypto_testsuite_params *ts_params = &testsuite_params; 5385 struct crypto_unittest_params *ut_params = &unittest_params; 5386 5387 if (MD5_HMAC_create_session(ts_params, ut_params, 5388 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 5389 return TEST_FAILED; 5390 5391 /* Generate Crypto op data structure */ 5392 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5393 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5394 TEST_ASSERT_NOT_NULL(ut_params->op, 5395 "Failed to allocate symmetric crypto operation struct"); 5396 5397 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 5398 16); 5399 5400 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 5401 return TEST_FAILED; 5402 5403 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5404 ut_params->op), "failed to process sym crypto op"); 5405 5406 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5407 "crypto op processing failed"); 5408 5409 if (ut_params->op->sym->m_dst) { 5410 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 5411 uint8_t *, plaintext_pad_len); 5412 } else { 5413 auth_tag = plaintext + plaintext_pad_len; 5414 } 5415 5416 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5417 auth_tag, 5418 test_case->auth_tag.data, 5419 test_case->auth_tag.len, 5420 "HMAC_MD5 generated tag not as expected"); 5421 5422 return TEST_SUCCESS; 5423 } 5424 5425 static int 5426 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 5427 { 5428 uint8_t *plaintext; 5429 5430 struct crypto_testsuite_params *ts_params = &testsuite_params; 5431 struct crypto_unittest_params *ut_params = &unittest_params; 5432 5433 if (MD5_HMAC_create_session(ts_params, ut_params, 5434 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 5435 return TEST_FAILED; 5436 } 5437 5438 /* Generate Crypto op data structure */ 5439 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5440 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5441 TEST_ASSERT_NOT_NULL(ut_params->op, 5442 "Failed to allocate symmetric crypto operation struct"); 5443 5444 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 5445 return TEST_FAILED; 5446 5447 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5448 ut_params->op), "failed to process sym crypto op"); 5449 5450 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5451 "HMAC_MD5 crypto op processing failed"); 5452 5453 return TEST_SUCCESS; 5454 } 5455 5456 static int 5457 test_MD5_HMAC_generate_case_1(void) 5458 { 5459 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 5460 } 5461 5462 static int 5463 test_MD5_HMAC_verify_case_1(void) 5464 { 5465 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 5466 } 5467 5468 static int 5469 test_MD5_HMAC_generate_case_2(void) 5470 { 5471 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 5472 } 5473 5474 static int 5475 test_MD5_HMAC_verify_case_2(void) 5476 { 5477 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 5478 } 5479 5480 static int 5481 test_multi_session(void) 5482 { 5483 struct crypto_testsuite_params *ts_params = &testsuite_params; 5484 struct crypto_unittest_params *ut_params = &unittest_params; 5485 5486 struct rte_cryptodev_info dev_info; 5487 struct rte_cryptodev_sym_session **sessions; 5488 5489 uint16_t i; 5490 5491 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 5492 aes_cbc_key, hmac_sha512_key); 5493 5494 5495 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5496 5497 sessions = rte_malloc(NULL, 5498 (sizeof(struct rte_cryptodev_sym_session *) * 5499 dev_info.sym.max_nb_sessions) + 1, 0); 5500 5501 /* Create multiple crypto sessions*/ 5502 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) { 5503 sessions[i] = rte_cryptodev_sym_session_create( 5504 ts_params->valid_devs[0], 5505 &ut_params->auth_xform); 5506 TEST_ASSERT_NOT_NULL(sessions[i], 5507 "Session creation failed at session number %u", 5508 i); 5509 5510 /* Attempt to send a request on each session */ 5511 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 5512 sessions[i], 5513 ut_params, 5514 ts_params, 5515 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 5516 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 5517 aes_cbc_iv), 5518 "Failed to perform decrypt on request number %u.", i); 5519 /* free crypto operation structure */ 5520 if (ut_params->op) 5521 rte_crypto_op_free(ut_params->op); 5522 5523 /* 5524 * free mbuf - both obuf and ibuf are usually the same, 5525 * so check if they point at the same address is necessary, 5526 * to avoid freeing the mbuf twice. 5527 */ 5528 if (ut_params->obuf) { 5529 rte_pktmbuf_free(ut_params->obuf); 5530 if (ut_params->ibuf == ut_params->obuf) 5531 ut_params->ibuf = 0; 5532 ut_params->obuf = 0; 5533 } 5534 if (ut_params->ibuf) { 5535 rte_pktmbuf_free(ut_params->ibuf); 5536 ut_params->ibuf = 0; 5537 } 5538 } 5539 5540 /* Next session create should fail */ 5541 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0], 5542 &ut_params->auth_xform); 5543 TEST_ASSERT_NULL(sessions[i], 5544 "Session creation succeeded unexpectedly!"); 5545 5546 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) 5547 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 5548 sessions[i]); 5549 5550 rte_free(sessions); 5551 5552 return TEST_SUCCESS; 5553 } 5554 5555 struct multi_session_params { 5556 struct crypto_unittest_params ut_params; 5557 uint8_t *cipher_key; 5558 uint8_t *hmac_key; 5559 const uint8_t *cipher; 5560 const uint8_t *digest; 5561 uint8_t *iv; 5562 }; 5563 5564 #define MB_SESSION_NUMBER 3 5565 5566 static int 5567 test_multi_session_random_usage(void) 5568 { 5569 struct crypto_testsuite_params *ts_params = &testsuite_params; 5570 struct rte_cryptodev_info dev_info; 5571 struct rte_cryptodev_sym_session **sessions; 5572 uint32_t i, j; 5573 struct multi_session_params ut_paramz[] = { 5574 5575 { 5576 .cipher_key = ms_aes_cbc_key0, 5577 .hmac_key = ms_hmac_key0, 5578 .cipher = ms_aes_cbc_cipher0, 5579 .digest = ms_hmac_digest0, 5580 .iv = ms_aes_cbc_iv0 5581 }, 5582 { 5583 .cipher_key = ms_aes_cbc_key1, 5584 .hmac_key = ms_hmac_key1, 5585 .cipher = ms_aes_cbc_cipher1, 5586 .digest = ms_hmac_digest1, 5587 .iv = ms_aes_cbc_iv1 5588 }, 5589 { 5590 .cipher_key = ms_aes_cbc_key2, 5591 .hmac_key = ms_hmac_key2, 5592 .cipher = ms_aes_cbc_cipher2, 5593 .digest = ms_hmac_digest2, 5594 .iv = ms_aes_cbc_iv2 5595 }, 5596 5597 }; 5598 5599 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5600 5601 sessions = rte_malloc(NULL, 5602 (sizeof(struct rte_cryptodev_sym_session *) 5603 * dev_info.sym.max_nb_sessions) + 1, 0); 5604 5605 for (i = 0; i < MB_SESSION_NUMBER; i++) { 5606 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params, 5607 sizeof(struct crypto_unittest_params)); 5608 5609 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 5610 &ut_paramz[i].ut_params, 5611 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 5612 5613 /* Create multiple crypto sessions*/ 5614 sessions[i] = rte_cryptodev_sym_session_create( 5615 ts_params->valid_devs[0], 5616 &ut_paramz[i].ut_params.auth_xform); 5617 5618 TEST_ASSERT_NOT_NULL(sessions[i], 5619 "Session creation failed at session number %u", 5620 i); 5621 5622 } 5623 5624 srand(time(NULL)); 5625 for (i = 0; i < 40000; i++) { 5626 5627 j = rand() % MB_SESSION_NUMBER; 5628 5629 TEST_ASSERT_SUCCESS( 5630 test_AES_CBC_HMAC_SHA512_decrypt_perform( 5631 sessions[j], 5632 &ut_paramz[j].ut_params, 5633 ts_params, ut_paramz[j].cipher, 5634 ut_paramz[j].digest, 5635 ut_paramz[j].iv), 5636 "Failed to perform decrypt on request number %u.", i); 5637 5638 if (ut_paramz[j].ut_params.op) 5639 rte_crypto_op_free(ut_paramz[j].ut_params.op); 5640 5641 /* 5642 * free mbuf - both obuf and ibuf are usually the same, 5643 * so check if they point at the same address is necessary, 5644 * to avoid freeing the mbuf twice. 5645 */ 5646 if (ut_paramz[j].ut_params.obuf) { 5647 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 5648 if (ut_paramz[j].ut_params.ibuf 5649 == ut_paramz[j].ut_params.obuf) 5650 ut_paramz[j].ut_params.ibuf = 0; 5651 ut_paramz[j].ut_params.obuf = 0; 5652 } 5653 if (ut_paramz[j].ut_params.ibuf) { 5654 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 5655 ut_paramz[j].ut_params.ibuf = 0; 5656 } 5657 } 5658 5659 for (i = 0; i < MB_SESSION_NUMBER; i++) 5660 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 5661 sessions[i]); 5662 5663 rte_free(sessions); 5664 5665 return TEST_SUCCESS; 5666 } 5667 5668 static int 5669 test_null_cipher_only_operation(void) 5670 { 5671 struct crypto_testsuite_params *ts_params = &testsuite_params; 5672 struct crypto_unittest_params *ut_params = &unittest_params; 5673 5674 /* Generate test mbuf data and space for digest */ 5675 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 5676 catch_22_quote, QUOTE_512_BYTES, 0); 5677 5678 /* Setup Cipher Parameters */ 5679 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5680 ut_params->cipher_xform.next = NULL; 5681 5682 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 5683 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 5684 5685 /* Create Crypto session*/ 5686 ut_params->sess = rte_cryptodev_sym_session_create( 5687 ts_params->valid_devs[0], &ut_params->cipher_xform); 5688 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5689 5690 /* Generate Crypto op data structure */ 5691 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5692 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5693 TEST_ASSERT_NOT_NULL(ut_params->op, 5694 "Failed to allocate symmetric crypto operation struct"); 5695 5696 /* Set crypto operation data parameters */ 5697 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5698 5699 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5700 5701 /* set crypto operation source mbuf */ 5702 sym_op->m_src = ut_params->ibuf; 5703 5704 sym_op->cipher.data.offset = 0; 5705 sym_op->cipher.data.length = QUOTE_512_BYTES; 5706 5707 /* Process crypto operation */ 5708 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5709 ut_params->op); 5710 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 5711 5712 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5713 "crypto operation processing failed"); 5714 5715 /* Validate obuf */ 5716 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5717 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 5718 catch_22_quote, 5719 QUOTE_512_BYTES, 5720 "Ciphertext data not as expected"); 5721 5722 return TEST_SUCCESS; 5723 } 5724 5725 static int 5726 test_null_auth_only_operation(void) 5727 { 5728 struct crypto_testsuite_params *ts_params = &testsuite_params; 5729 struct crypto_unittest_params *ut_params = &unittest_params; 5730 5731 /* Generate test mbuf data and space for digest */ 5732 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 5733 catch_22_quote, QUOTE_512_BYTES, 0); 5734 5735 /* Setup HMAC Parameters */ 5736 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5737 ut_params->auth_xform.next = NULL; 5738 5739 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 5740 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 5741 5742 /* Create Crypto session*/ 5743 ut_params->sess = rte_cryptodev_sym_session_create( 5744 ts_params->valid_devs[0], &ut_params->auth_xform); 5745 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5746 5747 /* Generate Crypto op data structure */ 5748 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5749 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5750 TEST_ASSERT_NOT_NULL(ut_params->op, 5751 "Failed to allocate symmetric crypto operation struct"); 5752 5753 /* Set crypto operation data parameters */ 5754 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5755 5756 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5757 5758 sym_op->m_src = ut_params->ibuf; 5759 5760 sym_op->auth.data.offset = 0; 5761 sym_op->auth.data.length = QUOTE_512_BYTES; 5762 5763 /* Process crypto operation */ 5764 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5765 ut_params->op); 5766 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 5767 5768 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5769 "crypto operation processing failed"); 5770 5771 return TEST_SUCCESS; 5772 } 5773 5774 static int 5775 test_null_cipher_auth_operation(void) 5776 { 5777 struct crypto_testsuite_params *ts_params = &testsuite_params; 5778 struct crypto_unittest_params *ut_params = &unittest_params; 5779 5780 /* Generate test mbuf data and space for digest */ 5781 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 5782 catch_22_quote, QUOTE_512_BYTES, 0); 5783 5784 /* Setup Cipher Parameters */ 5785 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5786 ut_params->cipher_xform.next = &ut_params->auth_xform; 5787 5788 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 5789 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 5790 5791 /* Setup HMAC Parameters */ 5792 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5793 ut_params->auth_xform.next = NULL; 5794 5795 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 5796 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 5797 5798 /* Create Crypto session*/ 5799 ut_params->sess = rte_cryptodev_sym_session_create( 5800 ts_params->valid_devs[0], &ut_params->cipher_xform); 5801 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5802 5803 /* Generate Crypto op data structure */ 5804 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5805 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5806 TEST_ASSERT_NOT_NULL(ut_params->op, 5807 "Failed to allocate symmetric crypto operation struct"); 5808 5809 /* Set crypto operation data parameters */ 5810 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5811 5812 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5813 5814 sym_op->m_src = ut_params->ibuf; 5815 5816 sym_op->cipher.data.offset = 0; 5817 sym_op->cipher.data.length = QUOTE_512_BYTES; 5818 5819 sym_op->auth.data.offset = 0; 5820 sym_op->auth.data.length = QUOTE_512_BYTES; 5821 5822 /* Process crypto operation */ 5823 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5824 ut_params->op); 5825 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 5826 5827 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5828 "crypto operation processing failed"); 5829 5830 /* Validate obuf */ 5831 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5832 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 5833 catch_22_quote, 5834 QUOTE_512_BYTES, 5835 "Ciphertext data not as expected"); 5836 5837 return TEST_SUCCESS; 5838 } 5839 5840 static int 5841 test_null_auth_cipher_operation(void) 5842 { 5843 struct crypto_testsuite_params *ts_params = &testsuite_params; 5844 struct crypto_unittest_params *ut_params = &unittest_params; 5845 5846 /* Generate test mbuf data and space for digest */ 5847 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 5848 catch_22_quote, QUOTE_512_BYTES, 0); 5849 5850 /* Setup Cipher Parameters */ 5851 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5852 ut_params->cipher_xform.next = NULL; 5853 5854 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 5855 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 5856 5857 /* Setup HMAC Parameters */ 5858 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5859 ut_params->auth_xform.next = &ut_params->cipher_xform; 5860 5861 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 5862 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 5863 5864 /* Create Crypto session*/ 5865 ut_params->sess = rte_cryptodev_sym_session_create( 5866 ts_params->valid_devs[0], &ut_params->cipher_xform); 5867 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5868 5869 /* Generate Crypto op data structure */ 5870 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5871 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5872 TEST_ASSERT_NOT_NULL(ut_params->op, 5873 "Failed to allocate symmetric crypto operation struct"); 5874 5875 /* Set crypto operation data parameters */ 5876 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5877 5878 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5879 5880 sym_op->m_src = ut_params->ibuf; 5881 5882 sym_op->cipher.data.offset = 0; 5883 sym_op->cipher.data.length = QUOTE_512_BYTES; 5884 5885 sym_op->auth.data.offset = 0; 5886 sym_op->auth.data.length = QUOTE_512_BYTES; 5887 5888 /* Process crypto operation */ 5889 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5890 ut_params->op); 5891 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 5892 5893 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5894 "crypto operation processing failed"); 5895 5896 /* Validate obuf */ 5897 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5898 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 5899 catch_22_quote, 5900 QUOTE_512_BYTES, 5901 "Ciphertext data not as expected"); 5902 5903 return TEST_SUCCESS; 5904 } 5905 5906 5907 static int 5908 test_null_invalid_operation(void) 5909 { 5910 struct crypto_testsuite_params *ts_params = &testsuite_params; 5911 struct crypto_unittest_params *ut_params = &unittest_params; 5912 5913 /* Setup Cipher Parameters */ 5914 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5915 ut_params->cipher_xform.next = NULL; 5916 5917 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 5918 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 5919 5920 /* Create Crypto session*/ 5921 ut_params->sess = rte_cryptodev_sym_session_create( 5922 ts_params->valid_devs[0], &ut_params->cipher_xform); 5923 TEST_ASSERT_NULL(ut_params->sess, 5924 "Session creation succeeded unexpectedly"); 5925 5926 5927 /* Setup HMAC Parameters */ 5928 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5929 ut_params->auth_xform.next = NULL; 5930 5931 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 5932 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 5933 5934 /* Create Crypto session*/ 5935 ut_params->sess = rte_cryptodev_sym_session_create( 5936 ts_params->valid_devs[0], &ut_params->auth_xform); 5937 TEST_ASSERT_NULL(ut_params->sess, 5938 "Session creation succeeded unexpectedly"); 5939 5940 return TEST_SUCCESS; 5941 } 5942 5943 5944 #define NULL_BURST_LENGTH (32) 5945 5946 static int 5947 test_null_burst_operation(void) 5948 { 5949 struct crypto_testsuite_params *ts_params = &testsuite_params; 5950 struct crypto_unittest_params *ut_params = &unittest_params; 5951 5952 unsigned i, burst_len = NULL_BURST_LENGTH; 5953 5954 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 5955 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 5956 5957 /* Setup Cipher Parameters */ 5958 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5959 ut_params->cipher_xform.next = &ut_params->auth_xform; 5960 5961 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 5962 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 5963 5964 /* Setup HMAC Parameters */ 5965 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5966 ut_params->auth_xform.next = NULL; 5967 5968 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 5969 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 5970 5971 /* Create Crypto session*/ 5972 ut_params->sess = rte_cryptodev_sym_session_create( 5973 ts_params->valid_devs[0], &ut_params->cipher_xform); 5974 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5975 5976 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 5977 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 5978 burst_len, "failed to generate burst of crypto ops"); 5979 5980 /* Generate an operation for each mbuf in burst */ 5981 for (i = 0; i < burst_len; i++) { 5982 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5983 5984 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 5985 5986 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 5987 sizeof(unsigned)); 5988 *data = i; 5989 5990 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 5991 5992 burst[i]->sym->m_src = m; 5993 } 5994 5995 /* Process crypto operation */ 5996 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 5997 0, burst, burst_len), 5998 burst_len, 5999 "Error enqueuing burst"); 6000 6001 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 6002 0, burst_dequeued, burst_len), 6003 burst_len, 6004 "Error dequeuing burst"); 6005 6006 6007 for (i = 0; i < burst_len; i++) { 6008 TEST_ASSERT_EQUAL( 6009 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 6010 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 6011 uint32_t *), 6012 "data not as expected"); 6013 6014 rte_pktmbuf_free(burst[i]->sym->m_src); 6015 rte_crypto_op_free(burst[i]); 6016 } 6017 6018 return TEST_SUCCESS; 6019 } 6020 6021 static void 6022 generate_gmac_large_plaintext(uint8_t *data) 6023 { 6024 uint16_t i; 6025 6026 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 6027 memcpy(&data[i], &data[0], 32); 6028 } 6029 6030 static int 6031 create_gmac_operation(enum rte_crypto_auth_operation op, 6032 const struct gmac_test_data *tdata) 6033 { 6034 struct crypto_testsuite_params *ts_params = &testsuite_params; 6035 struct crypto_unittest_params *ut_params = &unittest_params; 6036 struct rte_crypto_sym_op *sym_op; 6037 6038 unsigned iv_pad_len; 6039 unsigned aad_pad_len; 6040 6041 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16); 6042 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 6043 6044 /* 6045 * Runtime generate the large plain text instead of use hard code 6046 * plain text vector. It is done to avoid create huge source file 6047 * with the test vector. 6048 */ 6049 if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH) 6050 generate_gmac_large_plaintext(tdata->aad.data); 6051 6052 /* Generate Crypto op data structure */ 6053 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6054 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6055 TEST_ASSERT_NOT_NULL(ut_params->op, 6056 "Failed to allocate symmetric crypto operation struct"); 6057 6058 sym_op = ut_params->op->sym; 6059 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6060 aad_pad_len); 6061 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 6062 "no room to append aad"); 6063 6064 sym_op->auth.aad.length = tdata->aad.len; 6065 sym_op->auth.aad.phys_addr = 6066 rte_pktmbuf_mtophys(ut_params->ibuf); 6067 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len); 6068 6069 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 6070 ut_params->ibuf, tdata->gmac_tag.len); 6071 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 6072 "no room to append digest"); 6073 6074 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 6075 ut_params->ibuf, aad_pad_len); 6076 sym_op->auth.digest.length = tdata->gmac_tag.len; 6077 6078 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 6079 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 6080 tdata->gmac_tag.len); 6081 TEST_HEXDUMP(stdout, "digest:", 6082 sym_op->auth.digest.data, 6083 sym_op->auth.digest.length); 6084 } 6085 6086 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 6087 ut_params->ibuf, iv_pad_len); 6088 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 6089 6090 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 6091 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 6092 sym_op->cipher.iv.length = tdata->iv.len; 6093 6094 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len); 6095 6096 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len); 6097 6098 sym_op->cipher.data.length = 0; 6099 sym_op->cipher.data.offset = 0; 6100 6101 sym_op->auth.data.offset = 0; 6102 sym_op->auth.data.length = 0; 6103 6104 return 0; 6105 } 6106 6107 static int create_gmac_session(uint8_t dev_id, 6108 enum rte_crypto_cipher_operation op, 6109 const struct gmac_test_data *tdata, 6110 enum rte_crypto_auth_operation auth_op) 6111 { 6112 uint8_t cipher_key[tdata->key.len]; 6113 6114 struct crypto_unittest_params *ut_params = &unittest_params; 6115 6116 memcpy(cipher_key, tdata->key.data, tdata->key.len); 6117 6118 /* For GMAC we setup cipher parameters */ 6119 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6120 ut_params->cipher_xform.next = NULL; 6121 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM; 6122 ut_params->cipher_xform.cipher.op = op; 6123 ut_params->cipher_xform.cipher.key.data = cipher_key; 6124 ut_params->cipher_xform.cipher.key.length = tdata->key.len; 6125 6126 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6127 ut_params->auth_xform.next = NULL; 6128 6129 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 6130 ut_params->auth_xform.auth.op = auth_op; 6131 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 6132 ut_params->auth_xform.auth.add_auth_data_length = 0; 6133 ut_params->auth_xform.auth.key.length = 0; 6134 ut_params->auth_xform.auth.key.data = NULL; 6135 6136 ut_params->cipher_xform.next = &ut_params->auth_xform; 6137 6138 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 6139 &ut_params->cipher_xform); 6140 6141 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 6142 6143 return 0; 6144 } 6145 6146 static int 6147 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 6148 { 6149 struct crypto_testsuite_params *ts_params = &testsuite_params; 6150 struct crypto_unittest_params *ut_params = &unittest_params; 6151 6152 int retval; 6153 6154 uint8_t *auth_tag, *p; 6155 uint16_t aad_pad_len; 6156 6157 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 6158 "No GMAC length in the source data"); 6159 6160 retval = create_gmac_session(ts_params->valid_devs[0], 6161 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6162 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 6163 6164 if (retval < 0) 6165 return retval; 6166 6167 if (tdata->aad.len > MBUF_SIZE) 6168 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 6169 else 6170 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6171 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6172 "Failed to allocate input buffer in mempool"); 6173 6174 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6175 rte_pktmbuf_tailroom(ut_params->ibuf)); 6176 6177 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 6178 6179 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *); 6180 6181 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 6182 tdata); 6183 6184 if (retval < 0) 6185 return retval; 6186 6187 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 6188 6189 ut_params->op->sym->m_src = ut_params->ibuf; 6190 6191 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 6192 ut_params->op), "failed to process sym crypto op"); 6193 6194 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6195 "crypto op processing failed"); 6196 6197 if (ut_params->op->sym->m_dst) { 6198 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 6199 uint8_t *, aad_pad_len); 6200 } else { 6201 auth_tag = p + aad_pad_len; 6202 } 6203 6204 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 6205 6206 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6207 auth_tag, 6208 tdata->gmac_tag.data, 6209 tdata->gmac_tag.len, 6210 "GMAC Generated auth tag not as expected"); 6211 6212 return 0; 6213 } 6214 6215 static int 6216 test_AES_GMAC_authentication_test_case_1(void) 6217 { 6218 return test_AES_GMAC_authentication(&gmac_test_case_1); 6219 } 6220 6221 static int 6222 test_AES_GMAC_authentication_test_case_2(void) 6223 { 6224 return test_AES_GMAC_authentication(&gmac_test_case_2); 6225 } 6226 6227 static int 6228 test_AES_GMAC_authentication_test_case_3(void) 6229 { 6230 return test_AES_GMAC_authentication(&gmac_test_case_3); 6231 } 6232 6233 static int 6234 test_AES_GMAC_authentication_test_case_4(void) 6235 { 6236 return test_AES_GMAC_authentication(&gmac_test_case_4); 6237 } 6238 6239 static int 6240 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 6241 { 6242 struct crypto_testsuite_params *ts_params = &testsuite_params; 6243 struct crypto_unittest_params *ut_params = &unittest_params; 6244 int retval; 6245 6246 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 6247 "No GMAC length in the source data"); 6248 6249 retval = create_gmac_session(ts_params->valid_devs[0], 6250 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6251 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 6252 6253 if (retval < 0) 6254 return retval; 6255 6256 if (tdata->aad.len > MBUF_SIZE) 6257 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 6258 else 6259 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6260 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6261 "Failed to allocate input buffer in mempool"); 6262 6263 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6264 rte_pktmbuf_tailroom(ut_params->ibuf)); 6265 6266 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 6267 tdata); 6268 6269 if (retval < 0) 6270 return retval; 6271 6272 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 6273 6274 ut_params->op->sym->m_src = ut_params->ibuf; 6275 6276 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 6277 ut_params->op), "failed to process sym crypto op"); 6278 6279 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6280 "crypto op processing failed"); 6281 6282 return 0; 6283 6284 } 6285 6286 static int 6287 test_AES_GMAC_authentication_verify_test_case_1(void) 6288 { 6289 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 6290 } 6291 6292 static int 6293 test_AES_GMAC_authentication_verify_test_case_2(void) 6294 { 6295 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 6296 } 6297 6298 static int 6299 test_AES_GMAC_authentication_verify_test_case_3(void) 6300 { 6301 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 6302 } 6303 6304 static int 6305 test_AES_GMAC_authentication_verify_test_case_4(void) 6306 { 6307 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 6308 } 6309 6310 struct test_crypto_vector { 6311 enum rte_crypto_cipher_algorithm crypto_algo; 6312 6313 struct { 6314 uint8_t data[64]; 6315 unsigned int len; 6316 } cipher_key; 6317 6318 struct { 6319 uint8_t data[64]; 6320 unsigned int len; 6321 } iv; 6322 6323 struct { 6324 const uint8_t *data; 6325 unsigned int len; 6326 } plaintext; 6327 6328 struct { 6329 const uint8_t *data; 6330 unsigned int len; 6331 } ciphertext; 6332 6333 enum rte_crypto_auth_algorithm auth_algo; 6334 6335 struct { 6336 uint8_t data[128]; 6337 unsigned int len; 6338 } auth_key; 6339 6340 struct { 6341 const uint8_t *data; 6342 unsigned int len; 6343 } aad; 6344 6345 struct { 6346 uint8_t data[128]; 6347 unsigned int len; 6348 } digest; 6349 }; 6350 6351 static const struct test_crypto_vector 6352 hmac_sha1_test_crypto_vector = { 6353 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 6354 .plaintext = { 6355 .data = plaintext_hash, 6356 .len = 512 6357 }, 6358 .auth_key = { 6359 .data = { 6360 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 6361 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 6362 0xDE, 0xF4, 0xDE, 0xAD 6363 }, 6364 .len = 20 6365 }, 6366 .digest = { 6367 .data = { 6368 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 6369 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 6370 0x3F, 0x91, 0x64, 0x59 6371 }, 6372 .len = 20 6373 } 6374 }; 6375 6376 static const struct test_crypto_vector 6377 aes128_gmac_test_vector = { 6378 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 6379 .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM, 6380 .aad = { 6381 .data = plaintext_hash, 6382 .len = 512 6383 }, 6384 .iv = { 6385 .data = { 6386 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 6387 0x08, 0x09, 0x0A, 0x0B 6388 }, 6389 .len = 12 6390 }, 6391 .cipher_key = { 6392 .data = { 6393 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 6394 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 6395 }, 6396 .len = 16 6397 }, 6398 .digest = { 6399 .data = { 6400 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 6401 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 6402 }, 6403 .len = 16 6404 } 6405 }; 6406 6407 static const struct test_crypto_vector 6408 aes128cbc_hmac_sha1_test_vector = { 6409 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 6410 .cipher_key = { 6411 .data = { 6412 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 6413 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 6414 }, 6415 .len = 16 6416 }, 6417 .iv = { 6418 .data = { 6419 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 6420 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 6421 }, 6422 .len = 16 6423 }, 6424 .plaintext = { 6425 .data = plaintext_hash, 6426 .len = 512 6427 }, 6428 .ciphertext = { 6429 .data = ciphertext512_aes128cbc, 6430 .len = 512 6431 }, 6432 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 6433 .auth_key = { 6434 .data = { 6435 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 6436 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 6437 0xDE, 0xF4, 0xDE, 0xAD 6438 }, 6439 .len = 20 6440 }, 6441 .digest = { 6442 .data = { 6443 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 6444 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 6445 0x18, 0x8C, 0x1D, 0x32 6446 }, 6447 .len = 20 6448 } 6449 }; 6450 6451 static void 6452 data_corruption(uint8_t *data) 6453 { 6454 data[0] += 1; 6455 } 6456 6457 static void 6458 tag_corruption(uint8_t *data, unsigned int tag_offset) 6459 { 6460 data[tag_offset] += 1; 6461 } 6462 6463 static int 6464 create_auth_session(struct crypto_unittest_params *ut_params, 6465 uint8_t dev_id, 6466 const struct test_crypto_vector *reference, 6467 enum rte_crypto_auth_operation auth_op) 6468 { 6469 uint8_t auth_key[reference->auth_key.len + 1]; 6470 6471 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 6472 6473 /* Setup Authentication Parameters */ 6474 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6475 ut_params->auth_xform.auth.op = auth_op; 6476 ut_params->auth_xform.next = NULL; 6477 ut_params->auth_xform.auth.algo = reference->auth_algo; 6478 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 6479 ut_params->auth_xform.auth.key.data = auth_key; 6480 ut_params->auth_xform.auth.digest_length = reference->digest.len; 6481 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len; 6482 6483 /* Create Crypto session*/ 6484 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 6485 &ut_params->auth_xform); 6486 6487 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 6488 6489 return 0; 6490 } 6491 6492 static int 6493 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 6494 uint8_t dev_id, 6495 const struct test_crypto_vector *reference, 6496 enum rte_crypto_auth_operation auth_op, 6497 enum rte_crypto_cipher_operation cipher_op) 6498 { 6499 uint8_t cipher_key[reference->cipher_key.len + 1]; 6500 uint8_t auth_key[reference->auth_key.len + 1]; 6501 6502 memcpy(cipher_key, reference->cipher_key.data, 6503 reference->cipher_key.len); 6504 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 6505 6506 /* Setup Authentication Parameters */ 6507 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6508 ut_params->auth_xform.auth.op = auth_op; 6509 ut_params->auth_xform.next = &ut_params->cipher_xform; 6510 ut_params->auth_xform.auth.algo = reference->auth_algo; 6511 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 6512 ut_params->auth_xform.auth.key.data = auth_key; 6513 ut_params->auth_xform.auth.digest_length = reference->digest.len; 6514 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len; 6515 6516 /* Setup Cipher Parameters */ 6517 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6518 ut_params->cipher_xform.next = NULL; 6519 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 6520 ut_params->cipher_xform.cipher.op = cipher_op; 6521 ut_params->cipher_xform.cipher.key.data = cipher_key; 6522 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 6523 6524 /* Create Crypto session*/ 6525 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 6526 &ut_params->auth_xform); 6527 6528 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 6529 6530 return 0; 6531 } 6532 6533 static int 6534 create_auth_operation(struct crypto_testsuite_params *ts_params, 6535 struct crypto_unittest_params *ut_params, 6536 const struct test_crypto_vector *reference, 6537 unsigned int auth_generate) 6538 { 6539 /* Generate Crypto op data structure */ 6540 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6541 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6542 TEST_ASSERT_NOT_NULL(ut_params->op, 6543 "Failed to allocate pktmbuf offload"); 6544 6545 /* Set crypto operation data parameters */ 6546 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 6547 6548 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 6549 6550 /* set crypto operation source mbuf */ 6551 sym_op->m_src = ut_params->ibuf; 6552 6553 /* digest */ 6554 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 6555 ut_params->ibuf, reference->digest.len); 6556 6557 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 6558 "no room to append auth tag"); 6559 6560 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 6561 ut_params->ibuf, reference->plaintext.len); 6562 sym_op->auth.digest.length = reference->digest.len; 6563 6564 if (auth_generate) 6565 memset(sym_op->auth.digest.data, 0, reference->digest.len); 6566 else 6567 memcpy(sym_op->auth.digest.data, 6568 reference->digest.data, 6569 reference->digest.len); 6570 6571 TEST_HEXDUMP(stdout, "digest:", 6572 sym_op->auth.digest.data, 6573 sym_op->auth.digest.length); 6574 6575 sym_op->auth.data.length = reference->plaintext.len; 6576 sym_op->auth.data.offset = 0; 6577 6578 return 0; 6579 } 6580 6581 static int 6582 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 6583 struct crypto_unittest_params *ut_params, 6584 const struct test_crypto_vector *reference, 6585 unsigned int auth_generate) 6586 { 6587 /* Generate Crypto op data structure */ 6588 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6589 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6590 TEST_ASSERT_NOT_NULL(ut_params->op, 6591 "Failed to allocate pktmbuf offload"); 6592 6593 /* Set crypto operation data parameters */ 6594 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 6595 6596 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 6597 6598 /* set crypto operation source mbuf */ 6599 sym_op->m_src = ut_params->ibuf; 6600 6601 /* aad */ 6602 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6603 reference->aad.len); 6604 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD"); 6605 memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len); 6606 6607 TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len); 6608 6609 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 6610 sym_op->auth.aad.length = reference->aad.len; 6611 6612 /* digest */ 6613 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 6614 ut_params->ibuf, reference->digest.len); 6615 6616 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 6617 "no room to append auth tag"); 6618 6619 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 6620 ut_params->ibuf, reference->ciphertext.len); 6621 sym_op->auth.digest.length = reference->digest.len; 6622 6623 if (auth_generate) 6624 memset(sym_op->auth.digest.data, 0, reference->digest.len); 6625 else 6626 memcpy(sym_op->auth.digest.data, 6627 reference->digest.data, 6628 reference->digest.len); 6629 6630 TEST_HEXDUMP(stdout, "digest:", 6631 sym_op->auth.digest.data, 6632 sym_op->auth.digest.length); 6633 6634 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 6635 ut_params->ibuf, reference->iv.len); 6636 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 6637 6638 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 6639 sym_op->cipher.iv.length = reference->iv.len; 6640 6641 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len); 6642 6643 sym_op->cipher.data.length = 0; 6644 sym_op->cipher.data.offset = 0; 6645 6646 sym_op->auth.data.length = 0; 6647 sym_op->auth.data.offset = 0; 6648 6649 return 0; 6650 } 6651 6652 static int 6653 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 6654 struct crypto_unittest_params *ut_params, 6655 const struct test_crypto_vector *reference, 6656 unsigned int auth_generate) 6657 { 6658 /* Generate Crypto op data structure */ 6659 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6660 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6661 TEST_ASSERT_NOT_NULL(ut_params->op, 6662 "Failed to allocate pktmbuf offload"); 6663 6664 /* Set crypto operation data parameters */ 6665 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 6666 6667 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 6668 6669 /* set crypto operation source mbuf */ 6670 sym_op->m_src = ut_params->ibuf; 6671 6672 /* digest */ 6673 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 6674 ut_params->ibuf, reference->digest.len); 6675 6676 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 6677 "no room to append auth tag"); 6678 6679 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 6680 ut_params->ibuf, reference->ciphertext.len); 6681 sym_op->auth.digest.length = reference->digest.len; 6682 6683 if (auth_generate) 6684 memset(sym_op->auth.digest.data, 0, reference->digest.len); 6685 else 6686 memcpy(sym_op->auth.digest.data, 6687 reference->digest.data, 6688 reference->digest.len); 6689 6690 TEST_HEXDUMP(stdout, "digest:", 6691 sym_op->auth.digest.data, 6692 sym_op->auth.digest.length); 6693 6694 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 6695 ut_params->ibuf, reference->iv.len); 6696 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 6697 6698 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 6699 sym_op->cipher.iv.length = reference->iv.len; 6700 6701 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len); 6702 6703 sym_op->cipher.data.length = reference->ciphertext.len; 6704 sym_op->cipher.data.offset = reference->iv.len; 6705 6706 sym_op->auth.data.length = reference->ciphertext.len; 6707 sym_op->auth.data.offset = reference->iv.len; 6708 6709 return 0; 6710 } 6711 6712 static int 6713 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 6714 struct crypto_unittest_params *ut_params, 6715 const struct test_crypto_vector *reference) 6716 { 6717 return create_auth_operation(ts_params, ut_params, reference, 0); 6718 } 6719 6720 static int 6721 create_auth_verify_GMAC_operation( 6722 struct crypto_testsuite_params *ts_params, 6723 struct crypto_unittest_params *ut_params, 6724 const struct test_crypto_vector *reference) 6725 { 6726 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 6727 } 6728 6729 static int 6730 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 6731 struct crypto_unittest_params *ut_params, 6732 const struct test_crypto_vector *reference) 6733 { 6734 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 6735 } 6736 6737 static int 6738 test_authentication_verify_fail_when_data_corruption( 6739 struct crypto_testsuite_params *ts_params, 6740 struct crypto_unittest_params *ut_params, 6741 const struct test_crypto_vector *reference, 6742 unsigned int data_corrupted) 6743 { 6744 int retval; 6745 6746 uint8_t *plaintext; 6747 6748 /* Create session */ 6749 retval = create_auth_session(ut_params, 6750 ts_params->valid_devs[0], 6751 reference, 6752 RTE_CRYPTO_AUTH_OP_VERIFY); 6753 if (retval < 0) 6754 return retval; 6755 6756 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6757 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6758 "Failed to allocate input buffer in mempool"); 6759 6760 /* clear mbuf payload */ 6761 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6762 rte_pktmbuf_tailroom(ut_params->ibuf)); 6763 6764 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6765 reference->plaintext.len); 6766 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 6767 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 6768 6769 TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len); 6770 6771 /* Create operation */ 6772 retval = create_auth_verify_operation(ts_params, ut_params, reference); 6773 6774 if (retval < 0) 6775 return retval; 6776 6777 if (data_corrupted) 6778 data_corruption(plaintext); 6779 else 6780 tag_corruption(plaintext, reference->plaintext.len); 6781 6782 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6783 ut_params->op); 6784 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 6785 TEST_ASSERT_EQUAL(ut_params->op->status, 6786 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 6787 "authentication not failed"); 6788 6789 ut_params->obuf = ut_params->op->sym->m_src; 6790 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 6791 6792 return 0; 6793 } 6794 6795 static int 6796 test_authentication_verify_GMAC_fail_when_corruption( 6797 struct crypto_testsuite_params *ts_params, 6798 struct crypto_unittest_params *ut_params, 6799 const struct test_crypto_vector *reference, 6800 unsigned int data_corrupted) 6801 { 6802 int retval; 6803 6804 /* Create session */ 6805 retval = create_auth_cipher_session(ut_params, 6806 ts_params->valid_devs[0], 6807 reference, 6808 RTE_CRYPTO_AUTH_OP_VERIFY, 6809 RTE_CRYPTO_CIPHER_OP_DECRYPT); 6810 if (retval < 0) 6811 return retval; 6812 6813 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6814 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6815 "Failed to allocate input buffer in mempool"); 6816 6817 /* clear mbuf payload */ 6818 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6819 rte_pktmbuf_tailroom(ut_params->ibuf)); 6820 6821 /* Create operation */ 6822 retval = create_auth_verify_GMAC_operation(ts_params, 6823 ut_params, 6824 reference); 6825 6826 if (retval < 0) 6827 return retval; 6828 6829 if (data_corrupted) 6830 data_corruption(ut_params->op->sym->auth.aad.data); 6831 else 6832 tag_corruption(ut_params->op->sym->auth.aad.data, 6833 reference->aad.len); 6834 6835 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6836 ut_params->op); 6837 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 6838 TEST_ASSERT_EQUAL(ut_params->op->status, 6839 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 6840 "authentication not failed"); 6841 6842 ut_params->obuf = ut_params->op->sym->m_src; 6843 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 6844 6845 return 0; 6846 } 6847 6848 static int 6849 test_authenticated_decryption_fail_when_corruption( 6850 struct crypto_testsuite_params *ts_params, 6851 struct crypto_unittest_params *ut_params, 6852 const struct test_crypto_vector *reference, 6853 unsigned int data_corrupted) 6854 { 6855 int retval; 6856 6857 uint8_t *ciphertext; 6858 6859 /* Create session */ 6860 retval = create_auth_cipher_session(ut_params, 6861 ts_params->valid_devs[0], 6862 reference, 6863 RTE_CRYPTO_AUTH_OP_VERIFY, 6864 RTE_CRYPTO_CIPHER_OP_DECRYPT); 6865 if (retval < 0) 6866 return retval; 6867 6868 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6869 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6870 "Failed to allocate input buffer in mempool"); 6871 6872 /* clear mbuf payload */ 6873 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6874 rte_pktmbuf_tailroom(ut_params->ibuf)); 6875 6876 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6877 reference->ciphertext.len); 6878 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 6879 memcpy(ciphertext, reference->ciphertext.data, 6880 reference->ciphertext.len); 6881 6882 /* Create operation */ 6883 retval = create_cipher_auth_verify_operation(ts_params, 6884 ut_params, 6885 reference); 6886 6887 if (retval < 0) 6888 return retval; 6889 6890 if (data_corrupted) 6891 data_corruption(ciphertext); 6892 else 6893 tag_corruption(ciphertext, reference->ciphertext.len); 6894 6895 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6896 ut_params->op); 6897 6898 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 6899 TEST_ASSERT_EQUAL(ut_params->op->status, 6900 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 6901 "authentication not failed"); 6902 6903 ut_params->obuf = ut_params->op->sym->m_src; 6904 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 6905 6906 return 0; 6907 } 6908 6909 static int 6910 create_gcm_operation_SGL(enum rte_crypto_cipher_operation op, 6911 const struct gcm_test_data *tdata, 6912 void *digest_mem, uint64_t digest_phys) 6913 { 6914 struct crypto_testsuite_params *ts_params = &testsuite_params; 6915 struct crypto_unittest_params *ut_params = &unittest_params; 6916 6917 const unsigned int auth_tag_len = tdata->auth_tag.len; 6918 const unsigned int iv_len = tdata->iv.len; 6919 const unsigned int aad_len = tdata->aad.len; 6920 6921 unsigned int iv_pad_len = 0; 6922 6923 /* Generate Crypto op data structure */ 6924 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6925 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6926 TEST_ASSERT_NOT_NULL(ut_params->op, 6927 "Failed to allocate symmetric crypto operation struct"); 6928 6929 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 6930 6931 sym_op->auth.digest.data = digest_mem; 6932 6933 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 6934 "no room to append digest"); 6935 6936 sym_op->auth.digest.phys_addr = digest_phys; 6937 sym_op->auth.digest.length = auth_tag_len; 6938 6939 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 6940 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data, 6941 auth_tag_len); 6942 TEST_HEXDUMP(stdout, "digest:", 6943 sym_op->auth.digest.data, 6944 sym_op->auth.digest.length); 6945 } 6946 6947 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 6948 6949 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 6950 ut_params->ibuf, iv_pad_len); 6951 6952 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, 6953 "no room to prepend iv"); 6954 6955 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 6956 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 6957 sym_op->cipher.iv.length = iv_len; 6958 6959 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, iv_pad_len); 6960 6961 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 6962 ut_params->ibuf, aad_len); 6963 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 6964 "no room to prepend aad"); 6965 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 6966 ut_params->ibuf); 6967 sym_op->auth.aad.length = aad_len; 6968 6969 memset(sym_op->auth.aad.data, 0, aad_len); 6970 rte_memcpy(sym_op->auth.aad.data, tdata->aad.data, aad_len); 6971 6972 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len); 6973 TEST_HEXDUMP(stdout, "aad:", 6974 sym_op->auth.aad.data, aad_len); 6975 6976 sym_op->cipher.data.length = tdata->plaintext.len; 6977 sym_op->cipher.data.offset = aad_len + iv_pad_len; 6978 6979 sym_op->auth.data.offset = aad_len + iv_pad_len; 6980 sym_op->auth.data.length = tdata->plaintext.len; 6981 6982 return 0; 6983 } 6984 6985 #define SGL_MAX_NO 16 6986 6987 static int 6988 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata, 6989 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 6990 { 6991 struct crypto_testsuite_params *ts_params = &testsuite_params; 6992 struct crypto_unittest_params *ut_params = &unittest_params; 6993 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 6994 int retval; 6995 int to_trn = 0; 6996 int to_trn_tbl[SGL_MAX_NO]; 6997 int segs = 1; 6998 unsigned int trn_data = 0; 6999 uint8_t *plaintext, *ciphertext, *auth_tag; 7000 7001 if (fragsz > tdata->plaintext.len) 7002 fragsz = tdata->plaintext.len; 7003 7004 uint16_t plaintext_len = fragsz; 7005 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 7006 7007 if (fragsz_oop > tdata->plaintext.len) 7008 frag_size_oop = tdata->plaintext.len; 7009 7010 int ecx = 0; 7011 void *digest_mem = NULL; 7012 7013 uint32_t prepend_len = ALIGN_POW2_ROUNDUP(tdata->iv.len, 16) 7014 + tdata->aad.len; 7015 7016 if (tdata->plaintext.len % fragsz != 0) { 7017 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 7018 return 1; 7019 } else { 7020 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 7021 return 1; 7022 } 7023 7024 /* 7025 * For out-op-place we need to alloc another mbuf 7026 */ 7027 if (oop) { 7028 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7029 rte_pktmbuf_append(ut_params->obuf, 7030 frag_size_oop + prepend_len); 7031 buf_oop = ut_params->obuf; 7032 } 7033 7034 /* Create GCM session */ 7035 retval = create_gcm_session(ts_params->valid_devs[0], 7036 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7037 tdata->key.data, tdata->key.len, 7038 tdata->aad.len, tdata->auth_tag.len, 7039 RTE_CRYPTO_AUTH_OP_GENERATE); 7040 if (retval < 0) 7041 return retval; 7042 7043 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7044 7045 /* clear mbuf payload */ 7046 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7047 rte_pktmbuf_tailroom(ut_params->ibuf)); 7048 7049 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7050 plaintext_len); 7051 7052 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7053 7054 trn_data += plaintext_len; 7055 7056 buf = ut_params->ibuf; 7057 7058 /* 7059 * Loop until no more fragments 7060 */ 7061 7062 while (trn_data < tdata->plaintext.len) { 7063 ++segs; 7064 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 7065 (tdata->plaintext.len - trn_data) : fragsz; 7066 7067 to_trn_tbl[ecx++] = to_trn; 7068 7069 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7070 buf = buf->next; 7071 7072 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 7073 rte_pktmbuf_tailroom(buf)); 7074 7075 /* OOP */ 7076 if (oop && !fragsz_oop) { 7077 buf_last_oop = buf_oop->next = 7078 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7079 buf_oop = buf_oop->next; 7080 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7081 0, rte_pktmbuf_tailroom(buf_oop)); 7082 rte_pktmbuf_append(buf_oop, to_trn); 7083 } 7084 7085 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 7086 to_trn); 7087 7088 memcpy(plaintext, tdata->plaintext.data + trn_data, 7089 to_trn); 7090 trn_data += to_trn; 7091 if (trn_data == tdata->plaintext.len) { 7092 if (oop) { 7093 if (!fragsz_oop) 7094 digest_mem = rte_pktmbuf_append(buf_oop, 7095 tdata->auth_tag.len); 7096 } else 7097 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 7098 tdata->auth_tag.len); 7099 } 7100 } 7101 7102 uint64_t digest_phys = 0; 7103 7104 ut_params->ibuf->nb_segs = segs; 7105 7106 segs = 1; 7107 if (fragsz_oop && oop) { 7108 to_trn = 0; 7109 ecx = 0; 7110 7111 if (frag_size_oop == tdata->plaintext.len) { 7112 digest_mem = rte_pktmbuf_append(ut_params->obuf, 7113 tdata->auth_tag.len); 7114 7115 digest_phys = rte_pktmbuf_mtophys_offset( 7116 ut_params->obuf, 7117 tdata->plaintext.len + prepend_len); 7118 } 7119 7120 trn_data = frag_size_oop; 7121 while (trn_data < tdata->plaintext.len) { 7122 ++segs; 7123 to_trn = 7124 (tdata->plaintext.len - trn_data < 7125 frag_size_oop) ? 7126 (tdata->plaintext.len - trn_data) : 7127 frag_size_oop; 7128 7129 to_trn_tbl[ecx++] = to_trn; 7130 7131 buf_last_oop = buf_oop->next = 7132 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7133 buf_oop = buf_oop->next; 7134 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7135 0, rte_pktmbuf_tailroom(buf_oop)); 7136 rte_pktmbuf_append(buf_oop, to_trn); 7137 7138 trn_data += to_trn; 7139 7140 if (trn_data == tdata->plaintext.len) { 7141 digest_mem = rte_pktmbuf_append(buf_oop, 7142 tdata->auth_tag.len); 7143 } 7144 } 7145 7146 ut_params->obuf->nb_segs = segs; 7147 } 7148 7149 /* 7150 * Place digest at the end of the last buffer 7151 */ 7152 if (!digest_phys) 7153 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn; 7154 if (oop && buf_last_oop) 7155 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn; 7156 7157 if (!digest_mem && !oop) { 7158 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7159 + tdata->auth_tag.len); 7160 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf, 7161 tdata->plaintext.len); 7162 } 7163 7164 /* Create GCM opertaion */ 7165 retval = create_gcm_operation_SGL(RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7166 tdata, digest_mem, digest_phys); 7167 7168 if (retval < 0) 7169 return retval; 7170 7171 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7172 7173 ut_params->op->sym->m_src = ut_params->ibuf; 7174 if (oop) 7175 ut_params->op->sym->m_dst = ut_params->obuf; 7176 7177 /* Process crypto operation */ 7178 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 7179 ut_params->op), "failed to process sym crypto op"); 7180 7181 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7182 "crypto op processing failed"); 7183 7184 7185 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7186 uint8_t *, prepend_len); 7187 if (oop) { 7188 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7189 uint8_t *, prepend_len); 7190 } 7191 7192 if (fragsz_oop) 7193 fragsz = fragsz_oop; 7194 7195 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7196 ciphertext, 7197 tdata->ciphertext.data, 7198 fragsz, 7199 "GCM Ciphertext data not as expected"); 7200 7201 buf = ut_params->op->sym->m_src->next; 7202 if (oop) 7203 buf = ut_params->op->sym->m_dst->next; 7204 7205 unsigned int off = fragsz; 7206 7207 ecx = 0; 7208 while (buf) { 7209 ciphertext = rte_pktmbuf_mtod(buf, 7210 uint8_t *); 7211 7212 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7213 ciphertext, 7214 tdata->ciphertext.data + off, 7215 to_trn_tbl[ecx], 7216 "GCM Ciphertext data not as expected"); 7217 7218 off += to_trn_tbl[ecx++]; 7219 buf = buf->next; 7220 } 7221 7222 auth_tag = digest_mem; 7223 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7224 auth_tag, 7225 tdata->auth_tag.data, 7226 tdata->auth_tag.len, 7227 "GCM Generated auth tag not as expected"); 7228 7229 return 0; 7230 } 7231 7232 #define IN_PLACE 0 7233 #define OUT_OF_PLACE 1 7234 7235 static int 7236 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 7237 { 7238 return test_AES_GCM_authenticated_encryption_SGL( 7239 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 7240 } 7241 7242 static int 7243 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 7244 { 7245 return test_AES_GCM_authenticated_encryption_SGL( 7246 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 7247 } 7248 7249 static int 7250 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 7251 { 7252 return test_AES_GCM_authenticated_encryption_SGL( 7253 &gcm_test_case_8, OUT_OF_PLACE, 400, 7254 gcm_test_case_8.plaintext.len); 7255 } 7256 7257 static int 7258 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 7259 { 7260 7261 return test_AES_GCM_authenticated_encryption_SGL( 7262 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 7263 } 7264 7265 static int 7266 test_authentication_verify_fail_when_data_corrupted( 7267 struct crypto_testsuite_params *ts_params, 7268 struct crypto_unittest_params *ut_params, 7269 const struct test_crypto_vector *reference) 7270 { 7271 return test_authentication_verify_fail_when_data_corruption( 7272 ts_params, ut_params, reference, 1); 7273 } 7274 7275 static int 7276 test_authentication_verify_fail_when_tag_corrupted( 7277 struct crypto_testsuite_params *ts_params, 7278 struct crypto_unittest_params *ut_params, 7279 const struct test_crypto_vector *reference) 7280 { 7281 return test_authentication_verify_fail_when_data_corruption( 7282 ts_params, ut_params, reference, 0); 7283 } 7284 7285 static int 7286 test_authentication_verify_GMAC_fail_when_data_corrupted( 7287 struct crypto_testsuite_params *ts_params, 7288 struct crypto_unittest_params *ut_params, 7289 const struct test_crypto_vector *reference) 7290 { 7291 return test_authentication_verify_GMAC_fail_when_corruption( 7292 ts_params, ut_params, reference, 1); 7293 } 7294 7295 static int 7296 test_authentication_verify_GMAC_fail_when_tag_corrupted( 7297 struct crypto_testsuite_params *ts_params, 7298 struct crypto_unittest_params *ut_params, 7299 const struct test_crypto_vector *reference) 7300 { 7301 return test_authentication_verify_GMAC_fail_when_corruption( 7302 ts_params, ut_params, reference, 0); 7303 } 7304 7305 static int 7306 test_authenticated_decryption_fail_when_data_corrupted( 7307 struct crypto_testsuite_params *ts_params, 7308 struct crypto_unittest_params *ut_params, 7309 const struct test_crypto_vector *reference) 7310 { 7311 return test_authenticated_decryption_fail_when_corruption( 7312 ts_params, ut_params, reference, 1); 7313 } 7314 7315 static int 7316 test_authenticated_decryption_fail_when_tag_corrupted( 7317 struct crypto_testsuite_params *ts_params, 7318 struct crypto_unittest_params *ut_params, 7319 const struct test_crypto_vector *reference) 7320 { 7321 return test_authenticated_decryption_fail_when_corruption( 7322 ts_params, ut_params, reference, 0); 7323 } 7324 7325 static int 7326 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 7327 { 7328 return test_authentication_verify_fail_when_data_corrupted( 7329 &testsuite_params, &unittest_params, 7330 &hmac_sha1_test_crypto_vector); 7331 } 7332 7333 static int 7334 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 7335 { 7336 return test_authentication_verify_fail_when_tag_corrupted( 7337 &testsuite_params, &unittest_params, 7338 &hmac_sha1_test_crypto_vector); 7339 } 7340 7341 static int 7342 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 7343 { 7344 return test_authentication_verify_GMAC_fail_when_data_corrupted( 7345 &testsuite_params, &unittest_params, 7346 &aes128_gmac_test_vector); 7347 } 7348 7349 static int 7350 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 7351 { 7352 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 7353 &testsuite_params, &unittest_params, 7354 &aes128_gmac_test_vector); 7355 } 7356 7357 static int 7358 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 7359 { 7360 return test_authenticated_decryption_fail_when_data_corrupted( 7361 &testsuite_params, 7362 &unittest_params, 7363 &aes128cbc_hmac_sha1_test_vector); 7364 } 7365 7366 static int 7367 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 7368 { 7369 return test_authenticated_decryption_fail_when_tag_corrupted( 7370 &testsuite_params, 7371 &unittest_params, 7372 &aes128cbc_hmac_sha1_test_vector); 7373 } 7374 7375 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 7376 7377 /* global AESNI slave IDs for the scheduler test */ 7378 uint8_t aesni_ids[2]; 7379 7380 static int 7381 test_scheduler_attach_slave_op(void) 7382 { 7383 struct crypto_testsuite_params *ts_params = &testsuite_params; 7384 uint8_t sched_id = ts_params->valid_devs[0]; 7385 uint32_t nb_devs, qp_id, i, nb_devs_attached = 0; 7386 int ret; 7387 struct rte_cryptodev_config config = { 7388 .nb_queue_pairs = 8, 7389 .socket_id = SOCKET_ID_ANY, 7390 .session_mp = { 7391 .nb_objs = 2048, 7392 .cache_size = 256 7393 } 7394 }; 7395 struct rte_cryptodev_qp_conf qp_conf = {2048}; 7396 7397 /* create 2 AESNI_MB if necessary */ 7398 nb_devs = rte_cryptodev_count_devtype( 7399 RTE_CRYPTODEV_AESNI_MB_PMD); 7400 if (nb_devs < 2) { 7401 for (i = nb_devs; i < 2; i++) { 7402 ret = rte_eal_vdev_init( 7403 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 7404 7405 TEST_ASSERT(ret == 0, 7406 "Failed to create instance %u of" 7407 " pmd : %s", 7408 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 7409 } 7410 } 7411 7412 /* attach 2 AESNI_MB cdevs */ 7413 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 7414 i++) { 7415 struct rte_cryptodev_info info; 7416 7417 rte_cryptodev_info_get(i, &info); 7418 if (info.dev_type != RTE_CRYPTODEV_AESNI_MB_PMD) 7419 continue; 7420 7421 ret = rte_cryptodev_configure(i, &config); 7422 TEST_ASSERT(ret == 0, 7423 "Failed to configure device %u of pmd : %s", i, 7424 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 7425 7426 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 7427 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 7428 i, qp_id, &qp_conf, 7429 rte_cryptodev_socket_id(i)), 7430 "Failed to setup queue pair %u on " 7431 "cryptodev %u", qp_id, i); 7432 } 7433 7434 ret = rte_cryptodev_scheduler_slave_attach(sched_id, 7435 (uint8_t)i); 7436 7437 TEST_ASSERT(ret == 0, 7438 "Failed to attach device %u of pmd : %s", i, 7439 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 7440 7441 aesni_ids[nb_devs_attached] = (uint8_t)i; 7442 7443 nb_devs_attached++; 7444 } 7445 7446 return 0; 7447 } 7448 7449 static int 7450 test_scheduler_detach_slave_op(void) 7451 { 7452 struct crypto_testsuite_params *ts_params = &testsuite_params; 7453 uint8_t sched_id = ts_params->valid_devs[0]; 7454 uint32_t i; 7455 int ret; 7456 7457 for (i = 0; i < 2; i++) { 7458 ret = rte_cryptodev_scheduler_slave_detach(sched_id, 7459 aesni_ids[i]); 7460 TEST_ASSERT(ret == 0, 7461 "Failed to detach device %u", aesni_ids[i]); 7462 } 7463 7464 return 0; 7465 } 7466 7467 static int 7468 test_scheduler_mode_op(void) 7469 { 7470 struct crypto_testsuite_params *ts_params = &testsuite_params; 7471 uint8_t sched_id = ts_params->valid_devs[0]; 7472 struct rte_cryptodev_scheduler_ops op = {0}; 7473 struct rte_cryptodev_scheduler dummy_scheduler = { 7474 .description = "dummy scheduler to test mode", 7475 .name = "dummy scheduler", 7476 .mode = CDEV_SCHED_MODE_USERDEFINED, 7477 .ops = &op 7478 }; 7479 int ret; 7480 7481 /* set user defined mode */ 7482 ret = rte_cryptodev_scheduler_load_user_scheduler(sched_id, 7483 &dummy_scheduler); 7484 TEST_ASSERT(ret == 0, 7485 "Failed to set cdev %u to user defined mode", sched_id); 7486 7487 /* set round robin mode */ 7488 ret = rte_crpytodev_scheduler_mode_set(sched_id, 7489 CDEV_SCHED_MODE_ROUNDROBIN); 7490 TEST_ASSERT(ret == 0, 7491 "Failed to set cdev %u to round-robin mode", sched_id); 7492 TEST_ASSERT(rte_crpytodev_scheduler_mode_get(sched_id) == 7493 CDEV_SCHED_MODE_ROUNDROBIN, "Scheduling Mode " 7494 "not match"); 7495 7496 return 0; 7497 } 7498 7499 static struct unit_test_suite cryptodev_scheduler_testsuite = { 7500 .suite_name = "Crypto Device Scheduler Unit Test Suite", 7501 .setup = testsuite_setup, 7502 .teardown = testsuite_teardown, 7503 .unit_test_cases = { 7504 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 7505 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_op), 7506 TEST_CASE_ST(ut_setup, ut_teardown, 7507 test_AES_chain_scheduler_all), 7508 TEST_CASE_ST(ut_setup, ut_teardown, 7509 test_AES_cipheronly_scheduler_all), 7510 TEST_CASE_ST(ut_setup, ut_teardown, 7511 test_authonly_scheduler_all), 7512 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 7513 TEST_CASES_END() /**< NULL terminate unit test array */ 7514 } 7515 }; 7516 7517 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */ 7518 7519 static struct unit_test_suite cryptodev_qat_testsuite = { 7520 .suite_name = "Crypto QAT Unit Test Suite", 7521 .setup = testsuite_setup, 7522 .teardown = testsuite_teardown, 7523 .unit_test_cases = { 7524 TEST_CASE_ST(ut_setup, ut_teardown, 7525 test_device_configure_invalid_dev_id), 7526 TEST_CASE_ST(ut_setup, ut_teardown, 7527 test_device_configure_invalid_queue_pair_ids), 7528 TEST_CASE_ST(ut_setup, ut_teardown, 7529 test_queue_pair_descriptor_setup), 7530 TEST_CASE_ST(ut_setup, ut_teardown, 7531 test_multi_session), 7532 7533 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all), 7534 TEST_CASE_ST(ut_setup, ut_teardown, 7535 test_AES_cipheronly_qat_all), 7536 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all), 7537 TEST_CASE_ST(ut_setup, ut_teardown, 7538 test_3DES_cipheronly_qat_all), 7539 TEST_CASE_ST(ut_setup, ut_teardown, 7540 test_DES_cipheronly_qat_all), 7541 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 7542 7543 /** AES GCM Authenticated Encryption */ 7544 TEST_CASE_ST(ut_setup, ut_teardown, 7545 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 7546 TEST_CASE_ST(ut_setup, ut_teardown, 7547 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 7548 TEST_CASE_ST(ut_setup, ut_teardown, 7549 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 7550 TEST_CASE_ST(ut_setup, ut_teardown, 7551 test_mb_AES_GCM_authenticated_encryption_test_case_1), 7552 TEST_CASE_ST(ut_setup, ut_teardown, 7553 test_mb_AES_GCM_authenticated_encryption_test_case_2), 7554 TEST_CASE_ST(ut_setup, ut_teardown, 7555 test_mb_AES_GCM_authenticated_encryption_test_case_3), 7556 TEST_CASE_ST(ut_setup, ut_teardown, 7557 test_mb_AES_GCM_authenticated_encryption_test_case_4), 7558 TEST_CASE_ST(ut_setup, ut_teardown, 7559 test_mb_AES_GCM_authenticated_encryption_test_case_5), 7560 TEST_CASE_ST(ut_setup, ut_teardown, 7561 test_mb_AES_GCM_authenticated_encryption_test_case_6), 7562 TEST_CASE_ST(ut_setup, ut_teardown, 7563 test_mb_AES_GCM_authenticated_encryption_test_case_7), 7564 7565 /** AES GCM Authenticated Decryption */ 7566 TEST_CASE_ST(ut_setup, ut_teardown, 7567 test_mb_AES_GCM_authenticated_decryption_test_case_1), 7568 TEST_CASE_ST(ut_setup, ut_teardown, 7569 test_mb_AES_GCM_authenticated_decryption_test_case_2), 7570 TEST_CASE_ST(ut_setup, ut_teardown, 7571 test_mb_AES_GCM_authenticated_decryption_test_case_3), 7572 TEST_CASE_ST(ut_setup, ut_teardown, 7573 test_mb_AES_GCM_authenticated_decryption_test_case_4), 7574 TEST_CASE_ST(ut_setup, ut_teardown, 7575 test_mb_AES_GCM_authenticated_decryption_test_case_5), 7576 TEST_CASE_ST(ut_setup, ut_teardown, 7577 test_mb_AES_GCM_authenticated_decryption_test_case_6), 7578 TEST_CASE_ST(ut_setup, ut_teardown, 7579 test_mb_AES_GCM_authenticated_decryption_test_case_7), 7580 7581 /** AES GMAC Authentication */ 7582 TEST_CASE_ST(ut_setup, ut_teardown, 7583 test_AES_GMAC_authentication_test_case_1), 7584 TEST_CASE_ST(ut_setup, ut_teardown, 7585 test_AES_GMAC_authentication_verify_test_case_1), 7586 TEST_CASE_ST(ut_setup, ut_teardown, 7587 test_AES_GMAC_authentication_test_case_2), 7588 TEST_CASE_ST(ut_setup, ut_teardown, 7589 test_AES_GMAC_authentication_verify_test_case_2), 7590 TEST_CASE_ST(ut_setup, ut_teardown, 7591 test_AES_GMAC_authentication_test_case_3), 7592 TEST_CASE_ST(ut_setup, ut_teardown, 7593 test_AES_GMAC_authentication_verify_test_case_3), 7594 7595 /** SNOW 3G encrypt only (UEA2) */ 7596 TEST_CASE_ST(ut_setup, ut_teardown, 7597 test_snow3g_encryption_test_case_1), 7598 TEST_CASE_ST(ut_setup, ut_teardown, 7599 test_snow3g_encryption_test_case_2), 7600 TEST_CASE_ST(ut_setup, ut_teardown, 7601 test_snow3g_encryption_test_case_3), 7602 TEST_CASE_ST(ut_setup, ut_teardown, 7603 test_snow3g_encryption_test_case_4), 7604 TEST_CASE_ST(ut_setup, ut_teardown, 7605 test_snow3g_encryption_test_case_5), 7606 7607 TEST_CASE_ST(ut_setup, ut_teardown, 7608 test_snow3g_encryption_test_case_1_oop), 7609 TEST_CASE_ST(ut_setup, ut_teardown, 7610 test_snow3g_decryption_test_case_1_oop), 7611 7612 /** SNOW 3G decrypt only (UEA2) */ 7613 TEST_CASE_ST(ut_setup, ut_teardown, 7614 test_snow3g_decryption_test_case_1), 7615 TEST_CASE_ST(ut_setup, ut_teardown, 7616 test_snow3g_decryption_test_case_2), 7617 TEST_CASE_ST(ut_setup, ut_teardown, 7618 test_snow3g_decryption_test_case_3), 7619 TEST_CASE_ST(ut_setup, ut_teardown, 7620 test_snow3g_decryption_test_case_4), 7621 TEST_CASE_ST(ut_setup, ut_teardown, 7622 test_snow3g_decryption_test_case_5), 7623 TEST_CASE_ST(ut_setup, ut_teardown, 7624 test_snow3g_hash_generate_test_case_1), 7625 TEST_CASE_ST(ut_setup, ut_teardown, 7626 test_snow3g_hash_generate_test_case_2), 7627 TEST_CASE_ST(ut_setup, ut_teardown, 7628 test_snow3g_hash_generate_test_case_3), 7629 TEST_CASE_ST(ut_setup, ut_teardown, 7630 test_snow3g_hash_verify_test_case_1), 7631 TEST_CASE_ST(ut_setup, ut_teardown, 7632 test_snow3g_hash_verify_test_case_2), 7633 TEST_CASE_ST(ut_setup, ut_teardown, 7634 test_snow3g_hash_verify_test_case_3), 7635 TEST_CASE_ST(ut_setup, ut_teardown, 7636 test_snow3g_cipher_auth_test_case_1), 7637 TEST_CASE_ST(ut_setup, ut_teardown, 7638 test_snow3g_auth_cipher_test_case_1), 7639 7640 /** HMAC_MD5 Authentication */ 7641 TEST_CASE_ST(ut_setup, ut_teardown, 7642 test_MD5_HMAC_generate_case_1), 7643 TEST_CASE_ST(ut_setup, ut_teardown, 7644 test_MD5_HMAC_verify_case_1), 7645 TEST_CASE_ST(ut_setup, ut_teardown, 7646 test_MD5_HMAC_generate_case_2), 7647 TEST_CASE_ST(ut_setup, ut_teardown, 7648 test_MD5_HMAC_verify_case_2), 7649 7650 /** NULL tests */ 7651 TEST_CASE_ST(ut_setup, ut_teardown, 7652 test_null_auth_only_operation), 7653 TEST_CASE_ST(ut_setup, ut_teardown, 7654 test_null_cipher_only_operation), 7655 TEST_CASE_ST(ut_setup, ut_teardown, 7656 test_null_cipher_auth_operation), 7657 TEST_CASE_ST(ut_setup, ut_teardown, 7658 test_null_auth_cipher_operation), 7659 7660 TEST_CASE_ST(ut_setup, ut_teardown, 7661 test_kasumi_hash_generate_test_case_6), 7662 7663 /** KASUMI tests */ 7664 TEST_CASE_ST(ut_setup, ut_teardown, 7665 test_kasumi_encryption_test_case_1), 7666 TEST_CASE_ST(ut_setup, ut_teardown, 7667 test_kasumi_encryption_test_case_3), 7668 TEST_CASE_ST(ut_setup, ut_teardown, 7669 test_kasumi_auth_cipher_test_case_1), 7670 TEST_CASE_ST(ut_setup, ut_teardown, 7671 test_kasumi_cipher_auth_test_case_1), 7672 7673 /** Negative tests */ 7674 TEST_CASE_ST(ut_setup, ut_teardown, 7675 authentication_verify_HMAC_SHA1_fail_data_corrupt), 7676 TEST_CASE_ST(ut_setup, ut_teardown, 7677 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 7678 TEST_CASE_ST(ut_setup, ut_teardown, 7679 authentication_verify_AES128_GMAC_fail_data_corrupt), 7680 TEST_CASE_ST(ut_setup, ut_teardown, 7681 authentication_verify_AES128_GMAC_fail_tag_corrupt), 7682 TEST_CASE_ST(ut_setup, ut_teardown, 7683 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 7684 TEST_CASE_ST(ut_setup, ut_teardown, 7685 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 7686 7687 TEST_CASES_END() /**< NULL terminate unit test array */ 7688 } 7689 }; 7690 7691 static struct unit_test_suite cryptodev_aesni_mb_testsuite = { 7692 .suite_name = "Crypto Device AESNI MB Unit Test Suite", 7693 .setup = testsuite_setup, 7694 .teardown = testsuite_teardown, 7695 .unit_test_cases = { 7696 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all), 7697 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all), 7698 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all), 7699 7700 TEST_CASES_END() /**< NULL terminate unit test array */ 7701 } 7702 }; 7703 7704 static struct unit_test_suite cryptodev_openssl_testsuite = { 7705 .suite_name = "Crypto Device OPENSSL Unit Test Suite", 7706 .setup = testsuite_setup, 7707 .teardown = testsuite_teardown, 7708 .unit_test_cases = { 7709 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 7710 TEST_CASE_ST(ut_setup, ut_teardown, 7711 test_multi_session_random_usage), 7712 TEST_CASE_ST(ut_setup, ut_teardown, 7713 test_AES_chain_openssl_all), 7714 TEST_CASE_ST(ut_setup, ut_teardown, 7715 test_AES_cipheronly_openssl_all), 7716 TEST_CASE_ST(ut_setup, ut_teardown, 7717 test_3DES_chain_openssl_all), 7718 TEST_CASE_ST(ut_setup, ut_teardown, 7719 test_3DES_cipheronly_openssl_all), 7720 TEST_CASE_ST(ut_setup, ut_teardown, 7721 test_authonly_openssl_all), 7722 7723 /** AES GCM Authenticated Encryption */ 7724 TEST_CASE_ST(ut_setup, ut_teardown, 7725 test_mb_AES_GCM_authenticated_encryption_test_case_1), 7726 TEST_CASE_ST(ut_setup, ut_teardown, 7727 test_mb_AES_GCM_authenticated_encryption_test_case_2), 7728 TEST_CASE_ST(ut_setup, ut_teardown, 7729 test_mb_AES_GCM_authenticated_encryption_test_case_3), 7730 TEST_CASE_ST(ut_setup, ut_teardown, 7731 test_mb_AES_GCM_authenticated_encryption_test_case_4), 7732 TEST_CASE_ST(ut_setup, ut_teardown, 7733 test_mb_AES_GCM_authenticated_encryption_test_case_5), 7734 TEST_CASE_ST(ut_setup, ut_teardown, 7735 test_mb_AES_GCM_authenticated_encryption_test_case_6), 7736 TEST_CASE_ST(ut_setup, ut_teardown, 7737 test_mb_AES_GCM_authenticated_encryption_test_case_7), 7738 7739 /** AES GCM Authenticated Decryption */ 7740 TEST_CASE_ST(ut_setup, ut_teardown, 7741 test_mb_AES_GCM_authenticated_decryption_test_case_1), 7742 TEST_CASE_ST(ut_setup, ut_teardown, 7743 test_mb_AES_GCM_authenticated_decryption_test_case_2), 7744 TEST_CASE_ST(ut_setup, ut_teardown, 7745 test_mb_AES_GCM_authenticated_decryption_test_case_3), 7746 TEST_CASE_ST(ut_setup, ut_teardown, 7747 test_mb_AES_GCM_authenticated_decryption_test_case_4), 7748 TEST_CASE_ST(ut_setup, ut_teardown, 7749 test_mb_AES_GCM_authenticated_decryption_test_case_5), 7750 TEST_CASE_ST(ut_setup, ut_teardown, 7751 test_mb_AES_GCM_authenticated_decryption_test_case_6), 7752 TEST_CASE_ST(ut_setup, ut_teardown, 7753 test_mb_AES_GCM_authenticated_decryption_test_case_7), 7754 7755 /** AES GMAC Authentication */ 7756 TEST_CASE_ST(ut_setup, ut_teardown, 7757 test_AES_GMAC_authentication_test_case_1), 7758 TEST_CASE_ST(ut_setup, ut_teardown, 7759 test_AES_GMAC_authentication_verify_test_case_1), 7760 TEST_CASE_ST(ut_setup, ut_teardown, 7761 test_AES_GMAC_authentication_test_case_2), 7762 TEST_CASE_ST(ut_setup, ut_teardown, 7763 test_AES_GMAC_authentication_verify_test_case_2), 7764 TEST_CASE_ST(ut_setup, ut_teardown, 7765 test_AES_GMAC_authentication_test_case_3), 7766 TEST_CASE_ST(ut_setup, ut_teardown, 7767 test_AES_GMAC_authentication_verify_test_case_3), 7768 TEST_CASE_ST(ut_setup, ut_teardown, 7769 test_AES_GMAC_authentication_test_case_4), 7770 TEST_CASE_ST(ut_setup, ut_teardown, 7771 test_AES_GMAC_authentication_verify_test_case_4), 7772 7773 /** Scatter-Gather */ 7774 TEST_CASE_ST(ut_setup, ut_teardown, 7775 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 7776 7777 /** Negative tests */ 7778 TEST_CASE_ST(ut_setup, ut_teardown, 7779 authentication_verify_HMAC_SHA1_fail_data_corrupt), 7780 TEST_CASE_ST(ut_setup, ut_teardown, 7781 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 7782 TEST_CASE_ST(ut_setup, ut_teardown, 7783 authentication_verify_AES128_GMAC_fail_data_corrupt), 7784 TEST_CASE_ST(ut_setup, ut_teardown, 7785 authentication_verify_AES128_GMAC_fail_tag_corrupt), 7786 TEST_CASE_ST(ut_setup, ut_teardown, 7787 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 7788 TEST_CASE_ST(ut_setup, ut_teardown, 7789 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 7790 7791 TEST_CASES_END() /**< NULL terminate unit test array */ 7792 } 7793 }; 7794 7795 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = { 7796 .suite_name = "Crypto Device AESNI GCM Unit Test Suite", 7797 .setup = testsuite_setup, 7798 .teardown = testsuite_teardown, 7799 .unit_test_cases = { 7800 /** AES GCM Authenticated Encryption */ 7801 TEST_CASE_ST(ut_setup, ut_teardown, 7802 test_mb_AES_GCM_authenticated_encryption_test_case_1), 7803 TEST_CASE_ST(ut_setup, ut_teardown, 7804 test_mb_AES_GCM_authenticated_encryption_test_case_2), 7805 TEST_CASE_ST(ut_setup, ut_teardown, 7806 test_mb_AES_GCM_authenticated_encryption_test_case_3), 7807 TEST_CASE_ST(ut_setup, ut_teardown, 7808 test_mb_AES_GCM_authenticated_encryption_test_case_4), 7809 TEST_CASE_ST(ut_setup, ut_teardown, 7810 test_mb_AES_GCM_authenticated_encryption_test_case_5), 7811 TEST_CASE_ST(ut_setup, ut_teardown, 7812 test_mb_AES_GCM_authenticated_encryption_test_case_6), 7813 TEST_CASE_ST(ut_setup, ut_teardown, 7814 test_mb_AES_GCM_authenticated_encryption_test_case_7), 7815 7816 /** AES GCM Authenticated Decryption */ 7817 TEST_CASE_ST(ut_setup, ut_teardown, 7818 test_mb_AES_GCM_authenticated_decryption_test_case_1), 7819 TEST_CASE_ST(ut_setup, ut_teardown, 7820 test_mb_AES_GCM_authenticated_decryption_test_case_2), 7821 TEST_CASE_ST(ut_setup, ut_teardown, 7822 test_mb_AES_GCM_authenticated_decryption_test_case_3), 7823 TEST_CASE_ST(ut_setup, ut_teardown, 7824 test_mb_AES_GCM_authenticated_decryption_test_case_4), 7825 TEST_CASE_ST(ut_setup, ut_teardown, 7826 test_mb_AES_GCM_authenticated_decryption_test_case_5), 7827 TEST_CASE_ST(ut_setup, ut_teardown, 7828 test_mb_AES_GCM_authenticated_decryption_test_case_6), 7829 TEST_CASE_ST(ut_setup, ut_teardown, 7830 test_mb_AES_GCM_authenticated_decryption_test_case_7), 7831 7832 /** AES GCM Authenticated Encryption 256 bits key */ 7833 TEST_CASE_ST(ut_setup, ut_teardown, 7834 test_mb_AES_GCM_auth_encryption_test_case_256_1), 7835 TEST_CASE_ST(ut_setup, ut_teardown, 7836 test_mb_AES_GCM_auth_encryption_test_case_256_2), 7837 TEST_CASE_ST(ut_setup, ut_teardown, 7838 test_mb_AES_GCM_auth_encryption_test_case_256_3), 7839 TEST_CASE_ST(ut_setup, ut_teardown, 7840 test_mb_AES_GCM_auth_encryption_test_case_256_4), 7841 TEST_CASE_ST(ut_setup, ut_teardown, 7842 test_mb_AES_GCM_auth_encryption_test_case_256_5), 7843 TEST_CASE_ST(ut_setup, ut_teardown, 7844 test_mb_AES_GCM_auth_encryption_test_case_256_6), 7845 TEST_CASE_ST(ut_setup, ut_teardown, 7846 test_mb_AES_GCM_auth_encryption_test_case_256_7), 7847 7848 /** AES GCM Authenticated Decryption 256 bits key */ 7849 TEST_CASE_ST(ut_setup, ut_teardown, 7850 test_mb_AES_GCM_auth_decryption_test_case_256_1), 7851 TEST_CASE_ST(ut_setup, ut_teardown, 7852 test_mb_AES_GCM_auth_decryption_test_case_256_2), 7853 TEST_CASE_ST(ut_setup, ut_teardown, 7854 test_mb_AES_GCM_auth_decryption_test_case_256_3), 7855 TEST_CASE_ST(ut_setup, ut_teardown, 7856 test_mb_AES_GCM_auth_decryption_test_case_256_4), 7857 TEST_CASE_ST(ut_setup, ut_teardown, 7858 test_mb_AES_GCM_auth_decryption_test_case_256_5), 7859 TEST_CASE_ST(ut_setup, ut_teardown, 7860 test_mb_AES_GCM_auth_decryption_test_case_256_6), 7861 TEST_CASE_ST(ut_setup, ut_teardown, 7862 test_mb_AES_GCM_auth_decryption_test_case_256_7), 7863 7864 /** AES GCM Authenticated Encryption big aad size */ 7865 TEST_CASE_ST(ut_setup, ut_teardown, 7866 test_mb_AES_GCM_auth_encryption_test_case_aad_1), 7867 TEST_CASE_ST(ut_setup, ut_teardown, 7868 test_mb_AES_GCM_auth_encryption_test_case_aad_2), 7869 7870 /** AES GCM Authenticated Decryption big aad size */ 7871 TEST_CASE_ST(ut_setup, ut_teardown, 7872 test_mb_AES_GCM_auth_decryption_test_case_aad_1), 7873 TEST_CASE_ST(ut_setup, ut_teardown, 7874 test_mb_AES_GCM_auth_decryption_test_case_aad_2), 7875 7876 /** AES GMAC Authentication */ 7877 TEST_CASE_ST(ut_setup, ut_teardown, 7878 test_AES_GMAC_authentication_test_case_1), 7879 TEST_CASE_ST(ut_setup, ut_teardown, 7880 test_AES_GMAC_authentication_verify_test_case_1), 7881 TEST_CASE_ST(ut_setup, ut_teardown, 7882 test_AES_GMAC_authentication_test_case_3), 7883 TEST_CASE_ST(ut_setup, ut_teardown, 7884 test_AES_GMAC_authentication_verify_test_case_3), 7885 TEST_CASE_ST(ut_setup, ut_teardown, 7886 test_AES_GMAC_authentication_test_case_4), 7887 TEST_CASE_ST(ut_setup, ut_teardown, 7888 test_AES_GMAC_authentication_verify_test_case_4), 7889 7890 /** Negative tests */ 7891 TEST_CASE_ST(ut_setup, ut_teardown, 7892 authentication_verify_AES128_GMAC_fail_data_corrupt), 7893 TEST_CASE_ST(ut_setup, ut_teardown, 7894 authentication_verify_AES128_GMAC_fail_tag_corrupt), 7895 7896 /** Out of place tests */ 7897 TEST_CASE_ST(ut_setup, ut_teardown, 7898 test_mb_AES_GCM_authenticated_encryption_oop), 7899 TEST_CASE_ST(ut_setup, ut_teardown, 7900 test_mb_AES_GCM_authenticated_decryption_oop), 7901 7902 /** Session-less tests */ 7903 TEST_CASE_ST(ut_setup, ut_teardown, 7904 test_mb_AES_GCM_authenticated_encryption_sessionless), 7905 TEST_CASE_ST(ut_setup, ut_teardown, 7906 test_mb_AES_GCM_authenticated_decryption_sessionless), 7907 7908 /** Scatter-Gather */ 7909 TEST_CASE_ST(ut_setup, ut_teardown, 7910 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 7911 7912 TEST_CASES_END() /**< NULL terminate unit test array */ 7913 } 7914 }; 7915 7916 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = { 7917 .suite_name = "Crypto Device SW KASUMI Unit Test Suite", 7918 .setup = testsuite_setup, 7919 .teardown = testsuite_teardown, 7920 .unit_test_cases = { 7921 /** KASUMI encrypt only (UEA1) */ 7922 TEST_CASE_ST(ut_setup, ut_teardown, 7923 test_kasumi_encryption_test_case_1), 7924 TEST_CASE_ST(ut_setup, ut_teardown, 7925 test_kasumi_encryption_test_case_1_sgl), 7926 TEST_CASE_ST(ut_setup, ut_teardown, 7927 test_kasumi_encryption_test_case_2), 7928 TEST_CASE_ST(ut_setup, ut_teardown, 7929 test_kasumi_encryption_test_case_3), 7930 TEST_CASE_ST(ut_setup, ut_teardown, 7931 test_kasumi_encryption_test_case_4), 7932 TEST_CASE_ST(ut_setup, ut_teardown, 7933 test_kasumi_encryption_test_case_5), 7934 /** KASUMI decrypt only (UEA1) */ 7935 TEST_CASE_ST(ut_setup, ut_teardown, 7936 test_kasumi_decryption_test_case_1), 7937 TEST_CASE_ST(ut_setup, ut_teardown, 7938 test_kasumi_decryption_test_case_2), 7939 TEST_CASE_ST(ut_setup, ut_teardown, 7940 test_kasumi_decryption_test_case_3), 7941 TEST_CASE_ST(ut_setup, ut_teardown, 7942 test_kasumi_decryption_test_case_4), 7943 TEST_CASE_ST(ut_setup, ut_teardown, 7944 test_kasumi_decryption_test_case_5), 7945 7946 TEST_CASE_ST(ut_setup, ut_teardown, 7947 test_kasumi_encryption_test_case_1_oop), 7948 TEST_CASE_ST(ut_setup, ut_teardown, 7949 test_kasumi_encryption_test_case_1_oop_sgl), 7950 7951 7952 TEST_CASE_ST(ut_setup, ut_teardown, 7953 test_kasumi_decryption_test_case_1_oop), 7954 7955 /** KASUMI hash only (UIA1) */ 7956 TEST_CASE_ST(ut_setup, ut_teardown, 7957 test_kasumi_hash_generate_test_case_1), 7958 TEST_CASE_ST(ut_setup, ut_teardown, 7959 test_kasumi_hash_generate_test_case_2), 7960 TEST_CASE_ST(ut_setup, ut_teardown, 7961 test_kasumi_hash_generate_test_case_3), 7962 TEST_CASE_ST(ut_setup, ut_teardown, 7963 test_kasumi_hash_generate_test_case_4), 7964 TEST_CASE_ST(ut_setup, ut_teardown, 7965 test_kasumi_hash_generate_test_case_5), 7966 TEST_CASE_ST(ut_setup, ut_teardown, 7967 test_kasumi_hash_generate_test_case_6), 7968 TEST_CASE_ST(ut_setup, ut_teardown, 7969 test_kasumi_hash_verify_test_case_1), 7970 TEST_CASE_ST(ut_setup, ut_teardown, 7971 test_kasumi_hash_verify_test_case_2), 7972 TEST_CASE_ST(ut_setup, ut_teardown, 7973 test_kasumi_hash_verify_test_case_3), 7974 TEST_CASE_ST(ut_setup, ut_teardown, 7975 test_kasumi_hash_verify_test_case_4), 7976 TEST_CASE_ST(ut_setup, ut_teardown, 7977 test_kasumi_hash_verify_test_case_5), 7978 TEST_CASE_ST(ut_setup, ut_teardown, 7979 test_kasumi_auth_cipher_test_case_1), 7980 TEST_CASE_ST(ut_setup, ut_teardown, 7981 test_kasumi_cipher_auth_test_case_1), 7982 TEST_CASES_END() /**< NULL terminate unit test array */ 7983 } 7984 }; 7985 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = { 7986 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite", 7987 .setup = testsuite_setup, 7988 .teardown = testsuite_teardown, 7989 .unit_test_cases = { 7990 /** SNOW 3G encrypt only (UEA2) */ 7991 TEST_CASE_ST(ut_setup, ut_teardown, 7992 test_snow3g_encryption_test_case_1), 7993 TEST_CASE_ST(ut_setup, ut_teardown, 7994 test_snow3g_encryption_test_case_2), 7995 TEST_CASE_ST(ut_setup, ut_teardown, 7996 test_snow3g_encryption_test_case_3), 7997 TEST_CASE_ST(ut_setup, ut_teardown, 7998 test_snow3g_encryption_test_case_4), 7999 TEST_CASE_ST(ut_setup, ut_teardown, 8000 test_snow3g_encryption_test_case_5), 8001 8002 TEST_CASE_ST(ut_setup, ut_teardown, 8003 test_snow3g_encryption_test_case_1_oop), 8004 TEST_CASE_ST(ut_setup, ut_teardown, 8005 test_snow3g_encryption_test_case_1_oop_sgl), 8006 TEST_CASE_ST(ut_setup, ut_teardown, 8007 test_snow3g_decryption_test_case_1_oop), 8008 8009 TEST_CASE_ST(ut_setup, ut_teardown, 8010 test_snow3g_encryption_test_case_1_offset_oop), 8011 8012 /** SNOW 3G decrypt only (UEA2) */ 8013 TEST_CASE_ST(ut_setup, ut_teardown, 8014 test_snow3g_decryption_test_case_1), 8015 TEST_CASE_ST(ut_setup, ut_teardown, 8016 test_snow3g_decryption_test_case_2), 8017 TEST_CASE_ST(ut_setup, ut_teardown, 8018 test_snow3g_decryption_test_case_3), 8019 TEST_CASE_ST(ut_setup, ut_teardown, 8020 test_snow3g_decryption_test_case_4), 8021 TEST_CASE_ST(ut_setup, ut_teardown, 8022 test_snow3g_decryption_test_case_5), 8023 TEST_CASE_ST(ut_setup, ut_teardown, 8024 test_snow3g_hash_generate_test_case_1), 8025 TEST_CASE_ST(ut_setup, ut_teardown, 8026 test_snow3g_hash_generate_test_case_2), 8027 TEST_CASE_ST(ut_setup, ut_teardown, 8028 test_snow3g_hash_generate_test_case_3), 8029 /* Tests with buffers which length is not byte-aligned */ 8030 TEST_CASE_ST(ut_setup, ut_teardown, 8031 test_snow3g_hash_generate_test_case_4), 8032 TEST_CASE_ST(ut_setup, ut_teardown, 8033 test_snow3g_hash_generate_test_case_5), 8034 TEST_CASE_ST(ut_setup, ut_teardown, 8035 test_snow3g_hash_generate_test_case_6), 8036 TEST_CASE_ST(ut_setup, ut_teardown, 8037 test_snow3g_hash_verify_test_case_1), 8038 TEST_CASE_ST(ut_setup, ut_teardown, 8039 test_snow3g_hash_verify_test_case_2), 8040 TEST_CASE_ST(ut_setup, ut_teardown, 8041 test_snow3g_hash_verify_test_case_3), 8042 /* Tests with buffers which length is not byte-aligned */ 8043 TEST_CASE_ST(ut_setup, ut_teardown, 8044 test_snow3g_hash_verify_test_case_4), 8045 TEST_CASE_ST(ut_setup, ut_teardown, 8046 test_snow3g_hash_verify_test_case_5), 8047 TEST_CASE_ST(ut_setup, ut_teardown, 8048 test_snow3g_hash_verify_test_case_6), 8049 TEST_CASE_ST(ut_setup, ut_teardown, 8050 test_snow3g_cipher_auth_test_case_1), 8051 TEST_CASE_ST(ut_setup, ut_teardown, 8052 test_snow3g_auth_cipher_test_case_1), 8053 8054 TEST_CASES_END() /**< NULL terminate unit test array */ 8055 } 8056 }; 8057 8058 static struct unit_test_suite cryptodev_sw_zuc_testsuite = { 8059 .suite_name = "Crypto Device SW ZUC Unit Test Suite", 8060 .setup = testsuite_setup, 8061 .teardown = testsuite_teardown, 8062 .unit_test_cases = { 8063 /** ZUC encrypt only (EEA3) */ 8064 TEST_CASE_ST(ut_setup, ut_teardown, 8065 test_zuc_encryption_test_case_1), 8066 TEST_CASE_ST(ut_setup, ut_teardown, 8067 test_zuc_encryption_test_case_2), 8068 TEST_CASE_ST(ut_setup, ut_teardown, 8069 test_zuc_encryption_test_case_3), 8070 TEST_CASE_ST(ut_setup, ut_teardown, 8071 test_zuc_encryption_test_case_4), 8072 TEST_CASE_ST(ut_setup, ut_teardown, 8073 test_zuc_encryption_test_case_5), 8074 TEST_CASE_ST(ut_setup, ut_teardown, 8075 test_zuc_hash_generate_test_case_1), 8076 TEST_CASE_ST(ut_setup, ut_teardown, 8077 test_zuc_hash_generate_test_case_2), 8078 TEST_CASE_ST(ut_setup, ut_teardown, 8079 test_zuc_hash_generate_test_case_3), 8080 TEST_CASE_ST(ut_setup, ut_teardown, 8081 test_zuc_hash_generate_test_case_4), 8082 TEST_CASE_ST(ut_setup, ut_teardown, 8083 test_zuc_hash_generate_test_case_5), 8084 TEST_CASE_ST(ut_setup, ut_teardown, 8085 test_zuc_encryption_test_case_6_sgl), 8086 TEST_CASES_END() /**< NULL terminate unit test array */ 8087 } 8088 }; 8089 8090 static struct unit_test_suite cryptodev_null_testsuite = { 8091 .suite_name = "Crypto Device NULL Unit Test Suite", 8092 .setup = testsuite_setup, 8093 .teardown = testsuite_teardown, 8094 .unit_test_cases = { 8095 TEST_CASE_ST(ut_setup, ut_teardown, 8096 test_null_auth_only_operation), 8097 TEST_CASE_ST(ut_setup, ut_teardown, 8098 test_null_cipher_only_operation), 8099 TEST_CASE_ST(ut_setup, ut_teardown, 8100 test_null_cipher_auth_operation), 8101 TEST_CASE_ST(ut_setup, ut_teardown, 8102 test_null_auth_cipher_operation), 8103 TEST_CASE_ST(ut_setup, ut_teardown, 8104 test_null_invalid_operation), 8105 TEST_CASE_ST(ut_setup, ut_teardown, 8106 test_null_burst_operation), 8107 8108 TEST_CASES_END() /**< NULL terminate unit test array */ 8109 } 8110 }; 8111 8112 static struct unit_test_suite cryptodev_armv8_testsuite = { 8113 .suite_name = "Crypto Device ARMv8 Unit Test Suite", 8114 .setup = testsuite_setup, 8115 .teardown = testsuite_teardown, 8116 .unit_test_cases = { 8117 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all), 8118 8119 /** Negative tests */ 8120 TEST_CASE_ST(ut_setup, ut_teardown, 8121 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 8122 TEST_CASE_ST(ut_setup, ut_teardown, 8123 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 8124 8125 TEST_CASES_END() /**< NULL terminate unit test array */ 8126 } 8127 }; 8128 8129 static int 8130 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 8131 { 8132 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD; 8133 return unit_test_suite_runner(&cryptodev_qat_testsuite); 8134 } 8135 8136 static int 8137 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 8138 { 8139 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD; 8140 8141 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite); 8142 } 8143 8144 static int 8145 test_cryptodev_openssl(void) 8146 { 8147 gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD; 8148 8149 return unit_test_suite_runner(&cryptodev_openssl_testsuite); 8150 } 8151 8152 static int 8153 test_cryptodev_aesni_gcm(void) 8154 { 8155 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD; 8156 8157 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite); 8158 } 8159 8160 static int 8161 test_cryptodev_null(void) 8162 { 8163 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD; 8164 8165 return unit_test_suite_runner(&cryptodev_null_testsuite); 8166 } 8167 8168 static int 8169 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 8170 { 8171 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD; 8172 8173 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite); 8174 } 8175 8176 static int 8177 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 8178 { 8179 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD; 8180 8181 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite); 8182 } 8183 8184 static int 8185 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 8186 { 8187 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD; 8188 8189 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite); 8190 } 8191 8192 static int 8193 test_cryptodev_armv8(void) 8194 { 8195 gbl_cryptodev_type = RTE_CRYPTODEV_ARMV8_PMD; 8196 8197 return unit_test_suite_runner(&cryptodev_armv8_testsuite); 8198 } 8199 8200 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 8201 8202 static int 8203 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 8204 { 8205 gbl_cryptodev_type = RTE_CRYPTODEV_SCHEDULER_PMD; 8206 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 8207 } 8208 8209 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 8210 8211 #endif 8212 8213 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 8214 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 8215 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 8216 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 8217 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 8218 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 8219 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 8220 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 8221 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 8222