1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * * Neither the name of Intel Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <rte_common.h> 34 #include <rte_hexdump.h> 35 #include <rte_mbuf.h> 36 #include <rte_malloc.h> 37 #include <rte_memcpy.h> 38 39 #include <rte_crypto.h> 40 #include <rte_cryptodev.h> 41 #include <rte_cryptodev_pmd.h> 42 43 #include "test.h" 44 #include "test_cryptodev.h" 45 46 #include "test_cryptodev_blockcipher.h" 47 #include "test_cryptodev_aes_test_vectors.h" 48 #include "test_cryptodev_des_test_vectors.h" 49 #include "test_cryptodev_hash_test_vectors.h" 50 #include "test_cryptodev_kasumi_test_vectors.h" 51 #include "test_cryptodev_kasumi_hash_test_vectors.h" 52 #include "test_cryptodev_snow3g_test_vectors.h" 53 #include "test_cryptodev_snow3g_hash_test_vectors.h" 54 #include "test_cryptodev_zuc_test_vectors.h" 55 #include "test_cryptodev_zuc_hash_test_vectors.h" 56 #include "test_cryptodev_gcm_test_vectors.h" 57 #include "test_cryptodev_hmac_test_vectors.h" 58 59 static enum rte_cryptodev_type gbl_cryptodev_type; 60 61 struct crypto_testsuite_params { 62 struct rte_mempool *mbuf_pool; 63 struct rte_mempool *large_mbuf_pool; 64 struct rte_mempool *op_mpool; 65 struct rte_cryptodev_config conf; 66 struct rte_cryptodev_qp_conf qp_conf; 67 68 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 69 uint8_t valid_dev_count; 70 }; 71 72 struct crypto_unittest_params { 73 struct rte_crypto_sym_xform cipher_xform; 74 struct rte_crypto_sym_xform auth_xform; 75 76 struct rte_cryptodev_sym_session *sess; 77 78 struct rte_crypto_op *op; 79 80 struct rte_mbuf *obuf, *ibuf; 81 82 uint8_t *digest; 83 }; 84 85 #define ALIGN_POW2_ROUNDUP(num, align) \ 86 (((num) + (align) - 1) & ~((align) - 1)) 87 88 /* 89 * Forward declarations. 90 */ 91 static int 92 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 93 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 94 uint8_t *hmac_key); 95 96 static int 97 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 98 struct crypto_unittest_params *ut_params, 99 struct crypto_testsuite_params *ts_param, 100 const uint8_t *cipher, 101 const uint8_t *digest, 102 const uint8_t *iv); 103 104 static struct rte_mbuf * 105 setup_test_string(struct rte_mempool *mpool, 106 const char *string, size_t len, uint8_t blocksize) 107 { 108 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 109 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 110 111 memset(m->buf_addr, 0, m->buf_len); 112 if (m) { 113 char *dst = rte_pktmbuf_append(m, t_len); 114 115 if (!dst) { 116 rte_pktmbuf_free(m); 117 return NULL; 118 } 119 if (string != NULL) 120 rte_memcpy(dst, string, t_len); 121 else 122 memset(dst, 0, t_len); 123 } 124 125 return m; 126 } 127 128 /* Get number of bytes in X bits (rounding up) */ 129 static uint32_t 130 ceil_byte_length(uint32_t num_bits) 131 { 132 if (num_bits % 8) 133 return ((num_bits >> 3) + 1); 134 else 135 return (num_bits >> 3); 136 } 137 138 static struct rte_crypto_op * 139 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 140 { 141 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 142 printf("Error sending packet for encryption"); 143 return NULL; 144 } 145 146 op = NULL; 147 148 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 149 rte_pause(); 150 151 return op; 152 } 153 154 static struct crypto_testsuite_params testsuite_params = { NULL }; 155 static struct crypto_unittest_params unittest_params; 156 157 static int 158 testsuite_setup(void) 159 { 160 struct crypto_testsuite_params *ts_params = &testsuite_params; 161 struct rte_cryptodev_info info; 162 unsigned i, nb_devs, dev_id; 163 int ret; 164 uint16_t qp_id; 165 166 memset(ts_params, 0, sizeof(*ts_params)); 167 168 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 169 if (ts_params->mbuf_pool == NULL) { 170 /* Not already created so create */ 171 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 172 "CRYPTO_MBUFPOOL", 173 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 174 rte_socket_id()); 175 if (ts_params->mbuf_pool == NULL) { 176 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 177 return TEST_FAILED; 178 } 179 } 180 181 ts_params->large_mbuf_pool = rte_mempool_lookup( 182 "CRYPTO_LARGE_MBUFPOOL"); 183 if (ts_params->large_mbuf_pool == NULL) { 184 /* Not already created so create */ 185 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 186 "CRYPTO_LARGE_MBUFPOOL", 187 1, 0, 0, UINT16_MAX, 188 rte_socket_id()); 189 if (ts_params->large_mbuf_pool == NULL) { 190 RTE_LOG(ERR, USER1, 191 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 192 return TEST_FAILED; 193 } 194 } 195 196 ts_params->op_mpool = rte_crypto_op_pool_create( 197 "MBUF_CRYPTO_SYM_OP_POOL", 198 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 199 NUM_MBUFS, MBUF_CACHE_SIZE, 200 DEFAULT_NUM_XFORMS * 201 sizeof(struct rte_crypto_sym_xform), 202 rte_socket_id()); 203 if (ts_params->op_mpool == NULL) { 204 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 205 return TEST_FAILED; 206 } 207 208 /* Create 2 AESNI MB devices if required */ 209 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) { 210 #ifndef RTE_LIBRTE_PMD_AESNI_MB 211 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be" 212 " enabled in config file to run this testsuite.\n"); 213 return TEST_FAILED; 214 #endif 215 nb_devs = rte_cryptodev_count_devtype( 216 RTE_CRYPTODEV_AESNI_MB_PMD); 217 if (nb_devs < 2) { 218 for (i = nb_devs; i < 2; i++) { 219 ret = rte_eal_vdev_init( 220 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 221 222 TEST_ASSERT(ret == 0, 223 "Failed to create instance %u of" 224 " pmd : %s", 225 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 226 } 227 } 228 } 229 230 /* Create 2 AESNI GCM devices if required */ 231 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) { 232 #ifndef RTE_LIBRTE_PMD_AESNI_GCM 233 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be" 234 " enabled in config file to run this testsuite.\n"); 235 return TEST_FAILED; 236 #endif 237 nb_devs = rte_cryptodev_count_devtype( 238 RTE_CRYPTODEV_AESNI_GCM_PMD); 239 if (nb_devs < 2) { 240 for (i = nb_devs; i < 2; i++) { 241 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 242 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 243 "Failed to create instance %u of" 244 " pmd : %s", 245 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 246 } 247 } 248 } 249 250 /* Create 2 SNOW 3G devices if required */ 251 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) { 252 #ifndef RTE_LIBRTE_PMD_SNOW3G 253 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be" 254 " enabled in config file to run this testsuite.\n"); 255 return TEST_FAILED; 256 #endif 257 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD); 258 if (nb_devs < 2) { 259 for (i = nb_devs; i < 2; i++) { 260 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 261 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 262 "Failed to create instance %u of" 263 " pmd : %s", 264 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 265 } 266 } 267 } 268 269 /* Create 2 KASUMI devices if required */ 270 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) { 271 #ifndef RTE_LIBRTE_PMD_KASUMI 272 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be" 273 " enabled in config file to run this testsuite.\n"); 274 return TEST_FAILED; 275 #endif 276 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD); 277 if (nb_devs < 2) { 278 for (i = nb_devs; i < 2; i++) { 279 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 280 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 281 "Failed to create instance %u of" 282 " pmd : %s", 283 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 284 } 285 } 286 } 287 288 /* Create 2 ZUC devices if required */ 289 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) { 290 #ifndef RTE_LIBRTE_PMD_ZUC 291 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be" 292 " enabled in config file to run this testsuite.\n"); 293 return TEST_FAILED; 294 #endif 295 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD); 296 if (nb_devs < 2) { 297 for (i = nb_devs; i < 2; i++) { 298 TEST_ASSERT_SUCCESS(rte_eal_vdev_init( 299 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 300 "Failed to create instance %u of" 301 " pmd : %s", 302 i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 303 } 304 } 305 } 306 307 /* Create 2 NULL devices if required */ 308 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) { 309 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO 310 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be" 311 " enabled in config file to run this testsuite.\n"); 312 return TEST_FAILED; 313 #endif 314 nb_devs = rte_cryptodev_count_devtype( 315 RTE_CRYPTODEV_NULL_PMD); 316 if (nb_devs < 2) { 317 for (i = nb_devs; i < 2; i++) { 318 int dev_id = rte_eal_vdev_init( 319 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 320 321 TEST_ASSERT(dev_id >= 0, 322 "Failed to create instance %u of" 323 " pmd : %s", 324 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 325 } 326 } 327 } 328 329 /* Create 2 LIBCRYPTO devices if required */ 330 if (gbl_cryptodev_type == RTE_CRYPTODEV_LIBCRYPTO_PMD) { 331 #ifndef RTE_LIBRTE_PMD_LIBCRYPTO 332 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_LIBCRYPTO must be" 333 " enabled in config file to run this testsuite.\n"); 334 return TEST_FAILED; 335 #endif 336 nb_devs = rte_cryptodev_count_devtype( 337 RTE_CRYPTODEV_LIBCRYPTO_PMD); 338 if (nb_devs < 2) { 339 for (i = nb_devs; i < 2; i++) { 340 ret = rte_eal_vdev_init( 341 RTE_STR(CRYPTODEV_NAME_LIBCRYPTO_PMD), 342 NULL); 343 344 TEST_ASSERT(ret == 0, "Failed to create " 345 "instance %u of pmd : %s", i, 346 RTE_STR(CRYPTODEV_NAME_LIBCRYPTO_PMD)); 347 } 348 } 349 } 350 351 #ifndef RTE_LIBRTE_PMD_QAT 352 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) { 353 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled " 354 "in config file to run this testsuite.\n"); 355 return TEST_FAILED; 356 } 357 #endif 358 359 nb_devs = rte_cryptodev_count(); 360 if (nb_devs < 1) { 361 RTE_LOG(ERR, USER1, "No crypto devices found?\n"); 362 return TEST_FAILED; 363 } 364 365 /* Create list of valid crypto devs */ 366 for (i = 0; i < nb_devs; i++) { 367 rte_cryptodev_info_get(i, &info); 368 if (info.dev_type == gbl_cryptodev_type) 369 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 370 } 371 372 if (ts_params->valid_dev_count < 1) 373 return TEST_FAILED; 374 375 /* Set up all the qps on the first of the valid devices found */ 376 377 dev_id = ts_params->valid_devs[0]; 378 379 rte_cryptodev_info_get(dev_id, &info); 380 381 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 382 ts_params->conf.socket_id = SOCKET_ID_ANY; 383 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions; 384 385 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 386 &ts_params->conf), 387 "Failed to configure cryptodev %u with %u qps", 388 dev_id, ts_params->conf.nb_queue_pairs); 389 390 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 391 392 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 393 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 394 dev_id, qp_id, &ts_params->qp_conf, 395 rte_cryptodev_socket_id(dev_id)), 396 "Failed to setup queue pair %u on cryptodev %u", 397 qp_id, dev_id); 398 } 399 400 return TEST_SUCCESS; 401 } 402 403 static void 404 testsuite_teardown(void) 405 { 406 struct crypto_testsuite_params *ts_params = &testsuite_params; 407 408 if (ts_params->mbuf_pool != NULL) { 409 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 410 rte_mempool_avail_count(ts_params->mbuf_pool)); 411 } 412 413 if (ts_params->op_mpool != NULL) { 414 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 415 rte_mempool_avail_count(ts_params->op_mpool)); 416 } 417 418 } 419 420 static int 421 ut_setup(void) 422 { 423 struct crypto_testsuite_params *ts_params = &testsuite_params; 424 struct crypto_unittest_params *ut_params = &unittest_params; 425 426 uint16_t qp_id; 427 428 /* Clear unit test parameters before running test */ 429 memset(ut_params, 0, sizeof(*ut_params)); 430 431 /* Reconfigure device to default parameters */ 432 ts_params->conf.socket_id = SOCKET_ID_ANY; 433 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT; 434 435 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 436 &ts_params->conf), 437 "Failed to configure cryptodev %u", 438 ts_params->valid_devs[0]); 439 440 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 441 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 442 ts_params->valid_devs[0], qp_id, 443 &ts_params->qp_conf, 444 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 445 "Failed to setup queue pair %u on cryptodev %u", 446 qp_id, ts_params->valid_devs[0]); 447 } 448 449 450 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 451 452 /* Start the device */ 453 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 454 "Failed to start cryptodev %u", 455 ts_params->valid_devs[0]); 456 457 return TEST_SUCCESS; 458 } 459 460 static void 461 ut_teardown(void) 462 { 463 struct crypto_testsuite_params *ts_params = &testsuite_params; 464 struct crypto_unittest_params *ut_params = &unittest_params; 465 struct rte_cryptodev_stats stats; 466 467 /* free crypto session structure */ 468 if (ut_params->sess) { 469 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 470 ut_params->sess); 471 ut_params->sess = NULL; 472 } 473 474 /* free crypto operation structure */ 475 if (ut_params->op) 476 rte_crypto_op_free(ut_params->op); 477 478 /* 479 * free mbuf - both obuf and ibuf are usually the same, 480 * so check if they point at the same address is necessary, 481 * to avoid freeing the mbuf twice. 482 */ 483 if (ut_params->obuf) { 484 rte_pktmbuf_free(ut_params->obuf); 485 if (ut_params->ibuf == ut_params->obuf) 486 ut_params->ibuf = 0; 487 ut_params->obuf = 0; 488 } 489 if (ut_params->ibuf) { 490 rte_pktmbuf_free(ut_params->ibuf); 491 ut_params->ibuf = 0; 492 } 493 494 if (ts_params->mbuf_pool != NULL) 495 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 496 rte_mempool_avail_count(ts_params->mbuf_pool)); 497 498 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 499 500 /* Stop the device */ 501 rte_cryptodev_stop(ts_params->valid_devs[0]); 502 } 503 504 static int 505 test_device_configure_invalid_dev_id(void) 506 { 507 struct crypto_testsuite_params *ts_params = &testsuite_params; 508 uint16_t dev_id, num_devs = 0; 509 510 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 511 "Need at least %d devices for test", 1); 512 513 /* valid dev_id values */ 514 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1]; 515 516 /* Stop the device in case it's started so it can be configured */ 517 rte_cryptodev_stop(ts_params->valid_devs[dev_id]); 518 519 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 520 "Failed test for rte_cryptodev_configure: " 521 "invalid dev_num %u", dev_id); 522 523 /* invalid dev_id values */ 524 dev_id = num_devs; 525 526 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 527 "Failed test for rte_cryptodev_configure: " 528 "invalid dev_num %u", dev_id); 529 530 dev_id = 0xff; 531 532 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 533 "Failed test for rte_cryptodev_configure:" 534 "invalid dev_num %u", dev_id); 535 536 return TEST_SUCCESS; 537 } 538 539 static int 540 test_device_configure_invalid_queue_pair_ids(void) 541 { 542 struct crypto_testsuite_params *ts_params = &testsuite_params; 543 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 544 545 /* Stop the device in case it's started so it can be configured */ 546 rte_cryptodev_stop(ts_params->valid_devs[0]); 547 548 /* valid - one queue pairs */ 549 ts_params->conf.nb_queue_pairs = 1; 550 551 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 552 &ts_params->conf), 553 "Failed to configure cryptodev: dev_id %u, qp_id %u", 554 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 555 556 557 /* valid - max value queue pairs */ 558 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE; 559 560 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 561 &ts_params->conf), 562 "Failed to configure cryptodev: dev_id %u, qp_id %u", 563 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 564 565 566 /* invalid - zero queue pairs */ 567 ts_params->conf.nb_queue_pairs = 0; 568 569 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 570 &ts_params->conf), 571 "Failed test for rte_cryptodev_configure, dev_id %u," 572 " invalid qps: %u", 573 ts_params->valid_devs[0], 574 ts_params->conf.nb_queue_pairs); 575 576 577 /* invalid - max value supported by field queue pairs */ 578 ts_params->conf.nb_queue_pairs = UINT16_MAX; 579 580 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 581 &ts_params->conf), 582 "Failed test for rte_cryptodev_configure, dev_id %u," 583 " invalid qps: %u", 584 ts_params->valid_devs[0], 585 ts_params->conf.nb_queue_pairs); 586 587 588 /* invalid - max value + 1 queue pairs */ 589 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1; 590 591 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 592 &ts_params->conf), 593 "Failed test for rte_cryptodev_configure, dev_id %u," 594 " invalid qps: %u", 595 ts_params->valid_devs[0], 596 ts_params->conf.nb_queue_pairs); 597 598 /* revert to original testsuite value */ 599 ts_params->conf.nb_queue_pairs = orig_nb_qps; 600 601 return TEST_SUCCESS; 602 } 603 604 static int 605 test_queue_pair_descriptor_setup(void) 606 { 607 struct crypto_testsuite_params *ts_params = &testsuite_params; 608 struct rte_cryptodev_info dev_info; 609 struct rte_cryptodev_qp_conf qp_conf = { 610 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 611 }; 612 613 uint16_t qp_id; 614 615 /* Stop the device in case it's started so it can be configured */ 616 rte_cryptodev_stop(ts_params->valid_devs[0]); 617 618 619 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 620 621 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions; 622 623 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 624 &ts_params->conf), "Failed to configure cryptodev %u", 625 ts_params->valid_devs[0]); 626 627 628 /* 629 * Test various ring sizes on this device. memzones can't be 630 * freed so are re-used if ring is released and re-created. 631 */ 632 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 633 634 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 635 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 636 ts_params->valid_devs[0], qp_id, &qp_conf, 637 rte_cryptodev_socket_id( 638 ts_params->valid_devs[0])), 639 "Failed test for " 640 "rte_cryptodev_queue_pair_setup: num_inflights " 641 "%u on qp %u on cryptodev %u", 642 qp_conf.nb_descriptors, qp_id, 643 ts_params->valid_devs[0]); 644 } 645 646 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 647 648 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 649 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 650 ts_params->valid_devs[0], qp_id, &qp_conf, 651 rte_cryptodev_socket_id( 652 ts_params->valid_devs[0])), 653 "Failed test for" 654 " rte_cryptodev_queue_pair_setup: num_inflights" 655 " %u on qp %u on cryptodev %u", 656 qp_conf.nb_descriptors, qp_id, 657 ts_params->valid_devs[0]); 658 } 659 660 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 661 662 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 663 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 664 ts_params->valid_devs[0], qp_id, &qp_conf, 665 rte_cryptodev_socket_id( 666 ts_params->valid_devs[0])), 667 "Failed test for " 668 "rte_cryptodev_queue_pair_setup: num_inflights" 669 " %u on qp %u on cryptodev %u", 670 qp_conf.nb_descriptors, qp_id, 671 ts_params->valid_devs[0]); 672 } 673 674 /* invalid number of descriptors - max supported + 2 */ 675 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2; 676 677 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 678 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 679 ts_params->valid_devs[0], qp_id, &qp_conf, 680 rte_cryptodev_socket_id( 681 ts_params->valid_devs[0])), 682 "Unexpectedly passed test for " 683 "rte_cryptodev_queue_pair_setup:" 684 "num_inflights %u on qp %u on cryptodev %u", 685 qp_conf.nb_descriptors, qp_id, 686 ts_params->valid_devs[0]); 687 } 688 689 /* invalid number of descriptors - max value of parameter */ 690 qp_conf.nb_descriptors = UINT32_MAX-1; 691 692 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 693 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 694 ts_params->valid_devs[0], qp_id, &qp_conf, 695 rte_cryptodev_socket_id( 696 ts_params->valid_devs[0])), 697 "Unexpectedly passed test for " 698 "rte_cryptodev_queue_pair_setup:" 699 "num_inflights %u on qp %u on cryptodev %u", 700 qp_conf.nb_descriptors, qp_id, 701 ts_params->valid_devs[0]); 702 } 703 704 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 705 706 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 707 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 708 ts_params->valid_devs[0], qp_id, &qp_conf, 709 rte_cryptodev_socket_id( 710 ts_params->valid_devs[0])), 711 "Failed test for" 712 " rte_cryptodev_queue_pair_setup:" 713 "num_inflights %u on qp %u on cryptodev %u", 714 qp_conf.nb_descriptors, qp_id, 715 ts_params->valid_devs[0]); 716 } 717 718 /* invalid number of descriptors - max supported + 1 */ 719 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1; 720 721 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 722 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 723 ts_params->valid_devs[0], qp_id, &qp_conf, 724 rte_cryptodev_socket_id( 725 ts_params->valid_devs[0])), 726 "Unexpectedly passed test for " 727 "rte_cryptodev_queue_pair_setup:" 728 "num_inflights %u on qp %u on cryptodev %u", 729 qp_conf.nb_descriptors, qp_id, 730 ts_params->valid_devs[0]); 731 } 732 733 /* test invalid queue pair id */ 734 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 735 736 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */ 737 738 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 739 ts_params->valid_devs[0], 740 qp_id, &qp_conf, 741 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 742 "Failed test for rte_cryptodev_queue_pair_setup:" 743 "invalid qp %u on cryptodev %u", 744 qp_id, ts_params->valid_devs[0]); 745 746 qp_id = 0xffff; /*invalid*/ 747 748 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 749 ts_params->valid_devs[0], 750 qp_id, &qp_conf, 751 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 752 "Failed test for rte_cryptodev_queue_pair_setup:" 753 "invalid qp %u on cryptodev %u", 754 qp_id, ts_params->valid_devs[0]); 755 756 return TEST_SUCCESS; 757 } 758 759 /* ***** Plaintext data for tests ***** */ 760 761 const char catch_22_quote_1[] = 762 "There was only one catch and that was Catch-22, which " 763 "specified that a concern for one's safety in the face of " 764 "dangers that were real and immediate was the process of a " 765 "rational mind. Orr was crazy and could be grounded. All he " 766 "had to do was ask; and as soon as he did, he would no longer " 767 "be crazy and would have to fly more missions. Orr would be " 768 "crazy to fly more missions and sane if he didn't, but if he " 769 "was sane he had to fly them. If he flew them he was crazy " 770 "and didn't have to; but if he didn't want to he was sane and " 771 "had to. Yossarian was moved very deeply by the absolute " 772 "simplicity of this clause of Catch-22 and let out a " 773 "respectful whistle. \"That's some catch, that Catch-22\", he " 774 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 775 776 const char catch_22_quote[] = 777 "What a lousy earth! He wondered how many people were " 778 "destitute that same night even in his own prosperous country, " 779 "how many homes were shanties, how many husbands were drunk " 780 "and wives socked, and how many children were bullied, abused, " 781 "or abandoned. How many families hungered for food they could " 782 "not afford to buy? How many hearts were broken? How many " 783 "suicides would take place that same night, how many people " 784 "would go insane? How many cockroaches and landlords would " 785 "triumph? How many winners were losers, successes failures, " 786 "and rich men poor men? How many wise guys were stupid? How " 787 "many happy endings were unhappy endings? How many honest men " 788 "were liars, brave men cowards, loyal men traitors, how many " 789 "sainted men were corrupt, how many people in positions of " 790 "trust had sold their souls to bodyguards, how many had never " 791 "had souls? How many straight-and-narrow paths were crooked " 792 "paths? How many best families were worst families and how " 793 "many good people were bad people? When you added them all up " 794 "and then subtracted, you might be left with only the children, " 795 "and perhaps with Albert Einstein and an old violinist or " 796 "sculptor somewhere."; 797 798 #define QUOTE_480_BYTES (480) 799 #define QUOTE_512_BYTES (512) 800 #define QUOTE_768_BYTES (768) 801 #define QUOTE_1024_BYTES (1024) 802 803 804 805 /* ***** SHA1 Hash Tests ***** */ 806 807 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 808 809 static uint8_t hmac_sha1_key[] = { 810 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 811 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 812 0xDE, 0xF4, 0xDE, 0xAD }; 813 814 /* ***** SHA224 Hash Tests ***** */ 815 816 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 817 818 819 /* ***** AES-CBC Cipher Tests ***** */ 820 821 #define CIPHER_KEY_LENGTH_AES_CBC (16) 822 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 823 824 static uint8_t aes_cbc_key[] = { 825 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 826 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 827 828 static uint8_t aes_cbc_iv[] = { 829 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 830 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 831 832 833 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 834 835 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 836 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 837 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 838 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 839 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 840 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 841 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 842 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 843 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 844 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 845 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 846 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 847 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 848 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 849 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 850 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 851 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 852 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 853 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 854 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 855 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 856 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 857 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 858 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 859 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 860 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 861 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 862 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 863 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 864 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 865 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 866 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 867 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 868 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 869 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 870 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 871 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 872 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 873 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 874 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 875 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 876 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 877 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 878 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 879 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 880 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 881 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 882 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 883 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 884 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 885 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 886 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 887 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 888 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 889 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 890 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 891 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 892 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 893 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 894 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 895 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 896 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 897 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 898 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 899 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 900 }; 901 902 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 903 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 904 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 905 0x18, 0x8c, 0x1d, 0x32 906 }; 907 908 909 /* Multisession Vector context Test */ 910 /*Begin Session 0 */ 911 static uint8_t ms_aes_cbc_key0[] = { 912 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 913 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 914 }; 915 916 static uint8_t ms_aes_cbc_iv0[] = { 917 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 918 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 919 }; 920 921 static const uint8_t ms_aes_cbc_cipher0[] = { 922 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 923 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 924 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 925 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 926 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 927 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 928 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 929 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 930 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 931 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 932 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 933 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 934 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 935 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 936 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 937 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 938 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 939 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 940 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 941 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 942 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 943 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 944 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 945 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 946 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 947 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 948 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 949 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 950 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 951 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 952 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 953 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 954 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 955 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 956 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 957 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 958 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 959 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 960 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 961 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 962 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 963 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 964 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 965 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 966 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 967 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 968 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 969 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 970 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 971 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 972 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 973 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 974 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 975 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 976 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 977 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 978 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 979 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 980 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 981 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 982 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 983 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 984 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 985 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 986 }; 987 988 989 static uint8_t ms_hmac_key0[] = { 990 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 991 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 992 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 993 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 994 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 995 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 996 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 997 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 998 }; 999 1000 static const uint8_t ms_hmac_digest0[] = { 1001 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1002 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1003 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1004 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1005 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1006 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1007 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1008 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1009 }; 1010 1011 /* End Session 0 */ 1012 /* Begin session 1 */ 1013 1014 static uint8_t ms_aes_cbc_key1[] = { 1015 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1016 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1017 }; 1018 1019 static uint8_t ms_aes_cbc_iv1[] = { 1020 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1021 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1022 }; 1023 1024 static const uint8_t ms_aes_cbc_cipher1[] = { 1025 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1026 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1027 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1028 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1029 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1030 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1031 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1032 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1033 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1034 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1035 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1036 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1037 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1038 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1039 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1040 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1041 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1042 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1043 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1044 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1045 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1046 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1047 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1048 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1049 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1050 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1051 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1052 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1053 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1054 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1055 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1056 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1057 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1058 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1059 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1060 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1061 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1062 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1063 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1064 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1065 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1066 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1067 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1068 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1069 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1070 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1071 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1072 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1073 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1074 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1075 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1076 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1077 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1078 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1079 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1080 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1081 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1082 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1083 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1084 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1085 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1086 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1087 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1088 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1089 1090 }; 1091 1092 static uint8_t ms_hmac_key1[] = { 1093 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1094 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1095 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1096 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1097 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1098 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1099 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1100 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1101 }; 1102 1103 static const uint8_t ms_hmac_digest1[] = { 1104 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1105 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1106 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1107 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1108 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1109 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1110 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1111 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1112 }; 1113 /* End Session 1 */ 1114 /* Begin Session 2 */ 1115 static uint8_t ms_aes_cbc_key2[] = { 1116 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1117 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1118 }; 1119 1120 static uint8_t ms_aes_cbc_iv2[] = { 1121 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1122 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1123 }; 1124 1125 static const uint8_t ms_aes_cbc_cipher2[] = { 1126 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1127 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1128 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1129 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1130 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1131 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1132 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1133 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1134 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1135 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1136 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1137 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1138 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1139 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1140 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1141 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1142 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1143 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1144 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1145 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1146 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1147 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1148 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1149 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1150 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1151 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1152 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1153 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1154 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1155 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1156 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1157 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1158 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1159 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1160 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1161 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1162 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1163 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1164 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1165 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1166 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1167 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1168 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1169 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1170 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1171 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1172 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1173 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1174 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1175 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1176 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1177 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1178 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1179 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1180 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1181 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1182 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1183 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1184 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1185 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1186 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1187 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1188 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1189 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1190 }; 1191 1192 static uint8_t ms_hmac_key2[] = { 1193 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1194 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1195 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1196 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1197 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1198 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1199 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1200 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1201 }; 1202 1203 static const uint8_t ms_hmac_digest2[] = { 1204 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1205 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1206 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1207 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1208 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1209 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1210 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1211 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1212 }; 1213 1214 /* End Session 2 */ 1215 1216 1217 static int 1218 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1219 { 1220 struct crypto_testsuite_params *ts_params = &testsuite_params; 1221 struct crypto_unittest_params *ut_params = &unittest_params; 1222 1223 /* Generate test mbuf data and space for digest */ 1224 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1225 catch_22_quote, QUOTE_512_BYTES, 0); 1226 1227 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1228 DIGEST_BYTE_LENGTH_SHA1); 1229 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1230 1231 /* Setup Cipher Parameters */ 1232 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1233 ut_params->cipher_xform.next = &ut_params->auth_xform; 1234 1235 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1236 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1237 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1238 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1239 1240 /* Setup HMAC Parameters */ 1241 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1242 1243 ut_params->auth_xform.next = NULL; 1244 1245 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1246 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1247 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1248 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1249 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1250 1251 /* Create crypto session*/ 1252 ut_params->sess = rte_cryptodev_sym_session_create( 1253 ts_params->valid_devs[0], 1254 &ut_params->cipher_xform); 1255 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1256 1257 /* Generate crypto op data structure */ 1258 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1259 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1260 TEST_ASSERT_NOT_NULL(ut_params->op, 1261 "Failed to allocate symmetric crypto operation struct"); 1262 1263 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1264 1265 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1266 1267 /* set crypto operation source mbuf */ 1268 sym_op->m_src = ut_params->ibuf; 1269 1270 /* Set crypto operation authentication parameters */ 1271 sym_op->auth.digest.data = ut_params->digest; 1272 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1273 ut_params->ibuf, QUOTE_512_BYTES); 1274 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1; 1275 1276 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1277 sym_op->auth.data.length = QUOTE_512_BYTES; 1278 1279 /* Set crypto operation cipher parameters */ 1280 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf, 1281 CIPHER_IV_LENGTH_AES_CBC); 1282 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1283 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1284 1285 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv, 1286 CIPHER_IV_LENGTH_AES_CBC); 1287 1288 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1289 sym_op->cipher.data.length = QUOTE_512_BYTES; 1290 1291 /* Process crypto operation */ 1292 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 1293 ut_params->op), "failed to process sym crypto op"); 1294 1295 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1296 "crypto op processing failed"); 1297 1298 /* Validate obuf */ 1299 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 1300 uint8_t *, CIPHER_IV_LENGTH_AES_CBC); 1301 1302 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1303 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1304 QUOTE_512_BYTES, 1305 "ciphertext data not as expected"); 1306 1307 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1308 1309 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1310 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1311 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ? 1312 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1313 DIGEST_BYTE_LENGTH_SHA1, 1314 "Generated digest data not as expected"); 1315 1316 return TEST_SUCCESS; 1317 } 1318 1319 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1320 1321 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1322 1323 static uint8_t hmac_sha512_key[] = { 1324 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1325 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1326 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1327 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1328 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1329 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1330 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1331 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1332 1333 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1334 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1335 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1336 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1337 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1338 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1339 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1340 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1341 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1342 1343 1344 1345 static int 1346 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1347 struct crypto_unittest_params *ut_params, 1348 uint8_t *cipher_key, 1349 uint8_t *hmac_key); 1350 1351 static int 1352 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1353 struct crypto_unittest_params *ut_params, 1354 struct crypto_testsuite_params *ts_params, 1355 const uint8_t *cipher, 1356 const uint8_t *digest, 1357 const uint8_t *iv); 1358 1359 1360 static int 1361 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1362 struct crypto_unittest_params *ut_params, 1363 uint8_t *cipher_key, 1364 uint8_t *hmac_key) 1365 { 1366 1367 /* Setup Cipher Parameters */ 1368 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1369 ut_params->cipher_xform.next = NULL; 1370 1371 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1372 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1373 ut_params->cipher_xform.cipher.key.data = cipher_key; 1374 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1375 1376 /* Setup HMAC Parameters */ 1377 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1378 ut_params->auth_xform.next = &ut_params->cipher_xform; 1379 1380 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1381 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1382 ut_params->auth_xform.auth.key.data = hmac_key; 1383 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1384 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1385 1386 return TEST_SUCCESS; 1387 } 1388 1389 1390 static int 1391 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1392 struct crypto_unittest_params *ut_params, 1393 struct crypto_testsuite_params *ts_params, 1394 const uint8_t *cipher, 1395 const uint8_t *digest, 1396 const uint8_t *iv) 1397 { 1398 /* Generate test mbuf data and digest */ 1399 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1400 (const char *) 1401 cipher, 1402 QUOTE_512_BYTES, 0); 1403 1404 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1405 DIGEST_BYTE_LENGTH_SHA512); 1406 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1407 1408 rte_memcpy(ut_params->digest, 1409 digest, 1410 DIGEST_BYTE_LENGTH_SHA512); 1411 1412 /* Generate Crypto op data structure */ 1413 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1414 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1415 TEST_ASSERT_NOT_NULL(ut_params->op, 1416 "Failed to allocate symmetric crypto operation struct"); 1417 1418 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1419 1420 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1421 1422 /* set crypto operation source mbuf */ 1423 sym_op->m_src = ut_params->ibuf; 1424 1425 sym_op->auth.digest.data = ut_params->digest; 1426 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1427 ut_params->ibuf, QUOTE_512_BYTES); 1428 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512; 1429 1430 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1431 sym_op->auth.data.length = QUOTE_512_BYTES; 1432 1433 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 1434 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC); 1435 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset( 1436 ut_params->ibuf, 0); 1437 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1438 1439 rte_memcpy(sym_op->cipher.iv.data, iv, 1440 CIPHER_IV_LENGTH_AES_CBC); 1441 1442 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC; 1443 sym_op->cipher.data.length = QUOTE_512_BYTES; 1444 1445 /* Process crypto operation */ 1446 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 1447 ut_params->op), "failed to process sym crypto op"); 1448 1449 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1450 "crypto op processing failed"); 1451 1452 ut_params->obuf = ut_params->op->sym->m_src; 1453 1454 /* Validate obuf */ 1455 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1456 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + 1457 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote, 1458 QUOTE_512_BYTES, 1459 "Plaintext data not as expected"); 1460 1461 /* Validate obuf */ 1462 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1463 "Digest verification failed"); 1464 1465 return TEST_SUCCESS; 1466 } 1467 1468 static int 1469 test_AES_chain_mb_all(void) 1470 { 1471 struct crypto_testsuite_params *ts_params = &testsuite_params; 1472 int status; 1473 1474 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1475 ts_params->op_mpool, ts_params->valid_devs[0], 1476 RTE_CRYPTODEV_AESNI_MB_PMD, 1477 BLKCIPHER_AES_CHAIN_TYPE); 1478 1479 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1480 1481 return TEST_SUCCESS; 1482 } 1483 1484 static int 1485 test_AES_chain_libcrypto_all(void) 1486 { 1487 struct crypto_testsuite_params *ts_params = &testsuite_params; 1488 int status; 1489 1490 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1491 ts_params->op_mpool, ts_params->valid_devs[0], 1492 RTE_CRYPTODEV_LIBCRYPTO_PMD, 1493 BLKCIPHER_AES_CHAIN_TYPE); 1494 1495 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1496 1497 return TEST_SUCCESS; 1498 } 1499 1500 static int 1501 test_AES_cipheronly_libcrypto_all(void) 1502 { 1503 struct crypto_testsuite_params *ts_params = &testsuite_params; 1504 int status; 1505 1506 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1507 ts_params->op_mpool, ts_params->valid_devs[0], 1508 RTE_CRYPTODEV_LIBCRYPTO_PMD, 1509 BLKCIPHER_AES_CIPHERONLY_TYPE); 1510 1511 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1512 1513 return TEST_SUCCESS; 1514 } 1515 1516 static int 1517 test_AES_chain_qat_all(void) 1518 { 1519 struct crypto_testsuite_params *ts_params = &testsuite_params; 1520 int status; 1521 1522 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1523 ts_params->op_mpool, ts_params->valid_devs[0], 1524 RTE_CRYPTODEV_QAT_SYM_PMD, 1525 BLKCIPHER_AES_CHAIN_TYPE); 1526 1527 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1528 1529 return TEST_SUCCESS; 1530 } 1531 1532 static int 1533 test_authonly_libcrypto_all(void) 1534 { 1535 struct crypto_testsuite_params *ts_params = &testsuite_params; 1536 int status; 1537 1538 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1539 ts_params->op_mpool, ts_params->valid_devs[0], 1540 RTE_CRYPTODEV_LIBCRYPTO_PMD, 1541 BLKCIPHER_AUTHONLY_TYPE); 1542 1543 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1544 1545 return TEST_SUCCESS; 1546 } 1547 1548 /* ***** SNOW 3G Tests ***** */ 1549 static int 1550 create_wireless_algo_hash_session(uint8_t dev_id, 1551 const uint8_t *key, const uint8_t key_len, 1552 const uint8_t aad_len, const uint8_t auth_len, 1553 enum rte_crypto_auth_operation op, 1554 enum rte_crypto_auth_algorithm algo) 1555 { 1556 uint8_t hash_key[key_len]; 1557 1558 struct crypto_unittest_params *ut_params = &unittest_params; 1559 1560 memcpy(hash_key, key, key_len); 1561 1562 TEST_HEXDUMP(stdout, "key:", key, key_len); 1563 1564 /* Setup Authentication Parameters */ 1565 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1566 ut_params->auth_xform.next = NULL; 1567 1568 ut_params->auth_xform.auth.op = op; 1569 ut_params->auth_xform.auth.algo = algo; 1570 ut_params->auth_xform.auth.key.length = key_len; 1571 ut_params->auth_xform.auth.key.data = hash_key; 1572 ut_params->auth_xform.auth.digest_length = auth_len; 1573 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1574 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1575 &ut_params->auth_xform); 1576 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1577 return 0; 1578 } 1579 1580 static int 1581 create_wireless_algo_cipher_session(uint8_t dev_id, 1582 enum rte_crypto_cipher_operation op, 1583 enum rte_crypto_cipher_algorithm algo, 1584 const uint8_t *key, const uint8_t key_len) 1585 { 1586 uint8_t cipher_key[key_len]; 1587 1588 struct crypto_unittest_params *ut_params = &unittest_params; 1589 1590 memcpy(cipher_key, key, key_len); 1591 1592 /* Setup Cipher Parameters */ 1593 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1594 ut_params->cipher_xform.next = NULL; 1595 1596 ut_params->cipher_xform.cipher.algo = algo; 1597 ut_params->cipher_xform.cipher.op = op; 1598 ut_params->cipher_xform.cipher.key.data = cipher_key; 1599 ut_params->cipher_xform.cipher.key.length = key_len; 1600 1601 TEST_HEXDUMP(stdout, "key:", key, key_len); 1602 1603 /* Create Crypto session */ 1604 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1605 &ut_params-> 1606 cipher_xform); 1607 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1608 return 0; 1609 } 1610 1611 static int 1612 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len, 1613 const unsigned cipher_len, 1614 const unsigned cipher_offset, 1615 enum rte_crypto_cipher_algorithm algo) 1616 { 1617 struct crypto_testsuite_params *ts_params = &testsuite_params; 1618 struct crypto_unittest_params *ut_params = &unittest_params; 1619 unsigned iv_pad_len = 0; 1620 1621 /* Generate Crypto op data structure */ 1622 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1623 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1624 TEST_ASSERT_NOT_NULL(ut_params->op, 1625 "Failed to allocate pktmbuf offload"); 1626 1627 /* Set crypto operation data parameters */ 1628 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1629 1630 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1631 1632 /* set crypto operation source mbuf */ 1633 sym_op->m_src = ut_params->ibuf; 1634 1635 /* iv */ 1636 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 1637 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 1638 else 1639 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 1640 1641 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf 1642 , iv_pad_len); 1643 1644 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 1645 1646 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 1647 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1648 sym_op->cipher.iv.length = iv_pad_len; 1649 1650 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 1651 sym_op->cipher.data.length = cipher_len; 1652 sym_op->cipher.data.offset = cipher_offset; 1653 return 0; 1654 } 1655 1656 static int 1657 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len, 1658 const unsigned cipher_len, 1659 const unsigned cipher_offset, 1660 enum rte_crypto_cipher_algorithm algo) 1661 { 1662 struct crypto_testsuite_params *ts_params = &testsuite_params; 1663 struct crypto_unittest_params *ut_params = &unittest_params; 1664 unsigned iv_pad_len = 0; 1665 1666 /* Generate Crypto op data structure */ 1667 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1668 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1669 TEST_ASSERT_NOT_NULL(ut_params->op, 1670 "Failed to allocate pktmbuf offload"); 1671 1672 /* Set crypto operation data parameters */ 1673 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1674 1675 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1676 1677 /* set crypto operation source mbuf */ 1678 sym_op->m_src = ut_params->ibuf; 1679 sym_op->m_dst = ut_params->obuf; 1680 1681 /* iv */ 1682 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 1683 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 1684 else 1685 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 1686 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf, 1687 iv_pad_len); 1688 1689 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 1690 1691 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 1692 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1693 sym_op->cipher.iv.length = iv_pad_len; 1694 1695 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 1696 sym_op->cipher.data.length = cipher_len; 1697 sym_op->cipher.data.offset = cipher_offset; 1698 return 0; 1699 } 1700 1701 static int 1702 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 1703 enum rte_crypto_cipher_operation cipher_op, 1704 enum rte_crypto_auth_operation auth_op, 1705 enum rte_crypto_auth_algorithm auth_algo, 1706 enum rte_crypto_cipher_algorithm cipher_algo, 1707 const uint8_t *key, const uint8_t key_len, 1708 const uint8_t aad_len, const uint8_t auth_len) 1709 1710 { 1711 uint8_t cipher_auth_key[key_len]; 1712 1713 struct crypto_unittest_params *ut_params = &unittest_params; 1714 1715 memcpy(cipher_auth_key, key, key_len); 1716 1717 /* Setup Authentication Parameters */ 1718 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1719 ut_params->auth_xform.next = NULL; 1720 1721 ut_params->auth_xform.auth.op = auth_op; 1722 ut_params->auth_xform.auth.algo = auth_algo; 1723 ut_params->auth_xform.auth.key.length = key_len; 1724 /* Hash key = cipher key */ 1725 ut_params->auth_xform.auth.key.data = cipher_auth_key; 1726 ut_params->auth_xform.auth.digest_length = auth_len; 1727 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1728 1729 /* Setup Cipher Parameters */ 1730 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1731 ut_params->cipher_xform.next = &ut_params->auth_xform; 1732 1733 ut_params->cipher_xform.cipher.algo = cipher_algo; 1734 ut_params->cipher_xform.cipher.op = cipher_op; 1735 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 1736 ut_params->cipher_xform.cipher.key.length = key_len; 1737 1738 TEST_HEXDUMP(stdout, "key:", key, key_len); 1739 1740 /* Create Crypto session*/ 1741 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1742 &ut_params->cipher_xform); 1743 1744 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1745 return 0; 1746 } 1747 1748 static int 1749 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 1750 enum rte_crypto_cipher_operation cipher_op, 1751 enum rte_crypto_auth_operation auth_op, 1752 enum rte_crypto_auth_algorithm auth_algo, 1753 enum rte_crypto_cipher_algorithm cipher_algo, 1754 const uint8_t *key, const uint8_t key_len, 1755 const uint8_t aad_len, const uint8_t auth_len) 1756 { 1757 uint8_t auth_cipher_key[key_len]; 1758 1759 struct crypto_unittest_params *ut_params = &unittest_params; 1760 1761 memcpy(auth_cipher_key, key, key_len); 1762 1763 /* Setup Authentication Parameters */ 1764 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1765 ut_params->auth_xform.auth.op = auth_op; 1766 ut_params->auth_xform.next = &ut_params->cipher_xform; 1767 ut_params->auth_xform.auth.algo = auth_algo; 1768 ut_params->auth_xform.auth.key.length = key_len; 1769 ut_params->auth_xform.auth.key.data = auth_cipher_key; 1770 ut_params->auth_xform.auth.digest_length = auth_len; 1771 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 1772 1773 /* Setup Cipher Parameters */ 1774 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1775 ut_params->cipher_xform.next = NULL; 1776 ut_params->cipher_xform.cipher.algo = cipher_algo; 1777 ut_params->cipher_xform.cipher.op = cipher_op; 1778 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 1779 ut_params->cipher_xform.cipher.key.length = key_len; 1780 1781 TEST_HEXDUMP(stdout, "key:", key, key_len); 1782 1783 /* Create Crypto session*/ 1784 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 1785 &ut_params->auth_xform); 1786 1787 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1788 1789 return 0; 1790 } 1791 1792 static int 1793 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 1794 const unsigned auth_tag_len, 1795 const uint8_t *aad, const unsigned aad_len, 1796 unsigned data_pad_len, 1797 enum rte_crypto_auth_operation op, 1798 enum rte_crypto_auth_algorithm algo, 1799 const unsigned auth_len, const unsigned auth_offset) 1800 { 1801 struct crypto_testsuite_params *ts_params = &testsuite_params; 1802 1803 struct crypto_unittest_params *ut_params = &unittest_params; 1804 1805 unsigned aad_buffer_len; 1806 1807 /* Generate Crypto op data structure */ 1808 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1809 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1810 TEST_ASSERT_NOT_NULL(ut_params->op, 1811 "Failed to allocate pktmbuf offload"); 1812 1813 /* Set crypto operation data parameters */ 1814 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1815 1816 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1817 1818 /* set crypto operation source mbuf */ 1819 sym_op->m_src = ut_params->ibuf; 1820 1821 /* aad */ 1822 /* 1823 * Always allocate the aad up to the block size. 1824 * The cryptodev API calls out - 1825 * - the array must be big enough to hold the AAD, plus any 1826 * space to round this up to the nearest multiple of the 1827 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G). 1828 */ 1829 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9) 1830 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 1831 else 1832 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 1833 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 1834 ut_params->ibuf, aad_buffer_len); 1835 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 1836 "no room to prepend aad"); 1837 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 1838 ut_params->ibuf); 1839 sym_op->auth.aad.length = aad_len; 1840 1841 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 1842 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 1843 1844 TEST_HEXDUMP(stdout, "aad:", 1845 sym_op->auth.aad.data, aad_len); 1846 1847 /* digest */ 1848 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 1849 ut_params->ibuf, auth_tag_len); 1850 1851 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 1852 "no room to append auth tag"); 1853 ut_params->digest = sym_op->auth.digest.data; 1854 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1855 ut_params->ibuf, data_pad_len + aad_len); 1856 sym_op->auth.digest.length = auth_tag_len; 1857 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 1858 memset(sym_op->auth.digest.data, 0, auth_tag_len); 1859 else 1860 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 1861 1862 TEST_HEXDUMP(stdout, "digest:", 1863 sym_op->auth.digest.data, 1864 sym_op->auth.digest.length); 1865 1866 sym_op->auth.data.length = auth_len; 1867 sym_op->auth.data.offset = auth_offset; 1868 1869 return 0; 1870 } 1871 1872 static int 1873 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 1874 const unsigned auth_tag_len, 1875 const uint8_t *aad, const uint8_t aad_len, 1876 unsigned data_pad_len, 1877 enum rte_crypto_auth_operation op, 1878 enum rte_crypto_auth_algorithm auth_algo, 1879 enum rte_crypto_cipher_algorithm cipher_algo, 1880 const uint8_t *iv, const uint8_t iv_len, 1881 const unsigned cipher_len, const unsigned cipher_offset, 1882 const unsigned auth_len, const unsigned auth_offset) 1883 { 1884 struct crypto_testsuite_params *ts_params = &testsuite_params; 1885 struct crypto_unittest_params *ut_params = &unittest_params; 1886 1887 unsigned iv_pad_len = 0; 1888 unsigned aad_buffer_len; 1889 1890 /* Generate Crypto op data structure */ 1891 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1892 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1893 TEST_ASSERT_NOT_NULL(ut_params->op, 1894 "Failed to allocate pktmbuf offload"); 1895 /* Set crypto operation data parameters */ 1896 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1897 1898 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1899 1900 /* set crypto operation source mbuf */ 1901 sym_op->m_src = ut_params->ibuf; 1902 1903 /* digest */ 1904 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 1905 ut_params->ibuf, auth_tag_len); 1906 1907 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 1908 "no room to append auth tag"); 1909 ut_params->digest = sym_op->auth.digest.data; 1910 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 1911 ut_params->ibuf, data_pad_len); 1912 sym_op->auth.digest.length = auth_tag_len; 1913 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 1914 memset(sym_op->auth.digest.data, 0, auth_tag_len); 1915 else 1916 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 1917 1918 TEST_HEXDUMP(stdout, "digest:", 1919 sym_op->auth.digest.data, 1920 sym_op->auth.digest.length); 1921 1922 /* aad */ 1923 /* 1924 * Always allocate the aad up to the block size. 1925 * The cryptodev API calls out - 1926 * - the array must be big enough to hold the AAD, plus any 1927 * space to round this up to the nearest multiple of the 1928 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G). 1929 */ 1930 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9) 1931 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 1932 else 1933 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 1934 sym_op->auth.aad.data = 1935 (uint8_t *)rte_pktmbuf_prepend( 1936 ut_params->ibuf, aad_buffer_len); 1937 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 1938 "no room to prepend aad"); 1939 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 1940 ut_params->ibuf); 1941 sym_op->auth.aad.length = aad_len; 1942 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 1943 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 1944 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len); 1945 1946 /* iv */ 1947 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 1948 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 1949 else 1950 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 1951 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 1952 ut_params->ibuf, iv_pad_len); 1953 1954 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 1955 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 1956 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 1957 sym_op->cipher.iv.length = iv_pad_len; 1958 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 1959 sym_op->cipher.data.length = cipher_len; 1960 sym_op->cipher.data.offset = cipher_offset + auth_offset; 1961 sym_op->auth.data.length = auth_len; 1962 sym_op->auth.data.offset = auth_offset + cipher_offset; 1963 1964 return 0; 1965 } 1966 1967 static int 1968 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len, 1969 const uint8_t *iv, const uint8_t iv_len, 1970 const uint8_t *aad, const uint8_t aad_len, 1971 unsigned data_pad_len, 1972 const unsigned cipher_len, const unsigned cipher_offset, 1973 const unsigned auth_len, const unsigned auth_offset, 1974 enum rte_crypto_auth_algorithm auth_algo, 1975 enum rte_crypto_cipher_algorithm cipher_algo) 1976 { 1977 struct crypto_testsuite_params *ts_params = &testsuite_params; 1978 struct crypto_unittest_params *ut_params = &unittest_params; 1979 1980 unsigned iv_pad_len = 0; 1981 unsigned aad_buffer_len = 0; 1982 1983 /* Generate Crypto op data structure */ 1984 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1985 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1986 TEST_ASSERT_NOT_NULL(ut_params->op, 1987 "Failed to allocate pktmbuf offload"); 1988 1989 /* Set crypto operation data parameters */ 1990 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1991 1992 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1993 1994 /* set crypto operation source mbuf */ 1995 sym_op->m_src = ut_params->ibuf; 1996 1997 /* digest */ 1998 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 1999 ut_params->ibuf, auth_tag_len); 2000 2001 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2002 "no room to append auth tag"); 2003 2004 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 2005 ut_params->ibuf, data_pad_len); 2006 sym_op->auth.digest.length = auth_tag_len; 2007 2008 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2009 2010 TEST_HEXDUMP(stdout, "digest:", 2011 sym_op->auth.digest.data, 2012 sym_op->auth.digest.length); 2013 2014 /* aad */ 2015 /* 2016 * Always allocate the aad up to the block size. 2017 * The cryptodev API calls out - 2018 * - the array must be big enough to hold the AAD, plus any 2019 * space to round this up to the nearest multiple of the 2020 * block size (8 bytes for KASUMI 16 bytes). 2021 */ 2022 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9) 2023 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8); 2024 else 2025 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 2026 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 2027 ut_params->ibuf, aad_buffer_len); 2028 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 2029 "no room to prepend aad"); 2030 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 2031 ut_params->ibuf); 2032 sym_op->auth.aad.length = aad_len; 2033 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 2034 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 2035 TEST_HEXDUMP(stdout, "aad:", 2036 sym_op->auth.aad.data, aad_len); 2037 2038 /* iv */ 2039 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8) 2040 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8); 2041 else 2042 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 2043 2044 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 2045 ut_params->ibuf, iv_pad_len); 2046 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 2047 2048 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 2049 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 2050 sym_op->cipher.iv.length = iv_pad_len; 2051 2052 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 2053 2054 sym_op->cipher.data.length = cipher_len; 2055 sym_op->cipher.data.offset = auth_offset + cipher_offset; 2056 2057 sym_op->auth.data.length = auth_len; 2058 sym_op->auth.data.offset = auth_offset + cipher_offset; 2059 2060 return 0; 2061 } 2062 2063 static int 2064 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2065 { 2066 struct crypto_testsuite_params *ts_params = &testsuite_params; 2067 struct crypto_unittest_params *ut_params = &unittest_params; 2068 2069 int retval; 2070 unsigned plaintext_pad_len; 2071 unsigned plaintext_len; 2072 uint8_t *plaintext; 2073 2074 /* Create SNOW 3G session */ 2075 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2076 tdata->key.data, tdata->key.len, 2077 tdata->aad.len, tdata->digest.len, 2078 RTE_CRYPTO_AUTH_OP_GENERATE, 2079 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2080 if (retval < 0) 2081 return retval; 2082 2083 /* alloc mbuf and set payload */ 2084 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2085 2086 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2087 rte_pktmbuf_tailroom(ut_params->ibuf)); 2088 2089 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2090 /* Append data which is padded to a multiple of */ 2091 /* the algorithms block size */ 2092 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2093 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2094 plaintext_pad_len); 2095 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2096 2097 /* Create SNOW 3G operation */ 2098 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2099 tdata->aad.data, tdata->aad.len, 2100 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2101 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 2102 tdata->validAuthLenInBits.len, 2103 tdata->validAuthOffsetLenInBits.len); 2104 if (retval < 0) 2105 return retval; 2106 2107 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2108 ut_params->op); 2109 ut_params->obuf = ut_params->op->sym->m_src; 2110 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2111 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2112 + plaintext_pad_len + tdata->aad.len; 2113 2114 /* Validate obuf */ 2115 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2116 ut_params->digest, 2117 tdata->digest.data, 2118 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2119 "SNOW 3G Generated auth tag not as expected"); 2120 2121 return 0; 2122 } 2123 2124 static int 2125 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2126 { 2127 struct crypto_testsuite_params *ts_params = &testsuite_params; 2128 struct crypto_unittest_params *ut_params = &unittest_params; 2129 2130 int retval; 2131 unsigned plaintext_pad_len; 2132 unsigned plaintext_len; 2133 uint8_t *plaintext; 2134 2135 /* Create SNOW 3G session */ 2136 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2137 tdata->key.data, tdata->key.len, 2138 tdata->aad.len, tdata->digest.len, 2139 RTE_CRYPTO_AUTH_OP_VERIFY, 2140 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2141 if (retval < 0) 2142 return retval; 2143 /* alloc mbuf and set payload */ 2144 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2145 2146 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2147 rte_pktmbuf_tailroom(ut_params->ibuf)); 2148 2149 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2150 /* Append data which is padded to a multiple of */ 2151 /* the algorithms block size */ 2152 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2153 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2154 plaintext_pad_len); 2155 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2156 2157 /* Create SNOW 3G operation */ 2158 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2159 tdata->digest.len, 2160 tdata->aad.data, tdata->aad.len, 2161 plaintext_pad_len, 2162 RTE_CRYPTO_AUTH_OP_VERIFY, 2163 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 2164 tdata->validAuthLenInBits.len, 2165 tdata->validAuthOffsetLenInBits.len); 2166 if (retval < 0) 2167 return retval; 2168 2169 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2170 ut_params->op); 2171 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2172 ut_params->obuf = ut_params->op->sym->m_src; 2173 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2174 + plaintext_pad_len + tdata->aad.len; 2175 2176 /* Validate obuf */ 2177 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2178 return 0; 2179 else 2180 return -1; 2181 2182 return 0; 2183 } 2184 2185 static int 2186 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2187 { 2188 struct crypto_testsuite_params *ts_params = &testsuite_params; 2189 struct crypto_unittest_params *ut_params = &unittest_params; 2190 2191 int retval; 2192 unsigned plaintext_pad_len; 2193 unsigned plaintext_len; 2194 uint8_t *plaintext; 2195 2196 /* Create KASUMI session */ 2197 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2198 tdata->key.data, tdata->key.len, 2199 tdata->aad.len, tdata->digest.len, 2200 RTE_CRYPTO_AUTH_OP_GENERATE, 2201 RTE_CRYPTO_AUTH_KASUMI_F9); 2202 if (retval < 0) 2203 return retval; 2204 2205 /* alloc mbuf and set payload */ 2206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2207 2208 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2209 rte_pktmbuf_tailroom(ut_params->ibuf)); 2210 2211 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2212 /* Append data which is padded to a multiple of */ 2213 /* the algorithms block size */ 2214 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2215 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2216 plaintext_pad_len); 2217 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2218 2219 /* Create KASUMI operation */ 2220 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2221 tdata->aad.data, tdata->aad.len, 2222 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2223 RTE_CRYPTO_AUTH_KASUMI_F9, 2224 tdata->validAuthLenInBits.len, 2225 tdata->validAuthOffsetLenInBits.len); 2226 if (retval < 0) 2227 return retval; 2228 2229 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2230 ut_params->op); 2231 ut_params->obuf = ut_params->op->sym->m_src; 2232 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2233 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2234 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8); 2235 2236 /* Validate obuf */ 2237 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2238 ut_params->digest, 2239 tdata->digest.data, 2240 DIGEST_BYTE_LENGTH_KASUMI_F9, 2241 "KASUMI Generated auth tag not as expected"); 2242 2243 return 0; 2244 } 2245 2246 static int 2247 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2248 { 2249 struct crypto_testsuite_params *ts_params = &testsuite_params; 2250 struct crypto_unittest_params *ut_params = &unittest_params; 2251 2252 int retval; 2253 unsigned plaintext_pad_len; 2254 unsigned plaintext_len; 2255 uint8_t *plaintext; 2256 2257 /* Create KASUMI session */ 2258 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2259 tdata->key.data, tdata->key.len, 2260 tdata->aad.len, tdata->digest.len, 2261 RTE_CRYPTO_AUTH_OP_VERIFY, 2262 RTE_CRYPTO_AUTH_KASUMI_F9); 2263 if (retval < 0) 2264 return retval; 2265 /* alloc mbuf and set payload */ 2266 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2267 2268 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2269 rte_pktmbuf_tailroom(ut_params->ibuf)); 2270 2271 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2272 /* Append data which is padded to a multiple */ 2273 /* of the algorithms block size */ 2274 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2275 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2276 plaintext_pad_len); 2277 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2278 2279 /* Create KASUMI operation */ 2280 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2281 tdata->digest.len, 2282 tdata->aad.data, tdata->aad.len, 2283 plaintext_pad_len, 2284 RTE_CRYPTO_AUTH_OP_VERIFY, 2285 RTE_CRYPTO_AUTH_KASUMI_F9, 2286 tdata->validAuthLenInBits.len, 2287 tdata->validAuthOffsetLenInBits.len); 2288 if (retval < 0) 2289 return retval; 2290 2291 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2292 ut_params->op); 2293 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2294 ut_params->obuf = ut_params->op->sym->m_src; 2295 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2296 + plaintext_pad_len + tdata->aad.len; 2297 2298 /* Validate obuf */ 2299 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2300 return 0; 2301 else 2302 return -1; 2303 2304 return 0; 2305 } 2306 2307 static int 2308 test_snow3g_hash_generate_test_case_1(void) 2309 { 2310 return test_snow3g_authentication(&snow3g_hash_test_case_1); 2311 } 2312 2313 static int 2314 test_snow3g_hash_generate_test_case_2(void) 2315 { 2316 return test_snow3g_authentication(&snow3g_hash_test_case_2); 2317 } 2318 2319 static int 2320 test_snow3g_hash_generate_test_case_3(void) 2321 { 2322 return test_snow3g_authentication(&snow3g_hash_test_case_3); 2323 } 2324 2325 static int 2326 test_snow3g_hash_generate_test_case_4(void) 2327 { 2328 return test_snow3g_authentication(&snow3g_hash_test_case_4); 2329 } 2330 2331 static int 2332 test_snow3g_hash_generate_test_case_5(void) 2333 { 2334 return test_snow3g_authentication(&snow3g_hash_test_case_5); 2335 } 2336 2337 static int 2338 test_snow3g_hash_generate_test_case_6(void) 2339 { 2340 return test_snow3g_authentication(&snow3g_hash_test_case_6); 2341 } 2342 2343 static int 2344 test_snow3g_hash_verify_test_case_1(void) 2345 { 2346 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 2347 2348 } 2349 2350 static int 2351 test_snow3g_hash_verify_test_case_2(void) 2352 { 2353 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 2354 } 2355 2356 static int 2357 test_snow3g_hash_verify_test_case_3(void) 2358 { 2359 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 2360 } 2361 2362 static int 2363 test_snow3g_hash_verify_test_case_4(void) 2364 { 2365 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 2366 } 2367 2368 static int 2369 test_snow3g_hash_verify_test_case_5(void) 2370 { 2371 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 2372 } 2373 2374 static int 2375 test_snow3g_hash_verify_test_case_6(void) 2376 { 2377 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 2378 } 2379 2380 static int 2381 test_kasumi_hash_generate_test_case_1(void) 2382 { 2383 return test_kasumi_authentication(&kasumi_hash_test_case_1); 2384 } 2385 2386 static int 2387 test_kasumi_hash_generate_test_case_2(void) 2388 { 2389 return test_kasumi_authentication(&kasumi_hash_test_case_2); 2390 } 2391 2392 static int 2393 test_kasumi_hash_generate_test_case_3(void) 2394 { 2395 return test_kasumi_authentication(&kasumi_hash_test_case_3); 2396 } 2397 2398 static int 2399 test_kasumi_hash_generate_test_case_4(void) 2400 { 2401 return test_kasumi_authentication(&kasumi_hash_test_case_4); 2402 } 2403 2404 static int 2405 test_kasumi_hash_generate_test_case_5(void) 2406 { 2407 return test_kasumi_authentication(&kasumi_hash_test_case_5); 2408 } 2409 2410 static int 2411 test_kasumi_hash_generate_test_case_6(void) 2412 { 2413 return test_kasumi_authentication(&kasumi_hash_test_case_6); 2414 } 2415 2416 static int 2417 test_kasumi_hash_verify_test_case_1(void) 2418 { 2419 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 2420 } 2421 2422 static int 2423 test_kasumi_hash_verify_test_case_2(void) 2424 { 2425 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 2426 } 2427 2428 static int 2429 test_kasumi_hash_verify_test_case_3(void) 2430 { 2431 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 2432 } 2433 2434 static int 2435 test_kasumi_hash_verify_test_case_4(void) 2436 { 2437 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 2438 } 2439 2440 static int 2441 test_kasumi_hash_verify_test_case_5(void) 2442 { 2443 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 2444 } 2445 2446 static int 2447 test_kasumi_encryption(const struct kasumi_test_data *tdata) 2448 { 2449 struct crypto_testsuite_params *ts_params = &testsuite_params; 2450 struct crypto_unittest_params *ut_params = &unittest_params; 2451 2452 int retval; 2453 uint8_t *plaintext, *ciphertext; 2454 unsigned plaintext_pad_len; 2455 unsigned plaintext_len; 2456 2457 /* Create KASUMI session */ 2458 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2459 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2460 RTE_CRYPTO_CIPHER_KASUMI_F8, 2461 tdata->key.data, tdata->key.len); 2462 if (retval < 0) 2463 return retval; 2464 2465 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2466 2467 /* Clear mbuf payload */ 2468 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2469 rte_pktmbuf_tailroom(ut_params->ibuf)); 2470 2471 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2472 /* Append data which is padded to a multiple */ 2473 /* of the algorithms block size */ 2474 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2475 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2476 plaintext_pad_len); 2477 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2478 2479 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2480 2481 /* Create KASUMI operation */ 2482 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 2483 tdata->plaintext.len, 2484 tdata->validCipherOffsetLenInBits.len, 2485 RTE_CRYPTO_CIPHER_KASUMI_F8); 2486 if (retval < 0) 2487 return retval; 2488 2489 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2490 ut_params->op); 2491 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2492 2493 ut_params->obuf = ut_params->op->sym->m_dst; 2494 if (ut_params->obuf) 2495 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2496 + tdata->iv.len; 2497 else 2498 ciphertext = plaintext; 2499 2500 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2501 2502 /* Validate obuf */ 2503 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2504 ciphertext, 2505 tdata->ciphertext.data, 2506 tdata->validCipherLenInBits.len, 2507 "KASUMI Ciphertext data not as expected"); 2508 return 0; 2509 } 2510 2511 static int 2512 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 2513 { 2514 struct crypto_testsuite_params *ts_params = &testsuite_params; 2515 struct crypto_unittest_params *ut_params = &unittest_params; 2516 2517 int retval; 2518 uint8_t *plaintext, *ciphertext; 2519 unsigned plaintext_pad_len; 2520 unsigned plaintext_len; 2521 2522 /* Create KASUMI session */ 2523 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2524 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2525 RTE_CRYPTO_CIPHER_KASUMI_F8, 2526 tdata->key.data, tdata->key.len); 2527 if (retval < 0) 2528 return retval; 2529 2530 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2531 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2532 2533 /* Clear mbuf payload */ 2534 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2535 rte_pktmbuf_tailroom(ut_params->ibuf)); 2536 2537 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2538 /* Append data which is padded to a multiple */ 2539 /* of the algorithms block size */ 2540 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2541 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2542 plaintext_pad_len); 2543 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 2544 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2545 2546 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2547 2548 /* Create KASUMI operation */ 2549 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2550 tdata->iv.len, 2551 tdata->plaintext.len, 2552 tdata->validCipherOffsetLenInBits.len, 2553 RTE_CRYPTO_CIPHER_KASUMI_F8); 2554 if (retval < 0) 2555 return retval; 2556 2557 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2558 ut_params->op); 2559 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2560 2561 ut_params->obuf = ut_params->op->sym->m_dst; 2562 if (ut_params->obuf) 2563 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2564 + tdata->iv.len; 2565 else 2566 ciphertext = plaintext; 2567 2568 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2569 2570 /* Validate obuf */ 2571 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2572 ciphertext, 2573 tdata->ciphertext.data, 2574 tdata->validCipherLenInBits.len, 2575 "KASUMI Ciphertext data not as expected"); 2576 return 0; 2577 } 2578 2579 static int 2580 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 2581 { 2582 struct crypto_testsuite_params *ts_params = &testsuite_params; 2583 struct crypto_unittest_params *ut_params = &unittest_params; 2584 2585 int retval; 2586 uint8_t *ciphertext, *plaintext; 2587 unsigned ciphertext_pad_len; 2588 unsigned ciphertext_len; 2589 2590 /* Create KASUMI session */ 2591 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2592 RTE_CRYPTO_CIPHER_OP_DECRYPT, 2593 RTE_CRYPTO_CIPHER_KASUMI_F8, 2594 tdata->key.data, tdata->key.len); 2595 if (retval < 0) 2596 return retval; 2597 2598 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2599 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2600 2601 /* Clear mbuf payload */ 2602 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2603 rte_pktmbuf_tailroom(ut_params->ibuf)); 2604 2605 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 2606 /* Append data which is padded to a multiple */ 2607 /* of the algorithms block size */ 2608 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 2609 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2610 ciphertext_pad_len); 2611 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 2612 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 2613 2614 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 2615 2616 /* Create KASUMI operation */ 2617 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2618 tdata->iv.len, 2619 tdata->ciphertext.len, 2620 tdata->validCipherOffsetLenInBits.len, 2621 RTE_CRYPTO_CIPHER_KASUMI_F8); 2622 if (retval < 0) 2623 return retval; 2624 2625 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2626 ut_params->op); 2627 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2628 2629 ut_params->obuf = ut_params->op->sym->m_dst; 2630 if (ut_params->obuf) 2631 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2632 + tdata->iv.len; 2633 else 2634 plaintext = ciphertext; 2635 2636 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 2637 2638 /* Validate obuf */ 2639 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2640 plaintext, 2641 tdata->plaintext.data, 2642 tdata->validCipherLenInBits.len, 2643 "KASUMI Plaintext data not as expected"); 2644 return 0; 2645 } 2646 2647 static int 2648 test_kasumi_decryption(const struct kasumi_test_data *tdata) 2649 { 2650 struct crypto_testsuite_params *ts_params = &testsuite_params; 2651 struct crypto_unittest_params *ut_params = &unittest_params; 2652 2653 int retval; 2654 uint8_t *ciphertext, *plaintext; 2655 unsigned ciphertext_pad_len; 2656 unsigned ciphertext_len; 2657 2658 /* Create KASUMI session */ 2659 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2660 RTE_CRYPTO_CIPHER_OP_DECRYPT, 2661 RTE_CRYPTO_CIPHER_KASUMI_F8, 2662 tdata->key.data, tdata->key.len); 2663 if (retval < 0) 2664 return retval; 2665 2666 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2667 2668 /* Clear mbuf payload */ 2669 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2670 rte_pktmbuf_tailroom(ut_params->ibuf)); 2671 2672 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 2673 /* Append data which is padded to a multiple */ 2674 /* of the algorithms block size */ 2675 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 2676 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2677 ciphertext_pad_len); 2678 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 2679 2680 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 2681 2682 /* Create KASUMI operation */ 2683 retval = create_wireless_algo_cipher_operation(tdata->iv.data, 2684 tdata->iv.len, 2685 tdata->ciphertext.len, 2686 tdata->validCipherOffsetLenInBits.len, 2687 RTE_CRYPTO_CIPHER_KASUMI_F8); 2688 if (retval < 0) 2689 return retval; 2690 2691 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2692 ut_params->op); 2693 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2694 2695 ut_params->obuf = ut_params->op->sym->m_dst; 2696 if (ut_params->obuf) 2697 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2698 + tdata->iv.len; 2699 else 2700 plaintext = ciphertext; 2701 2702 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 2703 2704 /* Validate obuf */ 2705 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2706 plaintext, 2707 tdata->plaintext.data, 2708 tdata->validCipherLenInBits.len, 2709 "KASUMI Plaintext data not as expected"); 2710 return 0; 2711 } 2712 2713 static int 2714 test_snow3g_encryption(const struct snow3g_test_data *tdata) 2715 { 2716 struct crypto_testsuite_params *ts_params = &testsuite_params; 2717 struct crypto_unittest_params *ut_params = &unittest_params; 2718 2719 int retval; 2720 uint8_t *plaintext, *ciphertext; 2721 unsigned plaintext_pad_len; 2722 unsigned plaintext_len; 2723 2724 /* Create SNOW 3G session */ 2725 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2726 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2727 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 2728 tdata->key.data, tdata->key.len); 2729 if (retval < 0) 2730 return retval; 2731 2732 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2733 2734 /* Clear mbuf payload */ 2735 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2736 rte_pktmbuf_tailroom(ut_params->ibuf)); 2737 2738 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2739 /* Append data which is padded to a multiple of */ 2740 /* the algorithms block size */ 2741 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2742 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2743 plaintext_pad_len); 2744 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2745 2746 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2747 2748 /* Create SNOW 3G operation */ 2749 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 2750 tdata->validCipherLenInBits.len, 2751 tdata->validCipherOffsetLenInBits.len, 2752 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 2753 if (retval < 0) 2754 return retval; 2755 2756 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2757 ut_params->op); 2758 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2759 2760 ut_params->obuf = ut_params->op->sym->m_dst; 2761 if (ut_params->obuf) 2762 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2763 + tdata->iv.len; 2764 else 2765 ciphertext = plaintext; 2766 2767 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2768 2769 /* Validate obuf */ 2770 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2771 ciphertext, 2772 tdata->ciphertext.data, 2773 tdata->validDataLenInBits.len, 2774 "SNOW 3G Ciphertext data not as expected"); 2775 return 0; 2776 } 2777 2778 2779 static int 2780 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 2781 { 2782 struct crypto_testsuite_params *ts_params = &testsuite_params; 2783 struct crypto_unittest_params *ut_params = &unittest_params; 2784 uint8_t *plaintext, *ciphertext; 2785 2786 int retval; 2787 unsigned plaintext_pad_len; 2788 unsigned plaintext_len; 2789 2790 /* Create SNOW 3G session */ 2791 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2792 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2793 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 2794 tdata->key.data, tdata->key.len); 2795 if (retval < 0) 2796 return retval; 2797 2798 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2799 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2800 2801 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 2802 "Failed to allocate input buffer in mempool"); 2803 TEST_ASSERT_NOT_NULL(ut_params->obuf, 2804 "Failed to allocate output buffer in mempool"); 2805 2806 /* Clear mbuf payload */ 2807 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2808 rte_pktmbuf_tailroom(ut_params->ibuf)); 2809 2810 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2811 /* Append data which is padded to a multiple of */ 2812 /* the algorithms block size */ 2813 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2814 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2815 plaintext_pad_len); 2816 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 2817 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2818 2819 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 2820 2821 /* Create SNOW 3G operation */ 2822 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2823 tdata->iv.len, 2824 tdata->validCipherLenInBits.len, 2825 tdata->validCipherOffsetLenInBits.len, 2826 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 2827 if (retval < 0) 2828 return retval; 2829 2830 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2831 ut_params->op); 2832 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2833 2834 ut_params->obuf = ut_params->op->sym->m_dst; 2835 if (ut_params->obuf) 2836 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2837 + tdata->iv.len; 2838 else 2839 ciphertext = plaintext; 2840 2841 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 2842 2843 /* Validate obuf */ 2844 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2845 ciphertext, 2846 tdata->ciphertext.data, 2847 tdata->validDataLenInBits.len, 2848 "SNOW 3G Ciphertext data not as expected"); 2849 return 0; 2850 } 2851 2852 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 2853 static void 2854 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 2855 { 2856 uint8_t curr_byte, prev_byte; 2857 uint32_t length_in_bytes = ceil_byte_length(length + offset); 2858 uint8_t lower_byte_mask = (1 << offset) - 1; 2859 unsigned i; 2860 2861 prev_byte = buffer[0]; 2862 buffer[0] >>= offset; 2863 2864 for (i = 1; i < length_in_bytes; i++) { 2865 curr_byte = buffer[i]; 2866 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 2867 (curr_byte >> offset); 2868 prev_byte = curr_byte; 2869 } 2870 } 2871 2872 static int 2873 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 2874 { 2875 struct crypto_testsuite_params *ts_params = &testsuite_params; 2876 struct crypto_unittest_params *ut_params = &unittest_params; 2877 uint8_t *plaintext, *ciphertext; 2878 int retval; 2879 uint32_t plaintext_len; 2880 uint32_t plaintext_pad_len; 2881 uint8_t extra_offset = 4; 2882 uint8_t *expected_ciphertext_shifted; 2883 2884 /* Create SNOW 3G session */ 2885 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2886 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2887 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 2888 tdata->key.data, tdata->key.len); 2889 if (retval < 0) 2890 return retval; 2891 2892 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2893 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2894 2895 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 2896 "Failed to allocate input buffer in mempool"); 2897 TEST_ASSERT_NOT_NULL(ut_params->obuf, 2898 "Failed to allocate output buffer in mempool"); 2899 2900 /* Clear mbuf payload */ 2901 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2902 rte_pktmbuf_tailroom(ut_params->ibuf)); 2903 2904 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 2905 /* 2906 * Append data which is padded to a 2907 * multiple of the algorithms block size 2908 */ 2909 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2910 2911 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 2912 plaintext_pad_len); 2913 2914 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 2915 2916 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 2917 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 2918 2919 #ifdef RTE_APP_TEST_DEBUG 2920 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 2921 #endif 2922 /* Create SNOW 3G operation */ 2923 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 2924 tdata->iv.len, 2925 tdata->validCipherLenInBits.len, 2926 tdata->validCipherOffsetLenInBits.len + 2927 extra_offset, 2928 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 2929 if (retval < 0) 2930 return retval; 2931 2932 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2933 ut_params->op); 2934 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2935 2936 ut_params->obuf = ut_params->op->sym->m_dst; 2937 if (ut_params->obuf) 2938 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2939 + tdata->iv.len; 2940 else 2941 ciphertext = plaintext; 2942 2943 #ifdef RTE_APP_TEST_DEBUG 2944 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 2945 #endif 2946 2947 expected_ciphertext_shifted = rte_malloc(NULL, 2948 ceil_byte_length(plaintext_len + extra_offset), 0); 2949 2950 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 2951 "failed to reserve memory for ciphertext shifted\n"); 2952 2953 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 2954 ceil_byte_length(tdata->ciphertext.len)); 2955 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 2956 extra_offset); 2957 /* Validate obuf */ 2958 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 2959 ciphertext, 2960 expected_ciphertext_shifted, 2961 tdata->validDataLenInBits.len, 2962 extra_offset, 2963 "SNOW 3G Ciphertext data not as expected"); 2964 return 0; 2965 } 2966 2967 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 2968 { 2969 struct crypto_testsuite_params *ts_params = &testsuite_params; 2970 struct crypto_unittest_params *ut_params = &unittest_params; 2971 2972 int retval; 2973 2974 uint8_t *plaintext, *ciphertext; 2975 unsigned ciphertext_pad_len; 2976 unsigned ciphertext_len; 2977 2978 /* Create SNOW 3G session */ 2979 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2980 RTE_CRYPTO_CIPHER_OP_DECRYPT, 2981 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 2982 tdata->key.data, tdata->key.len); 2983 if (retval < 0) 2984 return retval; 2985 2986 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2987 2988 /* Clear mbuf payload */ 2989 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2990 rte_pktmbuf_tailroom(ut_params->ibuf)); 2991 2992 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 2993 /* Append data which is padded to a multiple of */ 2994 /* the algorithms block size */ 2995 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 2996 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2997 ciphertext_pad_len); 2998 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 2999 3000 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 3001 3002 /* Create SNOW 3G operation */ 3003 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 3004 tdata->validCipherLenInBits.len, 3005 tdata->validCipherOffsetLenInBits.len, 3006 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3007 if (retval < 0) 3008 return retval; 3009 3010 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3011 ut_params->op); 3012 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3013 ut_params->obuf = ut_params->op->sym->m_dst; 3014 if (ut_params->obuf) 3015 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3016 + tdata->iv.len; 3017 else 3018 plaintext = ciphertext; 3019 3020 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 3021 3022 /* Validate obuf */ 3023 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3024 tdata->plaintext.data, 3025 tdata->validDataLenInBits.len, 3026 "SNOW 3G Plaintext data not as expected"); 3027 return 0; 3028 } 3029 3030 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 3031 { 3032 struct crypto_testsuite_params *ts_params = &testsuite_params; 3033 struct crypto_unittest_params *ut_params = &unittest_params; 3034 3035 int retval; 3036 3037 uint8_t *plaintext, *ciphertext; 3038 unsigned ciphertext_pad_len; 3039 unsigned ciphertext_len; 3040 3041 /* Create SNOW 3G session */ 3042 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3043 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3044 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3045 tdata->key.data, tdata->key.len); 3046 if (retval < 0) 3047 return retval; 3048 3049 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3050 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3051 3052 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3053 "Failed to allocate input buffer"); 3054 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3055 "Failed to allocate output buffer"); 3056 3057 /* Clear mbuf payload */ 3058 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3059 rte_pktmbuf_tailroom(ut_params->ibuf)); 3060 3061 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 3062 rte_pktmbuf_tailroom(ut_params->obuf)); 3063 3064 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3065 /* Append data which is padded to a multiple of */ 3066 /* the algorithms block size */ 3067 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 3068 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3069 ciphertext_pad_len); 3070 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3071 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3072 3073 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len); 3074 3075 /* Create SNOW 3G operation */ 3076 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data, 3077 tdata->iv.len, 3078 tdata->validCipherLenInBits.len, 3079 tdata->validCipherOffsetLenInBits.len, 3080 RTE_CRYPTO_CIPHER_SNOW3G_UEA2); 3081 if (retval < 0) 3082 return retval; 3083 3084 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3085 ut_params->op); 3086 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3087 ut_params->obuf = ut_params->op->sym->m_dst; 3088 if (ut_params->obuf) 3089 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3090 + tdata->iv.len; 3091 else 3092 plaintext = ciphertext; 3093 3094 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len); 3095 3096 /* Validate obuf */ 3097 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3098 tdata->plaintext.data, 3099 tdata->validDataLenInBits.len, 3100 "SNOW 3G Plaintext data not as expected"); 3101 return 0; 3102 } 3103 3104 static int 3105 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 3106 { 3107 struct crypto_testsuite_params *ts_params = &testsuite_params; 3108 struct crypto_unittest_params *ut_params = &unittest_params; 3109 3110 int retval; 3111 3112 uint8_t *plaintext, *ciphertext; 3113 unsigned plaintext_pad_len; 3114 unsigned plaintext_len; 3115 3116 /* Create SNOW 3G session */ 3117 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 3118 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3119 RTE_CRYPTO_AUTH_OP_GENERATE, 3120 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3121 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3122 tdata->key.data, tdata->key.len, 3123 tdata->aad.len, tdata->digest.len); 3124 if (retval < 0) 3125 return retval; 3126 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 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 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3139 3140 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3141 3142 /* Create SNOW 3G operation */ 3143 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 3144 tdata->digest.len, tdata->aad.data, 3145 tdata->aad.len, /*tdata->plaintext.len,*/ 3146 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3147 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3148 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3149 tdata->iv.data, tdata->iv.len, 3150 tdata->validCipherLenInBits.len, 3151 tdata->validCipherOffsetLenInBits.len, 3152 tdata->validAuthLenInBits.len, 3153 tdata->validAuthOffsetLenInBits.len 3154 ); 3155 if (retval < 0) 3156 return retval; 3157 3158 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3159 ut_params->op); 3160 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3161 ut_params->obuf = ut_params->op->sym->m_src; 3162 if (ut_params->obuf) 3163 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3164 + tdata->iv.len + tdata->aad.len; 3165 else 3166 ciphertext = plaintext; 3167 3168 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3169 /* Validate obuf */ 3170 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3171 ciphertext, 3172 tdata->ciphertext.data, 3173 tdata->validDataLenInBits.len, 3174 "SNOW 3G Ciphertext data not as expected"); 3175 3176 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3177 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3178 3179 /* Validate obuf */ 3180 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3181 ut_params->digest, 3182 tdata->digest.data, 3183 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3184 "SNOW 3G Generated auth tag not as expected"); 3185 return 0; 3186 } 3187 static int 3188 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata) 3189 { 3190 struct crypto_testsuite_params *ts_params = &testsuite_params; 3191 struct crypto_unittest_params *ut_params = &unittest_params; 3192 3193 int retval; 3194 3195 uint8_t *plaintext, *ciphertext; 3196 unsigned plaintext_pad_len; 3197 unsigned plaintext_len; 3198 3199 /* Create SNOW 3G session */ 3200 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0], 3201 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3202 RTE_CRYPTO_AUTH_OP_GENERATE, 3203 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3204 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3205 tdata->key.data, tdata->key.len, 3206 tdata->aad.len, tdata->digest.len); 3207 if (retval < 0) 3208 return retval; 3209 3210 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3211 3212 /* clear mbuf payload */ 3213 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3214 rte_pktmbuf_tailroom(ut_params->ibuf)); 3215 3216 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3217 /* Append data which is padded to a multiple of */ 3218 /* the algorithms block size */ 3219 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3220 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3221 plaintext_pad_len); 3222 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3223 3224 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3225 3226 /* Create SNOW 3G operation */ 3227 retval = create_wireless_algo_auth_cipher_operation( 3228 tdata->digest.len, 3229 tdata->iv.data, tdata->iv.len, 3230 tdata->aad.data, tdata->aad.len, 3231 plaintext_pad_len, 3232 tdata->validCipherLenInBits.len, 3233 tdata->validCipherOffsetLenInBits.len, 3234 tdata->validAuthLenInBits.len, 3235 tdata->validAuthOffsetLenInBits.len, 3236 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 3237 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 3238 ); 3239 3240 if (retval < 0) 3241 return retval; 3242 3243 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3244 ut_params->op); 3245 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3246 ut_params->obuf = ut_params->op->sym->m_src; 3247 if (ut_params->obuf) 3248 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3249 + tdata->aad.len + tdata->iv.len; 3250 else 3251 ciphertext = plaintext; 3252 3253 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3254 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3255 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3256 3257 /* Validate obuf */ 3258 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3259 ciphertext, 3260 tdata->ciphertext.data, 3261 tdata->validDataLenInBits.len, 3262 "SNOW 3G Ciphertext data not as expected"); 3263 3264 /* Validate obuf */ 3265 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3266 ut_params->digest, 3267 tdata->digest.data, 3268 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3269 "SNOW 3G Generated auth tag not as expected"); 3270 return 0; 3271 } 3272 3273 static int 3274 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata) 3275 { 3276 struct crypto_testsuite_params *ts_params = &testsuite_params; 3277 struct crypto_unittest_params *ut_params = &unittest_params; 3278 3279 int retval; 3280 3281 uint8_t *plaintext, *ciphertext; 3282 unsigned plaintext_pad_len; 3283 unsigned plaintext_len; 3284 3285 /* Create KASUMI session */ 3286 retval = create_wireless_algo_auth_cipher_session( 3287 ts_params->valid_devs[0], 3288 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3289 RTE_CRYPTO_AUTH_OP_GENERATE, 3290 RTE_CRYPTO_AUTH_KASUMI_F9, 3291 RTE_CRYPTO_CIPHER_KASUMI_F8, 3292 tdata->key.data, tdata->key.len, 3293 tdata->aad.len, tdata->digest.len); 3294 if (retval < 0) 3295 return retval; 3296 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3297 3298 /* clear mbuf payload */ 3299 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3300 rte_pktmbuf_tailroom(ut_params->ibuf)); 3301 3302 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3303 /* Append data which is padded to a multiple of */ 3304 /* the algorithms block size */ 3305 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3306 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3307 plaintext_pad_len); 3308 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3309 3310 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3311 3312 /* Create KASUMI operation */ 3313 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len, 3314 tdata->iv.data, tdata->iv.len, 3315 tdata->aad.data, tdata->aad.len, 3316 plaintext_pad_len, 3317 tdata->validCipherLenInBits.len, 3318 tdata->validCipherOffsetLenInBits.len, 3319 tdata->validAuthLenInBits.len, 3320 tdata->validAuthOffsetLenInBits.len, 3321 RTE_CRYPTO_AUTH_KASUMI_F9, 3322 RTE_CRYPTO_CIPHER_KASUMI_F8 3323 ); 3324 3325 if (retval < 0) 3326 return retval; 3327 3328 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3329 ut_params->op); 3330 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3331 ut_params->obuf = ut_params->op->sym->m_src; 3332 if (ut_params->obuf) 3333 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3334 + tdata->iv.len + tdata->aad.len; 3335 else 3336 ciphertext = plaintext; 3337 3338 /* Validate obuf */ 3339 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3340 ciphertext, 3341 tdata->ciphertext.data, 3342 tdata->validCipherLenInBits.len, 3343 "KASUMI Ciphertext data not as expected"); 3344 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3345 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3346 3347 /* Validate obuf */ 3348 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3349 ut_params->digest, 3350 tdata->digest.data, 3351 DIGEST_BYTE_LENGTH_KASUMI_F9, 3352 "KASUMI Generated auth tag not as expected"); 3353 return 0; 3354 } 3355 3356 static int 3357 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 3358 { 3359 struct crypto_testsuite_params *ts_params = &testsuite_params; 3360 struct crypto_unittest_params *ut_params = &unittest_params; 3361 3362 int retval; 3363 3364 uint8_t *plaintext, *ciphertext; 3365 unsigned plaintext_pad_len; 3366 unsigned plaintext_len; 3367 3368 /* Create KASUMI session */ 3369 retval = create_wireless_algo_cipher_auth_session( 3370 ts_params->valid_devs[0], 3371 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3372 RTE_CRYPTO_AUTH_OP_GENERATE, 3373 RTE_CRYPTO_AUTH_KASUMI_F9, 3374 RTE_CRYPTO_CIPHER_KASUMI_F8, 3375 tdata->key.data, tdata->key.len, 3376 tdata->aad.len, tdata->digest.len); 3377 if (retval < 0) 3378 return retval; 3379 3380 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3381 3382 /* clear mbuf payload */ 3383 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3384 rte_pktmbuf_tailroom(ut_params->ibuf)); 3385 3386 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3387 /* Append data which is padded to a multiple of */ 3388 /* the algorithms block size */ 3389 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3390 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3391 plaintext_pad_len); 3392 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3393 3394 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3395 3396 /* Create KASUMI operation */ 3397 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 3398 tdata->digest.len, tdata->aad.data, 3399 tdata->aad.len, 3400 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3401 RTE_CRYPTO_AUTH_KASUMI_F9, 3402 RTE_CRYPTO_CIPHER_KASUMI_F8, 3403 tdata->iv.data, tdata->iv.len, 3404 tdata->validCipherLenInBits.len, 3405 tdata->validCipherOffsetLenInBits.len, 3406 tdata->validAuthLenInBits.len, 3407 tdata->validAuthOffsetLenInBits.len 3408 ); 3409 if (retval < 0) 3410 return retval; 3411 3412 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3413 ut_params->op); 3414 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3415 ut_params->obuf = ut_params->op->sym->m_src; 3416 if (ut_params->obuf) 3417 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3418 + tdata->aad.len + tdata->iv.len; 3419 else 3420 ciphertext = plaintext; 3421 3422 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3423 + plaintext_pad_len + tdata->aad.len + tdata->iv.len; 3424 3425 /* Validate obuf */ 3426 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3427 ciphertext, 3428 tdata->ciphertext.data, 3429 tdata->validCipherLenInBits.len, 3430 "KASUMI Ciphertext data not as expected"); 3431 3432 /* Validate obuf */ 3433 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3434 ut_params->digest, 3435 tdata->digest.data, 3436 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3437 "KASUMI Generated auth tag not as expected"); 3438 return 0; 3439 } 3440 3441 static int 3442 test_zuc_encryption(const struct zuc_test_data *tdata) 3443 { 3444 struct crypto_testsuite_params *ts_params = &testsuite_params; 3445 struct crypto_unittest_params *ut_params = &unittest_params; 3446 3447 int retval; 3448 uint8_t *plaintext, *ciphertext; 3449 unsigned plaintext_pad_len; 3450 unsigned plaintext_len; 3451 3452 /* Create ZUC session */ 3453 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3454 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3455 RTE_CRYPTO_CIPHER_ZUC_EEA3, 3456 tdata->key.data, tdata->key.len); 3457 if (retval < 0) 3458 return retval; 3459 3460 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3461 3462 /* Clear mbuf payload */ 3463 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3464 rte_pktmbuf_tailroom(ut_params->ibuf)); 3465 3466 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3467 /* Append data which is padded to a multiple */ 3468 /* of the algorithms block size */ 3469 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3470 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3471 plaintext_pad_len); 3472 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3473 3474 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len); 3475 3476 /* Create ZUC operation */ 3477 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len, 3478 tdata->plaintext.len, 3479 tdata->validCipherOffsetLenInBits.len, 3480 RTE_CRYPTO_CIPHER_ZUC_EEA3); 3481 if (retval < 0) 3482 return retval; 3483 3484 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3485 ut_params->op); 3486 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3487 3488 ut_params->obuf = ut_params->op->sym->m_dst; 3489 if (ut_params->obuf) 3490 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3491 + tdata->iv.len; 3492 else 3493 ciphertext = plaintext; 3494 3495 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len); 3496 3497 /* Validate obuf */ 3498 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3499 ciphertext, 3500 tdata->ciphertext.data, 3501 tdata->validCipherLenInBits.len, 3502 "ZUC Ciphertext data not as expected"); 3503 return 0; 3504 } 3505 3506 static int 3507 test_zuc_authentication(const struct zuc_hash_test_data *tdata) 3508 { 3509 struct crypto_testsuite_params *ts_params = &testsuite_params; 3510 struct crypto_unittest_params *ut_params = &unittest_params; 3511 3512 int retval; 3513 unsigned plaintext_pad_len; 3514 unsigned plaintext_len; 3515 uint8_t *plaintext; 3516 3517 /* Create ZUC session */ 3518 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3519 tdata->key.data, tdata->key.len, 3520 tdata->aad.len, tdata->digest.len, 3521 RTE_CRYPTO_AUTH_OP_GENERATE, 3522 RTE_CRYPTO_AUTH_ZUC_EIA3); 3523 if (retval < 0) 3524 return retval; 3525 3526 /* alloc mbuf and set payload */ 3527 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3528 3529 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3530 rte_pktmbuf_tailroom(ut_params->ibuf)); 3531 3532 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3533 /* Append data which is padded to a multiple of */ 3534 /* the algorithms block size */ 3535 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3536 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3537 plaintext_pad_len); 3538 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3539 3540 /* Create ZUC operation */ 3541 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3542 tdata->aad.data, tdata->aad.len, 3543 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3544 RTE_CRYPTO_AUTH_ZUC_EIA3, 3545 tdata->validAuthLenInBits.len, 3546 tdata->validAuthOffsetLenInBits.len); 3547 if (retval < 0) 3548 return retval; 3549 3550 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3551 ut_params->op); 3552 ut_params->obuf = ut_params->op->sym->m_src; 3553 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3554 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3555 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8); 3556 3557 /* Validate obuf */ 3558 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3559 ut_params->digest, 3560 tdata->digest.data, 3561 DIGEST_BYTE_LENGTH_KASUMI_F9, 3562 "ZUC Generated auth tag not as expected"); 3563 3564 return 0; 3565 } 3566 3567 static int 3568 test_kasumi_encryption_test_case_1(void) 3569 { 3570 return test_kasumi_encryption(&kasumi_test_case_1); 3571 } 3572 3573 static int 3574 test_kasumi_encryption_test_case_1_oop(void) 3575 { 3576 return test_kasumi_encryption_oop(&kasumi_test_case_1); 3577 } 3578 3579 static int 3580 test_kasumi_encryption_test_case_2(void) 3581 { 3582 return test_kasumi_encryption(&kasumi_test_case_2); 3583 } 3584 3585 static int 3586 test_kasumi_encryption_test_case_3(void) 3587 { 3588 return test_kasumi_encryption(&kasumi_test_case_3); 3589 } 3590 3591 static int 3592 test_kasumi_encryption_test_case_4(void) 3593 { 3594 return test_kasumi_encryption(&kasumi_test_case_4); 3595 } 3596 3597 static int 3598 test_kasumi_encryption_test_case_5(void) 3599 { 3600 return test_kasumi_encryption(&kasumi_test_case_5); 3601 } 3602 3603 static int 3604 test_kasumi_decryption_test_case_1(void) 3605 { 3606 return test_kasumi_decryption(&kasumi_test_case_1); 3607 } 3608 3609 static int 3610 test_kasumi_decryption_test_case_1_oop(void) 3611 { 3612 return test_kasumi_decryption_oop(&kasumi_test_case_1); 3613 } 3614 3615 static int 3616 test_kasumi_decryption_test_case_2(void) 3617 { 3618 return test_kasumi_decryption(&kasumi_test_case_2); 3619 } 3620 3621 static int 3622 test_kasumi_decryption_test_case_3(void) 3623 { 3624 return test_kasumi_decryption(&kasumi_test_case_3); 3625 } 3626 3627 static int 3628 test_kasumi_decryption_test_case_4(void) 3629 { 3630 return test_kasumi_decryption(&kasumi_test_case_4); 3631 } 3632 3633 static int 3634 test_kasumi_decryption_test_case_5(void) 3635 { 3636 return test_kasumi_decryption(&kasumi_test_case_5); 3637 } 3638 static int 3639 test_snow3g_encryption_test_case_1(void) 3640 { 3641 return test_snow3g_encryption(&snow3g_test_case_1); 3642 } 3643 3644 static int 3645 test_snow3g_encryption_test_case_1_oop(void) 3646 { 3647 return test_snow3g_encryption_oop(&snow3g_test_case_1); 3648 } 3649 3650 static int 3651 test_snow3g_encryption_test_case_1_offset_oop(void) 3652 { 3653 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 3654 } 3655 3656 static int 3657 test_snow3g_encryption_test_case_2(void) 3658 { 3659 return test_snow3g_encryption(&snow3g_test_case_2); 3660 } 3661 3662 static int 3663 test_snow3g_encryption_test_case_3(void) 3664 { 3665 return test_snow3g_encryption(&snow3g_test_case_3); 3666 } 3667 3668 static int 3669 test_snow3g_encryption_test_case_4(void) 3670 { 3671 return test_snow3g_encryption(&snow3g_test_case_4); 3672 } 3673 3674 static int 3675 test_snow3g_encryption_test_case_5(void) 3676 { 3677 return test_snow3g_encryption(&snow3g_test_case_5); 3678 } 3679 3680 static int 3681 test_snow3g_decryption_test_case_1(void) 3682 { 3683 return test_snow3g_decryption(&snow3g_test_case_1); 3684 } 3685 3686 static int 3687 test_snow3g_decryption_test_case_1_oop(void) 3688 { 3689 return test_snow3g_decryption_oop(&snow3g_test_case_1); 3690 } 3691 3692 static int 3693 test_snow3g_decryption_test_case_2(void) 3694 { 3695 return test_snow3g_decryption(&snow3g_test_case_2); 3696 } 3697 3698 static int 3699 test_snow3g_decryption_test_case_3(void) 3700 { 3701 return test_snow3g_decryption(&snow3g_test_case_3); 3702 } 3703 3704 static int 3705 test_snow3g_decryption_test_case_4(void) 3706 { 3707 return test_snow3g_decryption(&snow3g_test_case_4); 3708 } 3709 3710 static int 3711 test_snow3g_decryption_test_case_5(void) 3712 { 3713 return test_snow3g_decryption(&snow3g_test_case_5); 3714 } 3715 static int 3716 test_snow3g_cipher_auth_test_case_1(void) 3717 { 3718 return test_snow3g_cipher_auth(&snow3g_test_case_3); 3719 } 3720 3721 static int 3722 test_snow3g_auth_cipher_test_case_1(void) 3723 { 3724 return test_snow3g_auth_cipher(&snow3g_test_case_6); 3725 } 3726 3727 static int 3728 test_kasumi_auth_cipher_test_case_1(void) 3729 { 3730 return test_kasumi_auth_cipher(&kasumi_test_case_3); 3731 } 3732 3733 static int 3734 test_kasumi_cipher_auth_test_case_1(void) 3735 { 3736 return test_kasumi_cipher_auth(&kasumi_test_case_6); 3737 } 3738 3739 static int 3740 test_zuc_encryption_test_case_1(void) 3741 { 3742 return test_zuc_encryption(&zuc_test_case_1); 3743 } 3744 3745 static int 3746 test_zuc_encryption_test_case_2(void) 3747 { 3748 return test_zuc_encryption(&zuc_test_case_2); 3749 } 3750 3751 static int 3752 test_zuc_encryption_test_case_3(void) 3753 { 3754 return test_zuc_encryption(&zuc_test_case_3); 3755 } 3756 3757 static int 3758 test_zuc_encryption_test_case_4(void) 3759 { 3760 return test_zuc_encryption(&zuc_test_case_4); 3761 } 3762 3763 static int 3764 test_zuc_encryption_test_case_5(void) 3765 { 3766 return test_zuc_encryption(&zuc_test_case_5); 3767 } 3768 3769 static int 3770 test_zuc_hash_generate_test_case_1(void) 3771 { 3772 return test_zuc_authentication(&zuc_hash_test_case_1); 3773 } 3774 3775 static int 3776 test_zuc_hash_generate_test_case_2(void) 3777 { 3778 return test_zuc_authentication(&zuc_hash_test_case_2); 3779 } 3780 3781 static int 3782 test_zuc_hash_generate_test_case_3(void) 3783 { 3784 return test_zuc_authentication(&zuc_hash_test_case_3); 3785 } 3786 3787 static int 3788 test_zuc_hash_generate_test_case_4(void) 3789 { 3790 return test_zuc_authentication(&zuc_hash_test_case_4); 3791 } 3792 3793 static int 3794 test_zuc_hash_generate_test_case_5(void) 3795 { 3796 return test_zuc_authentication(&zuc_hash_test_case_5); 3797 } 3798 3799 static int 3800 test_3DES_chain_qat_all(void) 3801 { 3802 struct crypto_testsuite_params *ts_params = &testsuite_params; 3803 int status; 3804 3805 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 3806 ts_params->op_mpool, ts_params->valid_devs[0], 3807 RTE_CRYPTODEV_QAT_SYM_PMD, 3808 BLKCIPHER_3DES_CHAIN_TYPE); 3809 3810 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 3811 3812 return TEST_SUCCESS; 3813 } 3814 3815 static int 3816 test_3DES_cipheronly_qat_all(void) 3817 { 3818 struct crypto_testsuite_params *ts_params = &testsuite_params; 3819 int status; 3820 3821 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 3822 ts_params->op_mpool, ts_params->valid_devs[0], 3823 RTE_CRYPTODEV_QAT_SYM_PMD, 3824 BLKCIPHER_3DES_CIPHERONLY_TYPE); 3825 3826 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 3827 3828 return TEST_SUCCESS; 3829 } 3830 3831 static int 3832 test_3DES_chain_libcrypto_all(void) 3833 { 3834 struct crypto_testsuite_params *ts_params = &testsuite_params; 3835 int status; 3836 3837 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 3838 ts_params->op_mpool, ts_params->valid_devs[0], 3839 RTE_CRYPTODEV_LIBCRYPTO_PMD, 3840 BLKCIPHER_3DES_CHAIN_TYPE); 3841 3842 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 3843 3844 return TEST_SUCCESS; 3845 } 3846 3847 static int 3848 test_3DES_cipheronly_libcrypto_all(void) 3849 { 3850 struct crypto_testsuite_params *ts_params = &testsuite_params; 3851 int status; 3852 3853 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 3854 ts_params->op_mpool, ts_params->valid_devs[0], 3855 RTE_CRYPTODEV_LIBCRYPTO_PMD, 3856 BLKCIPHER_3DES_CIPHERONLY_TYPE); 3857 3858 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 3859 3860 return TEST_SUCCESS; 3861 } 3862 3863 /* ***** AES-GCM Tests ***** */ 3864 3865 static int 3866 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op, 3867 const uint8_t *key, const uint8_t key_len, 3868 const uint8_t aad_len, const uint8_t auth_len, 3869 enum rte_crypto_auth_operation auth_op) 3870 { 3871 uint8_t cipher_key[key_len]; 3872 3873 struct crypto_unittest_params *ut_params = &unittest_params; 3874 3875 memcpy(cipher_key, key, key_len); 3876 3877 /* Setup Cipher Parameters */ 3878 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3879 ut_params->cipher_xform.next = NULL; 3880 3881 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM; 3882 ut_params->auth_xform.auth.op = auth_op; 3883 ut_params->cipher_xform.cipher.op = op; 3884 ut_params->cipher_xform.cipher.key.data = cipher_key; 3885 ut_params->cipher_xform.cipher.key.length = key_len; 3886 3887 TEST_HEXDUMP(stdout, "key:", key, key_len); 3888 3889 /* Setup Authentication Parameters */ 3890 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3891 ut_params->auth_xform.next = NULL; 3892 3893 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM; 3894 3895 ut_params->auth_xform.auth.digest_length = auth_len; 3896 ut_params->auth_xform.auth.add_auth_data_length = aad_len; 3897 ut_params->auth_xform.auth.key.length = 0; 3898 ut_params->auth_xform.auth.key.data = NULL; 3899 3900 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 3901 ut_params->cipher_xform.next = &ut_params->auth_xform; 3902 3903 /* Create Crypto session*/ 3904 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 3905 &ut_params->cipher_xform); 3906 } else {/* Create Crypto session*/ 3907 ut_params->auth_xform.next = &ut_params->cipher_xform; 3908 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 3909 &ut_params->auth_xform); 3910 } 3911 3912 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 3913 3914 return 0; 3915 } 3916 3917 static int 3918 create_gcm_operation(enum rte_crypto_cipher_operation op, 3919 const uint8_t *auth_tag, const unsigned auth_tag_len, 3920 const uint8_t *iv, const unsigned iv_len, 3921 const uint8_t *aad, const unsigned aad_len, 3922 const unsigned data_len, unsigned data_pad_len) 3923 { 3924 struct crypto_testsuite_params *ts_params = &testsuite_params; 3925 struct crypto_unittest_params *ut_params = &unittest_params; 3926 3927 unsigned iv_pad_len = 0, aad_buffer_len; 3928 3929 /* Generate Crypto op data structure */ 3930 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3931 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3932 TEST_ASSERT_NOT_NULL(ut_params->op, 3933 "Failed to allocate symmetric crypto operation struct"); 3934 3935 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3936 3937 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3938 ut_params->ibuf, auth_tag_len); 3939 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3940 "no room to append digest"); 3941 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 3942 ut_params->ibuf, data_pad_len); 3943 sym_op->auth.digest.length = auth_tag_len; 3944 3945 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 3946 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3947 TEST_HEXDUMP(stdout, "digest:", 3948 sym_op->auth.digest.data, 3949 sym_op->auth.digest.length); 3950 } 3951 3952 /* iv */ 3953 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16); 3954 3955 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 3956 ut_params->ibuf, iv_pad_len); 3957 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 3958 3959 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 3960 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 3961 sym_op->cipher.iv.length = iv_len; 3962 3963 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len); 3964 3965 /* 3966 * Always allocate the aad up to the block size. 3967 * The cryptodev API calls out - 3968 * - the array must be big enough to hold the AAD, plus any 3969 * space to round this up to the nearest multiple of the 3970 * block size (16 bytes). 3971 */ 3972 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16); 3973 3974 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend( 3975 ut_params->ibuf, aad_buffer_len); 3976 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 3977 "no room to prepend aad"); 3978 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys( 3979 ut_params->ibuf); 3980 sym_op->auth.aad.length = aad_len; 3981 3982 memset(sym_op->auth.aad.data, 0, aad_buffer_len); 3983 rte_memcpy(sym_op->auth.aad.data, aad, aad_len); 3984 3985 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len); 3986 TEST_HEXDUMP(stdout, "aad:", 3987 sym_op->auth.aad.data, aad_len); 3988 3989 sym_op->cipher.data.length = data_len; 3990 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len; 3991 3992 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len; 3993 sym_op->auth.data.length = data_len; 3994 3995 return 0; 3996 } 3997 3998 static int 3999 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata) 4000 { 4001 struct crypto_testsuite_params *ts_params = &testsuite_params; 4002 struct crypto_unittest_params *ut_params = &unittest_params; 4003 4004 int retval; 4005 4006 uint8_t *plaintext, *ciphertext, *auth_tag; 4007 uint16_t plaintext_pad_len; 4008 4009 /* Create GCM session */ 4010 retval = create_gcm_session(ts_params->valid_devs[0], 4011 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4012 tdata->key.data, tdata->key.len, 4013 tdata->aad.len, tdata->auth_tag.len, 4014 RTE_CRYPTO_AUTH_OP_GENERATE); 4015 if (retval < 0) 4016 return retval; 4017 4018 4019 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4020 4021 /* clear mbuf payload */ 4022 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4023 rte_pktmbuf_tailroom(ut_params->ibuf)); 4024 4025 /* 4026 * Append data which is padded to a multiple 4027 * of the algorithms block size 4028 */ 4029 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 4030 4031 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4032 plaintext_pad_len); 4033 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 4034 4035 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4036 4037 /* Create GCM opertaion */ 4038 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4039 tdata->auth_tag.data, tdata->auth_tag.len, 4040 tdata->iv.data, tdata->iv.len, 4041 tdata->aad.data, tdata->aad.len, 4042 tdata->plaintext.len, plaintext_pad_len); 4043 if (retval < 0) 4044 return retval; 4045 4046 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4047 4048 ut_params->op->sym->m_src = ut_params->ibuf; 4049 4050 /* Process crypto operation */ 4051 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4052 ut_params->op), "failed to process sym crypto op"); 4053 4054 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4055 "crypto op processing failed"); 4056 4057 if (ut_params->op->sym->m_dst) { 4058 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 4059 uint8_t *); 4060 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 4061 uint8_t *, plaintext_pad_len); 4062 } else { 4063 ciphertext = plaintext; 4064 auth_tag = plaintext + plaintext_pad_len; 4065 } 4066 4067 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 4068 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 4069 4070 /* Validate obuf */ 4071 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4072 ciphertext, 4073 tdata->ciphertext.data, 4074 tdata->ciphertext.len, 4075 "GCM Ciphertext data not as expected"); 4076 4077 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4078 auth_tag, 4079 tdata->auth_tag.data, 4080 tdata->auth_tag.len, 4081 "GCM Generated auth tag not as expected"); 4082 4083 return 0; 4084 4085 } 4086 4087 static int 4088 test_mb_AES_GCM_authenticated_encryption_test_case_1(void) 4089 { 4090 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1); 4091 } 4092 4093 static int 4094 test_mb_AES_GCM_authenticated_encryption_test_case_2(void) 4095 { 4096 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2); 4097 } 4098 4099 static int 4100 test_mb_AES_GCM_authenticated_encryption_test_case_3(void) 4101 { 4102 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3); 4103 } 4104 4105 static int 4106 test_mb_AES_GCM_authenticated_encryption_test_case_4(void) 4107 { 4108 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4); 4109 } 4110 4111 static int 4112 test_mb_AES_GCM_authenticated_encryption_test_case_5(void) 4113 { 4114 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5); 4115 } 4116 4117 static int 4118 test_mb_AES_GCM_authenticated_encryption_test_case_6(void) 4119 { 4120 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6); 4121 } 4122 4123 static int 4124 test_mb_AES_GCM_authenticated_encryption_test_case_7(void) 4125 { 4126 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7); 4127 } 4128 4129 static int 4130 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata) 4131 { 4132 struct crypto_testsuite_params *ts_params = &testsuite_params; 4133 struct crypto_unittest_params *ut_params = &unittest_params; 4134 4135 int retval; 4136 4137 uint8_t *plaintext, *ciphertext; 4138 uint16_t ciphertext_pad_len; 4139 4140 /* Create GCM session */ 4141 retval = create_gcm_session(ts_params->valid_devs[0], 4142 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4143 tdata->key.data, tdata->key.len, 4144 tdata->aad.len, tdata->auth_tag.len, 4145 RTE_CRYPTO_AUTH_OP_VERIFY); 4146 if (retval < 0) 4147 return retval; 4148 4149 4150 /* alloc mbuf and set payload */ 4151 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4152 4153 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4154 rte_pktmbuf_tailroom(ut_params->ibuf)); 4155 4156 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 4157 4158 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4159 ciphertext_pad_len); 4160 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len); 4161 4162 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 4163 4164 /* Create GCM opertaion */ 4165 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, 4166 tdata->auth_tag.data, tdata->auth_tag.len, 4167 tdata->iv.data, tdata->iv.len, 4168 tdata->aad.data, tdata->aad.len, 4169 tdata->ciphertext.len, ciphertext_pad_len); 4170 if (retval < 0) 4171 return retval; 4172 4173 4174 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4175 4176 ut_params->op->sym->m_src = ut_params->ibuf; 4177 4178 /* Process crypto operation */ 4179 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4180 ut_params->op), "failed to process sym crypto op"); 4181 4182 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4183 "crypto op processing failed"); 4184 4185 if (ut_params->op->sym->m_dst) 4186 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 4187 uint8_t *); 4188 else 4189 plaintext = ciphertext; 4190 4191 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 4192 4193 /* Validate obuf */ 4194 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4195 plaintext, 4196 tdata->plaintext.data, 4197 tdata->plaintext.len, 4198 "GCM plaintext data not as expected"); 4199 4200 TEST_ASSERT_EQUAL(ut_params->op->status, 4201 RTE_CRYPTO_OP_STATUS_SUCCESS, 4202 "GCM authentication failed"); 4203 return 0; 4204 } 4205 4206 static int 4207 test_mb_AES_GCM_authenticated_decryption_test_case_1(void) 4208 { 4209 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1); 4210 } 4211 4212 static int 4213 test_mb_AES_GCM_authenticated_decryption_test_case_2(void) 4214 { 4215 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2); 4216 } 4217 4218 static int 4219 test_mb_AES_GCM_authenticated_decryption_test_case_3(void) 4220 { 4221 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3); 4222 } 4223 4224 static int 4225 test_mb_AES_GCM_authenticated_decryption_test_case_4(void) 4226 { 4227 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4); 4228 } 4229 4230 static int 4231 test_mb_AES_GCM_authenticated_decryption_test_case_5(void) 4232 { 4233 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5); 4234 } 4235 4236 static int 4237 test_mb_AES_GCM_authenticated_decryption_test_case_6(void) 4238 { 4239 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6); 4240 } 4241 4242 static int 4243 test_mb_AES_GCM_authenticated_decryption_test_case_7(void) 4244 { 4245 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7); 4246 } 4247 4248 static int 4249 test_stats(void) 4250 { 4251 struct crypto_testsuite_params *ts_params = &testsuite_params; 4252 struct rte_cryptodev_stats stats; 4253 struct rte_cryptodev *dev; 4254 cryptodev_stats_get_t temp_pfn; 4255 4256 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 4257 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 4258 &stats) == -ENODEV), 4259 "rte_cryptodev_stats_get invalid dev failed"); 4260 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 4261 "rte_cryptodev_stats_get invalid Param failed"); 4262 dev = &rte_cryptodevs[ts_params->valid_devs[0]]; 4263 temp_pfn = dev->dev_ops->stats_get; 4264 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0; 4265 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 4266 == -ENOTSUP), 4267 "rte_cryptodev_stats_get invalid Param failed"); 4268 dev->dev_ops->stats_get = temp_pfn; 4269 4270 /* Test expected values */ 4271 ut_setup(); 4272 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 4273 ut_teardown(); 4274 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 4275 &stats), 4276 "rte_cryptodev_stats_get failed"); 4277 TEST_ASSERT((stats.enqueued_count == 1), 4278 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4279 TEST_ASSERT((stats.dequeued_count == 1), 4280 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4281 TEST_ASSERT((stats.enqueue_err_count == 0), 4282 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4283 TEST_ASSERT((stats.dequeue_err_count == 0), 4284 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4285 4286 /* invalid device but should ignore and not reset device stats*/ 4287 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 4288 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 4289 &stats), 4290 "rte_cryptodev_stats_get failed"); 4291 TEST_ASSERT((stats.enqueued_count == 1), 4292 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4293 4294 /* check that a valid reset clears stats */ 4295 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 4296 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 4297 &stats), 4298 "rte_cryptodev_stats_get failed"); 4299 TEST_ASSERT((stats.enqueued_count == 0), 4300 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4301 TEST_ASSERT((stats.dequeued_count == 0), 4302 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 4303 4304 return TEST_SUCCESS; 4305 } 4306 4307 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 4308 struct crypto_unittest_params *ut_params, 4309 enum rte_crypto_auth_operation op, 4310 const struct HMAC_MD5_vector *test_case) 4311 { 4312 uint8_t key[64]; 4313 4314 memcpy(key, test_case->key.data, test_case->key.len); 4315 4316 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4317 ut_params->auth_xform.next = NULL; 4318 ut_params->auth_xform.auth.op = op; 4319 4320 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 4321 4322 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 4323 ut_params->auth_xform.auth.add_auth_data_length = 0; 4324 ut_params->auth_xform.auth.key.length = test_case->key.len; 4325 ut_params->auth_xform.auth.key.data = key; 4326 4327 ut_params->sess = rte_cryptodev_sym_session_create( 4328 ts_params->valid_devs[0], &ut_params->auth_xform); 4329 4330 if (ut_params->sess == NULL) 4331 return TEST_FAILED; 4332 4333 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4334 4335 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4336 rte_pktmbuf_tailroom(ut_params->ibuf)); 4337 4338 return 0; 4339 } 4340 4341 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 4342 const struct HMAC_MD5_vector *test_case, 4343 uint8_t **plaintext) 4344 { 4345 uint16_t plaintext_pad_len; 4346 4347 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4348 4349 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 4350 16); 4351 4352 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4353 plaintext_pad_len); 4354 memcpy(*plaintext, test_case->plaintext.data, 4355 test_case->plaintext.len); 4356 4357 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 4358 ut_params->ibuf, MD5_DIGEST_LEN); 4359 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 4360 "no room to append digest"); 4361 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 4362 ut_params->ibuf, plaintext_pad_len); 4363 sym_op->auth.digest.length = MD5_DIGEST_LEN; 4364 4365 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 4366 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 4367 test_case->auth_tag.len); 4368 } 4369 4370 sym_op->auth.data.offset = 0; 4371 sym_op->auth.data.length = test_case->plaintext.len; 4372 4373 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4374 ut_params->op->sym->m_src = ut_params->ibuf; 4375 4376 return 0; 4377 } 4378 4379 static int 4380 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 4381 { 4382 uint16_t plaintext_pad_len; 4383 uint8_t *plaintext, *auth_tag; 4384 4385 struct crypto_testsuite_params *ts_params = &testsuite_params; 4386 struct crypto_unittest_params *ut_params = &unittest_params; 4387 4388 if (MD5_HMAC_create_session(ts_params, ut_params, 4389 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 4390 return TEST_FAILED; 4391 4392 /* Generate Crypto op data structure */ 4393 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4394 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4395 TEST_ASSERT_NOT_NULL(ut_params->op, 4396 "Failed to allocate symmetric crypto operation struct"); 4397 4398 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 4399 16); 4400 4401 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 4402 return TEST_FAILED; 4403 4404 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4405 ut_params->op), "failed to process sym crypto op"); 4406 4407 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4408 "crypto op processing failed"); 4409 4410 if (ut_params->op->sym->m_dst) { 4411 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 4412 uint8_t *, plaintext_pad_len); 4413 } else { 4414 auth_tag = plaintext + plaintext_pad_len; 4415 } 4416 4417 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4418 auth_tag, 4419 test_case->auth_tag.data, 4420 test_case->auth_tag.len, 4421 "HMAC_MD5 generated tag not as expected"); 4422 4423 return TEST_SUCCESS; 4424 } 4425 4426 static int 4427 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 4428 { 4429 uint8_t *plaintext; 4430 4431 struct crypto_testsuite_params *ts_params = &testsuite_params; 4432 struct crypto_unittest_params *ut_params = &unittest_params; 4433 4434 if (MD5_HMAC_create_session(ts_params, ut_params, 4435 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 4436 return TEST_FAILED; 4437 } 4438 4439 /* Generate Crypto op data structure */ 4440 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4441 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4442 TEST_ASSERT_NOT_NULL(ut_params->op, 4443 "Failed to allocate symmetric crypto operation struct"); 4444 4445 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 4446 return TEST_FAILED; 4447 4448 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 4449 ut_params->op), "failed to process sym crypto op"); 4450 4451 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4452 "HMAC_MD5 crypto op processing failed"); 4453 4454 return TEST_SUCCESS; 4455 } 4456 4457 static int 4458 test_MD5_HMAC_generate_case_1(void) 4459 { 4460 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 4461 } 4462 4463 static int 4464 test_MD5_HMAC_verify_case_1(void) 4465 { 4466 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 4467 } 4468 4469 static int 4470 test_MD5_HMAC_generate_case_2(void) 4471 { 4472 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 4473 } 4474 4475 static int 4476 test_MD5_HMAC_verify_case_2(void) 4477 { 4478 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 4479 } 4480 4481 static int 4482 test_multi_session(void) 4483 { 4484 struct crypto_testsuite_params *ts_params = &testsuite_params; 4485 struct crypto_unittest_params *ut_params = &unittest_params; 4486 4487 struct rte_cryptodev_info dev_info; 4488 struct rte_cryptodev_sym_session **sessions; 4489 4490 uint16_t i; 4491 4492 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 4493 aes_cbc_key, hmac_sha512_key); 4494 4495 4496 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4497 4498 sessions = rte_malloc(NULL, 4499 (sizeof(struct rte_cryptodev_sym_session *) * 4500 dev_info.sym.max_nb_sessions) + 1, 0); 4501 4502 /* Create multiple crypto sessions*/ 4503 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) { 4504 sessions[i] = rte_cryptodev_sym_session_create( 4505 ts_params->valid_devs[0], 4506 &ut_params->auth_xform); 4507 TEST_ASSERT_NOT_NULL(sessions[i], 4508 "Session creation failed at session number %u", 4509 i); 4510 4511 /* Attempt to send a request on each session */ 4512 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 4513 sessions[i], 4514 ut_params, 4515 ts_params, 4516 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 4517 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 4518 aes_cbc_iv), 4519 "Failed to perform decrypt on request number %u.", i); 4520 /* free crypto operation structure */ 4521 if (ut_params->op) 4522 rte_crypto_op_free(ut_params->op); 4523 4524 /* 4525 * free mbuf - both obuf and ibuf are usually the same, 4526 * so check if they point at the same address is necessary, 4527 * to avoid freeing the mbuf twice. 4528 */ 4529 if (ut_params->obuf) { 4530 rte_pktmbuf_free(ut_params->obuf); 4531 if (ut_params->ibuf == ut_params->obuf) 4532 ut_params->ibuf = 0; 4533 ut_params->obuf = 0; 4534 } 4535 if (ut_params->ibuf) { 4536 rte_pktmbuf_free(ut_params->ibuf); 4537 ut_params->ibuf = 0; 4538 } 4539 } 4540 4541 /* Next session create should fail */ 4542 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0], 4543 &ut_params->auth_xform); 4544 TEST_ASSERT_NULL(sessions[i], 4545 "Session creation succeeded unexpectedly!"); 4546 4547 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) 4548 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 4549 sessions[i]); 4550 4551 rte_free(sessions); 4552 4553 return TEST_SUCCESS; 4554 } 4555 4556 struct multi_session_params { 4557 struct crypto_unittest_params ut_params; 4558 uint8_t *cipher_key; 4559 uint8_t *hmac_key; 4560 const uint8_t *cipher; 4561 const uint8_t *digest; 4562 uint8_t *iv; 4563 }; 4564 4565 #define MB_SESSION_NUMBER 3 4566 4567 static int 4568 test_multi_session_random_usage(void) 4569 { 4570 struct crypto_testsuite_params *ts_params = &testsuite_params; 4571 struct rte_cryptodev_info dev_info; 4572 struct rte_cryptodev_sym_session **sessions; 4573 uint32_t i, j; 4574 struct multi_session_params ut_paramz[] = { 4575 4576 { 4577 .cipher_key = ms_aes_cbc_key0, 4578 .hmac_key = ms_hmac_key0, 4579 .cipher = ms_aes_cbc_cipher0, 4580 .digest = ms_hmac_digest0, 4581 .iv = ms_aes_cbc_iv0 4582 }, 4583 { 4584 .cipher_key = ms_aes_cbc_key1, 4585 .hmac_key = ms_hmac_key1, 4586 .cipher = ms_aes_cbc_cipher1, 4587 .digest = ms_hmac_digest1, 4588 .iv = ms_aes_cbc_iv1 4589 }, 4590 { 4591 .cipher_key = ms_aes_cbc_key2, 4592 .hmac_key = ms_hmac_key2, 4593 .cipher = ms_aes_cbc_cipher2, 4594 .digest = ms_hmac_digest2, 4595 .iv = ms_aes_cbc_iv2 4596 }, 4597 4598 }; 4599 4600 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4601 4602 sessions = rte_malloc(NULL, 4603 (sizeof(struct rte_cryptodev_sym_session *) 4604 * dev_info.sym.max_nb_sessions) + 1, 0); 4605 4606 for (i = 0; i < MB_SESSION_NUMBER; i++) { 4607 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params, 4608 sizeof(struct crypto_unittest_params)); 4609 4610 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 4611 &ut_paramz[i].ut_params, 4612 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 4613 4614 /* Create multiple crypto sessions*/ 4615 sessions[i] = rte_cryptodev_sym_session_create( 4616 ts_params->valid_devs[0], 4617 &ut_paramz[i].ut_params.auth_xform); 4618 4619 TEST_ASSERT_NOT_NULL(sessions[i], 4620 "Session creation failed at session number %u", 4621 i); 4622 4623 } 4624 4625 srand(time(NULL)); 4626 for (i = 0; i < 40000; i++) { 4627 4628 j = rand() % MB_SESSION_NUMBER; 4629 4630 TEST_ASSERT_SUCCESS( 4631 test_AES_CBC_HMAC_SHA512_decrypt_perform( 4632 sessions[j], 4633 &ut_paramz[j].ut_params, 4634 ts_params, ut_paramz[j].cipher, 4635 ut_paramz[j].digest, 4636 ut_paramz[j].iv), 4637 "Failed to perform decrypt on request number %u.", i); 4638 4639 if (ut_paramz[j].ut_params.op) 4640 rte_crypto_op_free(ut_paramz[j].ut_params.op); 4641 4642 /* 4643 * free mbuf - both obuf and ibuf are usually the same, 4644 * so check if they point at the same address is necessary, 4645 * to avoid freeing the mbuf twice. 4646 */ 4647 if (ut_paramz[j].ut_params.obuf) { 4648 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 4649 if (ut_paramz[j].ut_params.ibuf 4650 == ut_paramz[j].ut_params.obuf) 4651 ut_paramz[j].ut_params.ibuf = 0; 4652 ut_paramz[j].ut_params.obuf = 0; 4653 } 4654 if (ut_paramz[j].ut_params.ibuf) { 4655 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 4656 ut_paramz[j].ut_params.ibuf = 0; 4657 } 4658 } 4659 4660 for (i = 0; i < MB_SESSION_NUMBER; i++) 4661 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 4662 sessions[i]); 4663 4664 rte_free(sessions); 4665 4666 return TEST_SUCCESS; 4667 } 4668 4669 static int 4670 test_null_cipher_only_operation(void) 4671 { 4672 struct crypto_testsuite_params *ts_params = &testsuite_params; 4673 struct crypto_unittest_params *ut_params = &unittest_params; 4674 4675 /* Generate test mbuf data and space for digest */ 4676 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 4677 catch_22_quote, QUOTE_512_BYTES, 0); 4678 4679 /* Setup Cipher Parameters */ 4680 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4681 ut_params->cipher_xform.next = NULL; 4682 4683 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 4684 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 4685 4686 /* Create Crypto session*/ 4687 ut_params->sess = rte_cryptodev_sym_session_create( 4688 ts_params->valid_devs[0], &ut_params->cipher_xform); 4689 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4690 4691 /* Generate Crypto op data structure */ 4692 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4693 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4694 TEST_ASSERT_NOT_NULL(ut_params->op, 4695 "Failed to allocate symmetric crypto operation struct"); 4696 4697 /* Set crypto operation data parameters */ 4698 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4699 4700 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4701 4702 /* set crypto operation source mbuf */ 4703 sym_op->m_src = ut_params->ibuf; 4704 4705 sym_op->cipher.data.offset = 0; 4706 sym_op->cipher.data.length = QUOTE_512_BYTES; 4707 4708 /* Process crypto operation */ 4709 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4710 ut_params->op); 4711 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 4712 4713 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4714 "crypto operation processing failed"); 4715 4716 /* Validate obuf */ 4717 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4718 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 4719 catch_22_quote, 4720 QUOTE_512_BYTES, 4721 "Ciphertext data not as expected"); 4722 4723 return TEST_SUCCESS; 4724 } 4725 4726 static int 4727 test_null_auth_only_operation(void) 4728 { 4729 struct crypto_testsuite_params *ts_params = &testsuite_params; 4730 struct crypto_unittest_params *ut_params = &unittest_params; 4731 4732 /* Generate test mbuf data and space for digest */ 4733 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 4734 catch_22_quote, QUOTE_512_BYTES, 0); 4735 4736 /* Setup HMAC Parameters */ 4737 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4738 ut_params->auth_xform.next = NULL; 4739 4740 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 4741 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 4742 4743 /* Create Crypto session*/ 4744 ut_params->sess = rte_cryptodev_sym_session_create( 4745 ts_params->valid_devs[0], &ut_params->auth_xform); 4746 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4747 4748 /* Generate Crypto op data structure */ 4749 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4750 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4751 TEST_ASSERT_NOT_NULL(ut_params->op, 4752 "Failed to allocate symmetric crypto operation struct"); 4753 4754 /* Set crypto operation data parameters */ 4755 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4756 4757 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4758 4759 sym_op->m_src = ut_params->ibuf; 4760 4761 sym_op->auth.data.offset = 0; 4762 sym_op->auth.data.length = QUOTE_512_BYTES; 4763 4764 /* Process crypto operation */ 4765 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4766 ut_params->op); 4767 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 4768 4769 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4770 "crypto operation processing failed"); 4771 4772 return TEST_SUCCESS; 4773 } 4774 4775 static int 4776 test_null_cipher_auth_operation(void) 4777 { 4778 struct crypto_testsuite_params *ts_params = &testsuite_params; 4779 struct crypto_unittest_params *ut_params = &unittest_params; 4780 4781 /* Generate test mbuf data and space for digest */ 4782 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 4783 catch_22_quote, QUOTE_512_BYTES, 0); 4784 4785 /* Setup Cipher Parameters */ 4786 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4787 ut_params->cipher_xform.next = &ut_params->auth_xform; 4788 4789 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 4790 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 4791 4792 /* Setup HMAC Parameters */ 4793 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4794 ut_params->auth_xform.next = NULL; 4795 4796 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 4797 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 4798 4799 /* Create Crypto session*/ 4800 ut_params->sess = rte_cryptodev_sym_session_create( 4801 ts_params->valid_devs[0], &ut_params->cipher_xform); 4802 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4803 4804 /* Generate Crypto op data structure */ 4805 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4806 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4807 TEST_ASSERT_NOT_NULL(ut_params->op, 4808 "Failed to allocate symmetric crypto operation struct"); 4809 4810 /* Set crypto operation data parameters */ 4811 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4812 4813 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4814 4815 sym_op->m_src = ut_params->ibuf; 4816 4817 sym_op->cipher.data.offset = 0; 4818 sym_op->cipher.data.length = QUOTE_512_BYTES; 4819 4820 sym_op->auth.data.offset = 0; 4821 sym_op->auth.data.length = QUOTE_512_BYTES; 4822 4823 /* Process crypto operation */ 4824 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4825 ut_params->op); 4826 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 4827 4828 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4829 "crypto operation processing failed"); 4830 4831 /* Validate obuf */ 4832 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4833 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 4834 catch_22_quote, 4835 QUOTE_512_BYTES, 4836 "Ciphertext data not as expected"); 4837 4838 return TEST_SUCCESS; 4839 } 4840 4841 static int 4842 test_null_auth_cipher_operation(void) 4843 { 4844 struct crypto_testsuite_params *ts_params = &testsuite_params; 4845 struct crypto_unittest_params *ut_params = &unittest_params; 4846 4847 /* Generate test mbuf data and space for digest */ 4848 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 4849 catch_22_quote, QUOTE_512_BYTES, 0); 4850 4851 /* Setup Cipher Parameters */ 4852 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4853 ut_params->cipher_xform.next = NULL; 4854 4855 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 4856 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 4857 4858 /* Setup HMAC Parameters */ 4859 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4860 ut_params->auth_xform.next = &ut_params->cipher_xform; 4861 4862 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 4863 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 4864 4865 /* Create Crypto session*/ 4866 ut_params->sess = rte_cryptodev_sym_session_create( 4867 ts_params->valid_devs[0], &ut_params->cipher_xform); 4868 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4869 4870 /* Generate Crypto op data structure */ 4871 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 4872 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 4873 TEST_ASSERT_NOT_NULL(ut_params->op, 4874 "Failed to allocate symmetric crypto operation struct"); 4875 4876 /* Set crypto operation data parameters */ 4877 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 4878 4879 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 4880 4881 sym_op->m_src = ut_params->ibuf; 4882 4883 sym_op->cipher.data.offset = 0; 4884 sym_op->cipher.data.length = QUOTE_512_BYTES; 4885 4886 sym_op->auth.data.offset = 0; 4887 sym_op->auth.data.length = QUOTE_512_BYTES; 4888 4889 /* Process crypto operation */ 4890 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4891 ut_params->op); 4892 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 4893 4894 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 4895 "crypto operation processing failed"); 4896 4897 /* Validate obuf */ 4898 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4899 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 4900 catch_22_quote, 4901 QUOTE_512_BYTES, 4902 "Ciphertext data not as expected"); 4903 4904 return TEST_SUCCESS; 4905 } 4906 4907 4908 static int 4909 test_null_invalid_operation(void) 4910 { 4911 struct crypto_testsuite_params *ts_params = &testsuite_params; 4912 struct crypto_unittest_params *ut_params = &unittest_params; 4913 4914 /* Setup Cipher Parameters */ 4915 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4916 ut_params->cipher_xform.next = NULL; 4917 4918 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 4919 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 4920 4921 /* Create Crypto session*/ 4922 ut_params->sess = rte_cryptodev_sym_session_create( 4923 ts_params->valid_devs[0], &ut_params->cipher_xform); 4924 TEST_ASSERT_NULL(ut_params->sess, 4925 "Session creation succeeded unexpectedly"); 4926 4927 4928 /* Setup HMAC Parameters */ 4929 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4930 ut_params->auth_xform.next = NULL; 4931 4932 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 4933 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 4934 4935 /* Create Crypto session*/ 4936 ut_params->sess = rte_cryptodev_sym_session_create( 4937 ts_params->valid_devs[0], &ut_params->auth_xform); 4938 TEST_ASSERT_NULL(ut_params->sess, 4939 "Session creation succeeded unexpectedly"); 4940 4941 return TEST_SUCCESS; 4942 } 4943 4944 4945 #define NULL_BURST_LENGTH (32) 4946 4947 static int 4948 test_null_burst_operation(void) 4949 { 4950 struct crypto_testsuite_params *ts_params = &testsuite_params; 4951 struct crypto_unittest_params *ut_params = &unittest_params; 4952 4953 unsigned i, burst_len = NULL_BURST_LENGTH; 4954 4955 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 4956 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 4957 4958 /* Setup Cipher Parameters */ 4959 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4960 ut_params->cipher_xform.next = &ut_params->auth_xform; 4961 4962 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 4963 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 4964 4965 /* Setup HMAC Parameters */ 4966 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4967 ut_params->auth_xform.next = NULL; 4968 4969 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 4970 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 4971 4972 /* Create Crypto session*/ 4973 ut_params->sess = rte_cryptodev_sym_session_create( 4974 ts_params->valid_devs[0], &ut_params->cipher_xform); 4975 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 4976 4977 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 4978 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 4979 burst_len, "failed to generate burst of crypto ops"); 4980 4981 /* Generate an operation for each mbuf in burst */ 4982 for (i = 0; i < burst_len; i++) { 4983 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4984 4985 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 4986 4987 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 4988 sizeof(unsigned)); 4989 *data = i; 4990 4991 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 4992 4993 burst[i]->sym->m_src = m; 4994 } 4995 4996 /* Process crypto operation */ 4997 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 4998 0, burst, burst_len), 4999 burst_len, 5000 "Error enqueuing burst"); 5001 5002 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 5003 0, burst_dequeued, burst_len), 5004 burst_len, 5005 "Error dequeuing burst"); 5006 5007 5008 for (i = 0; i < burst_len; i++) { 5009 TEST_ASSERT_EQUAL( 5010 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 5011 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 5012 uint32_t *), 5013 "data not as expected"); 5014 5015 rte_pktmbuf_free(burst[i]->sym->m_src); 5016 rte_crypto_op_free(burst[i]); 5017 } 5018 5019 return TEST_SUCCESS; 5020 } 5021 5022 static void 5023 generate_gmac_large_plaintext(uint8_t *data) 5024 { 5025 uint16_t i; 5026 5027 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 5028 memcpy(&data[i], &data[0], 32); 5029 } 5030 5031 static int 5032 create_gmac_operation(enum rte_crypto_auth_operation op, 5033 const struct gmac_test_data *tdata) 5034 { 5035 struct crypto_testsuite_params *ts_params = &testsuite_params; 5036 struct crypto_unittest_params *ut_params = &unittest_params; 5037 struct rte_crypto_sym_op *sym_op; 5038 5039 unsigned iv_pad_len; 5040 unsigned aad_pad_len; 5041 5042 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16); 5043 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 5044 5045 /* 5046 * Runtime generate the large plain text instead of use hard code 5047 * plain text vector. It is done to avoid create huge source file 5048 * with the test vector. 5049 */ 5050 if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH) 5051 generate_gmac_large_plaintext(tdata->aad.data); 5052 5053 /* Generate Crypto op data structure */ 5054 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5055 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5056 TEST_ASSERT_NOT_NULL(ut_params->op, 5057 "Failed to allocate symmetric crypto operation struct"); 5058 5059 sym_op = ut_params->op->sym; 5060 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5061 aad_pad_len); 5062 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, 5063 "no room to append aad"); 5064 5065 sym_op->auth.aad.length = tdata->aad.len; 5066 sym_op->auth.aad.phys_addr = 5067 rte_pktmbuf_mtophys(ut_params->ibuf); 5068 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len); 5069 5070 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 5071 ut_params->ibuf, tdata->gmac_tag.len); 5072 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 5073 "no room to append digest"); 5074 5075 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 5076 ut_params->ibuf, aad_pad_len); 5077 sym_op->auth.digest.length = tdata->gmac_tag.len; 5078 5079 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 5080 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 5081 tdata->gmac_tag.len); 5082 TEST_HEXDUMP(stdout, "digest:", 5083 sym_op->auth.digest.data, 5084 sym_op->auth.digest.length); 5085 } 5086 5087 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 5088 ut_params->ibuf, iv_pad_len); 5089 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 5090 5091 memset(sym_op->cipher.iv.data, 0, iv_pad_len); 5092 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 5093 sym_op->cipher.iv.length = tdata->iv.len; 5094 5095 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len); 5096 5097 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len); 5098 5099 sym_op->cipher.data.length = 0; 5100 sym_op->cipher.data.offset = 0; 5101 5102 sym_op->auth.data.offset = 0; 5103 sym_op->auth.data.length = 0; 5104 5105 return 0; 5106 } 5107 5108 static int create_gmac_session(uint8_t dev_id, 5109 enum rte_crypto_cipher_operation op, 5110 const struct gmac_test_data *tdata, 5111 enum rte_crypto_auth_operation auth_op) 5112 { 5113 uint8_t cipher_key[tdata->key.len]; 5114 5115 struct crypto_unittest_params *ut_params = &unittest_params; 5116 5117 memcpy(cipher_key, tdata->key.data, tdata->key.len); 5118 5119 /* For GMAC we setup cipher parameters */ 5120 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5121 ut_params->cipher_xform.next = NULL; 5122 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM; 5123 ut_params->cipher_xform.cipher.op = op; 5124 ut_params->cipher_xform.cipher.key.data = cipher_key; 5125 ut_params->cipher_xform.cipher.key.length = tdata->key.len; 5126 5127 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5128 ut_params->auth_xform.next = NULL; 5129 5130 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 5131 ut_params->auth_xform.auth.op = auth_op; 5132 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 5133 ut_params->auth_xform.auth.add_auth_data_length = 0; 5134 ut_params->auth_xform.auth.key.length = 0; 5135 ut_params->auth_xform.auth.key.data = NULL; 5136 5137 ut_params->cipher_xform.next = &ut_params->auth_xform; 5138 5139 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 5140 &ut_params->cipher_xform); 5141 5142 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5143 5144 return 0; 5145 } 5146 5147 static int 5148 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 5149 { 5150 struct crypto_testsuite_params *ts_params = &testsuite_params; 5151 struct crypto_unittest_params *ut_params = &unittest_params; 5152 5153 int retval; 5154 5155 uint8_t *auth_tag, *p; 5156 uint16_t aad_pad_len; 5157 5158 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 5159 "No GMAC length in the source data"); 5160 5161 retval = create_gmac_session(ts_params->valid_devs[0], 5162 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5163 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 5164 5165 if (retval < 0) 5166 return retval; 5167 5168 if (tdata->aad.len > MBUF_SIZE) 5169 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 5170 else 5171 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5172 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5173 "Failed to allocate input buffer in mempool"); 5174 5175 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5176 rte_pktmbuf_tailroom(ut_params->ibuf)); 5177 5178 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 5179 5180 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *); 5181 5182 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 5183 tdata); 5184 5185 if (retval < 0) 5186 return retval; 5187 5188 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5189 5190 ut_params->op->sym->m_src = ut_params->ibuf; 5191 5192 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5193 ut_params->op), "failed to process sym crypto op"); 5194 5195 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5196 "crypto op processing failed"); 5197 5198 if (ut_params->op->sym->m_dst) { 5199 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 5200 uint8_t *, aad_pad_len); 5201 } else { 5202 auth_tag = p + aad_pad_len; 5203 } 5204 5205 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 5206 5207 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5208 auth_tag, 5209 tdata->gmac_tag.data, 5210 tdata->gmac_tag.len, 5211 "GMAC Generated auth tag not as expected"); 5212 5213 return 0; 5214 } 5215 5216 static int 5217 test_AES_GMAC_authentication_test_case_1(void) 5218 { 5219 return test_AES_GMAC_authentication(&gmac_test_case_1); 5220 } 5221 5222 static int 5223 test_AES_GMAC_authentication_test_case_2(void) 5224 { 5225 return test_AES_GMAC_authentication(&gmac_test_case_2); 5226 } 5227 5228 static int 5229 test_AES_GMAC_authentication_test_case_3(void) 5230 { 5231 return test_AES_GMAC_authentication(&gmac_test_case_3); 5232 } 5233 5234 static int 5235 test_AES_GMAC_authentication_test_case_4(void) 5236 { 5237 return test_AES_GMAC_authentication(&gmac_test_case_4); 5238 } 5239 5240 static int 5241 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 5242 { 5243 struct crypto_testsuite_params *ts_params = &testsuite_params; 5244 struct crypto_unittest_params *ut_params = &unittest_params; 5245 int retval; 5246 5247 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 5248 "No GMAC length in the source data"); 5249 5250 retval = create_gmac_session(ts_params->valid_devs[0], 5251 RTE_CRYPTO_CIPHER_OP_DECRYPT, 5252 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 5253 5254 if (retval < 0) 5255 return retval; 5256 5257 if (tdata->aad.len > MBUF_SIZE) 5258 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 5259 else 5260 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5261 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5262 "Failed to allocate input buffer in mempool"); 5263 5264 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5265 rte_pktmbuf_tailroom(ut_params->ibuf)); 5266 5267 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 5268 tdata); 5269 5270 if (retval < 0) 5271 return retval; 5272 5273 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5274 5275 ut_params->op->sym->m_src = ut_params->ibuf; 5276 5277 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 5278 ut_params->op), "failed to process sym crypto op"); 5279 5280 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 5281 "crypto op processing failed"); 5282 5283 return 0; 5284 5285 } 5286 5287 static int 5288 test_AES_GMAC_authentication_verify_test_case_1(void) 5289 { 5290 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 5291 } 5292 5293 static int 5294 test_AES_GMAC_authentication_verify_test_case_2(void) 5295 { 5296 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 5297 } 5298 5299 static int 5300 test_AES_GMAC_authentication_verify_test_case_3(void) 5301 { 5302 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 5303 } 5304 5305 static int 5306 test_AES_GMAC_authentication_verify_test_case_4(void) 5307 { 5308 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 5309 } 5310 5311 struct test_crypto_vector { 5312 enum rte_crypto_cipher_algorithm crypto_algo; 5313 5314 struct { 5315 uint8_t data[64]; 5316 unsigned int len; 5317 } cipher_key; 5318 5319 struct { 5320 uint8_t data[64]; 5321 unsigned int len; 5322 } iv; 5323 5324 struct { 5325 const uint8_t *data; 5326 unsigned int len; 5327 } plaintext; 5328 5329 struct { 5330 const uint8_t *data; 5331 unsigned int len; 5332 } ciphertext; 5333 5334 enum rte_crypto_auth_algorithm auth_algo; 5335 5336 struct { 5337 uint8_t data[128]; 5338 unsigned int len; 5339 } auth_key; 5340 5341 struct { 5342 const uint8_t *data; 5343 unsigned int len; 5344 } aad; 5345 5346 struct { 5347 uint8_t data[128]; 5348 unsigned int len; 5349 } digest; 5350 }; 5351 5352 static const struct test_crypto_vector 5353 hmac_sha1_test_crypto_vector = { 5354 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 5355 .plaintext = { 5356 .data = plaintext_hash, 5357 .len = 512 5358 }, 5359 .auth_key = { 5360 .data = { 5361 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 5362 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 5363 0xDE, 0xF4, 0xDE, 0xAD 5364 }, 5365 .len = 20 5366 }, 5367 .digest = { 5368 .data = { 5369 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 5370 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 5371 0x3F, 0x91, 0x64, 0x59 5372 }, 5373 .len = 20 5374 } 5375 }; 5376 5377 static const struct test_crypto_vector 5378 aes128_gmac_test_vector = { 5379 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 5380 .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM, 5381 .aad = { 5382 .data = plaintext_hash, 5383 .len = 512 5384 }, 5385 .iv = { 5386 .data = { 5387 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 5388 0x08, 0x09, 0x0A, 0x0B 5389 }, 5390 .len = 12 5391 }, 5392 .cipher_key = { 5393 .data = { 5394 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 5395 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 5396 }, 5397 .len = 16 5398 }, 5399 .digest = { 5400 .data = { 5401 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 5402 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 5403 }, 5404 .len = 16 5405 } 5406 }; 5407 5408 static const struct test_crypto_vector 5409 aes128cbc_hmac_sha1_test_vector = { 5410 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 5411 .cipher_key = { 5412 .data = { 5413 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 5414 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 5415 }, 5416 .len = 16 5417 }, 5418 .iv = { 5419 .data = { 5420 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 5421 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 5422 }, 5423 .len = 16 5424 }, 5425 .plaintext = { 5426 .data = plaintext_hash, 5427 .len = 512 5428 }, 5429 .ciphertext = { 5430 .data = ciphertext512_aes128cbc, 5431 .len = 512 5432 }, 5433 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 5434 .auth_key = { 5435 .data = { 5436 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 5437 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 5438 0xDE, 0xF4, 0xDE, 0xAD 5439 }, 5440 .len = 20 5441 }, 5442 .digest = { 5443 .data = { 5444 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 5445 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 5446 0x18, 0x8C, 0x1D, 0x32 5447 }, 5448 .len = 20 5449 } 5450 }; 5451 5452 static void 5453 data_corruption(uint8_t *data) 5454 { 5455 data[0] += 1; 5456 } 5457 5458 static void 5459 tag_corruption(uint8_t *data, unsigned int tag_offset) 5460 { 5461 data[tag_offset] += 1; 5462 } 5463 5464 static int 5465 create_auth_session(struct crypto_unittest_params *ut_params, 5466 uint8_t dev_id, 5467 const struct test_crypto_vector *reference, 5468 enum rte_crypto_auth_operation auth_op) 5469 { 5470 uint8_t auth_key[reference->auth_key.len + 1]; 5471 5472 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 5473 5474 /* Setup Authentication Parameters */ 5475 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5476 ut_params->auth_xform.auth.op = auth_op; 5477 ut_params->auth_xform.next = NULL; 5478 ut_params->auth_xform.auth.algo = reference->auth_algo; 5479 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 5480 ut_params->auth_xform.auth.key.data = auth_key; 5481 ut_params->auth_xform.auth.digest_length = reference->digest.len; 5482 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len; 5483 5484 /* Create Crypto session*/ 5485 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 5486 &ut_params->auth_xform); 5487 5488 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5489 5490 return 0; 5491 } 5492 5493 static int 5494 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 5495 uint8_t dev_id, 5496 const struct test_crypto_vector *reference, 5497 enum rte_crypto_auth_operation auth_op, 5498 enum rte_crypto_cipher_operation cipher_op) 5499 { 5500 uint8_t cipher_key[reference->cipher_key.len + 1]; 5501 uint8_t auth_key[reference->auth_key.len + 1]; 5502 5503 memcpy(cipher_key, reference->cipher_key.data, 5504 reference->cipher_key.len); 5505 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 5506 5507 /* Setup Authentication Parameters */ 5508 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5509 ut_params->auth_xform.auth.op = auth_op; 5510 ut_params->auth_xform.next = &ut_params->cipher_xform; 5511 ut_params->auth_xform.auth.algo = reference->auth_algo; 5512 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 5513 ut_params->auth_xform.auth.key.data = auth_key; 5514 ut_params->auth_xform.auth.digest_length = reference->digest.len; 5515 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len; 5516 5517 /* Setup Cipher Parameters */ 5518 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5519 ut_params->cipher_xform.next = NULL; 5520 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 5521 ut_params->cipher_xform.cipher.op = cipher_op; 5522 ut_params->cipher_xform.cipher.key.data = cipher_key; 5523 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 5524 5525 /* Create Crypto session*/ 5526 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 5527 &ut_params->auth_xform); 5528 5529 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 5530 5531 return 0; 5532 } 5533 5534 static int 5535 create_auth_operation(struct crypto_testsuite_params *ts_params, 5536 struct crypto_unittest_params *ut_params, 5537 const struct test_crypto_vector *reference, 5538 unsigned int auth_generate) 5539 { 5540 /* Generate Crypto op data structure */ 5541 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5542 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5543 TEST_ASSERT_NOT_NULL(ut_params->op, 5544 "Failed to allocate pktmbuf offload"); 5545 5546 /* Set crypto operation data parameters */ 5547 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5548 5549 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5550 5551 /* set crypto operation source mbuf */ 5552 sym_op->m_src = ut_params->ibuf; 5553 5554 /* digest */ 5555 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 5556 ut_params->ibuf, reference->digest.len); 5557 5558 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 5559 "no room to append auth tag"); 5560 5561 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 5562 ut_params->ibuf, reference->plaintext.len); 5563 sym_op->auth.digest.length = reference->digest.len; 5564 5565 if (auth_generate) 5566 memset(sym_op->auth.digest.data, 0, reference->digest.len); 5567 else 5568 memcpy(sym_op->auth.digest.data, 5569 reference->digest.data, 5570 reference->digest.len); 5571 5572 TEST_HEXDUMP(stdout, "digest:", 5573 sym_op->auth.digest.data, 5574 sym_op->auth.digest.length); 5575 5576 sym_op->auth.data.length = reference->plaintext.len; 5577 sym_op->auth.data.offset = 0; 5578 5579 return 0; 5580 } 5581 5582 static int 5583 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 5584 struct crypto_unittest_params *ut_params, 5585 const struct test_crypto_vector *reference, 5586 unsigned int auth_generate) 5587 { 5588 /* Generate Crypto op data structure */ 5589 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5590 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5591 TEST_ASSERT_NOT_NULL(ut_params->op, 5592 "Failed to allocate pktmbuf offload"); 5593 5594 /* Set crypto operation data parameters */ 5595 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5596 5597 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5598 5599 /* set crypto operation source mbuf */ 5600 sym_op->m_src = ut_params->ibuf; 5601 5602 /* aad */ 5603 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5604 reference->aad.len); 5605 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD"); 5606 memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len); 5607 5608 TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len); 5609 5610 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 5611 sym_op->auth.aad.length = reference->aad.len; 5612 5613 /* digest */ 5614 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 5615 ut_params->ibuf, reference->digest.len); 5616 5617 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 5618 "no room to append auth tag"); 5619 5620 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 5621 ut_params->ibuf, reference->ciphertext.len); 5622 sym_op->auth.digest.length = reference->digest.len; 5623 5624 if (auth_generate) 5625 memset(sym_op->auth.digest.data, 0, reference->digest.len); 5626 else 5627 memcpy(sym_op->auth.digest.data, 5628 reference->digest.data, 5629 reference->digest.len); 5630 5631 TEST_HEXDUMP(stdout, "digest:", 5632 sym_op->auth.digest.data, 5633 sym_op->auth.digest.length); 5634 5635 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 5636 ut_params->ibuf, reference->iv.len); 5637 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 5638 5639 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 5640 sym_op->cipher.iv.length = reference->iv.len; 5641 5642 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len); 5643 5644 sym_op->cipher.data.length = 0; 5645 sym_op->cipher.data.offset = 0; 5646 5647 sym_op->auth.data.length = 0; 5648 sym_op->auth.data.offset = 0; 5649 5650 return 0; 5651 } 5652 5653 static int 5654 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 5655 struct crypto_unittest_params *ut_params, 5656 const struct test_crypto_vector *reference, 5657 unsigned int auth_generate) 5658 { 5659 /* Generate Crypto op data structure */ 5660 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 5661 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 5662 TEST_ASSERT_NOT_NULL(ut_params->op, 5663 "Failed to allocate pktmbuf offload"); 5664 5665 /* Set crypto operation data parameters */ 5666 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 5667 5668 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 5669 5670 /* set crypto operation source mbuf */ 5671 sym_op->m_src = ut_params->ibuf; 5672 5673 /* digest */ 5674 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 5675 ut_params->ibuf, reference->digest.len); 5676 5677 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 5678 "no room to append auth tag"); 5679 5680 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset( 5681 ut_params->ibuf, reference->ciphertext.len); 5682 sym_op->auth.digest.length = reference->digest.len; 5683 5684 if (auth_generate) 5685 memset(sym_op->auth.digest.data, 0, reference->digest.len); 5686 else 5687 memcpy(sym_op->auth.digest.data, 5688 reference->digest.data, 5689 reference->digest.len); 5690 5691 TEST_HEXDUMP(stdout, "digest:", 5692 sym_op->auth.digest.data, 5693 sym_op->auth.digest.length); 5694 5695 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend( 5696 ut_params->ibuf, reference->iv.len); 5697 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv"); 5698 5699 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf); 5700 sym_op->cipher.iv.length = reference->iv.len; 5701 5702 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len); 5703 5704 sym_op->cipher.data.length = reference->ciphertext.len; 5705 sym_op->cipher.data.offset = reference->iv.len; 5706 5707 sym_op->auth.data.length = reference->ciphertext.len; 5708 sym_op->auth.data.offset = reference->iv.len; 5709 5710 return 0; 5711 } 5712 5713 static int 5714 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 5715 struct crypto_unittest_params *ut_params, 5716 const struct test_crypto_vector *reference) 5717 { 5718 return create_auth_operation(ts_params, ut_params, reference, 0); 5719 } 5720 5721 static int 5722 create_auth_verify_GMAC_operation( 5723 struct crypto_testsuite_params *ts_params, 5724 struct crypto_unittest_params *ut_params, 5725 const struct test_crypto_vector *reference) 5726 { 5727 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 5728 } 5729 5730 static int 5731 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 5732 struct crypto_unittest_params *ut_params, 5733 const struct test_crypto_vector *reference) 5734 { 5735 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 5736 } 5737 5738 static int 5739 test_authentication_verify_fail_when_data_corruption( 5740 struct crypto_testsuite_params *ts_params, 5741 struct crypto_unittest_params *ut_params, 5742 const struct test_crypto_vector *reference, 5743 unsigned int data_corrupted) 5744 { 5745 int retval; 5746 5747 uint8_t *plaintext; 5748 5749 /* Create session */ 5750 retval = create_auth_session(ut_params, 5751 ts_params->valid_devs[0], 5752 reference, 5753 RTE_CRYPTO_AUTH_OP_VERIFY); 5754 if (retval < 0) 5755 return retval; 5756 5757 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5758 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5759 "Failed to allocate input buffer in mempool"); 5760 5761 /* clear mbuf payload */ 5762 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5763 rte_pktmbuf_tailroom(ut_params->ibuf)); 5764 5765 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5766 reference->plaintext.len); 5767 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 5768 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 5769 5770 TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len); 5771 5772 /* Create operation */ 5773 retval = create_auth_verify_operation(ts_params, ut_params, reference); 5774 5775 if (retval < 0) 5776 return retval; 5777 5778 if (data_corrupted) 5779 data_corruption(plaintext); 5780 else 5781 tag_corruption(plaintext, reference->plaintext.len); 5782 5783 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5784 ut_params->op); 5785 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 5786 TEST_ASSERT_EQUAL(ut_params->op->status, 5787 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 5788 "authentication not failed"); 5789 5790 ut_params->obuf = ut_params->op->sym->m_src; 5791 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 5792 5793 return 0; 5794 } 5795 5796 static int 5797 test_authentication_verify_GMAC_fail_when_corruption( 5798 struct crypto_testsuite_params *ts_params, 5799 struct crypto_unittest_params *ut_params, 5800 const struct test_crypto_vector *reference, 5801 unsigned int data_corrupted) 5802 { 5803 int retval; 5804 5805 /* Create session */ 5806 retval = create_auth_cipher_session(ut_params, 5807 ts_params->valid_devs[0], 5808 reference, 5809 RTE_CRYPTO_AUTH_OP_VERIFY, 5810 RTE_CRYPTO_CIPHER_OP_DECRYPT); 5811 if (retval < 0) 5812 return retval; 5813 5814 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5815 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5816 "Failed to allocate input buffer in mempool"); 5817 5818 /* clear mbuf payload */ 5819 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5820 rte_pktmbuf_tailroom(ut_params->ibuf)); 5821 5822 /* Create operation */ 5823 retval = create_auth_verify_GMAC_operation(ts_params, 5824 ut_params, 5825 reference); 5826 5827 if (retval < 0) 5828 return retval; 5829 5830 if (data_corrupted) 5831 data_corruption(ut_params->op->sym->auth.aad.data); 5832 else 5833 tag_corruption(ut_params->op->sym->auth.aad.data, 5834 reference->aad.len); 5835 5836 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5837 ut_params->op); 5838 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 5839 TEST_ASSERT_EQUAL(ut_params->op->status, 5840 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 5841 "authentication not failed"); 5842 5843 ut_params->obuf = ut_params->op->sym->m_src; 5844 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 5845 5846 return 0; 5847 } 5848 5849 static int 5850 test_authenticated_decryption_fail_when_corruption( 5851 struct crypto_testsuite_params *ts_params, 5852 struct crypto_unittest_params *ut_params, 5853 const struct test_crypto_vector *reference, 5854 unsigned int data_corrupted) 5855 { 5856 int retval; 5857 5858 uint8_t *ciphertext; 5859 5860 /* Create session */ 5861 retval = create_auth_cipher_session(ut_params, 5862 ts_params->valid_devs[0], 5863 reference, 5864 RTE_CRYPTO_AUTH_OP_VERIFY, 5865 RTE_CRYPTO_CIPHER_OP_DECRYPT); 5866 if (retval < 0) 5867 return retval; 5868 5869 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5870 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5871 "Failed to allocate input buffer in mempool"); 5872 5873 /* clear mbuf payload */ 5874 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5875 rte_pktmbuf_tailroom(ut_params->ibuf)); 5876 5877 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5878 reference->ciphertext.len); 5879 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 5880 memcpy(ciphertext, reference->ciphertext.data, 5881 reference->ciphertext.len); 5882 5883 /* Create operation */ 5884 retval = create_cipher_auth_verify_operation(ts_params, 5885 ut_params, 5886 reference); 5887 5888 if (retval < 0) 5889 return retval; 5890 5891 if (data_corrupted) 5892 data_corruption(ciphertext); 5893 else 5894 tag_corruption(ciphertext, reference->ciphertext.len); 5895 5896 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5897 ut_params->op); 5898 5899 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 5900 TEST_ASSERT_EQUAL(ut_params->op->status, 5901 RTE_CRYPTO_OP_STATUS_AUTH_FAILED, 5902 "authentication not failed"); 5903 5904 ut_params->obuf = ut_params->op->sym->m_src; 5905 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 5906 5907 return 0; 5908 } 5909 5910 static int 5911 test_authentication_verify_fail_when_data_corrupted( 5912 struct crypto_testsuite_params *ts_params, 5913 struct crypto_unittest_params *ut_params, 5914 const struct test_crypto_vector *reference) 5915 { 5916 return test_authentication_verify_fail_when_data_corruption( 5917 ts_params, ut_params, reference, 1); 5918 } 5919 5920 static int 5921 test_authentication_verify_fail_when_tag_corrupted( 5922 struct crypto_testsuite_params *ts_params, 5923 struct crypto_unittest_params *ut_params, 5924 const struct test_crypto_vector *reference) 5925 { 5926 return test_authentication_verify_fail_when_data_corruption( 5927 ts_params, ut_params, reference, 0); 5928 } 5929 5930 static int 5931 test_authentication_verify_GMAC_fail_when_data_corrupted( 5932 struct crypto_testsuite_params *ts_params, 5933 struct crypto_unittest_params *ut_params, 5934 const struct test_crypto_vector *reference) 5935 { 5936 return test_authentication_verify_GMAC_fail_when_corruption( 5937 ts_params, ut_params, reference, 1); 5938 } 5939 5940 static int 5941 test_authentication_verify_GMAC_fail_when_tag_corrupted( 5942 struct crypto_testsuite_params *ts_params, 5943 struct crypto_unittest_params *ut_params, 5944 const struct test_crypto_vector *reference) 5945 { 5946 return test_authentication_verify_GMAC_fail_when_corruption( 5947 ts_params, ut_params, reference, 0); 5948 } 5949 5950 static int 5951 test_authenticated_decryption_fail_when_data_corrupted( 5952 struct crypto_testsuite_params *ts_params, 5953 struct crypto_unittest_params *ut_params, 5954 const struct test_crypto_vector *reference) 5955 { 5956 return test_authenticated_decryption_fail_when_corruption( 5957 ts_params, ut_params, reference, 1); 5958 } 5959 5960 static int 5961 test_authenticated_decryption_fail_when_tag_corrupted( 5962 struct crypto_testsuite_params *ts_params, 5963 struct crypto_unittest_params *ut_params, 5964 const struct test_crypto_vector *reference) 5965 { 5966 return test_authenticated_decryption_fail_when_corruption( 5967 ts_params, ut_params, reference, 0); 5968 } 5969 5970 static int 5971 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 5972 { 5973 return test_authentication_verify_fail_when_data_corrupted( 5974 &testsuite_params, &unittest_params, 5975 &hmac_sha1_test_crypto_vector); 5976 } 5977 5978 static int 5979 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 5980 { 5981 return test_authentication_verify_fail_when_tag_corrupted( 5982 &testsuite_params, &unittest_params, 5983 &hmac_sha1_test_crypto_vector); 5984 } 5985 5986 static int 5987 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 5988 { 5989 return test_authentication_verify_GMAC_fail_when_data_corrupted( 5990 &testsuite_params, &unittest_params, 5991 &aes128_gmac_test_vector); 5992 } 5993 5994 static int 5995 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 5996 { 5997 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 5998 &testsuite_params, &unittest_params, 5999 &aes128_gmac_test_vector); 6000 } 6001 6002 static int 6003 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 6004 { 6005 return test_authenticated_decryption_fail_when_data_corrupted( 6006 &testsuite_params, 6007 &unittest_params, 6008 &aes128cbc_hmac_sha1_test_vector); 6009 } 6010 6011 static int 6012 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 6013 { 6014 return test_authenticated_decryption_fail_when_tag_corrupted( 6015 &testsuite_params, 6016 &unittest_params, 6017 &aes128cbc_hmac_sha1_test_vector); 6018 } 6019 6020 static struct unit_test_suite cryptodev_qat_testsuite = { 6021 .suite_name = "Crypto QAT Unit Test Suite", 6022 .setup = testsuite_setup, 6023 .teardown = testsuite_teardown, 6024 .unit_test_cases = { 6025 TEST_CASE_ST(ut_setup, ut_teardown, 6026 test_device_configure_invalid_dev_id), 6027 TEST_CASE_ST(ut_setup, ut_teardown, 6028 test_device_configure_invalid_queue_pair_ids), 6029 TEST_CASE_ST(ut_setup, ut_teardown, 6030 test_queue_pair_descriptor_setup), 6031 TEST_CASE_ST(ut_setup, ut_teardown, 6032 test_multi_session), 6033 6034 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all), 6035 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all), 6036 TEST_CASE_ST(ut_setup, ut_teardown, 6037 test_3DES_cipheronly_qat_all), 6038 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 6039 6040 /** AES GCM Authenticated Encryption */ 6041 TEST_CASE_ST(ut_setup, ut_teardown, 6042 test_mb_AES_GCM_authenticated_encryption_test_case_1), 6043 TEST_CASE_ST(ut_setup, ut_teardown, 6044 test_mb_AES_GCM_authenticated_encryption_test_case_2), 6045 TEST_CASE_ST(ut_setup, ut_teardown, 6046 test_mb_AES_GCM_authenticated_encryption_test_case_3), 6047 TEST_CASE_ST(ut_setup, ut_teardown, 6048 test_mb_AES_GCM_authenticated_encryption_test_case_4), 6049 TEST_CASE_ST(ut_setup, ut_teardown, 6050 test_mb_AES_GCM_authenticated_encryption_test_case_5), 6051 TEST_CASE_ST(ut_setup, ut_teardown, 6052 test_mb_AES_GCM_authenticated_encryption_test_case_6), 6053 TEST_CASE_ST(ut_setup, ut_teardown, 6054 test_mb_AES_GCM_authenticated_encryption_test_case_7), 6055 6056 /** AES GCM Authenticated Decryption */ 6057 TEST_CASE_ST(ut_setup, ut_teardown, 6058 test_mb_AES_GCM_authenticated_decryption_test_case_1), 6059 TEST_CASE_ST(ut_setup, ut_teardown, 6060 test_mb_AES_GCM_authenticated_decryption_test_case_2), 6061 TEST_CASE_ST(ut_setup, ut_teardown, 6062 test_mb_AES_GCM_authenticated_decryption_test_case_3), 6063 TEST_CASE_ST(ut_setup, ut_teardown, 6064 test_mb_AES_GCM_authenticated_decryption_test_case_4), 6065 TEST_CASE_ST(ut_setup, ut_teardown, 6066 test_mb_AES_GCM_authenticated_decryption_test_case_5), 6067 TEST_CASE_ST(ut_setup, ut_teardown, 6068 test_mb_AES_GCM_authenticated_decryption_test_case_6), 6069 TEST_CASE_ST(ut_setup, ut_teardown, 6070 test_mb_AES_GCM_authenticated_decryption_test_case_7), 6071 6072 /** AES GMAC Authentication */ 6073 TEST_CASE_ST(ut_setup, ut_teardown, 6074 test_AES_GMAC_authentication_test_case_1), 6075 TEST_CASE_ST(ut_setup, ut_teardown, 6076 test_AES_GMAC_authentication_verify_test_case_1), 6077 TEST_CASE_ST(ut_setup, ut_teardown, 6078 test_AES_GMAC_authentication_test_case_2), 6079 TEST_CASE_ST(ut_setup, ut_teardown, 6080 test_AES_GMAC_authentication_verify_test_case_2), 6081 TEST_CASE_ST(ut_setup, ut_teardown, 6082 test_AES_GMAC_authentication_test_case_3), 6083 TEST_CASE_ST(ut_setup, ut_teardown, 6084 test_AES_GMAC_authentication_verify_test_case_3), 6085 6086 /** SNOW 3G encrypt only (UEA2) */ 6087 TEST_CASE_ST(ut_setup, ut_teardown, 6088 test_snow3g_encryption_test_case_1), 6089 TEST_CASE_ST(ut_setup, ut_teardown, 6090 test_snow3g_encryption_test_case_2), 6091 TEST_CASE_ST(ut_setup, ut_teardown, 6092 test_snow3g_encryption_test_case_3), 6093 TEST_CASE_ST(ut_setup, ut_teardown, 6094 test_snow3g_encryption_test_case_4), 6095 TEST_CASE_ST(ut_setup, ut_teardown, 6096 test_snow3g_encryption_test_case_5), 6097 6098 TEST_CASE_ST(ut_setup, ut_teardown, 6099 test_snow3g_encryption_test_case_1_oop), 6100 TEST_CASE_ST(ut_setup, ut_teardown, 6101 test_snow3g_decryption_test_case_1_oop), 6102 6103 /** SNOW 3G decrypt only (UEA2) */ 6104 TEST_CASE_ST(ut_setup, ut_teardown, 6105 test_snow3g_decryption_test_case_1), 6106 TEST_CASE_ST(ut_setup, ut_teardown, 6107 test_snow3g_decryption_test_case_2), 6108 TEST_CASE_ST(ut_setup, ut_teardown, 6109 test_snow3g_decryption_test_case_3), 6110 TEST_CASE_ST(ut_setup, ut_teardown, 6111 test_snow3g_decryption_test_case_4), 6112 TEST_CASE_ST(ut_setup, ut_teardown, 6113 test_snow3g_decryption_test_case_5), 6114 TEST_CASE_ST(ut_setup, ut_teardown, 6115 test_snow3g_hash_generate_test_case_1), 6116 TEST_CASE_ST(ut_setup, ut_teardown, 6117 test_snow3g_hash_generate_test_case_2), 6118 TEST_CASE_ST(ut_setup, ut_teardown, 6119 test_snow3g_hash_generate_test_case_3), 6120 TEST_CASE_ST(ut_setup, ut_teardown, 6121 test_snow3g_hash_verify_test_case_1), 6122 TEST_CASE_ST(ut_setup, ut_teardown, 6123 test_snow3g_hash_verify_test_case_2), 6124 TEST_CASE_ST(ut_setup, ut_teardown, 6125 test_snow3g_hash_verify_test_case_3), 6126 TEST_CASE_ST(ut_setup, ut_teardown, 6127 test_snow3g_cipher_auth_test_case_1), 6128 TEST_CASE_ST(ut_setup, ut_teardown, 6129 test_snow3g_auth_cipher_test_case_1), 6130 6131 /** HMAC_MD5 Authentication */ 6132 TEST_CASE_ST(ut_setup, ut_teardown, 6133 test_MD5_HMAC_generate_case_1), 6134 TEST_CASE_ST(ut_setup, ut_teardown, 6135 test_MD5_HMAC_verify_case_1), 6136 TEST_CASE_ST(ut_setup, ut_teardown, 6137 test_MD5_HMAC_generate_case_2), 6138 TEST_CASE_ST(ut_setup, ut_teardown, 6139 test_MD5_HMAC_verify_case_2), 6140 6141 /** NULL tests */ 6142 TEST_CASE_ST(ut_setup, ut_teardown, 6143 test_null_auth_only_operation), 6144 TEST_CASE_ST(ut_setup, ut_teardown, 6145 test_null_cipher_only_operation), 6146 TEST_CASE_ST(ut_setup, ut_teardown, 6147 test_null_cipher_auth_operation), 6148 TEST_CASE_ST(ut_setup, ut_teardown, 6149 test_null_auth_cipher_operation), 6150 6151 TEST_CASE_ST(ut_setup, ut_teardown, 6152 test_kasumi_hash_generate_test_case_6), 6153 6154 /** KASUMI tests */ 6155 TEST_CASE_ST(ut_setup, ut_teardown, 6156 test_kasumi_encryption_test_case_1), 6157 TEST_CASE_ST(ut_setup, ut_teardown, 6158 test_kasumi_encryption_test_case_3), 6159 TEST_CASE_ST(ut_setup, ut_teardown, 6160 test_kasumi_auth_cipher_test_case_1), 6161 TEST_CASE_ST(ut_setup, ut_teardown, 6162 test_kasumi_cipher_auth_test_case_1), 6163 6164 /** Negative tests */ 6165 TEST_CASE_ST(ut_setup, ut_teardown, 6166 authentication_verify_HMAC_SHA1_fail_data_corrupt), 6167 TEST_CASE_ST(ut_setup, ut_teardown, 6168 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 6169 TEST_CASE_ST(ut_setup, ut_teardown, 6170 authentication_verify_AES128_GMAC_fail_data_corrupt), 6171 TEST_CASE_ST(ut_setup, ut_teardown, 6172 authentication_verify_AES128_GMAC_fail_tag_corrupt), 6173 TEST_CASE_ST(ut_setup, ut_teardown, 6174 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 6175 TEST_CASE_ST(ut_setup, ut_teardown, 6176 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 6177 6178 TEST_CASES_END() /**< NULL terminate unit test array */ 6179 } 6180 }; 6181 6182 static struct unit_test_suite cryptodev_aesni_mb_testsuite = { 6183 .suite_name = "Crypto Device AESNI MB Unit Test Suite", 6184 .setup = testsuite_setup, 6185 .teardown = testsuite_teardown, 6186 .unit_test_cases = { 6187 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all), 6188 6189 TEST_CASES_END() /**< NULL terminate unit test array */ 6190 } 6191 }; 6192 6193 static struct unit_test_suite cryptodev_libcrypto_testsuite = { 6194 .suite_name = "Crypto Device LIBCRYPTO Unit Test Suite", 6195 .setup = testsuite_setup, 6196 .teardown = testsuite_teardown, 6197 .unit_test_cases = { 6198 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 6199 TEST_CASE_ST(ut_setup, ut_teardown, 6200 test_multi_session_random_usage), 6201 TEST_CASE_ST(ut_setup, ut_teardown, 6202 test_AES_chain_libcrypto_all), 6203 TEST_CASE_ST(ut_setup, ut_teardown, 6204 test_AES_cipheronly_libcrypto_all), 6205 TEST_CASE_ST(ut_setup, ut_teardown, 6206 test_3DES_chain_libcrypto_all), 6207 TEST_CASE_ST(ut_setup, ut_teardown, 6208 test_3DES_cipheronly_libcrypto_all), 6209 TEST_CASE_ST(ut_setup, ut_teardown, 6210 test_authonly_libcrypto_all), 6211 6212 /** AES GCM Authenticated Encryption */ 6213 TEST_CASE_ST(ut_setup, ut_teardown, 6214 test_mb_AES_GCM_authenticated_encryption_test_case_1), 6215 TEST_CASE_ST(ut_setup, ut_teardown, 6216 test_mb_AES_GCM_authenticated_encryption_test_case_2), 6217 TEST_CASE_ST(ut_setup, ut_teardown, 6218 test_mb_AES_GCM_authenticated_encryption_test_case_3), 6219 TEST_CASE_ST(ut_setup, ut_teardown, 6220 test_mb_AES_GCM_authenticated_encryption_test_case_4), 6221 TEST_CASE_ST(ut_setup, ut_teardown, 6222 test_mb_AES_GCM_authenticated_encryption_test_case_5), 6223 TEST_CASE_ST(ut_setup, ut_teardown, 6224 test_mb_AES_GCM_authenticated_encryption_test_case_6), 6225 TEST_CASE_ST(ut_setup, ut_teardown, 6226 test_mb_AES_GCM_authenticated_encryption_test_case_7), 6227 6228 /** AES GCM Authenticated Decryption */ 6229 TEST_CASE_ST(ut_setup, ut_teardown, 6230 test_mb_AES_GCM_authenticated_decryption_test_case_1), 6231 TEST_CASE_ST(ut_setup, ut_teardown, 6232 test_mb_AES_GCM_authenticated_decryption_test_case_2), 6233 TEST_CASE_ST(ut_setup, ut_teardown, 6234 test_mb_AES_GCM_authenticated_decryption_test_case_3), 6235 TEST_CASE_ST(ut_setup, ut_teardown, 6236 test_mb_AES_GCM_authenticated_decryption_test_case_4), 6237 TEST_CASE_ST(ut_setup, ut_teardown, 6238 test_mb_AES_GCM_authenticated_decryption_test_case_5), 6239 TEST_CASE_ST(ut_setup, ut_teardown, 6240 test_mb_AES_GCM_authenticated_decryption_test_case_6), 6241 TEST_CASE_ST(ut_setup, ut_teardown, 6242 test_mb_AES_GCM_authenticated_decryption_test_case_7), 6243 6244 /** AES GMAC Authentication */ 6245 TEST_CASE_ST(ut_setup, ut_teardown, 6246 test_AES_GMAC_authentication_test_case_1), 6247 TEST_CASE_ST(ut_setup, ut_teardown, 6248 test_AES_GMAC_authentication_verify_test_case_1), 6249 TEST_CASE_ST(ut_setup, ut_teardown, 6250 test_AES_GMAC_authentication_test_case_2), 6251 TEST_CASE_ST(ut_setup, ut_teardown, 6252 test_AES_GMAC_authentication_verify_test_case_2), 6253 TEST_CASE_ST(ut_setup, ut_teardown, 6254 test_AES_GMAC_authentication_test_case_3), 6255 TEST_CASE_ST(ut_setup, ut_teardown, 6256 test_AES_GMAC_authentication_verify_test_case_3), 6257 TEST_CASE_ST(ut_setup, ut_teardown, 6258 test_AES_GMAC_authentication_test_case_4), 6259 TEST_CASE_ST(ut_setup, ut_teardown, 6260 test_AES_GMAC_authentication_verify_test_case_4), 6261 6262 /** Negative tests */ 6263 TEST_CASE_ST(ut_setup, ut_teardown, 6264 authentication_verify_HMAC_SHA1_fail_data_corrupt), 6265 TEST_CASE_ST(ut_setup, ut_teardown, 6266 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 6267 TEST_CASE_ST(ut_setup, ut_teardown, 6268 authentication_verify_AES128_GMAC_fail_data_corrupt), 6269 TEST_CASE_ST(ut_setup, ut_teardown, 6270 authentication_verify_AES128_GMAC_fail_tag_corrupt), 6271 TEST_CASE_ST(ut_setup, ut_teardown, 6272 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 6273 TEST_CASE_ST(ut_setup, ut_teardown, 6274 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 6275 6276 TEST_CASES_END() /**< NULL terminate unit test array */ 6277 } 6278 }; 6279 6280 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = { 6281 .suite_name = "Crypto Device AESNI GCM Unit Test Suite", 6282 .setup = testsuite_setup, 6283 .teardown = testsuite_teardown, 6284 .unit_test_cases = { 6285 /** AES GCM Authenticated Encryption */ 6286 TEST_CASE_ST(ut_setup, ut_teardown, 6287 test_mb_AES_GCM_authenticated_encryption_test_case_1), 6288 TEST_CASE_ST(ut_setup, ut_teardown, 6289 test_mb_AES_GCM_authenticated_encryption_test_case_2), 6290 TEST_CASE_ST(ut_setup, ut_teardown, 6291 test_mb_AES_GCM_authenticated_encryption_test_case_3), 6292 TEST_CASE_ST(ut_setup, ut_teardown, 6293 test_mb_AES_GCM_authenticated_encryption_test_case_4), 6294 TEST_CASE_ST(ut_setup, ut_teardown, 6295 test_mb_AES_GCM_authenticated_encryption_test_case_5), 6296 TEST_CASE_ST(ut_setup, ut_teardown, 6297 test_mb_AES_GCM_authenticated_encryption_test_case_6), 6298 TEST_CASE_ST(ut_setup, ut_teardown, 6299 test_mb_AES_GCM_authenticated_encryption_test_case_7), 6300 6301 /** AES GCM Authenticated Decryption */ 6302 TEST_CASE_ST(ut_setup, ut_teardown, 6303 test_mb_AES_GCM_authenticated_decryption_test_case_1), 6304 TEST_CASE_ST(ut_setup, ut_teardown, 6305 test_mb_AES_GCM_authenticated_decryption_test_case_2), 6306 TEST_CASE_ST(ut_setup, ut_teardown, 6307 test_mb_AES_GCM_authenticated_decryption_test_case_3), 6308 TEST_CASE_ST(ut_setup, ut_teardown, 6309 test_mb_AES_GCM_authenticated_decryption_test_case_4), 6310 TEST_CASE_ST(ut_setup, ut_teardown, 6311 test_mb_AES_GCM_authenticated_decryption_test_case_5), 6312 TEST_CASE_ST(ut_setup, ut_teardown, 6313 test_mb_AES_GCM_authenticated_decryption_test_case_6), 6314 TEST_CASE_ST(ut_setup, ut_teardown, 6315 test_mb_AES_GCM_authenticated_decryption_test_case_7), 6316 6317 TEST_CASES_END() /**< NULL terminate unit test array */ 6318 } 6319 }; 6320 6321 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = { 6322 .suite_name = "Crypto Device SW KASUMI Unit Test Suite", 6323 .setup = testsuite_setup, 6324 .teardown = testsuite_teardown, 6325 .unit_test_cases = { 6326 /** KASUMI encrypt only (UEA1) */ 6327 TEST_CASE_ST(ut_setup, ut_teardown, 6328 test_kasumi_encryption_test_case_1), 6329 TEST_CASE_ST(ut_setup, ut_teardown, 6330 test_kasumi_encryption_test_case_2), 6331 TEST_CASE_ST(ut_setup, ut_teardown, 6332 test_kasumi_encryption_test_case_3), 6333 TEST_CASE_ST(ut_setup, ut_teardown, 6334 test_kasumi_encryption_test_case_4), 6335 TEST_CASE_ST(ut_setup, ut_teardown, 6336 test_kasumi_encryption_test_case_5), 6337 /** KASUMI decrypt only (UEA1) */ 6338 TEST_CASE_ST(ut_setup, ut_teardown, 6339 test_kasumi_decryption_test_case_1), 6340 TEST_CASE_ST(ut_setup, ut_teardown, 6341 test_kasumi_decryption_test_case_2), 6342 TEST_CASE_ST(ut_setup, ut_teardown, 6343 test_kasumi_decryption_test_case_3), 6344 TEST_CASE_ST(ut_setup, ut_teardown, 6345 test_kasumi_decryption_test_case_4), 6346 TEST_CASE_ST(ut_setup, ut_teardown, 6347 test_kasumi_decryption_test_case_5), 6348 6349 TEST_CASE_ST(ut_setup, ut_teardown, 6350 test_kasumi_encryption_test_case_1_oop), 6351 TEST_CASE_ST(ut_setup, ut_teardown, 6352 test_kasumi_decryption_test_case_1_oop), 6353 6354 /** KASUMI hash only (UIA1) */ 6355 TEST_CASE_ST(ut_setup, ut_teardown, 6356 test_kasumi_hash_generate_test_case_1), 6357 TEST_CASE_ST(ut_setup, ut_teardown, 6358 test_kasumi_hash_generate_test_case_2), 6359 TEST_CASE_ST(ut_setup, ut_teardown, 6360 test_kasumi_hash_generate_test_case_3), 6361 TEST_CASE_ST(ut_setup, ut_teardown, 6362 test_kasumi_hash_generate_test_case_4), 6363 TEST_CASE_ST(ut_setup, ut_teardown, 6364 test_kasumi_hash_generate_test_case_5), 6365 TEST_CASE_ST(ut_setup, ut_teardown, 6366 test_kasumi_hash_generate_test_case_6), 6367 TEST_CASE_ST(ut_setup, ut_teardown, 6368 test_kasumi_hash_verify_test_case_1), 6369 TEST_CASE_ST(ut_setup, ut_teardown, 6370 test_kasumi_hash_verify_test_case_2), 6371 TEST_CASE_ST(ut_setup, ut_teardown, 6372 test_kasumi_hash_verify_test_case_3), 6373 TEST_CASE_ST(ut_setup, ut_teardown, 6374 test_kasumi_hash_verify_test_case_4), 6375 TEST_CASE_ST(ut_setup, ut_teardown, 6376 test_kasumi_hash_verify_test_case_5), 6377 TEST_CASE_ST(ut_setup, ut_teardown, 6378 test_kasumi_auth_cipher_test_case_1), 6379 TEST_CASE_ST(ut_setup, ut_teardown, 6380 test_kasumi_cipher_auth_test_case_1), 6381 TEST_CASES_END() /**< NULL terminate unit test array */ 6382 } 6383 }; 6384 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = { 6385 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite", 6386 .setup = testsuite_setup, 6387 .teardown = testsuite_teardown, 6388 .unit_test_cases = { 6389 /** SNOW 3G encrypt only (UEA2) */ 6390 TEST_CASE_ST(ut_setup, ut_teardown, 6391 test_snow3g_encryption_test_case_1), 6392 TEST_CASE_ST(ut_setup, ut_teardown, 6393 test_snow3g_encryption_test_case_2), 6394 TEST_CASE_ST(ut_setup, ut_teardown, 6395 test_snow3g_encryption_test_case_3), 6396 TEST_CASE_ST(ut_setup, ut_teardown, 6397 test_snow3g_encryption_test_case_4), 6398 TEST_CASE_ST(ut_setup, ut_teardown, 6399 test_snow3g_encryption_test_case_5), 6400 6401 TEST_CASE_ST(ut_setup, ut_teardown, 6402 test_snow3g_encryption_test_case_1_oop), 6403 TEST_CASE_ST(ut_setup, ut_teardown, 6404 test_snow3g_decryption_test_case_1_oop), 6405 6406 TEST_CASE_ST(ut_setup, ut_teardown, 6407 test_snow3g_encryption_test_case_1_offset_oop), 6408 6409 /** SNOW 3G decrypt only (UEA2) */ 6410 TEST_CASE_ST(ut_setup, ut_teardown, 6411 test_snow3g_decryption_test_case_1), 6412 TEST_CASE_ST(ut_setup, ut_teardown, 6413 test_snow3g_decryption_test_case_2), 6414 TEST_CASE_ST(ut_setup, ut_teardown, 6415 test_snow3g_decryption_test_case_3), 6416 TEST_CASE_ST(ut_setup, ut_teardown, 6417 test_snow3g_decryption_test_case_4), 6418 TEST_CASE_ST(ut_setup, ut_teardown, 6419 test_snow3g_decryption_test_case_5), 6420 TEST_CASE_ST(ut_setup, ut_teardown, 6421 test_snow3g_hash_generate_test_case_1), 6422 TEST_CASE_ST(ut_setup, ut_teardown, 6423 test_snow3g_hash_generate_test_case_2), 6424 TEST_CASE_ST(ut_setup, ut_teardown, 6425 test_snow3g_hash_generate_test_case_3), 6426 /* Tests with buffers which length is not byte-aligned */ 6427 TEST_CASE_ST(ut_setup, ut_teardown, 6428 test_snow3g_hash_generate_test_case_4), 6429 TEST_CASE_ST(ut_setup, ut_teardown, 6430 test_snow3g_hash_generate_test_case_5), 6431 TEST_CASE_ST(ut_setup, ut_teardown, 6432 test_snow3g_hash_generate_test_case_6), 6433 TEST_CASE_ST(ut_setup, ut_teardown, 6434 test_snow3g_hash_verify_test_case_1), 6435 TEST_CASE_ST(ut_setup, ut_teardown, 6436 test_snow3g_hash_verify_test_case_2), 6437 TEST_CASE_ST(ut_setup, ut_teardown, 6438 test_snow3g_hash_verify_test_case_3), 6439 /* Tests with buffers which length is not byte-aligned */ 6440 TEST_CASE_ST(ut_setup, ut_teardown, 6441 test_snow3g_hash_verify_test_case_4), 6442 TEST_CASE_ST(ut_setup, ut_teardown, 6443 test_snow3g_hash_verify_test_case_5), 6444 TEST_CASE_ST(ut_setup, ut_teardown, 6445 test_snow3g_hash_verify_test_case_6), 6446 TEST_CASE_ST(ut_setup, ut_teardown, 6447 test_snow3g_cipher_auth_test_case_1), 6448 TEST_CASE_ST(ut_setup, ut_teardown, 6449 test_snow3g_auth_cipher_test_case_1), 6450 6451 TEST_CASES_END() /**< NULL terminate unit test array */ 6452 } 6453 }; 6454 6455 static struct unit_test_suite cryptodev_sw_zuc_testsuite = { 6456 .suite_name = "Crypto Device SW ZUC Unit Test Suite", 6457 .setup = testsuite_setup, 6458 .teardown = testsuite_teardown, 6459 .unit_test_cases = { 6460 /** ZUC encrypt only (EEA3) */ 6461 TEST_CASE_ST(ut_setup, ut_teardown, 6462 test_zuc_encryption_test_case_1), 6463 TEST_CASE_ST(ut_setup, ut_teardown, 6464 test_zuc_encryption_test_case_2), 6465 TEST_CASE_ST(ut_setup, ut_teardown, 6466 test_zuc_encryption_test_case_3), 6467 TEST_CASE_ST(ut_setup, ut_teardown, 6468 test_zuc_encryption_test_case_4), 6469 TEST_CASE_ST(ut_setup, ut_teardown, 6470 test_zuc_encryption_test_case_5), 6471 TEST_CASE_ST(ut_setup, ut_teardown, 6472 test_zuc_hash_generate_test_case_1), 6473 TEST_CASE_ST(ut_setup, ut_teardown, 6474 test_zuc_hash_generate_test_case_2), 6475 TEST_CASE_ST(ut_setup, ut_teardown, 6476 test_zuc_hash_generate_test_case_3), 6477 TEST_CASE_ST(ut_setup, ut_teardown, 6478 test_zuc_hash_generate_test_case_4), 6479 TEST_CASE_ST(ut_setup, ut_teardown, 6480 test_zuc_hash_generate_test_case_5), 6481 TEST_CASES_END() /**< NULL terminate unit test array */ 6482 } 6483 }; 6484 6485 static struct unit_test_suite cryptodev_null_testsuite = { 6486 .suite_name = "Crypto Device NULL Unit Test Suite", 6487 .setup = testsuite_setup, 6488 .teardown = testsuite_teardown, 6489 .unit_test_cases = { 6490 TEST_CASE_ST(ut_setup, ut_teardown, 6491 test_null_auth_only_operation), 6492 TEST_CASE_ST(ut_setup, ut_teardown, 6493 test_null_cipher_only_operation), 6494 TEST_CASE_ST(ut_setup, ut_teardown, 6495 test_null_cipher_auth_operation), 6496 TEST_CASE_ST(ut_setup, ut_teardown, 6497 test_null_auth_cipher_operation), 6498 TEST_CASE_ST(ut_setup, ut_teardown, 6499 test_null_invalid_operation), 6500 TEST_CASE_ST(ut_setup, ut_teardown, 6501 test_null_burst_operation), 6502 6503 TEST_CASES_END() /**< NULL terminate unit test array */ 6504 } 6505 }; 6506 6507 static int 6508 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 6509 { 6510 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD; 6511 return unit_test_suite_runner(&cryptodev_qat_testsuite); 6512 } 6513 6514 static int 6515 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 6516 { 6517 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD; 6518 6519 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite); 6520 } 6521 6522 static int 6523 test_cryptodev_libcrypto(void) 6524 { 6525 gbl_cryptodev_type = RTE_CRYPTODEV_LIBCRYPTO_PMD; 6526 6527 return unit_test_suite_runner(&cryptodev_libcrypto_testsuite); 6528 } 6529 6530 static int 6531 test_cryptodev_aesni_gcm(void) 6532 { 6533 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD; 6534 6535 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite); 6536 } 6537 6538 static int 6539 test_cryptodev_null(void) 6540 { 6541 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD; 6542 6543 return unit_test_suite_runner(&cryptodev_null_testsuite); 6544 } 6545 6546 static int 6547 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 6548 { 6549 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD; 6550 6551 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite); 6552 } 6553 6554 static int 6555 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 6556 { 6557 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD; 6558 6559 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite); 6560 } 6561 6562 static int 6563 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 6564 { 6565 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD; 6566 6567 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite); 6568 } 6569 6570 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 6571 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 6572 REGISTER_TEST_COMMAND(cryptodev_libcrypto_autotest, test_cryptodev_libcrypto); 6573 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 6574 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 6575 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 6576 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 6577 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 6578