1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 */ 4 5 #include <time.h> 6 7 #include <rte_common.h> 8 #include <rte_hexdump.h> 9 #include <rte_mbuf.h> 10 #include <rte_malloc.h> 11 #include <rte_memcpy.h> 12 #include <rte_pause.h> 13 #include <rte_bus_vdev.h> 14 15 #include <rte_crypto.h> 16 #include <rte_cryptodev.h> 17 #include <rte_cryptodev_pmd.h> 18 #include <rte_string_fns.h> 19 20 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 21 #include <rte_cryptodev_scheduler.h> 22 #include <rte_cryptodev_scheduler_operations.h> 23 #endif 24 25 #include <rte_lcore.h> 26 27 #include "test.h" 28 #include "test_cryptodev.h" 29 30 #include "test_cryptodev_blockcipher.h" 31 #include "test_cryptodev_aes_test_vectors.h" 32 #include "test_cryptodev_des_test_vectors.h" 33 #include "test_cryptodev_hash_test_vectors.h" 34 #include "test_cryptodev_kasumi_test_vectors.h" 35 #include "test_cryptodev_kasumi_hash_test_vectors.h" 36 #include "test_cryptodev_snow3g_test_vectors.h" 37 #include "test_cryptodev_snow3g_hash_test_vectors.h" 38 #include "test_cryptodev_zuc_test_vectors.h" 39 #include "test_cryptodev_aead_test_vectors.h" 40 #include "test_cryptodev_hmac_test_vectors.h" 41 #include "test_cryptodev_mixed_test_vectors.h" 42 #ifdef RTE_LIBRTE_SECURITY 43 #include "test_cryptodev_security_pdcp_test_vectors.h" 44 #include "test_cryptodev_security_pdcp_test_func.h" 45 #endif 46 47 #define VDEV_ARGS_SIZE 100 48 #define MAX_NB_SESSIONS 4 49 50 #define IN_PLACE 0 51 #define OUT_OF_PLACE 1 52 53 static int gbl_driver_id; 54 55 static enum rte_security_session_action_type gbl_action_type = 56 RTE_SECURITY_ACTION_TYPE_NONE; 57 58 struct crypto_testsuite_params { 59 struct rte_mempool *mbuf_pool; 60 struct rte_mempool *large_mbuf_pool; 61 struct rte_mempool *op_mpool; 62 struct rte_mempool *session_mpool; 63 struct rte_mempool *session_priv_mpool; 64 struct rte_cryptodev_config conf; 65 struct rte_cryptodev_qp_conf qp_conf; 66 67 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 68 uint8_t valid_dev_count; 69 }; 70 71 struct crypto_unittest_params { 72 struct rte_crypto_sym_xform cipher_xform; 73 struct rte_crypto_sym_xform auth_xform; 74 struct rte_crypto_sym_xform aead_xform; 75 76 union { 77 struct rte_cryptodev_sym_session *sess; 78 #ifdef RTE_LIBRTE_SECURITY 79 struct rte_security_session *sec_session; 80 #endif 81 }; 82 #ifdef RTE_LIBRTE_SECURITY 83 enum rte_security_session_action_type type; 84 #endif 85 struct rte_crypto_op *op; 86 87 struct rte_mbuf *obuf, *ibuf; 88 89 uint8_t *digest; 90 }; 91 92 #define ALIGN_POW2_ROUNDUP(num, align) \ 93 (((num) + (align) - 1) & ~((align) - 1)) 94 95 /* 96 * Forward declarations. 97 */ 98 static int 99 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 100 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 101 uint8_t *hmac_key); 102 103 static int 104 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 105 struct crypto_unittest_params *ut_params, 106 struct crypto_testsuite_params *ts_param, 107 const uint8_t *cipher, 108 const uint8_t *digest, 109 const uint8_t *iv); 110 111 static struct rte_mbuf * 112 setup_test_string(struct rte_mempool *mpool, 113 const char *string, size_t len, uint8_t blocksize) 114 { 115 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 116 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 117 118 memset(m->buf_addr, 0, m->buf_len); 119 if (m) { 120 char *dst = rte_pktmbuf_append(m, t_len); 121 122 if (!dst) { 123 rte_pktmbuf_free(m); 124 return NULL; 125 } 126 if (string != NULL) 127 rte_memcpy(dst, string, t_len); 128 else 129 memset(dst, 0, t_len); 130 } 131 132 return m; 133 } 134 135 /* Get number of bytes in X bits (rounding up) */ 136 static uint32_t 137 ceil_byte_length(uint32_t num_bits) 138 { 139 if (num_bits % 8) 140 return ((num_bits >> 3) + 1); 141 else 142 return (num_bits >> 3); 143 } 144 145 static void 146 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 147 { 148 int32_t n, st; 149 void *iv; 150 struct rte_crypto_sym_op *sop; 151 union rte_crypto_sym_ofs ofs; 152 struct rte_crypto_sgl sgl; 153 struct rte_crypto_sym_vec symvec; 154 struct rte_crypto_vec vec[UINT8_MAX]; 155 156 sop = op->sym; 157 158 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 159 sop->aead.data.length, vec, RTE_DIM(vec)); 160 161 if (n < 0 || n != sop->m_src->nb_segs) { 162 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 163 return; 164 } 165 166 sgl.vec = vec; 167 sgl.num = n; 168 symvec.sgl = &sgl; 169 iv = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 170 symvec.iv = &iv; 171 symvec.aad = (void **)&sop->aead.aad.data; 172 symvec.digest = (void **)&sop->aead.digest.data; 173 symvec.status = &st; 174 symvec.num = 1; 175 176 ofs.raw = 0; 177 178 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 179 &symvec); 180 181 if (n != 1) 182 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 183 else 184 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 185 } 186 187 static void 188 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 189 { 190 int32_t n, st; 191 void *iv; 192 struct rte_crypto_sym_op *sop; 193 union rte_crypto_sym_ofs ofs; 194 struct rte_crypto_sgl sgl; 195 struct rte_crypto_sym_vec symvec; 196 struct rte_crypto_vec vec[UINT8_MAX]; 197 198 sop = op->sym; 199 200 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 201 sop->auth.data.length, vec, RTE_DIM(vec)); 202 203 if (n < 0 || n != sop->m_src->nb_segs) { 204 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 205 return; 206 } 207 208 sgl.vec = vec; 209 sgl.num = n; 210 symvec.sgl = &sgl; 211 iv = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 212 symvec.iv = &iv; 213 symvec.aad = (void **)&sop->aead.aad.data; 214 symvec.digest = (void **)&sop->auth.digest.data; 215 symvec.status = &st; 216 symvec.num = 1; 217 218 ofs.raw = 0; 219 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 220 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 221 (sop->cipher.data.offset + sop->cipher.data.length); 222 223 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 224 &symvec); 225 226 if (n != 1) 227 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 228 else 229 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 230 } 231 232 static struct rte_crypto_op * 233 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 234 { 235 236 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 237 238 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 239 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 240 return NULL; 241 } 242 243 op = NULL; 244 245 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 246 rte_pause(); 247 248 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 249 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 250 return NULL; 251 } 252 253 return op; 254 } 255 256 static struct crypto_testsuite_params testsuite_params = { NULL }; 257 static struct crypto_unittest_params unittest_params; 258 259 static int 260 testsuite_setup(void) 261 { 262 struct crypto_testsuite_params *ts_params = &testsuite_params; 263 struct rte_cryptodev_info info; 264 uint32_t i = 0, nb_devs, dev_id; 265 int ret; 266 uint16_t qp_id; 267 268 memset(ts_params, 0, sizeof(*ts_params)); 269 270 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 271 if (ts_params->mbuf_pool == NULL) { 272 /* Not already created so create */ 273 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 274 "CRYPTO_MBUFPOOL", 275 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 276 rte_socket_id()); 277 if (ts_params->mbuf_pool == NULL) { 278 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 279 return TEST_FAILED; 280 } 281 } 282 283 ts_params->large_mbuf_pool = rte_mempool_lookup( 284 "CRYPTO_LARGE_MBUFPOOL"); 285 if (ts_params->large_mbuf_pool == NULL) { 286 /* Not already created so create */ 287 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 288 "CRYPTO_LARGE_MBUFPOOL", 289 1, 0, 0, UINT16_MAX, 290 rte_socket_id()); 291 if (ts_params->large_mbuf_pool == NULL) { 292 RTE_LOG(ERR, USER1, 293 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 294 return TEST_FAILED; 295 } 296 } 297 298 ts_params->op_mpool = rte_crypto_op_pool_create( 299 "MBUF_CRYPTO_SYM_OP_POOL", 300 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 301 NUM_MBUFS, MBUF_CACHE_SIZE, 302 DEFAULT_NUM_XFORMS * 303 sizeof(struct rte_crypto_sym_xform) + 304 MAXIMUM_IV_LENGTH, 305 rte_socket_id()); 306 if (ts_params->op_mpool == NULL) { 307 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 308 return TEST_FAILED; 309 } 310 311 /* Create an AESNI MB device if required */ 312 if (gbl_driver_id == rte_cryptodev_driver_id_get( 313 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) { 314 nb_devs = rte_cryptodev_device_count_by_driver( 315 rte_cryptodev_driver_id_get( 316 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 317 if (nb_devs < 1) { 318 ret = rte_vdev_init( 319 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 320 321 TEST_ASSERT(ret == 0, 322 "Failed to create instance of" 323 " pmd : %s", 324 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 325 } 326 } 327 328 /* Create an AESNI GCM device if required */ 329 if (gbl_driver_id == rte_cryptodev_driver_id_get( 330 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) { 331 nb_devs = rte_cryptodev_device_count_by_driver( 332 rte_cryptodev_driver_id_get( 333 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))); 334 if (nb_devs < 1) { 335 TEST_ASSERT_SUCCESS(rte_vdev_init( 336 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 337 "Failed to create instance of" 338 " pmd : %s", 339 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 340 } 341 } 342 343 /* Create a SNOW 3G device if required */ 344 if (gbl_driver_id == rte_cryptodev_driver_id_get( 345 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) { 346 nb_devs = rte_cryptodev_device_count_by_driver( 347 rte_cryptodev_driver_id_get( 348 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))); 349 if (nb_devs < 1) { 350 TEST_ASSERT_SUCCESS(rte_vdev_init( 351 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 352 "Failed to create instance of" 353 " pmd : %s", 354 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 355 } 356 } 357 358 /* Create a KASUMI device if required */ 359 if (gbl_driver_id == rte_cryptodev_driver_id_get( 360 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) { 361 nb_devs = rte_cryptodev_device_count_by_driver( 362 rte_cryptodev_driver_id_get( 363 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))); 364 if (nb_devs < 1) { 365 TEST_ASSERT_SUCCESS(rte_vdev_init( 366 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 367 "Failed to create instance of" 368 " pmd : %s", 369 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 370 } 371 } 372 373 /* Create a ZUC device if required */ 374 if (gbl_driver_id == rte_cryptodev_driver_id_get( 375 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) { 376 nb_devs = rte_cryptodev_device_count_by_driver( 377 rte_cryptodev_driver_id_get( 378 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))); 379 if (nb_devs < 1) { 380 TEST_ASSERT_SUCCESS(rte_vdev_init( 381 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 382 "Failed to create instance of" 383 " pmd : %s", 384 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 385 } 386 } 387 388 /* Create a NULL device if required */ 389 if (gbl_driver_id == rte_cryptodev_driver_id_get( 390 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) { 391 nb_devs = rte_cryptodev_device_count_by_driver( 392 rte_cryptodev_driver_id_get( 393 RTE_STR(CRYPTODEV_NAME_NULL_PMD))); 394 if (nb_devs < 1) { 395 ret = rte_vdev_init( 396 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 397 398 TEST_ASSERT(ret == 0, 399 "Failed to create instance of" 400 " pmd : %s", 401 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 402 } 403 } 404 405 /* Create an OPENSSL device if required */ 406 if (gbl_driver_id == rte_cryptodev_driver_id_get( 407 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 408 nb_devs = rte_cryptodev_device_count_by_driver( 409 rte_cryptodev_driver_id_get( 410 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 411 if (nb_devs < 1) { 412 ret = rte_vdev_init( 413 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 414 NULL); 415 416 TEST_ASSERT(ret == 0, "Failed to create " 417 "instance of pmd : %s", 418 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 419 } 420 } 421 422 /* Create a ARMv8 device if required */ 423 if (gbl_driver_id == rte_cryptodev_driver_id_get( 424 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) { 425 nb_devs = rte_cryptodev_device_count_by_driver( 426 rte_cryptodev_driver_id_get( 427 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))); 428 if (nb_devs < 1) { 429 ret = rte_vdev_init( 430 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 431 NULL); 432 433 TEST_ASSERT(ret == 0, "Failed to create " 434 "instance of pmd : %s", 435 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 436 } 437 } 438 439 /* Create a MVSAM device if required */ 440 if (gbl_driver_id == rte_cryptodev_driver_id_get( 441 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) { 442 nb_devs = rte_cryptodev_device_count_by_driver( 443 rte_cryptodev_driver_id_get( 444 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))); 445 if (nb_devs < 1) { 446 ret = rte_vdev_init( 447 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD), 448 NULL); 449 450 TEST_ASSERT(ret == 0, "Failed to create " 451 "instance of pmd : %s", 452 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 453 } 454 } 455 456 /* Create an CCP device if required */ 457 if (gbl_driver_id == rte_cryptodev_driver_id_get( 458 RTE_STR(CRYPTODEV_NAME_CCP_PMD))) { 459 nb_devs = rte_cryptodev_device_count_by_driver( 460 rte_cryptodev_driver_id_get( 461 RTE_STR(CRYPTODEV_NAME_CCP_PMD))); 462 if (nb_devs < 1) { 463 ret = rte_vdev_init( 464 RTE_STR(CRYPTODEV_NAME_CCP_PMD), 465 NULL); 466 467 TEST_ASSERT(ret == 0, "Failed to create " 468 "instance of pmd : %s", 469 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 470 } 471 } 472 473 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 474 char vdev_args[VDEV_ARGS_SIZE] = {""}; 475 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 476 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 477 uint16_t slave_core_count = 0; 478 uint16_t socket_id = 0; 479 480 if (gbl_driver_id == rte_cryptodev_driver_id_get( 481 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 482 483 /* Identify the Slave Cores 484 * Use 2 slave cores for the device args 485 */ 486 RTE_LCORE_FOREACH_SLAVE(i) { 487 if (slave_core_count > 1) 488 break; 489 snprintf(vdev_args, sizeof(vdev_args), 490 "%s%d", temp_str, i); 491 strcpy(temp_str, vdev_args); 492 strlcat(temp_str, ";", sizeof(temp_str)); 493 slave_core_count++; 494 socket_id = rte_lcore_to_socket_id(i); 495 } 496 if (slave_core_count != 2) { 497 RTE_LOG(ERR, USER1, 498 "Cryptodev scheduler test require at least " 499 "two slave cores to run. " 500 "Please use the correct coremask.\n"); 501 return TEST_FAILED; 502 } 503 strcpy(temp_str, vdev_args); 504 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 505 temp_str, socket_id); 506 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 507 nb_devs = rte_cryptodev_device_count_by_driver( 508 rte_cryptodev_driver_id_get( 509 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 510 if (nb_devs < 1) { 511 ret = rte_vdev_init( 512 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 513 vdev_args); 514 TEST_ASSERT(ret == 0, 515 "Failed to create instance %u of" 516 " pmd : %s", 517 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 518 } 519 } 520 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */ 521 522 nb_devs = rte_cryptodev_count(); 523 if (nb_devs < 1) { 524 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 525 return TEST_SKIPPED; 526 } 527 528 /* Create list of valid crypto devs */ 529 for (i = 0; i < nb_devs; i++) { 530 rte_cryptodev_info_get(i, &info); 531 if (info.driver_id == gbl_driver_id) 532 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 533 } 534 535 if (ts_params->valid_dev_count < 1) 536 return TEST_FAILED; 537 538 /* Set up all the qps on the first of the valid devices found */ 539 540 dev_id = ts_params->valid_devs[0]; 541 542 rte_cryptodev_info_get(dev_id, &info); 543 544 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 545 ts_params->conf.socket_id = SOCKET_ID_ANY; 546 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 547 548 unsigned int session_size = 549 rte_cryptodev_sym_get_private_session_size(dev_id); 550 551 /* 552 * Create mempool with maximum number of sessions * 2, 553 * to include the session headers 554 */ 555 if (info.sym.max_nb_sessions != 0 && 556 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 557 RTE_LOG(ERR, USER1, "Device does not support " 558 "at least %u sessions\n", 559 MAX_NB_SESSIONS); 560 return TEST_FAILED; 561 } 562 563 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 564 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 565 SOCKET_ID_ANY); 566 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 567 "session mempool allocation failed"); 568 569 ts_params->session_priv_mpool = rte_mempool_create( 570 "test_sess_mp_priv", 571 MAX_NB_SESSIONS, 572 session_size, 573 0, 0, NULL, NULL, NULL, 574 NULL, SOCKET_ID_ANY, 575 0); 576 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 577 "session mempool allocation failed"); 578 579 580 581 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 582 &ts_params->conf), 583 "Failed to configure cryptodev %u with %u qps", 584 dev_id, ts_params->conf.nb_queue_pairs); 585 586 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 587 ts_params->qp_conf.mp_session = ts_params->session_mpool; 588 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 589 590 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 591 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 592 dev_id, qp_id, &ts_params->qp_conf, 593 rte_cryptodev_socket_id(dev_id)), 594 "Failed to setup queue pair %u on cryptodev %u", 595 qp_id, dev_id); 596 } 597 598 return TEST_SUCCESS; 599 } 600 601 static void 602 testsuite_teardown(void) 603 { 604 struct crypto_testsuite_params *ts_params = &testsuite_params; 605 606 if (ts_params->mbuf_pool != NULL) { 607 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 608 rte_mempool_avail_count(ts_params->mbuf_pool)); 609 } 610 611 if (ts_params->op_mpool != NULL) { 612 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 613 rte_mempool_avail_count(ts_params->op_mpool)); 614 } 615 616 /* Free session mempools */ 617 if (ts_params->session_priv_mpool != NULL) { 618 rte_mempool_free(ts_params->session_priv_mpool); 619 ts_params->session_priv_mpool = NULL; 620 } 621 622 if (ts_params->session_mpool != NULL) { 623 rte_mempool_free(ts_params->session_mpool); 624 ts_params->session_mpool = NULL; 625 } 626 } 627 628 static int 629 ut_setup(void) 630 { 631 struct crypto_testsuite_params *ts_params = &testsuite_params; 632 struct crypto_unittest_params *ut_params = &unittest_params; 633 634 uint16_t qp_id; 635 636 /* Clear unit test parameters before running test */ 637 memset(ut_params, 0, sizeof(*ut_params)); 638 639 /* Reconfigure device to default parameters */ 640 ts_params->conf.socket_id = SOCKET_ID_ANY; 641 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 642 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 643 ts_params->qp_conf.mp_session = ts_params->session_mpool; 644 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 645 646 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 647 &ts_params->conf), 648 "Failed to configure cryptodev %u", 649 ts_params->valid_devs[0]); 650 651 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 652 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 653 ts_params->valid_devs[0], qp_id, 654 &ts_params->qp_conf, 655 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 656 "Failed to setup queue pair %u on cryptodev %u", 657 qp_id, ts_params->valid_devs[0]); 658 } 659 660 661 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 662 663 /* Start the device */ 664 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 665 "Failed to start cryptodev %u", 666 ts_params->valid_devs[0]); 667 668 return TEST_SUCCESS; 669 } 670 671 static void 672 ut_teardown(void) 673 { 674 struct crypto_testsuite_params *ts_params = &testsuite_params; 675 struct crypto_unittest_params *ut_params = &unittest_params; 676 struct rte_cryptodev_stats stats; 677 678 /* free crypto session structure */ 679 #ifdef RTE_LIBRTE_SECURITY 680 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 681 if (ut_params->sec_session) { 682 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 683 (ts_params->valid_devs[0]), 684 ut_params->sec_session); 685 ut_params->sec_session = NULL; 686 } 687 } else 688 #endif 689 { 690 if (ut_params->sess) { 691 rte_cryptodev_sym_session_clear( 692 ts_params->valid_devs[0], 693 ut_params->sess); 694 rte_cryptodev_sym_session_free(ut_params->sess); 695 ut_params->sess = NULL; 696 } 697 } 698 699 /* free crypto operation structure */ 700 if (ut_params->op) 701 rte_crypto_op_free(ut_params->op); 702 703 /* 704 * free mbuf - both obuf and ibuf are usually the same, 705 * so check if they point at the same address is necessary, 706 * to avoid freeing the mbuf twice. 707 */ 708 if (ut_params->obuf) { 709 rte_pktmbuf_free(ut_params->obuf); 710 if (ut_params->ibuf == ut_params->obuf) 711 ut_params->ibuf = 0; 712 ut_params->obuf = 0; 713 } 714 if (ut_params->ibuf) { 715 rte_pktmbuf_free(ut_params->ibuf); 716 ut_params->ibuf = 0; 717 } 718 719 if (ts_params->mbuf_pool != NULL) 720 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 721 rte_mempool_avail_count(ts_params->mbuf_pool)); 722 723 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 724 725 /* Stop the device */ 726 rte_cryptodev_stop(ts_params->valid_devs[0]); 727 } 728 729 static int 730 test_device_configure_invalid_dev_id(void) 731 { 732 struct crypto_testsuite_params *ts_params = &testsuite_params; 733 uint16_t dev_id, num_devs = 0; 734 735 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 736 "Need at least %d devices for test", 1); 737 738 /* valid dev_id values */ 739 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1]; 740 741 /* Stop the device in case it's started so it can be configured */ 742 rte_cryptodev_stop(dev_id); 743 744 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 745 "Failed test for rte_cryptodev_configure: " 746 "invalid dev_num %u", dev_id); 747 748 /* invalid dev_id values */ 749 dev_id = num_devs; 750 751 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 752 "Failed test for rte_cryptodev_configure: " 753 "invalid dev_num %u", dev_id); 754 755 dev_id = 0xff; 756 757 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 758 "Failed test for rte_cryptodev_configure:" 759 "invalid dev_num %u", dev_id); 760 761 return TEST_SUCCESS; 762 } 763 764 static int 765 test_device_configure_invalid_queue_pair_ids(void) 766 { 767 struct crypto_testsuite_params *ts_params = &testsuite_params; 768 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 769 770 /* This test is for QAT and NITROX PMDs only */ 771 if (gbl_driver_id != rte_cryptodev_driver_id_get( 772 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)) && 773 gbl_driver_id != rte_cryptodev_driver_id_get( 774 RTE_STR(CRYPTODEV_NAME_NITROX_PMD))) 775 return -ENOTSUP; 776 777 /* Stop the device in case it's started so it can be configured */ 778 rte_cryptodev_stop(ts_params->valid_devs[0]); 779 780 /* valid - one queue pairs */ 781 ts_params->conf.nb_queue_pairs = 1; 782 783 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 784 &ts_params->conf), 785 "Failed to configure cryptodev: dev_id %u, qp_id %u", 786 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 787 788 789 /* valid - max value queue pairs */ 790 ts_params->conf.nb_queue_pairs = orig_nb_qps; 791 792 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 793 &ts_params->conf), 794 "Failed to configure cryptodev: dev_id %u, qp_id %u", 795 ts_params->valid_devs[0], 796 ts_params->conf.nb_queue_pairs); 797 798 799 /* invalid - zero queue pairs */ 800 ts_params->conf.nb_queue_pairs = 0; 801 802 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 803 &ts_params->conf), 804 "Failed test for rte_cryptodev_configure, dev_id %u," 805 " invalid qps: %u", 806 ts_params->valid_devs[0], 807 ts_params->conf.nb_queue_pairs); 808 809 810 /* invalid - max value supported by field queue pairs */ 811 ts_params->conf.nb_queue_pairs = UINT16_MAX; 812 813 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 814 &ts_params->conf), 815 "Failed test for rte_cryptodev_configure, dev_id %u," 816 " invalid qps: %u", 817 ts_params->valid_devs[0], 818 ts_params->conf.nb_queue_pairs); 819 820 821 /* invalid - max value + 1 queue pairs */ 822 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 823 824 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 825 &ts_params->conf), 826 "Failed test for rte_cryptodev_configure, dev_id %u," 827 " invalid qps: %u", 828 ts_params->valid_devs[0], 829 ts_params->conf.nb_queue_pairs); 830 831 /* revert to original testsuite value */ 832 ts_params->conf.nb_queue_pairs = orig_nb_qps; 833 834 return TEST_SUCCESS; 835 } 836 837 static int 838 test_queue_pair_descriptor_setup(void) 839 { 840 struct crypto_testsuite_params *ts_params = &testsuite_params; 841 struct rte_cryptodev_info dev_info; 842 struct rte_cryptodev_qp_conf qp_conf = { 843 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 844 }; 845 846 uint16_t qp_id; 847 848 /* This test is for QAT PMD only */ 849 if (gbl_driver_id != rte_cryptodev_driver_id_get( 850 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD))) 851 return -ENOTSUP; 852 853 /* Stop the device in case it's started so it can be configured */ 854 rte_cryptodev_stop(ts_params->valid_devs[0]); 855 856 857 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 858 859 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 860 &ts_params->conf), 861 "Failed to configure cryptodev %u", 862 ts_params->valid_devs[0]); 863 864 /* 865 * Test various ring sizes on this device. memzones can't be 866 * freed so are re-used if ring is released and re-created. 867 */ 868 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 869 qp_conf.mp_session = ts_params->session_mpool; 870 qp_conf.mp_session_private = ts_params->session_priv_mpool; 871 872 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 873 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 874 ts_params->valid_devs[0], qp_id, &qp_conf, 875 rte_cryptodev_socket_id( 876 ts_params->valid_devs[0])), 877 "Failed test for " 878 "rte_cryptodev_queue_pair_setup: num_inflights " 879 "%u on qp %u on cryptodev %u", 880 qp_conf.nb_descriptors, qp_id, 881 ts_params->valid_devs[0]); 882 } 883 884 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 885 886 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 887 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 888 ts_params->valid_devs[0], qp_id, &qp_conf, 889 rte_cryptodev_socket_id( 890 ts_params->valid_devs[0])), 891 "Failed test for" 892 " rte_cryptodev_queue_pair_setup: num_inflights" 893 " %u on qp %u on cryptodev %u", 894 qp_conf.nb_descriptors, qp_id, 895 ts_params->valid_devs[0]); 896 } 897 898 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 899 900 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 901 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 902 ts_params->valid_devs[0], qp_id, &qp_conf, 903 rte_cryptodev_socket_id( 904 ts_params->valid_devs[0])), 905 "Failed test for " 906 "rte_cryptodev_queue_pair_setup: num_inflights" 907 " %u on qp %u on cryptodev %u", 908 qp_conf.nb_descriptors, qp_id, 909 ts_params->valid_devs[0]); 910 } 911 912 /* invalid number of descriptors - max supported + 2 */ 913 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2; 914 915 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 916 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 917 ts_params->valid_devs[0], qp_id, &qp_conf, 918 rte_cryptodev_socket_id( 919 ts_params->valid_devs[0])), 920 "Unexpectedly passed test for " 921 "rte_cryptodev_queue_pair_setup:" 922 "num_inflights %u on qp %u on cryptodev %u", 923 qp_conf.nb_descriptors, qp_id, 924 ts_params->valid_devs[0]); 925 } 926 927 /* invalid number of descriptors - max value of parameter */ 928 qp_conf.nb_descriptors = UINT32_MAX-1; 929 930 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 931 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 932 ts_params->valid_devs[0], qp_id, &qp_conf, 933 rte_cryptodev_socket_id( 934 ts_params->valid_devs[0])), 935 "Unexpectedly passed test for " 936 "rte_cryptodev_queue_pair_setup:" 937 "num_inflights %u on qp %u on cryptodev %u", 938 qp_conf.nb_descriptors, qp_id, 939 ts_params->valid_devs[0]); 940 } 941 942 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 943 944 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 945 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 946 ts_params->valid_devs[0], qp_id, &qp_conf, 947 rte_cryptodev_socket_id( 948 ts_params->valid_devs[0])), 949 "Failed test for" 950 " rte_cryptodev_queue_pair_setup:" 951 "num_inflights %u on qp %u on cryptodev %u", 952 qp_conf.nb_descriptors, qp_id, 953 ts_params->valid_devs[0]); 954 } 955 956 /* invalid number of descriptors - max supported + 1 */ 957 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1; 958 959 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 960 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 961 ts_params->valid_devs[0], qp_id, &qp_conf, 962 rte_cryptodev_socket_id( 963 ts_params->valid_devs[0])), 964 "Unexpectedly passed test for " 965 "rte_cryptodev_queue_pair_setup:" 966 "num_inflights %u on qp %u on cryptodev %u", 967 qp_conf.nb_descriptors, qp_id, 968 ts_params->valid_devs[0]); 969 } 970 971 /* test invalid queue pair id */ 972 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 973 974 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 975 976 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 977 ts_params->valid_devs[0], 978 qp_id, &qp_conf, 979 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 980 "Failed test for rte_cryptodev_queue_pair_setup:" 981 "invalid qp %u on cryptodev %u", 982 qp_id, ts_params->valid_devs[0]); 983 984 qp_id = 0xffff; /*invalid*/ 985 986 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 987 ts_params->valid_devs[0], 988 qp_id, &qp_conf, 989 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 990 "Failed test for rte_cryptodev_queue_pair_setup:" 991 "invalid qp %u on cryptodev %u", 992 qp_id, ts_params->valid_devs[0]); 993 994 return TEST_SUCCESS; 995 } 996 997 /* ***** Plaintext data for tests ***** */ 998 999 const char catch_22_quote_1[] = 1000 "There was only one catch and that was Catch-22, which " 1001 "specified that a concern for one's safety in the face of " 1002 "dangers that were real and immediate was the process of a " 1003 "rational mind. Orr was crazy and could be grounded. All he " 1004 "had to do was ask; and as soon as he did, he would no longer " 1005 "be crazy and would have to fly more missions. Orr would be " 1006 "crazy to fly more missions and sane if he didn't, but if he " 1007 "was sane he had to fly them. If he flew them he was crazy " 1008 "and didn't have to; but if he didn't want to he was sane and " 1009 "had to. Yossarian was moved very deeply by the absolute " 1010 "simplicity of this clause of Catch-22 and let out a " 1011 "respectful whistle. \"That's some catch, that Catch-22\", he " 1012 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1013 1014 const char catch_22_quote[] = 1015 "What a lousy earth! He wondered how many people were " 1016 "destitute that same night even in his own prosperous country, " 1017 "how many homes were shanties, how many husbands were drunk " 1018 "and wives socked, and how many children were bullied, abused, " 1019 "or abandoned. How many families hungered for food they could " 1020 "not afford to buy? How many hearts were broken? How many " 1021 "suicides would take place that same night, how many people " 1022 "would go insane? How many cockroaches and landlords would " 1023 "triumph? How many winners were losers, successes failures, " 1024 "and rich men poor men? How many wise guys were stupid? How " 1025 "many happy endings were unhappy endings? How many honest men " 1026 "were liars, brave men cowards, loyal men traitors, how many " 1027 "sainted men were corrupt, how many people in positions of " 1028 "trust had sold their souls to bodyguards, how many had never " 1029 "had souls? How many straight-and-narrow paths were crooked " 1030 "paths? How many best families were worst families and how " 1031 "many good people were bad people? When you added them all up " 1032 "and then subtracted, you might be left with only the children, " 1033 "and perhaps with Albert Einstein and an old violinist or " 1034 "sculptor somewhere."; 1035 1036 #define QUOTE_480_BYTES (480) 1037 #define QUOTE_512_BYTES (512) 1038 #define QUOTE_768_BYTES (768) 1039 #define QUOTE_1024_BYTES (1024) 1040 1041 1042 1043 /* ***** SHA1 Hash Tests ***** */ 1044 1045 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1046 1047 static uint8_t hmac_sha1_key[] = { 1048 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1049 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1050 0xDE, 0xF4, 0xDE, 0xAD }; 1051 1052 /* ***** SHA224 Hash Tests ***** */ 1053 1054 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1055 1056 1057 /* ***** AES-CBC Cipher Tests ***** */ 1058 1059 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1060 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1061 1062 static uint8_t aes_cbc_key[] = { 1063 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1064 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1065 1066 static uint8_t aes_cbc_iv[] = { 1067 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1068 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1069 1070 1071 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1072 1073 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1074 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1075 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1076 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1077 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1078 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1079 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1080 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1081 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1082 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1083 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1084 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1085 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1086 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1087 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1088 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1089 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1090 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1091 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1092 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1093 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1094 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1095 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1096 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1097 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1098 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1099 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1100 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1101 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1102 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1103 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1104 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1105 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1106 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1107 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1108 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1109 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1110 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1111 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1112 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1113 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1114 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1115 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1116 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1117 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1118 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1119 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1120 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1121 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1122 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1123 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1124 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1125 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1126 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1127 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1128 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1129 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1130 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1131 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1132 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1133 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1134 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1135 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1136 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1137 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1138 }; 1139 1140 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1141 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1142 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1143 0x18, 0x8c, 0x1d, 0x32 1144 }; 1145 1146 1147 /* Multisession Vector context Test */ 1148 /*Begin Session 0 */ 1149 static uint8_t ms_aes_cbc_key0[] = { 1150 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1151 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1152 }; 1153 1154 static uint8_t ms_aes_cbc_iv0[] = { 1155 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1156 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1157 }; 1158 1159 static const uint8_t ms_aes_cbc_cipher0[] = { 1160 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1161 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1162 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1163 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1164 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1165 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1166 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1167 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1168 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1169 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1170 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1171 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1172 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1173 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1174 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1175 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1176 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1177 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1178 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1179 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1180 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1181 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1182 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1183 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1184 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1185 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1186 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1187 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1188 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1189 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1190 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1191 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1192 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1193 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1194 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1195 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1196 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1197 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1198 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1199 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1200 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1201 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1202 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1203 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1204 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1205 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1206 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1207 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1208 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1209 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1210 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1211 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1212 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1213 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1214 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1215 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1216 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1217 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1218 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1219 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1220 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1221 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1222 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1223 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1224 }; 1225 1226 1227 static uint8_t ms_hmac_key0[] = { 1228 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1229 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1230 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1231 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1232 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1233 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1234 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1235 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1236 }; 1237 1238 static const uint8_t ms_hmac_digest0[] = { 1239 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1240 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1241 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1242 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1243 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1244 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1245 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1246 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1247 }; 1248 1249 /* End Session 0 */ 1250 /* Begin session 1 */ 1251 1252 static uint8_t ms_aes_cbc_key1[] = { 1253 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1254 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1255 }; 1256 1257 static uint8_t ms_aes_cbc_iv1[] = { 1258 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1259 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1260 }; 1261 1262 static const uint8_t ms_aes_cbc_cipher1[] = { 1263 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1264 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1265 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1266 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1267 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1268 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1269 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1270 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1271 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1272 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1273 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1274 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1275 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1276 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1277 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1278 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1279 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1280 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1281 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1282 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1283 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1284 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1285 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1286 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1287 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1288 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1289 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1290 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1291 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1292 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1293 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1294 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1295 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1296 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1297 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1298 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1299 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1300 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1301 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1302 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1303 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1304 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1305 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1306 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1307 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1308 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1309 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1310 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1311 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1312 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1313 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1314 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1315 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1316 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1317 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1318 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1319 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1320 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1321 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1322 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1323 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1324 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1325 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1326 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1327 1328 }; 1329 1330 static uint8_t ms_hmac_key1[] = { 1331 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1332 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1333 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1334 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1335 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1336 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1337 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1338 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1339 }; 1340 1341 static const uint8_t ms_hmac_digest1[] = { 1342 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1343 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1344 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1345 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1346 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1347 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1348 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1349 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1350 }; 1351 /* End Session 1 */ 1352 /* Begin Session 2 */ 1353 static uint8_t ms_aes_cbc_key2[] = { 1354 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1355 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1356 }; 1357 1358 static uint8_t ms_aes_cbc_iv2[] = { 1359 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1360 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1361 }; 1362 1363 static const uint8_t ms_aes_cbc_cipher2[] = { 1364 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1365 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1366 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1367 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1368 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1369 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1370 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1371 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1372 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1373 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1374 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1375 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1376 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1377 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1378 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1379 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1380 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1381 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1382 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1383 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1384 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1385 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1386 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1387 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1388 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1389 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1390 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1391 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1392 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1393 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1394 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1395 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1396 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1397 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1398 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1399 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1400 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1401 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1402 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1403 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1404 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1405 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1406 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1407 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1408 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1409 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1410 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1411 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1412 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1413 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1414 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1415 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1416 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1417 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1418 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1419 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1420 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1421 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1422 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1423 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1424 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1425 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1426 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1427 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1428 }; 1429 1430 static uint8_t ms_hmac_key2[] = { 1431 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1432 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1433 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1434 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1435 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1436 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1437 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1438 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1439 }; 1440 1441 static const uint8_t ms_hmac_digest2[] = { 1442 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1443 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1444 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1445 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1446 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1447 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1448 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1449 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1450 }; 1451 1452 /* End Session 2 */ 1453 1454 1455 static int 1456 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1457 { 1458 struct crypto_testsuite_params *ts_params = &testsuite_params; 1459 struct crypto_unittest_params *ut_params = &unittest_params; 1460 1461 /* Verify the capabilities */ 1462 struct rte_cryptodev_sym_capability_idx cap_idx; 1463 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1464 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 1465 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1466 &cap_idx) == NULL) 1467 return -ENOTSUP; 1468 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1469 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 1470 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1471 &cap_idx) == NULL) 1472 return -ENOTSUP; 1473 1474 /* Generate test mbuf data and space for digest */ 1475 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1476 catch_22_quote, QUOTE_512_BYTES, 0); 1477 1478 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1479 DIGEST_BYTE_LENGTH_SHA1); 1480 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1481 1482 /* Setup Cipher Parameters */ 1483 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1484 ut_params->cipher_xform.next = &ut_params->auth_xform; 1485 1486 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1487 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1488 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1489 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1490 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1491 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1492 1493 /* Setup HMAC Parameters */ 1494 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1495 1496 ut_params->auth_xform.next = NULL; 1497 1498 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1499 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1500 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1501 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1502 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1503 1504 ut_params->sess = rte_cryptodev_sym_session_create( 1505 ts_params->session_mpool); 1506 1507 /* Create crypto session*/ 1508 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 1509 ut_params->sess, &ut_params->cipher_xform, 1510 ts_params->session_priv_mpool); 1511 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1512 1513 /* Generate crypto op data structure */ 1514 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1515 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1516 TEST_ASSERT_NOT_NULL(ut_params->op, 1517 "Failed to allocate symmetric crypto operation struct"); 1518 1519 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1520 1521 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1522 1523 /* set crypto operation source mbuf */ 1524 sym_op->m_src = ut_params->ibuf; 1525 1526 /* Set crypto operation authentication parameters */ 1527 sym_op->auth.digest.data = ut_params->digest; 1528 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1529 ut_params->ibuf, QUOTE_512_BYTES); 1530 1531 sym_op->auth.data.offset = 0; 1532 sym_op->auth.data.length = QUOTE_512_BYTES; 1533 1534 /* Copy IV at the end of the crypto operation */ 1535 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1536 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 1537 1538 /* Set crypto operation cipher parameters */ 1539 sym_op->cipher.data.offset = 0; 1540 sym_op->cipher.data.length = QUOTE_512_BYTES; 1541 1542 /* Process crypto operation */ 1543 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1544 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1545 ut_params->op); 1546 else 1547 TEST_ASSERT_NOT_NULL( 1548 process_crypto_request(ts_params->valid_devs[0], 1549 ut_params->op), 1550 "failed to process sym crypto op"); 1551 1552 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1553 "crypto op processing failed"); 1554 1555 /* Validate obuf */ 1556 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 1557 uint8_t *); 1558 1559 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1560 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1561 QUOTE_512_BYTES, 1562 "ciphertext data not as expected"); 1563 1564 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1565 1566 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1567 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1568 gbl_driver_id == rte_cryptodev_driver_id_get( 1569 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 1570 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1571 DIGEST_BYTE_LENGTH_SHA1, 1572 "Generated digest data not as expected"); 1573 1574 return TEST_SUCCESS; 1575 } 1576 1577 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1578 1579 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1580 1581 static uint8_t hmac_sha512_key[] = { 1582 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1583 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1584 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1585 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1586 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1587 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1588 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1589 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1590 1591 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1592 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1593 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1594 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1595 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1596 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1597 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1598 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1599 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1600 1601 1602 1603 static int 1604 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1605 struct crypto_unittest_params *ut_params, 1606 uint8_t *cipher_key, 1607 uint8_t *hmac_key); 1608 1609 static int 1610 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1611 struct crypto_unittest_params *ut_params, 1612 struct crypto_testsuite_params *ts_params, 1613 const uint8_t *cipher, 1614 const uint8_t *digest, 1615 const uint8_t *iv); 1616 1617 1618 static int 1619 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1620 struct crypto_unittest_params *ut_params, 1621 uint8_t *cipher_key, 1622 uint8_t *hmac_key) 1623 { 1624 1625 /* Setup Cipher Parameters */ 1626 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1627 ut_params->cipher_xform.next = NULL; 1628 1629 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1630 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1631 ut_params->cipher_xform.cipher.key.data = cipher_key; 1632 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1633 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1634 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1635 1636 /* Setup HMAC Parameters */ 1637 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1638 ut_params->auth_xform.next = &ut_params->cipher_xform; 1639 1640 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1641 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1642 ut_params->auth_xform.auth.key.data = hmac_key; 1643 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1644 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1645 1646 return TEST_SUCCESS; 1647 } 1648 1649 1650 static int 1651 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1652 struct crypto_unittest_params *ut_params, 1653 struct crypto_testsuite_params *ts_params, 1654 const uint8_t *cipher, 1655 const uint8_t *digest, 1656 const uint8_t *iv) 1657 { 1658 /* Generate test mbuf data and digest */ 1659 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1660 (const char *) 1661 cipher, 1662 QUOTE_512_BYTES, 0); 1663 1664 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1665 DIGEST_BYTE_LENGTH_SHA512); 1666 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1667 1668 rte_memcpy(ut_params->digest, 1669 digest, 1670 DIGEST_BYTE_LENGTH_SHA512); 1671 1672 /* Generate Crypto op data structure */ 1673 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1674 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1675 TEST_ASSERT_NOT_NULL(ut_params->op, 1676 "Failed to allocate symmetric crypto operation struct"); 1677 1678 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1679 1680 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1681 1682 /* set crypto operation source mbuf */ 1683 sym_op->m_src = ut_params->ibuf; 1684 1685 sym_op->auth.digest.data = ut_params->digest; 1686 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1687 ut_params->ibuf, QUOTE_512_BYTES); 1688 1689 sym_op->auth.data.offset = 0; 1690 sym_op->auth.data.length = QUOTE_512_BYTES; 1691 1692 /* Copy IV at the end of the crypto operation */ 1693 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1694 iv, CIPHER_IV_LENGTH_AES_CBC); 1695 1696 sym_op->cipher.data.offset = 0; 1697 sym_op->cipher.data.length = QUOTE_512_BYTES; 1698 1699 /* Process crypto operation */ 1700 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1701 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1702 ut_params->op); 1703 else 1704 TEST_ASSERT_NOT_NULL( 1705 process_crypto_request(ts_params->valid_devs[0], 1706 ut_params->op), 1707 "failed to process sym crypto op"); 1708 1709 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1710 "crypto op processing failed"); 1711 1712 ut_params->obuf = ut_params->op->sym->m_src; 1713 1714 /* Validate obuf */ 1715 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1716 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 1717 catch_22_quote, 1718 QUOTE_512_BYTES, 1719 "Plaintext data not as expected"); 1720 1721 /* Validate obuf */ 1722 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1723 "Digest verification failed"); 1724 1725 return TEST_SUCCESS; 1726 } 1727 1728 static int 1729 test_blockcipher(enum blockcipher_test_type test_type) 1730 { 1731 struct crypto_testsuite_params *ts_params = &testsuite_params; 1732 int status; 1733 1734 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1735 ts_params->op_mpool, 1736 ts_params->session_mpool, ts_params->session_priv_mpool, 1737 ts_params->valid_devs[0], 1738 gbl_driver_id, 1739 test_type); 1740 1741 if (status == -ENOTSUP) 1742 return status; 1743 1744 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1745 1746 return TEST_SUCCESS; 1747 } 1748 1749 static int 1750 test_AES_cipheronly_all(void) 1751 { 1752 return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE); 1753 } 1754 1755 static int 1756 test_AES_docsis_all(void) 1757 { 1758 return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE); 1759 } 1760 1761 static int 1762 test_DES_docsis_all(void) 1763 { 1764 return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE); 1765 } 1766 1767 static int 1768 test_DES_cipheronly_all(void) 1769 { 1770 return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE); 1771 } 1772 1773 static int 1774 test_authonly_all(void) 1775 { 1776 return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE); 1777 } 1778 1779 static int 1780 test_AES_chain_all(void) 1781 { 1782 return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE); 1783 } 1784 1785 static int 1786 test_3DES_chain_all(void) 1787 { 1788 return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE); 1789 } 1790 1791 static int 1792 test_3DES_cipheronly_all(void) 1793 { 1794 return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE); 1795 } 1796 1797 /* ***** SNOW 3G Tests ***** */ 1798 static int 1799 create_wireless_algo_hash_session(uint8_t dev_id, 1800 const uint8_t *key, const uint8_t key_len, 1801 const uint8_t iv_len, const uint8_t auth_len, 1802 enum rte_crypto_auth_operation op, 1803 enum rte_crypto_auth_algorithm algo) 1804 { 1805 uint8_t hash_key[key_len]; 1806 int status; 1807 1808 struct crypto_testsuite_params *ts_params = &testsuite_params; 1809 struct crypto_unittest_params *ut_params = &unittest_params; 1810 1811 memcpy(hash_key, key, key_len); 1812 1813 debug_hexdump(stdout, "key:", key, key_len); 1814 1815 /* Setup Authentication Parameters */ 1816 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1817 ut_params->auth_xform.next = NULL; 1818 1819 ut_params->auth_xform.auth.op = op; 1820 ut_params->auth_xform.auth.algo = algo; 1821 ut_params->auth_xform.auth.key.length = key_len; 1822 ut_params->auth_xform.auth.key.data = hash_key; 1823 ut_params->auth_xform.auth.digest_length = auth_len; 1824 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 1825 ut_params->auth_xform.auth.iv.length = iv_len; 1826 ut_params->sess = rte_cryptodev_sym_session_create( 1827 ts_params->session_mpool); 1828 1829 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 1830 &ut_params->auth_xform, 1831 ts_params->session_priv_mpool); 1832 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 1833 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1834 return 0; 1835 } 1836 1837 static int 1838 create_wireless_algo_cipher_session(uint8_t dev_id, 1839 enum rte_crypto_cipher_operation op, 1840 enum rte_crypto_cipher_algorithm algo, 1841 const uint8_t *key, const uint8_t key_len, 1842 uint8_t iv_len) 1843 { 1844 uint8_t cipher_key[key_len]; 1845 int status; 1846 struct crypto_testsuite_params *ts_params = &testsuite_params; 1847 struct crypto_unittest_params *ut_params = &unittest_params; 1848 1849 memcpy(cipher_key, key, key_len); 1850 1851 /* Setup Cipher Parameters */ 1852 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1853 ut_params->cipher_xform.next = NULL; 1854 1855 ut_params->cipher_xform.cipher.algo = algo; 1856 ut_params->cipher_xform.cipher.op = op; 1857 ut_params->cipher_xform.cipher.key.data = cipher_key; 1858 ut_params->cipher_xform.cipher.key.length = key_len; 1859 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1860 ut_params->cipher_xform.cipher.iv.length = iv_len; 1861 1862 debug_hexdump(stdout, "key:", key, key_len); 1863 1864 /* Create Crypto session */ 1865 ut_params->sess = rte_cryptodev_sym_session_create( 1866 ts_params->session_mpool); 1867 1868 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 1869 &ut_params->cipher_xform, 1870 ts_params->session_priv_mpool); 1871 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 1872 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1873 return 0; 1874 } 1875 1876 static int 1877 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 1878 unsigned int cipher_len, 1879 unsigned int cipher_offset) 1880 { 1881 struct crypto_testsuite_params *ts_params = &testsuite_params; 1882 struct crypto_unittest_params *ut_params = &unittest_params; 1883 1884 /* Generate Crypto op data structure */ 1885 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1886 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1887 TEST_ASSERT_NOT_NULL(ut_params->op, 1888 "Failed to allocate pktmbuf offload"); 1889 1890 /* Set crypto operation data parameters */ 1891 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1892 1893 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1894 1895 /* set crypto operation source mbuf */ 1896 sym_op->m_src = ut_params->ibuf; 1897 1898 /* iv */ 1899 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1900 iv, iv_len); 1901 sym_op->cipher.data.length = cipher_len; 1902 sym_op->cipher.data.offset = cipher_offset; 1903 return 0; 1904 } 1905 1906 static int 1907 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 1908 unsigned int cipher_len, 1909 unsigned int cipher_offset) 1910 { 1911 struct crypto_testsuite_params *ts_params = &testsuite_params; 1912 struct crypto_unittest_params *ut_params = &unittest_params; 1913 1914 /* Generate Crypto op data structure */ 1915 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1916 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1917 TEST_ASSERT_NOT_NULL(ut_params->op, 1918 "Failed to allocate pktmbuf offload"); 1919 1920 /* Set crypto operation data parameters */ 1921 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1922 1923 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1924 1925 /* set crypto operation source mbuf */ 1926 sym_op->m_src = ut_params->ibuf; 1927 sym_op->m_dst = ut_params->obuf; 1928 1929 /* iv */ 1930 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1931 iv, iv_len); 1932 sym_op->cipher.data.length = cipher_len; 1933 sym_op->cipher.data.offset = cipher_offset; 1934 return 0; 1935 } 1936 1937 static int 1938 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 1939 enum rte_crypto_cipher_operation cipher_op, 1940 enum rte_crypto_auth_operation auth_op, 1941 enum rte_crypto_auth_algorithm auth_algo, 1942 enum rte_crypto_cipher_algorithm cipher_algo, 1943 const uint8_t *key, uint8_t key_len, 1944 uint8_t auth_iv_len, uint8_t auth_len, 1945 uint8_t cipher_iv_len) 1946 1947 { 1948 uint8_t cipher_auth_key[key_len]; 1949 int status; 1950 1951 struct crypto_testsuite_params *ts_params = &testsuite_params; 1952 struct crypto_unittest_params *ut_params = &unittest_params; 1953 1954 memcpy(cipher_auth_key, key, key_len); 1955 1956 /* Setup Authentication Parameters */ 1957 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1958 ut_params->auth_xform.next = NULL; 1959 1960 ut_params->auth_xform.auth.op = auth_op; 1961 ut_params->auth_xform.auth.algo = auth_algo; 1962 ut_params->auth_xform.auth.key.length = key_len; 1963 /* Hash key = cipher key */ 1964 ut_params->auth_xform.auth.key.data = cipher_auth_key; 1965 ut_params->auth_xform.auth.digest_length = auth_len; 1966 /* Auth IV will be after cipher IV */ 1967 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 1968 ut_params->auth_xform.auth.iv.length = auth_iv_len; 1969 1970 /* Setup Cipher Parameters */ 1971 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1972 ut_params->cipher_xform.next = &ut_params->auth_xform; 1973 1974 ut_params->cipher_xform.cipher.algo = cipher_algo; 1975 ut_params->cipher_xform.cipher.op = cipher_op; 1976 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 1977 ut_params->cipher_xform.cipher.key.length = key_len; 1978 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1979 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 1980 1981 debug_hexdump(stdout, "key:", key, key_len); 1982 1983 /* Create Crypto session*/ 1984 ut_params->sess = rte_cryptodev_sym_session_create( 1985 ts_params->session_mpool); 1986 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1987 1988 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 1989 &ut_params->cipher_xform, 1990 ts_params->session_priv_mpool); 1991 if (status == -ENOTSUP) 1992 return status; 1993 1994 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 1995 return 0; 1996 } 1997 1998 static int 1999 create_wireless_cipher_auth_session(uint8_t dev_id, 2000 enum rte_crypto_cipher_operation cipher_op, 2001 enum rte_crypto_auth_operation auth_op, 2002 enum rte_crypto_auth_algorithm auth_algo, 2003 enum rte_crypto_cipher_algorithm cipher_algo, 2004 const struct wireless_test_data *tdata) 2005 { 2006 const uint8_t key_len = tdata->key.len; 2007 uint8_t cipher_auth_key[key_len]; 2008 int status; 2009 2010 struct crypto_testsuite_params *ts_params = &testsuite_params; 2011 struct crypto_unittest_params *ut_params = &unittest_params; 2012 const uint8_t *key = tdata->key.data; 2013 const uint8_t auth_len = tdata->digest.len; 2014 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2015 uint8_t auth_iv_len = tdata->auth_iv.len; 2016 2017 memcpy(cipher_auth_key, key, key_len); 2018 2019 /* Setup Authentication Parameters */ 2020 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2021 ut_params->auth_xform.next = NULL; 2022 2023 ut_params->auth_xform.auth.op = auth_op; 2024 ut_params->auth_xform.auth.algo = auth_algo; 2025 ut_params->auth_xform.auth.key.length = key_len; 2026 /* Hash key = cipher key */ 2027 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2028 ut_params->auth_xform.auth.digest_length = auth_len; 2029 /* Auth IV will be after cipher IV */ 2030 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2031 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2032 2033 /* Setup Cipher Parameters */ 2034 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2035 ut_params->cipher_xform.next = &ut_params->auth_xform; 2036 2037 ut_params->cipher_xform.cipher.algo = cipher_algo; 2038 ut_params->cipher_xform.cipher.op = cipher_op; 2039 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2040 ut_params->cipher_xform.cipher.key.length = key_len; 2041 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2042 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2043 2044 2045 debug_hexdump(stdout, "key:", key, key_len); 2046 2047 /* Create Crypto session*/ 2048 ut_params->sess = rte_cryptodev_sym_session_create( 2049 ts_params->session_mpool); 2050 2051 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2052 &ut_params->cipher_xform, 2053 ts_params->session_priv_mpool); 2054 2055 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2056 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2057 return 0; 2058 } 2059 2060 static int 2061 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2062 const struct wireless_test_data *tdata) 2063 { 2064 return create_wireless_cipher_auth_session(dev_id, 2065 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2066 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2067 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2068 } 2069 2070 static int 2071 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2072 enum rte_crypto_cipher_operation cipher_op, 2073 enum rte_crypto_auth_operation auth_op, 2074 enum rte_crypto_auth_algorithm auth_algo, 2075 enum rte_crypto_cipher_algorithm cipher_algo, 2076 const uint8_t *key, const uint8_t key_len, 2077 uint8_t auth_iv_len, uint8_t auth_len, 2078 uint8_t cipher_iv_len) 2079 { 2080 uint8_t auth_cipher_key[key_len]; 2081 int status; 2082 struct crypto_testsuite_params *ts_params = &testsuite_params; 2083 struct crypto_unittest_params *ut_params = &unittest_params; 2084 2085 memcpy(auth_cipher_key, key, key_len); 2086 2087 /* Setup Authentication Parameters */ 2088 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2089 ut_params->auth_xform.auth.op = auth_op; 2090 ut_params->auth_xform.next = &ut_params->cipher_xform; 2091 ut_params->auth_xform.auth.algo = auth_algo; 2092 ut_params->auth_xform.auth.key.length = key_len; 2093 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2094 ut_params->auth_xform.auth.digest_length = auth_len; 2095 /* Auth IV will be after cipher IV */ 2096 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2097 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2098 2099 /* Setup Cipher Parameters */ 2100 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2101 ut_params->cipher_xform.next = NULL; 2102 ut_params->cipher_xform.cipher.algo = cipher_algo; 2103 ut_params->cipher_xform.cipher.op = cipher_op; 2104 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2105 ut_params->cipher_xform.cipher.key.length = key_len; 2106 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2107 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2108 2109 debug_hexdump(stdout, "key:", key, key_len); 2110 2111 /* Create Crypto session*/ 2112 ut_params->sess = rte_cryptodev_sym_session_create( 2113 ts_params->session_mpool); 2114 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2115 2116 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2117 ut_params->auth_xform.next = NULL; 2118 ut_params->cipher_xform.next = &ut_params->auth_xform; 2119 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2120 &ut_params->cipher_xform, 2121 ts_params->session_priv_mpool); 2122 2123 } else 2124 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2125 &ut_params->auth_xform, 2126 ts_params->session_priv_mpool); 2127 2128 if (status == -ENOTSUP) 2129 return status; 2130 2131 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2132 2133 return 0; 2134 } 2135 2136 static int 2137 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2138 unsigned int auth_tag_len, 2139 const uint8_t *iv, unsigned int iv_len, 2140 unsigned int data_pad_len, 2141 enum rte_crypto_auth_operation op, 2142 unsigned int auth_len, unsigned int auth_offset) 2143 { 2144 struct crypto_testsuite_params *ts_params = &testsuite_params; 2145 2146 struct crypto_unittest_params *ut_params = &unittest_params; 2147 2148 /* Generate Crypto op data structure */ 2149 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2150 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2151 TEST_ASSERT_NOT_NULL(ut_params->op, 2152 "Failed to allocate pktmbuf offload"); 2153 2154 /* Set crypto operation data parameters */ 2155 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2156 2157 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2158 2159 /* set crypto operation source mbuf */ 2160 sym_op->m_src = ut_params->ibuf; 2161 2162 /* iv */ 2163 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2164 iv, iv_len); 2165 /* digest */ 2166 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2167 ut_params->ibuf, auth_tag_len); 2168 2169 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2170 "no room to append auth tag"); 2171 ut_params->digest = sym_op->auth.digest.data; 2172 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2173 ut_params->ibuf, data_pad_len); 2174 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2175 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2176 else 2177 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2178 2179 debug_hexdump(stdout, "digest:", 2180 sym_op->auth.digest.data, 2181 auth_tag_len); 2182 2183 sym_op->auth.data.length = auth_len; 2184 sym_op->auth.data.offset = auth_offset; 2185 2186 return 0; 2187 } 2188 2189 static int 2190 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2191 enum rte_crypto_auth_operation op) 2192 { 2193 struct crypto_testsuite_params *ts_params = &testsuite_params; 2194 struct crypto_unittest_params *ut_params = &unittest_params; 2195 2196 const uint8_t *auth_tag = tdata->digest.data; 2197 const unsigned int auth_tag_len = tdata->digest.len; 2198 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2199 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2200 2201 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2202 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2203 const uint8_t *auth_iv = tdata->auth_iv.data; 2204 const uint8_t auth_iv_len = tdata->auth_iv.len; 2205 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2206 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2207 2208 /* Generate Crypto op data structure */ 2209 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2210 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2211 TEST_ASSERT_NOT_NULL(ut_params->op, 2212 "Failed to allocate pktmbuf offload"); 2213 /* Set crypto operation data parameters */ 2214 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2215 2216 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2217 2218 /* set crypto operation source mbuf */ 2219 sym_op->m_src = ut_params->ibuf; 2220 2221 /* digest */ 2222 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2223 ut_params->ibuf, auth_tag_len); 2224 2225 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2226 "no room to append auth tag"); 2227 ut_params->digest = sym_op->auth.digest.data; 2228 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2229 ut_params->ibuf, data_pad_len); 2230 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2231 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2232 else 2233 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2234 2235 debug_hexdump(stdout, "digest:", 2236 sym_op->auth.digest.data, 2237 auth_tag_len); 2238 2239 /* Copy cipher and auth IVs at the end of the crypto operation */ 2240 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2241 IV_OFFSET); 2242 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2243 iv_ptr += cipher_iv_len; 2244 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2245 2246 sym_op->cipher.data.length = cipher_len; 2247 sym_op->cipher.data.offset = 0; 2248 sym_op->auth.data.length = auth_len; 2249 sym_op->auth.data.offset = 0; 2250 2251 return 0; 2252 } 2253 2254 static int 2255 create_zuc_cipher_hash_generate_operation( 2256 const struct wireless_test_data *tdata) 2257 { 2258 return create_wireless_cipher_hash_operation(tdata, 2259 RTE_CRYPTO_AUTH_OP_GENERATE); 2260 } 2261 2262 static int 2263 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2264 const unsigned auth_tag_len, 2265 const uint8_t *auth_iv, uint8_t auth_iv_len, 2266 unsigned data_pad_len, 2267 enum rte_crypto_auth_operation op, 2268 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2269 const unsigned cipher_len, const unsigned cipher_offset, 2270 const unsigned auth_len, const unsigned auth_offset) 2271 { 2272 struct crypto_testsuite_params *ts_params = &testsuite_params; 2273 struct crypto_unittest_params *ut_params = &unittest_params; 2274 2275 enum rte_crypto_cipher_algorithm cipher_algo = 2276 ut_params->cipher_xform.cipher.algo; 2277 enum rte_crypto_auth_algorithm auth_algo = 2278 ut_params->auth_xform.auth.algo; 2279 2280 /* Generate Crypto op data structure */ 2281 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2282 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2283 TEST_ASSERT_NOT_NULL(ut_params->op, 2284 "Failed to allocate pktmbuf offload"); 2285 /* Set crypto operation data parameters */ 2286 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2287 2288 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2289 2290 /* set crypto operation source mbuf */ 2291 sym_op->m_src = ut_params->ibuf; 2292 2293 /* digest */ 2294 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2295 ut_params->ibuf, auth_tag_len); 2296 2297 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2298 "no room to append auth tag"); 2299 ut_params->digest = sym_op->auth.digest.data; 2300 2301 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2302 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2303 ut_params->ibuf, data_pad_len); 2304 } else { 2305 struct rte_mbuf *m = ut_params->ibuf; 2306 unsigned int offset = data_pad_len; 2307 2308 while (offset > m->data_len && m->next != NULL) { 2309 offset -= m->data_len; 2310 m = m->next; 2311 } 2312 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2313 m, offset); 2314 } 2315 2316 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2317 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2318 else 2319 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2320 2321 debug_hexdump(stdout, "digest:", 2322 sym_op->auth.digest.data, 2323 auth_tag_len); 2324 2325 /* Copy cipher and auth IVs at the end of the crypto operation */ 2326 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2327 IV_OFFSET); 2328 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2329 iv_ptr += cipher_iv_len; 2330 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2331 2332 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2333 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2334 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2335 sym_op->cipher.data.length = cipher_len; 2336 sym_op->cipher.data.offset = cipher_offset; 2337 } else { 2338 sym_op->cipher.data.length = cipher_len >> 3; 2339 sym_op->cipher.data.offset = cipher_offset >> 3; 2340 } 2341 2342 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2343 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2344 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2345 sym_op->auth.data.length = auth_len; 2346 sym_op->auth.data.offset = auth_offset; 2347 } else { 2348 sym_op->auth.data.length = auth_len >> 3; 2349 sym_op->auth.data.offset = auth_offset >> 3; 2350 } 2351 2352 return 0; 2353 } 2354 2355 static int 2356 create_wireless_algo_auth_cipher_operation( 2357 const uint8_t *auth_tag, unsigned int auth_tag_len, 2358 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2359 const uint8_t *auth_iv, uint8_t auth_iv_len, 2360 unsigned int data_pad_len, 2361 unsigned int cipher_len, unsigned int cipher_offset, 2362 unsigned int auth_len, unsigned int auth_offset, 2363 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2364 { 2365 struct crypto_testsuite_params *ts_params = &testsuite_params; 2366 struct crypto_unittest_params *ut_params = &unittest_params; 2367 2368 enum rte_crypto_cipher_algorithm cipher_algo = 2369 ut_params->cipher_xform.cipher.algo; 2370 enum rte_crypto_auth_algorithm auth_algo = 2371 ut_params->auth_xform.auth.algo; 2372 2373 /* Generate Crypto op data structure */ 2374 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2375 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2376 TEST_ASSERT_NOT_NULL(ut_params->op, 2377 "Failed to allocate pktmbuf offload"); 2378 2379 /* Set crypto operation data parameters */ 2380 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2381 2382 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2383 2384 /* set crypto operation mbufs */ 2385 sym_op->m_src = ut_params->ibuf; 2386 if (op_mode == OUT_OF_PLACE) 2387 sym_op->m_dst = ut_params->obuf; 2388 2389 /* digest */ 2390 if (!do_sgl) { 2391 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2392 (op_mode == IN_PLACE ? 2393 ut_params->ibuf : ut_params->obuf), 2394 uint8_t *, data_pad_len); 2395 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2396 (op_mode == IN_PLACE ? 2397 ut_params->ibuf : ut_params->obuf), 2398 data_pad_len); 2399 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2400 } else { 2401 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2402 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2403 sym_op->m_src : sym_op->m_dst); 2404 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2405 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2406 sgl_buf = sgl_buf->next; 2407 } 2408 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 2409 uint8_t *, remaining_off); 2410 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 2411 remaining_off); 2412 memset(sym_op->auth.digest.data, 0, remaining_off); 2413 while (sgl_buf->next != NULL) { 2414 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 2415 0, rte_pktmbuf_data_len(sgl_buf)); 2416 sgl_buf = sgl_buf->next; 2417 } 2418 } 2419 2420 /* Copy digest for the verification */ 2421 if (verify) 2422 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2423 2424 /* Copy cipher and auth IVs at the end of the crypto operation */ 2425 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 2426 ut_params->op, uint8_t *, IV_OFFSET); 2427 2428 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2429 iv_ptr += cipher_iv_len; 2430 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2431 2432 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2433 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2434 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2435 sym_op->cipher.data.length = cipher_len; 2436 sym_op->cipher.data.offset = cipher_offset; 2437 } else { 2438 sym_op->cipher.data.length = cipher_len >> 3; 2439 sym_op->cipher.data.offset = cipher_offset >> 3; 2440 } 2441 2442 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2443 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2444 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2445 sym_op->auth.data.length = auth_len; 2446 sym_op->auth.data.offset = auth_offset; 2447 } else { 2448 sym_op->auth.data.length = auth_len >> 3; 2449 sym_op->auth.data.offset = auth_offset >> 3; 2450 } 2451 2452 return 0; 2453 } 2454 2455 static int 2456 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2457 { 2458 struct crypto_testsuite_params *ts_params = &testsuite_params; 2459 struct crypto_unittest_params *ut_params = &unittest_params; 2460 2461 int retval; 2462 unsigned plaintext_pad_len; 2463 unsigned plaintext_len; 2464 uint8_t *plaintext; 2465 2466 /* QAT PMD supports byte-aligned data only */ 2467 if ((tdata->validAuthLenInBits.len % 8 != 0) && 2468 (gbl_driver_id == rte_cryptodev_driver_id_get( 2469 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)))) 2470 return -ENOTSUP; 2471 2472 /* Verify the capabilities */ 2473 struct rte_cryptodev_sym_capability_idx cap_idx; 2474 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2475 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2476 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2477 &cap_idx) == NULL) 2478 return -ENOTSUP; 2479 2480 /* Create SNOW 3G session */ 2481 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2482 tdata->key.data, tdata->key.len, 2483 tdata->auth_iv.len, tdata->digest.len, 2484 RTE_CRYPTO_AUTH_OP_GENERATE, 2485 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2486 if (retval < 0) 2487 return retval; 2488 2489 /* alloc mbuf and set payload */ 2490 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2491 2492 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2493 rte_pktmbuf_tailroom(ut_params->ibuf)); 2494 2495 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2496 /* Append data which is padded to a multiple of */ 2497 /* the algorithms block size */ 2498 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2499 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2500 plaintext_pad_len); 2501 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2502 2503 /* Create SNOW 3G operation */ 2504 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2505 tdata->auth_iv.data, tdata->auth_iv.len, 2506 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2507 tdata->validAuthLenInBits.len, 2508 0); 2509 if (retval < 0) 2510 return retval; 2511 2512 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2513 ut_params->op); 2514 ut_params->obuf = ut_params->op->sym->m_src; 2515 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2516 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2517 + plaintext_pad_len; 2518 2519 /* Validate obuf */ 2520 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2521 ut_params->digest, 2522 tdata->digest.data, 2523 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2524 "SNOW 3G Generated auth tag not as expected"); 2525 2526 return 0; 2527 } 2528 2529 static int 2530 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2531 { 2532 struct crypto_testsuite_params *ts_params = &testsuite_params; 2533 struct crypto_unittest_params *ut_params = &unittest_params; 2534 2535 int retval; 2536 unsigned plaintext_pad_len; 2537 unsigned plaintext_len; 2538 uint8_t *plaintext; 2539 2540 /* QAT PMD supports byte-aligned data only */ 2541 if ((tdata->validAuthLenInBits.len % 8 != 0) && 2542 (gbl_driver_id == rte_cryptodev_driver_id_get( 2543 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)))) 2544 return -ENOTSUP; 2545 2546 /* Verify the capabilities */ 2547 struct rte_cryptodev_sym_capability_idx cap_idx; 2548 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2549 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2550 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2551 &cap_idx) == NULL) 2552 return -ENOTSUP; 2553 2554 /* Create SNOW 3G session */ 2555 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2556 tdata->key.data, tdata->key.len, 2557 tdata->auth_iv.len, tdata->digest.len, 2558 RTE_CRYPTO_AUTH_OP_VERIFY, 2559 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2560 if (retval < 0) 2561 return retval; 2562 /* alloc mbuf and set payload */ 2563 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2564 2565 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2566 rte_pktmbuf_tailroom(ut_params->ibuf)); 2567 2568 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2569 /* Append data which is padded to a multiple of */ 2570 /* the algorithms block size */ 2571 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2572 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2573 plaintext_pad_len); 2574 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2575 2576 /* Create SNOW 3G operation */ 2577 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2578 tdata->digest.len, 2579 tdata->auth_iv.data, tdata->auth_iv.len, 2580 plaintext_pad_len, 2581 RTE_CRYPTO_AUTH_OP_VERIFY, 2582 tdata->validAuthLenInBits.len, 2583 0); 2584 if (retval < 0) 2585 return retval; 2586 2587 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2588 ut_params->op); 2589 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2590 ut_params->obuf = ut_params->op->sym->m_src; 2591 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2592 + plaintext_pad_len; 2593 2594 /* Validate obuf */ 2595 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2596 return 0; 2597 else 2598 return -1; 2599 2600 return 0; 2601 } 2602 2603 static int 2604 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2605 { 2606 struct crypto_testsuite_params *ts_params = &testsuite_params; 2607 struct crypto_unittest_params *ut_params = &unittest_params; 2608 2609 int retval; 2610 unsigned plaintext_pad_len; 2611 unsigned plaintext_len; 2612 uint8_t *plaintext; 2613 2614 /* Verify the capabilities */ 2615 struct rte_cryptodev_sym_capability_idx cap_idx; 2616 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2617 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2618 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2619 &cap_idx) == NULL) 2620 return -ENOTSUP; 2621 2622 /* Create KASUMI session */ 2623 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2624 tdata->key.data, tdata->key.len, 2625 0, tdata->digest.len, 2626 RTE_CRYPTO_AUTH_OP_GENERATE, 2627 RTE_CRYPTO_AUTH_KASUMI_F9); 2628 if (retval < 0) 2629 return retval; 2630 2631 /* alloc mbuf and set payload */ 2632 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2633 2634 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2635 rte_pktmbuf_tailroom(ut_params->ibuf)); 2636 2637 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2638 /* Append data which is padded to a multiple of */ 2639 /* the algorithms block size */ 2640 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2641 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2642 plaintext_pad_len); 2643 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2644 2645 /* Create KASUMI operation */ 2646 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2647 NULL, 0, 2648 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2649 tdata->plaintext.len, 2650 0); 2651 if (retval < 0) 2652 return retval; 2653 2654 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2655 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2656 ut_params->op); 2657 else 2658 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2659 ut_params->op); 2660 2661 ut_params->obuf = ut_params->op->sym->m_src; 2662 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2663 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2664 + plaintext_pad_len; 2665 2666 /* Validate obuf */ 2667 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2668 ut_params->digest, 2669 tdata->digest.data, 2670 DIGEST_BYTE_LENGTH_KASUMI_F9, 2671 "KASUMI Generated auth tag not as expected"); 2672 2673 return 0; 2674 } 2675 2676 static int 2677 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2678 { 2679 struct crypto_testsuite_params *ts_params = &testsuite_params; 2680 struct crypto_unittest_params *ut_params = &unittest_params; 2681 2682 int retval; 2683 unsigned plaintext_pad_len; 2684 unsigned plaintext_len; 2685 uint8_t *plaintext; 2686 2687 /* Verify the capabilities */ 2688 struct rte_cryptodev_sym_capability_idx cap_idx; 2689 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2690 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2691 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2692 &cap_idx) == NULL) 2693 return -ENOTSUP; 2694 2695 /* Create KASUMI session */ 2696 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2697 tdata->key.data, tdata->key.len, 2698 0, tdata->digest.len, 2699 RTE_CRYPTO_AUTH_OP_VERIFY, 2700 RTE_CRYPTO_AUTH_KASUMI_F9); 2701 if (retval < 0) 2702 return retval; 2703 /* alloc mbuf and set payload */ 2704 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2705 2706 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2707 rte_pktmbuf_tailroom(ut_params->ibuf)); 2708 2709 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2710 /* Append data which is padded to a multiple */ 2711 /* of the algorithms block size */ 2712 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2713 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2714 plaintext_pad_len); 2715 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2716 2717 /* Create KASUMI operation */ 2718 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2719 tdata->digest.len, 2720 NULL, 0, 2721 plaintext_pad_len, 2722 RTE_CRYPTO_AUTH_OP_VERIFY, 2723 tdata->plaintext.len, 2724 0); 2725 if (retval < 0) 2726 return retval; 2727 2728 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2729 ut_params->op); 2730 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2731 ut_params->obuf = ut_params->op->sym->m_src; 2732 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2733 + plaintext_pad_len; 2734 2735 /* Validate obuf */ 2736 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2737 return 0; 2738 else 2739 return -1; 2740 2741 return 0; 2742 } 2743 2744 static int 2745 test_snow3g_hash_generate_test_case_1(void) 2746 { 2747 return test_snow3g_authentication(&snow3g_hash_test_case_1); 2748 } 2749 2750 static int 2751 test_snow3g_hash_generate_test_case_2(void) 2752 { 2753 return test_snow3g_authentication(&snow3g_hash_test_case_2); 2754 } 2755 2756 static int 2757 test_snow3g_hash_generate_test_case_3(void) 2758 { 2759 return test_snow3g_authentication(&snow3g_hash_test_case_3); 2760 } 2761 2762 static int 2763 test_snow3g_hash_generate_test_case_4(void) 2764 { 2765 return test_snow3g_authentication(&snow3g_hash_test_case_4); 2766 } 2767 2768 static int 2769 test_snow3g_hash_generate_test_case_5(void) 2770 { 2771 return test_snow3g_authentication(&snow3g_hash_test_case_5); 2772 } 2773 2774 static int 2775 test_snow3g_hash_generate_test_case_6(void) 2776 { 2777 return test_snow3g_authentication(&snow3g_hash_test_case_6); 2778 } 2779 2780 static int 2781 test_snow3g_hash_verify_test_case_1(void) 2782 { 2783 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 2784 2785 } 2786 2787 static int 2788 test_snow3g_hash_verify_test_case_2(void) 2789 { 2790 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 2791 } 2792 2793 static int 2794 test_snow3g_hash_verify_test_case_3(void) 2795 { 2796 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 2797 } 2798 2799 static int 2800 test_snow3g_hash_verify_test_case_4(void) 2801 { 2802 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 2803 } 2804 2805 static int 2806 test_snow3g_hash_verify_test_case_5(void) 2807 { 2808 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 2809 } 2810 2811 static int 2812 test_snow3g_hash_verify_test_case_6(void) 2813 { 2814 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 2815 } 2816 2817 static int 2818 test_kasumi_hash_generate_test_case_1(void) 2819 { 2820 return test_kasumi_authentication(&kasumi_hash_test_case_1); 2821 } 2822 2823 static int 2824 test_kasumi_hash_generate_test_case_2(void) 2825 { 2826 return test_kasumi_authentication(&kasumi_hash_test_case_2); 2827 } 2828 2829 static int 2830 test_kasumi_hash_generate_test_case_3(void) 2831 { 2832 return test_kasumi_authentication(&kasumi_hash_test_case_3); 2833 } 2834 2835 static int 2836 test_kasumi_hash_generate_test_case_4(void) 2837 { 2838 return test_kasumi_authentication(&kasumi_hash_test_case_4); 2839 } 2840 2841 static int 2842 test_kasumi_hash_generate_test_case_5(void) 2843 { 2844 return test_kasumi_authentication(&kasumi_hash_test_case_5); 2845 } 2846 2847 static int 2848 test_kasumi_hash_generate_test_case_6(void) 2849 { 2850 return test_kasumi_authentication(&kasumi_hash_test_case_6); 2851 } 2852 2853 static int 2854 test_kasumi_hash_verify_test_case_1(void) 2855 { 2856 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 2857 } 2858 2859 static int 2860 test_kasumi_hash_verify_test_case_2(void) 2861 { 2862 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 2863 } 2864 2865 static int 2866 test_kasumi_hash_verify_test_case_3(void) 2867 { 2868 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 2869 } 2870 2871 static int 2872 test_kasumi_hash_verify_test_case_4(void) 2873 { 2874 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 2875 } 2876 2877 static int 2878 test_kasumi_hash_verify_test_case_5(void) 2879 { 2880 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 2881 } 2882 2883 static int 2884 test_kasumi_encryption(const struct kasumi_test_data *tdata) 2885 { 2886 struct crypto_testsuite_params *ts_params = &testsuite_params; 2887 struct crypto_unittest_params *ut_params = &unittest_params; 2888 2889 int retval; 2890 uint8_t *plaintext, *ciphertext; 2891 unsigned plaintext_pad_len; 2892 unsigned plaintext_len; 2893 2894 /* Verify the capabilities */ 2895 struct rte_cryptodev_sym_capability_idx cap_idx; 2896 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2897 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 2898 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2899 &cap_idx) == NULL) 2900 return -ENOTSUP; 2901 2902 /* Create KASUMI session */ 2903 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2904 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2905 RTE_CRYPTO_CIPHER_KASUMI_F8, 2906 tdata->key.data, tdata->key.len, 2907 tdata->cipher_iv.len); 2908 if (retval < 0) 2909 return retval; 2910 2911 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2912 2913 /* Clear mbuf payload */ 2914 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2915 rte_pktmbuf_tailroom(ut_params->ibuf)); 2916 2917 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2918 /* Append data which is padded to a multiple */ 2919 /* of the algorithms block size */ 2920 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2921 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2922 plaintext_pad_len); 2923 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2924 2925 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 2926 2927 /* Create KASUMI operation */ 2928 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 2929 tdata->cipher_iv.len, 2930 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 2931 tdata->validCipherOffsetInBits.len); 2932 if (retval < 0) 2933 return retval; 2934 2935 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2936 ut_params->op); 2937 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2938 2939 ut_params->obuf = ut_params->op->sym->m_dst; 2940 if (ut_params->obuf) 2941 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 2942 else 2943 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 2944 2945 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 2946 2947 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 2948 (tdata->validCipherOffsetInBits.len >> 3); 2949 /* Validate obuf */ 2950 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 2951 ciphertext, 2952 reference_ciphertext, 2953 tdata->validCipherLenInBits.len, 2954 "KASUMI Ciphertext data not as expected"); 2955 return 0; 2956 } 2957 2958 static int 2959 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 2960 { 2961 struct crypto_testsuite_params *ts_params = &testsuite_params; 2962 struct crypto_unittest_params *ut_params = &unittest_params; 2963 2964 int retval; 2965 2966 unsigned int plaintext_pad_len; 2967 unsigned int plaintext_len; 2968 2969 uint8_t buffer[10000]; 2970 const uint8_t *ciphertext; 2971 2972 struct rte_cryptodev_info dev_info; 2973 2974 /* Verify the capabilities */ 2975 struct rte_cryptodev_sym_capability_idx cap_idx; 2976 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2977 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 2978 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2979 &cap_idx) == NULL) 2980 return -ENOTSUP; 2981 2982 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2983 2984 uint64_t feat_flags = dev_info.feature_flags; 2985 2986 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 2987 printf("Device doesn't support in-place scatter-gather. " 2988 "Test Skipped.\n"); 2989 return -ENOTSUP; 2990 } 2991 2992 /* Create KASUMI session */ 2993 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 2994 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2995 RTE_CRYPTO_CIPHER_KASUMI_F8, 2996 tdata->key.data, tdata->key.len, 2997 tdata->cipher_iv.len); 2998 if (retval < 0) 2999 return retval; 3000 3001 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3002 3003 3004 /* Append data which is padded to a multiple */ 3005 /* of the algorithms block size */ 3006 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3007 3008 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3009 plaintext_pad_len, 10, 0); 3010 3011 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3012 3013 /* Create KASUMI operation */ 3014 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3015 tdata->cipher_iv.len, 3016 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3017 tdata->validCipherOffsetInBits.len); 3018 if (retval < 0) 3019 return retval; 3020 3021 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3022 ut_params->op); 3023 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3024 3025 ut_params->obuf = ut_params->op->sym->m_dst; 3026 3027 if (ut_params->obuf) 3028 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3029 plaintext_len, buffer); 3030 else 3031 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3032 tdata->validCipherOffsetInBits.len >> 3, 3033 plaintext_len, buffer); 3034 3035 /* Validate obuf */ 3036 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3037 3038 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3039 (tdata->validCipherOffsetInBits.len >> 3); 3040 /* Validate obuf */ 3041 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3042 ciphertext, 3043 reference_ciphertext, 3044 tdata->validCipherLenInBits.len, 3045 "KASUMI Ciphertext data not as expected"); 3046 return 0; 3047 } 3048 3049 static int 3050 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3051 { 3052 struct crypto_testsuite_params *ts_params = &testsuite_params; 3053 struct crypto_unittest_params *ut_params = &unittest_params; 3054 3055 int retval; 3056 uint8_t *plaintext, *ciphertext; 3057 unsigned plaintext_pad_len; 3058 unsigned plaintext_len; 3059 3060 /* Verify the capabilities */ 3061 struct rte_cryptodev_sym_capability_idx cap_idx; 3062 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3063 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3064 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3065 &cap_idx) == NULL) 3066 return -ENOTSUP; 3067 3068 /* Create KASUMI session */ 3069 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3070 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3071 RTE_CRYPTO_CIPHER_KASUMI_F8, 3072 tdata->key.data, tdata->key.len, 3073 tdata->cipher_iv.len); 3074 if (retval < 0) 3075 return retval; 3076 3077 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3078 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3079 3080 /* Clear mbuf payload */ 3081 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3082 rte_pktmbuf_tailroom(ut_params->ibuf)); 3083 3084 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3085 /* Append data which is padded to a multiple */ 3086 /* of the algorithms block size */ 3087 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3088 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3089 plaintext_pad_len); 3090 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3091 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3092 3093 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3094 3095 /* Create KASUMI operation */ 3096 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3097 tdata->cipher_iv.len, 3098 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3099 tdata->validCipherOffsetInBits.len); 3100 if (retval < 0) 3101 return retval; 3102 3103 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3104 ut_params->op); 3105 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3106 3107 ut_params->obuf = ut_params->op->sym->m_dst; 3108 if (ut_params->obuf) 3109 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3110 else 3111 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3112 3113 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3114 3115 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3116 (tdata->validCipherOffsetInBits.len >> 3); 3117 /* Validate obuf */ 3118 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3119 ciphertext, 3120 reference_ciphertext, 3121 tdata->validCipherLenInBits.len, 3122 "KASUMI Ciphertext data not as expected"); 3123 return 0; 3124 } 3125 3126 static int 3127 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3128 { 3129 struct crypto_testsuite_params *ts_params = &testsuite_params; 3130 struct crypto_unittest_params *ut_params = &unittest_params; 3131 3132 int retval; 3133 unsigned int plaintext_pad_len; 3134 unsigned int plaintext_len; 3135 3136 const uint8_t *ciphertext; 3137 uint8_t buffer[2048]; 3138 3139 struct rte_cryptodev_info dev_info; 3140 3141 /* Verify the capabilities */ 3142 struct rte_cryptodev_sym_capability_idx cap_idx; 3143 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3144 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3145 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3146 &cap_idx) == NULL) 3147 return -ENOTSUP; 3148 3149 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3150 3151 uint64_t feat_flags = dev_info.feature_flags; 3152 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3153 printf("Device doesn't support out-of-place scatter-gather " 3154 "in both input and output mbufs. " 3155 "Test Skipped.\n"); 3156 return -ENOTSUP; 3157 } 3158 3159 /* Create KASUMI session */ 3160 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3161 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3162 RTE_CRYPTO_CIPHER_KASUMI_F8, 3163 tdata->key.data, tdata->key.len, 3164 tdata->cipher_iv.len); 3165 if (retval < 0) 3166 return retval; 3167 3168 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3169 /* Append data which is padded to a multiple */ 3170 /* of the algorithms block size */ 3171 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3172 3173 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3174 plaintext_pad_len, 10, 0); 3175 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3176 plaintext_pad_len, 3, 0); 3177 3178 /* Append data which is padded to a multiple */ 3179 /* of the algorithms block size */ 3180 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3181 3182 /* Create KASUMI operation */ 3183 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3184 tdata->cipher_iv.len, 3185 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3186 tdata->validCipherOffsetInBits.len); 3187 if (retval < 0) 3188 return retval; 3189 3190 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3191 ut_params->op); 3192 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3193 3194 ut_params->obuf = ut_params->op->sym->m_dst; 3195 if (ut_params->obuf) 3196 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3197 plaintext_pad_len, buffer); 3198 else 3199 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3200 tdata->validCipherOffsetInBits.len >> 3, 3201 plaintext_pad_len, buffer); 3202 3203 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3204 (tdata->validCipherOffsetInBits.len >> 3); 3205 /* Validate obuf */ 3206 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3207 ciphertext, 3208 reference_ciphertext, 3209 tdata->validCipherLenInBits.len, 3210 "KASUMI Ciphertext data not as expected"); 3211 return 0; 3212 } 3213 3214 3215 static int 3216 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3217 { 3218 struct crypto_testsuite_params *ts_params = &testsuite_params; 3219 struct crypto_unittest_params *ut_params = &unittest_params; 3220 3221 int retval; 3222 uint8_t *ciphertext, *plaintext; 3223 unsigned ciphertext_pad_len; 3224 unsigned ciphertext_len; 3225 3226 /* Verify the capabilities */ 3227 struct rte_cryptodev_sym_capability_idx cap_idx; 3228 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3229 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3230 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3231 &cap_idx) == NULL) 3232 return -ENOTSUP; 3233 3234 /* Create KASUMI session */ 3235 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3236 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3237 RTE_CRYPTO_CIPHER_KASUMI_F8, 3238 tdata->key.data, tdata->key.len, 3239 tdata->cipher_iv.len); 3240 if (retval < 0) 3241 return retval; 3242 3243 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3244 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3245 3246 /* Clear mbuf payload */ 3247 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3248 rte_pktmbuf_tailroom(ut_params->ibuf)); 3249 3250 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3251 /* Append data which is padded to a multiple */ 3252 /* of the algorithms block size */ 3253 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3254 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3255 ciphertext_pad_len); 3256 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3257 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3258 3259 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3260 3261 /* Create KASUMI operation */ 3262 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3263 tdata->cipher_iv.len, 3264 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3265 tdata->validCipherOffsetInBits.len); 3266 if (retval < 0) 3267 return retval; 3268 3269 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3270 ut_params->op); 3271 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3272 3273 ut_params->obuf = ut_params->op->sym->m_dst; 3274 if (ut_params->obuf) 3275 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3276 else 3277 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3278 3279 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3280 3281 const uint8_t *reference_plaintext = tdata->plaintext.data + 3282 (tdata->validCipherOffsetInBits.len >> 3); 3283 /* Validate obuf */ 3284 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3285 plaintext, 3286 reference_plaintext, 3287 tdata->validCipherLenInBits.len, 3288 "KASUMI Plaintext data not as expected"); 3289 return 0; 3290 } 3291 3292 static int 3293 test_kasumi_decryption(const struct kasumi_test_data *tdata) 3294 { 3295 struct crypto_testsuite_params *ts_params = &testsuite_params; 3296 struct crypto_unittest_params *ut_params = &unittest_params; 3297 3298 int retval; 3299 uint8_t *ciphertext, *plaintext; 3300 unsigned ciphertext_pad_len; 3301 unsigned ciphertext_len; 3302 3303 /* Verify the capabilities */ 3304 struct rte_cryptodev_sym_capability_idx cap_idx; 3305 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3306 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3307 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3308 &cap_idx) == NULL) 3309 return -ENOTSUP; 3310 3311 /* Create KASUMI session */ 3312 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3313 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3314 RTE_CRYPTO_CIPHER_KASUMI_F8, 3315 tdata->key.data, tdata->key.len, 3316 tdata->cipher_iv.len); 3317 if (retval < 0) 3318 return retval; 3319 3320 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3321 3322 /* Clear mbuf payload */ 3323 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3324 rte_pktmbuf_tailroom(ut_params->ibuf)); 3325 3326 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3327 /* Append data which is padded to a multiple */ 3328 /* of the algorithms block size */ 3329 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3330 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3331 ciphertext_pad_len); 3332 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3333 3334 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3335 3336 /* Create KASUMI operation */ 3337 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3338 tdata->cipher_iv.len, 3339 tdata->ciphertext.len, 3340 tdata->validCipherOffsetInBits.len); 3341 if (retval < 0) 3342 return retval; 3343 3344 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3345 ut_params->op); 3346 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3347 3348 ut_params->obuf = ut_params->op->sym->m_dst; 3349 if (ut_params->obuf) 3350 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3351 else 3352 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3353 3354 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3355 3356 const uint8_t *reference_plaintext = tdata->plaintext.data + 3357 (tdata->validCipherOffsetInBits.len >> 3); 3358 /* Validate obuf */ 3359 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3360 plaintext, 3361 reference_plaintext, 3362 tdata->validCipherLenInBits.len, 3363 "KASUMI Plaintext data not as expected"); 3364 return 0; 3365 } 3366 3367 static int 3368 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3369 { 3370 struct crypto_testsuite_params *ts_params = &testsuite_params; 3371 struct crypto_unittest_params *ut_params = &unittest_params; 3372 3373 int retval; 3374 uint8_t *plaintext, *ciphertext; 3375 unsigned plaintext_pad_len; 3376 unsigned plaintext_len; 3377 3378 /* Verify the capabilities */ 3379 struct rte_cryptodev_sym_capability_idx cap_idx; 3380 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3381 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3382 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3383 &cap_idx) == NULL) 3384 return -ENOTSUP; 3385 3386 /* Create SNOW 3G session */ 3387 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3388 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3389 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3390 tdata->key.data, tdata->key.len, 3391 tdata->cipher_iv.len); 3392 if (retval < 0) 3393 return retval; 3394 3395 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3396 3397 /* Clear mbuf payload */ 3398 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3399 rte_pktmbuf_tailroom(ut_params->ibuf)); 3400 3401 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3402 /* Append data which is padded to a multiple of */ 3403 /* the algorithms block size */ 3404 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3405 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3406 plaintext_pad_len); 3407 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3408 3409 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3410 3411 /* Create SNOW 3G operation */ 3412 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3413 tdata->cipher_iv.len, 3414 tdata->validCipherLenInBits.len, 3415 0); 3416 if (retval < 0) 3417 return retval; 3418 3419 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3420 ut_params->op); 3421 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3422 3423 ut_params->obuf = ut_params->op->sym->m_dst; 3424 if (ut_params->obuf) 3425 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3426 else 3427 ciphertext = plaintext; 3428 3429 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3430 3431 /* Validate obuf */ 3432 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3433 ciphertext, 3434 tdata->ciphertext.data, 3435 tdata->validDataLenInBits.len, 3436 "SNOW 3G Ciphertext data not as expected"); 3437 return 0; 3438 } 3439 3440 3441 static int 3442 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3443 { 3444 struct crypto_testsuite_params *ts_params = &testsuite_params; 3445 struct crypto_unittest_params *ut_params = &unittest_params; 3446 uint8_t *plaintext, *ciphertext; 3447 3448 int retval; 3449 unsigned plaintext_pad_len; 3450 unsigned plaintext_len; 3451 3452 /* Verify the capabilities */ 3453 struct rte_cryptodev_sym_capability_idx cap_idx; 3454 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3455 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3456 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3457 &cap_idx) == NULL) 3458 return -ENOTSUP; 3459 3460 /* Create SNOW 3G session */ 3461 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3462 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3463 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3464 tdata->key.data, tdata->key.len, 3465 tdata->cipher_iv.len); 3466 if (retval < 0) 3467 return retval; 3468 3469 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3470 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3471 3472 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3473 "Failed to allocate input buffer in mempool"); 3474 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3475 "Failed to allocate output buffer in mempool"); 3476 3477 /* Clear mbuf payload */ 3478 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3479 rte_pktmbuf_tailroom(ut_params->ibuf)); 3480 3481 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3482 /* Append data which is padded to a multiple of */ 3483 /* the algorithms block size */ 3484 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3485 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3486 plaintext_pad_len); 3487 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3488 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3489 3490 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3491 3492 /* Create SNOW 3G operation */ 3493 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3494 tdata->cipher_iv.len, 3495 tdata->validCipherLenInBits.len, 3496 0); 3497 if (retval < 0) 3498 return retval; 3499 3500 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3501 ut_params->op); 3502 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3503 3504 ut_params->obuf = ut_params->op->sym->m_dst; 3505 if (ut_params->obuf) 3506 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3507 else 3508 ciphertext = plaintext; 3509 3510 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3511 3512 /* Validate obuf */ 3513 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3514 ciphertext, 3515 tdata->ciphertext.data, 3516 tdata->validDataLenInBits.len, 3517 "SNOW 3G Ciphertext data not as expected"); 3518 return 0; 3519 } 3520 3521 static int 3522 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3523 { 3524 struct crypto_testsuite_params *ts_params = &testsuite_params; 3525 struct crypto_unittest_params *ut_params = &unittest_params; 3526 3527 int retval; 3528 unsigned int plaintext_pad_len; 3529 unsigned int plaintext_len; 3530 uint8_t buffer[10000]; 3531 const uint8_t *ciphertext; 3532 3533 struct rte_cryptodev_info dev_info; 3534 3535 /* Verify the capabilities */ 3536 struct rte_cryptodev_sym_capability_idx cap_idx; 3537 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3538 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3539 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3540 &cap_idx) == NULL) 3541 return -ENOTSUP; 3542 3543 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3544 3545 uint64_t feat_flags = dev_info.feature_flags; 3546 3547 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3548 printf("Device doesn't support out-of-place scatter-gather " 3549 "in both input and output mbufs. " 3550 "Test Skipped.\n"); 3551 return -ENOTSUP; 3552 } 3553 3554 /* Create SNOW 3G session */ 3555 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3556 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3557 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3558 tdata->key.data, tdata->key.len, 3559 tdata->cipher_iv.len); 3560 if (retval < 0) 3561 return retval; 3562 3563 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3564 /* Append data which is padded to a multiple of */ 3565 /* the algorithms block size */ 3566 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3567 3568 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3569 plaintext_pad_len, 10, 0); 3570 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3571 plaintext_pad_len, 3, 0); 3572 3573 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3574 "Failed to allocate input buffer in mempool"); 3575 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3576 "Failed to allocate output buffer in mempool"); 3577 3578 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3579 3580 /* Create SNOW 3G operation */ 3581 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3582 tdata->cipher_iv.len, 3583 tdata->validCipherLenInBits.len, 3584 0); 3585 if (retval < 0) 3586 return retval; 3587 3588 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3589 ut_params->op); 3590 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3591 3592 ut_params->obuf = ut_params->op->sym->m_dst; 3593 if (ut_params->obuf) 3594 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3595 plaintext_len, buffer); 3596 else 3597 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 3598 plaintext_len, buffer); 3599 3600 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3601 3602 /* Validate obuf */ 3603 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3604 ciphertext, 3605 tdata->ciphertext.data, 3606 tdata->validDataLenInBits.len, 3607 "SNOW 3G Ciphertext data not as expected"); 3608 3609 return 0; 3610 } 3611 3612 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3613 static void 3614 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3615 { 3616 uint8_t curr_byte, prev_byte; 3617 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3618 uint8_t lower_byte_mask = (1 << offset) - 1; 3619 unsigned i; 3620 3621 prev_byte = buffer[0]; 3622 buffer[0] >>= offset; 3623 3624 for (i = 1; i < length_in_bytes; i++) { 3625 curr_byte = buffer[i]; 3626 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 3627 (curr_byte >> offset); 3628 prev_byte = curr_byte; 3629 } 3630 } 3631 3632 static int 3633 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 3634 { 3635 struct crypto_testsuite_params *ts_params = &testsuite_params; 3636 struct crypto_unittest_params *ut_params = &unittest_params; 3637 uint8_t *plaintext, *ciphertext; 3638 int retval; 3639 uint32_t plaintext_len; 3640 uint32_t plaintext_pad_len; 3641 uint8_t extra_offset = 4; 3642 uint8_t *expected_ciphertext_shifted; 3643 3644 /* QAT PMD supports byte-aligned data only */ 3645 if (gbl_driver_id == rte_cryptodev_driver_id_get( 3646 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD))) 3647 return -ENOTSUP; 3648 3649 /* Verify the capabilities */ 3650 struct rte_cryptodev_sym_capability_idx cap_idx; 3651 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3652 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3653 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3654 &cap_idx) == NULL) 3655 return -ENOTSUP; 3656 3657 /* Create SNOW 3G session */ 3658 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3659 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3660 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3661 tdata->key.data, tdata->key.len, 3662 tdata->cipher_iv.len); 3663 if (retval < 0) 3664 return retval; 3665 3666 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3667 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3668 3669 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3670 "Failed to allocate input buffer in mempool"); 3671 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3672 "Failed to allocate output buffer in mempool"); 3673 3674 /* Clear mbuf payload */ 3675 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3676 rte_pktmbuf_tailroom(ut_params->ibuf)); 3677 3678 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 3679 /* 3680 * Append data which is padded to a 3681 * multiple of the algorithms block size 3682 */ 3683 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3684 3685 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 3686 plaintext_pad_len); 3687 3688 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3689 3690 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 3691 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 3692 3693 #ifdef RTE_APP_TEST_DEBUG 3694 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 3695 #endif 3696 /* Create SNOW 3G operation */ 3697 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3698 tdata->cipher_iv.len, 3699 tdata->validCipherLenInBits.len, 3700 extra_offset); 3701 if (retval < 0) 3702 return retval; 3703 3704 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3705 ut_params->op); 3706 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3707 3708 ut_params->obuf = ut_params->op->sym->m_dst; 3709 if (ut_params->obuf) 3710 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3711 else 3712 ciphertext = plaintext; 3713 3714 #ifdef RTE_APP_TEST_DEBUG 3715 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3716 #endif 3717 3718 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 3719 3720 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 3721 "failed to reserve memory for ciphertext shifted\n"); 3722 3723 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 3724 ceil_byte_length(tdata->ciphertext.len)); 3725 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 3726 extra_offset); 3727 /* Validate obuf */ 3728 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 3729 ciphertext, 3730 expected_ciphertext_shifted, 3731 tdata->validDataLenInBits.len, 3732 extra_offset, 3733 "SNOW 3G Ciphertext data not as expected"); 3734 return 0; 3735 } 3736 3737 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 3738 { 3739 struct crypto_testsuite_params *ts_params = &testsuite_params; 3740 struct crypto_unittest_params *ut_params = &unittest_params; 3741 3742 int retval; 3743 3744 uint8_t *plaintext, *ciphertext; 3745 unsigned ciphertext_pad_len; 3746 unsigned ciphertext_len; 3747 3748 /* Verify the capabilities */ 3749 struct rte_cryptodev_sym_capability_idx cap_idx; 3750 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3751 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3752 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3753 &cap_idx) == NULL) 3754 return -ENOTSUP; 3755 3756 /* Create SNOW 3G session */ 3757 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3758 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3759 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3760 tdata->key.data, tdata->key.len, 3761 tdata->cipher_iv.len); 3762 if (retval < 0) 3763 return retval; 3764 3765 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3766 3767 /* Clear mbuf payload */ 3768 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3769 rte_pktmbuf_tailroom(ut_params->ibuf)); 3770 3771 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3772 /* Append data which is padded to a multiple of */ 3773 /* the algorithms block size */ 3774 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 3775 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3776 ciphertext_pad_len); 3777 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3778 3779 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3780 3781 /* Create SNOW 3G operation */ 3782 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3783 tdata->cipher_iv.len, 3784 tdata->validCipherLenInBits.len, 3785 tdata->cipher.offset_bits); 3786 if (retval < 0) 3787 return retval; 3788 3789 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3790 ut_params->op); 3791 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3792 ut_params->obuf = ut_params->op->sym->m_dst; 3793 if (ut_params->obuf) 3794 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3795 else 3796 plaintext = ciphertext; 3797 3798 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3799 3800 /* Validate obuf */ 3801 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3802 tdata->plaintext.data, 3803 tdata->validDataLenInBits.len, 3804 "SNOW 3G Plaintext data not as expected"); 3805 return 0; 3806 } 3807 3808 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 3809 { 3810 struct crypto_testsuite_params *ts_params = &testsuite_params; 3811 struct crypto_unittest_params *ut_params = &unittest_params; 3812 3813 int retval; 3814 3815 uint8_t *plaintext, *ciphertext; 3816 unsigned ciphertext_pad_len; 3817 unsigned ciphertext_len; 3818 3819 /* Verify the capabilities */ 3820 struct rte_cryptodev_sym_capability_idx cap_idx; 3821 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3822 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3823 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3824 &cap_idx) == NULL) 3825 return -ENOTSUP; 3826 3827 /* Create SNOW 3G session */ 3828 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3829 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3830 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3831 tdata->key.data, tdata->key.len, 3832 tdata->cipher_iv.len); 3833 if (retval < 0) 3834 return retval; 3835 3836 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3837 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3838 3839 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3840 "Failed to allocate input buffer"); 3841 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3842 "Failed to allocate output buffer"); 3843 3844 /* Clear mbuf payload */ 3845 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3846 rte_pktmbuf_tailroom(ut_params->ibuf)); 3847 3848 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 3849 rte_pktmbuf_tailroom(ut_params->obuf)); 3850 3851 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3852 /* Append data which is padded to a multiple of */ 3853 /* the algorithms block size */ 3854 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 3855 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3856 ciphertext_pad_len); 3857 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3858 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3859 3860 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3861 3862 /* Create SNOW 3G operation */ 3863 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3864 tdata->cipher_iv.len, 3865 tdata->validCipherLenInBits.len, 3866 0); 3867 if (retval < 0) 3868 return retval; 3869 3870 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3871 ut_params->op); 3872 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3873 ut_params->obuf = ut_params->op->sym->m_dst; 3874 if (ut_params->obuf) 3875 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3876 else 3877 plaintext = ciphertext; 3878 3879 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3880 3881 /* Validate obuf */ 3882 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 3883 tdata->plaintext.data, 3884 tdata->validDataLenInBits.len, 3885 "SNOW 3G Plaintext data not as expected"); 3886 return 0; 3887 } 3888 3889 static int 3890 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 3891 { 3892 struct crypto_testsuite_params *ts_params = &testsuite_params; 3893 struct crypto_unittest_params *ut_params = &unittest_params; 3894 3895 int retval; 3896 3897 uint8_t *plaintext, *ciphertext; 3898 unsigned int plaintext_pad_len; 3899 unsigned int plaintext_len; 3900 3901 struct rte_cryptodev_sym_capability_idx cap_idx; 3902 3903 /* Check if device supports ZUC EEA3 */ 3904 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3905 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 3906 3907 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3908 &cap_idx) == NULL) 3909 return -ENOTSUP; 3910 3911 /* Check if device supports ZUC EIA3 */ 3912 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3913 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 3914 3915 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3916 &cap_idx) == NULL) 3917 return -ENOTSUP; 3918 3919 /* Create ZUC session */ 3920 retval = create_zuc_cipher_auth_encrypt_generate_session( 3921 ts_params->valid_devs[0], 3922 tdata); 3923 if (retval < 0) 3924 return retval; 3925 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3926 3927 /* clear mbuf payload */ 3928 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3929 rte_pktmbuf_tailroom(ut_params->ibuf)); 3930 3931 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3932 /* Append data which is padded to a multiple of */ 3933 /* the algorithms block size */ 3934 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3935 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3936 plaintext_pad_len); 3937 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3938 3939 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3940 3941 /* Create ZUC operation */ 3942 retval = create_zuc_cipher_hash_generate_operation(tdata); 3943 if (retval < 0) 3944 return retval; 3945 3946 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3947 ut_params->op); 3948 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3949 ut_params->obuf = ut_params->op->sym->m_src; 3950 if (ut_params->obuf) 3951 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3952 else 3953 ciphertext = plaintext; 3954 3955 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3956 /* Validate obuf */ 3957 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3958 ciphertext, 3959 tdata->ciphertext.data, 3960 tdata->validDataLenInBits.len, 3961 "ZUC Ciphertext data not as expected"); 3962 3963 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3964 + plaintext_pad_len; 3965 3966 /* Validate obuf */ 3967 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3968 ut_params->digest, 3969 tdata->digest.data, 3970 4, 3971 "ZUC Generated auth tag not as expected"); 3972 return 0; 3973 } 3974 3975 static int 3976 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 3977 { 3978 struct crypto_testsuite_params *ts_params = &testsuite_params; 3979 struct crypto_unittest_params *ut_params = &unittest_params; 3980 3981 int retval; 3982 3983 uint8_t *plaintext, *ciphertext; 3984 unsigned plaintext_pad_len; 3985 unsigned plaintext_len; 3986 3987 /* Verify the capabilities */ 3988 struct rte_cryptodev_sym_capability_idx cap_idx; 3989 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3990 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3991 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3992 &cap_idx) == NULL) 3993 return -ENOTSUP; 3994 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3995 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3996 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3997 &cap_idx) == NULL) 3998 return -ENOTSUP; 3999 4000 /* Create SNOW 3G session */ 4001 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4002 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4003 RTE_CRYPTO_AUTH_OP_GENERATE, 4004 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4005 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4006 tdata->key.data, tdata->key.len, 4007 tdata->auth_iv.len, tdata->digest.len, 4008 tdata->cipher_iv.len); 4009 if (retval < 0) 4010 return retval; 4011 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4012 4013 /* clear mbuf payload */ 4014 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4015 rte_pktmbuf_tailroom(ut_params->ibuf)); 4016 4017 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4018 /* Append data which is padded to a multiple of */ 4019 /* the algorithms block size */ 4020 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4021 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4022 plaintext_pad_len); 4023 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4024 4025 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4026 4027 /* Create SNOW 3G operation */ 4028 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4029 tdata->digest.len, tdata->auth_iv.data, 4030 tdata->auth_iv.len, 4031 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4032 tdata->cipher_iv.data, tdata->cipher_iv.len, 4033 tdata->validCipherLenInBits.len, 4034 0, 4035 tdata->validAuthLenInBits.len, 4036 0 4037 ); 4038 if (retval < 0) 4039 return retval; 4040 4041 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4042 ut_params->op); 4043 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4044 ut_params->obuf = ut_params->op->sym->m_src; 4045 if (ut_params->obuf) 4046 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4047 else 4048 ciphertext = plaintext; 4049 4050 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4051 /* Validate obuf */ 4052 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4053 ciphertext, 4054 tdata->ciphertext.data, 4055 tdata->validDataLenInBits.len, 4056 "SNOW 3G Ciphertext data not as expected"); 4057 4058 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4059 + plaintext_pad_len; 4060 4061 /* Validate obuf */ 4062 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4063 ut_params->digest, 4064 tdata->digest.data, 4065 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4066 "SNOW 3G Generated auth tag not as expected"); 4067 return 0; 4068 } 4069 4070 static int 4071 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4072 uint8_t op_mode, uint8_t verify) 4073 { 4074 struct crypto_testsuite_params *ts_params = &testsuite_params; 4075 struct crypto_unittest_params *ut_params = &unittest_params; 4076 4077 int retval; 4078 4079 uint8_t *plaintext = NULL, *ciphertext = NULL; 4080 unsigned int plaintext_pad_len; 4081 unsigned int plaintext_len; 4082 unsigned int ciphertext_pad_len; 4083 unsigned int ciphertext_len; 4084 4085 struct rte_cryptodev_info dev_info; 4086 4087 /* Verify the capabilities */ 4088 struct rte_cryptodev_sym_capability_idx cap_idx; 4089 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4090 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4091 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4092 &cap_idx) == NULL) 4093 return -ENOTSUP; 4094 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4095 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4096 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4097 &cap_idx) == NULL) 4098 return -ENOTSUP; 4099 4100 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4101 4102 uint64_t feat_flags = dev_info.feature_flags; 4103 4104 if (op_mode == OUT_OF_PLACE) { 4105 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4106 printf("Device doesn't support digest encrypted.\n"); 4107 return -ENOTSUP; 4108 } 4109 } 4110 4111 /* Create SNOW 3G session */ 4112 retval = create_wireless_algo_auth_cipher_session( 4113 ts_params->valid_devs[0], 4114 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4115 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4116 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4117 : RTE_CRYPTO_AUTH_OP_GENERATE), 4118 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4119 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4120 tdata->key.data, tdata->key.len, 4121 tdata->auth_iv.len, tdata->digest.len, 4122 tdata->cipher_iv.len); 4123 4124 if (retval < 0) 4125 return retval; 4126 4127 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4128 if (op_mode == OUT_OF_PLACE) 4129 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4130 4131 /* clear mbuf payload */ 4132 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4133 rte_pktmbuf_tailroom(ut_params->ibuf)); 4134 if (op_mode == OUT_OF_PLACE) 4135 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4136 rte_pktmbuf_tailroom(ut_params->obuf)); 4137 4138 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4139 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4140 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4141 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4142 4143 if (verify) { 4144 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4145 ciphertext_pad_len); 4146 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4147 if (op_mode == OUT_OF_PLACE) 4148 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4149 debug_hexdump(stdout, "ciphertext:", ciphertext, 4150 ciphertext_len); 4151 } else { 4152 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4153 plaintext_pad_len); 4154 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4155 if (op_mode == OUT_OF_PLACE) 4156 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4157 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4158 } 4159 4160 /* Create SNOW 3G operation */ 4161 retval = create_wireless_algo_auth_cipher_operation( 4162 tdata->digest.data, tdata->digest.len, 4163 tdata->cipher_iv.data, tdata->cipher_iv.len, 4164 tdata->auth_iv.data, tdata->auth_iv.len, 4165 (tdata->digest.offset_bytes == 0 ? 4166 (verify ? ciphertext_pad_len : plaintext_pad_len) 4167 : tdata->digest.offset_bytes), 4168 tdata->validCipherLenInBits.len, 4169 tdata->cipher.offset_bits, 4170 tdata->validAuthLenInBits.len, 4171 tdata->auth.offset_bits, 4172 op_mode, 0, verify); 4173 4174 if (retval < 0) 4175 return retval; 4176 4177 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4178 ut_params->op); 4179 4180 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4181 4182 ut_params->obuf = (op_mode == IN_PLACE ? 4183 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4184 4185 if (verify) { 4186 if (ut_params->obuf) 4187 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4188 uint8_t *); 4189 else 4190 plaintext = ciphertext + 4191 (tdata->cipher.offset_bits >> 3); 4192 4193 debug_hexdump(stdout, "plaintext:", plaintext, 4194 (tdata->plaintext.len >> 3) - tdata->digest.len); 4195 debug_hexdump(stdout, "plaintext expected:", 4196 tdata->plaintext.data, 4197 (tdata->plaintext.len >> 3) - tdata->digest.len); 4198 } else { 4199 if (ut_params->obuf) 4200 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4201 uint8_t *); 4202 else 4203 ciphertext = plaintext; 4204 4205 debug_hexdump(stdout, "ciphertext:", ciphertext, 4206 ciphertext_len); 4207 debug_hexdump(stdout, "ciphertext expected:", 4208 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4209 4210 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4211 + (tdata->digest.offset_bytes == 0 ? 4212 plaintext_pad_len : tdata->digest.offset_bytes); 4213 4214 debug_hexdump(stdout, "digest:", ut_params->digest, 4215 tdata->digest.len); 4216 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 4217 tdata->digest.len); 4218 } 4219 4220 /* Validate obuf */ 4221 if (verify) { 4222 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4223 plaintext, 4224 tdata->plaintext.data, 4225 tdata->plaintext.len >> 3, 4226 "SNOW 3G Plaintext data not as expected"); 4227 } else { 4228 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4229 ciphertext, 4230 tdata->ciphertext.data, 4231 tdata->validDataLenInBits.len, 4232 "SNOW 3G Ciphertext data not as expected"); 4233 4234 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4235 ut_params->digest, 4236 tdata->digest.data, 4237 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4238 "SNOW 3G Generated auth tag not as expected"); 4239 } 4240 return 0; 4241 } 4242 4243 static int 4244 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 4245 uint8_t op_mode, uint8_t verify) 4246 { 4247 struct crypto_testsuite_params *ts_params = &testsuite_params; 4248 struct crypto_unittest_params *ut_params = &unittest_params; 4249 4250 int retval; 4251 4252 const uint8_t *plaintext = NULL; 4253 const uint8_t *ciphertext = NULL; 4254 const uint8_t *digest = NULL; 4255 unsigned int plaintext_pad_len; 4256 unsigned int plaintext_len; 4257 unsigned int ciphertext_pad_len; 4258 unsigned int ciphertext_len; 4259 uint8_t buffer[10000]; 4260 uint8_t digest_buffer[10000]; 4261 4262 struct rte_cryptodev_info dev_info; 4263 4264 /* Verify the capabilities */ 4265 struct rte_cryptodev_sym_capability_idx cap_idx; 4266 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4267 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4268 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4269 &cap_idx) == NULL) 4270 return -ENOTSUP; 4271 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4272 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4273 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4274 &cap_idx) == NULL) 4275 return -ENOTSUP; 4276 4277 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4278 4279 uint64_t feat_flags = dev_info.feature_flags; 4280 4281 if (op_mode == IN_PLACE) { 4282 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4283 printf("Device doesn't support in-place scatter-gather " 4284 "in both input and output mbufs.\n"); 4285 return -ENOTSUP; 4286 } 4287 } else { 4288 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4289 printf("Device doesn't support out-of-place scatter-gather " 4290 "in both input and output mbufs.\n"); 4291 return -ENOTSUP; 4292 } 4293 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4294 printf("Device doesn't support digest encrypted.\n"); 4295 return -ENOTSUP; 4296 } 4297 } 4298 4299 /* Create SNOW 3G session */ 4300 retval = create_wireless_algo_auth_cipher_session( 4301 ts_params->valid_devs[0], 4302 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4303 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4304 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4305 : RTE_CRYPTO_AUTH_OP_GENERATE), 4306 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4307 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4308 tdata->key.data, tdata->key.len, 4309 tdata->auth_iv.len, tdata->digest.len, 4310 tdata->cipher_iv.len); 4311 4312 if (retval < 0) 4313 return retval; 4314 4315 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4316 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4317 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4318 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4319 4320 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4321 plaintext_pad_len, 15, 0); 4322 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4323 "Failed to allocate input buffer in mempool"); 4324 4325 if (op_mode == OUT_OF_PLACE) { 4326 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4327 plaintext_pad_len, 15, 0); 4328 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4329 "Failed to allocate output buffer in mempool"); 4330 } 4331 4332 if (verify) { 4333 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4334 tdata->ciphertext.data); 4335 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4336 ciphertext_len, buffer); 4337 debug_hexdump(stdout, "ciphertext:", ciphertext, 4338 ciphertext_len); 4339 } else { 4340 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4341 tdata->plaintext.data); 4342 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4343 plaintext_len, buffer); 4344 debug_hexdump(stdout, "plaintext:", plaintext, 4345 plaintext_len); 4346 } 4347 memset(buffer, 0, sizeof(buffer)); 4348 4349 /* Create SNOW 3G operation */ 4350 retval = create_wireless_algo_auth_cipher_operation( 4351 tdata->digest.data, tdata->digest.len, 4352 tdata->cipher_iv.data, tdata->cipher_iv.len, 4353 tdata->auth_iv.data, tdata->auth_iv.len, 4354 (tdata->digest.offset_bytes == 0 ? 4355 (verify ? ciphertext_pad_len : plaintext_pad_len) 4356 : tdata->digest.offset_bytes), 4357 tdata->validCipherLenInBits.len, 4358 tdata->cipher.offset_bits, 4359 tdata->validAuthLenInBits.len, 4360 tdata->auth.offset_bits, 4361 op_mode, 1, verify); 4362 4363 if (retval < 0) 4364 return retval; 4365 4366 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4367 ut_params->op); 4368 4369 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4370 4371 ut_params->obuf = (op_mode == IN_PLACE ? 4372 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4373 4374 if (verify) { 4375 if (ut_params->obuf) 4376 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4377 plaintext_len, buffer); 4378 else 4379 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4380 plaintext_len, buffer); 4381 4382 debug_hexdump(stdout, "plaintext:", plaintext, 4383 (tdata->plaintext.len >> 3) - tdata->digest.len); 4384 debug_hexdump(stdout, "plaintext expected:", 4385 tdata->plaintext.data, 4386 (tdata->plaintext.len >> 3) - tdata->digest.len); 4387 } else { 4388 if (ut_params->obuf) 4389 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4390 ciphertext_len, buffer); 4391 else 4392 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4393 ciphertext_len, buffer); 4394 4395 debug_hexdump(stdout, "ciphertext:", ciphertext, 4396 ciphertext_len); 4397 debug_hexdump(stdout, "ciphertext expected:", 4398 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4399 4400 if (ut_params->obuf) 4401 digest = rte_pktmbuf_read(ut_params->obuf, 4402 (tdata->digest.offset_bytes == 0 ? 4403 plaintext_pad_len : tdata->digest.offset_bytes), 4404 tdata->digest.len, digest_buffer); 4405 else 4406 digest = rte_pktmbuf_read(ut_params->ibuf, 4407 (tdata->digest.offset_bytes == 0 ? 4408 plaintext_pad_len : tdata->digest.offset_bytes), 4409 tdata->digest.len, digest_buffer); 4410 4411 debug_hexdump(stdout, "digest:", digest, 4412 tdata->digest.len); 4413 debug_hexdump(stdout, "digest expected:", 4414 tdata->digest.data, tdata->digest.len); 4415 } 4416 4417 /* Validate obuf */ 4418 if (verify) { 4419 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4420 plaintext, 4421 tdata->plaintext.data, 4422 tdata->plaintext.len >> 3, 4423 "SNOW 3G Plaintext data not as expected"); 4424 } else { 4425 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4426 ciphertext, 4427 tdata->ciphertext.data, 4428 tdata->validDataLenInBits.len, 4429 "SNOW 3G Ciphertext data not as expected"); 4430 4431 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4432 digest, 4433 tdata->digest.data, 4434 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4435 "SNOW 3G Generated auth tag not as expected"); 4436 } 4437 return 0; 4438 } 4439 4440 static int 4441 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 4442 uint8_t op_mode, uint8_t verify) 4443 { 4444 struct crypto_testsuite_params *ts_params = &testsuite_params; 4445 struct crypto_unittest_params *ut_params = &unittest_params; 4446 4447 int retval; 4448 4449 uint8_t *plaintext = NULL, *ciphertext = NULL; 4450 unsigned int plaintext_pad_len; 4451 unsigned int plaintext_len; 4452 unsigned int ciphertext_pad_len; 4453 unsigned int ciphertext_len; 4454 4455 struct rte_cryptodev_info dev_info; 4456 4457 /* Verify the capabilities */ 4458 struct rte_cryptodev_sym_capability_idx cap_idx; 4459 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4460 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4461 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4462 &cap_idx) == NULL) 4463 return -ENOTSUP; 4464 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4465 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4466 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4467 &cap_idx) == NULL) 4468 return -ENOTSUP; 4469 4470 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4471 4472 uint64_t feat_flags = dev_info.feature_flags; 4473 4474 if (op_mode == OUT_OF_PLACE) { 4475 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4476 printf("Device doesn't support digest encrypted.\n"); 4477 return -ENOTSUP; 4478 } 4479 } 4480 4481 /* Create KASUMI session */ 4482 retval = create_wireless_algo_auth_cipher_session( 4483 ts_params->valid_devs[0], 4484 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4485 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4486 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4487 : RTE_CRYPTO_AUTH_OP_GENERATE), 4488 RTE_CRYPTO_AUTH_KASUMI_F9, 4489 RTE_CRYPTO_CIPHER_KASUMI_F8, 4490 tdata->key.data, tdata->key.len, 4491 0, tdata->digest.len, 4492 tdata->cipher_iv.len); 4493 4494 if (retval < 0) 4495 return retval; 4496 4497 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4498 if (op_mode == OUT_OF_PLACE) 4499 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4500 4501 /* clear mbuf payload */ 4502 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4503 rte_pktmbuf_tailroom(ut_params->ibuf)); 4504 if (op_mode == OUT_OF_PLACE) 4505 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4506 rte_pktmbuf_tailroom(ut_params->obuf)); 4507 4508 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4509 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4510 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4511 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4512 4513 if (verify) { 4514 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4515 ciphertext_pad_len); 4516 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4517 if (op_mode == OUT_OF_PLACE) 4518 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4519 debug_hexdump(stdout, "ciphertext:", ciphertext, 4520 ciphertext_len); 4521 } else { 4522 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4523 plaintext_pad_len); 4524 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4525 if (op_mode == OUT_OF_PLACE) 4526 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4527 debug_hexdump(stdout, "plaintext:", plaintext, 4528 plaintext_len); 4529 } 4530 4531 /* Create KASUMI operation */ 4532 retval = create_wireless_algo_auth_cipher_operation( 4533 tdata->digest.data, tdata->digest.len, 4534 tdata->cipher_iv.data, tdata->cipher_iv.len, 4535 NULL, 0, 4536 (tdata->digest.offset_bytes == 0 ? 4537 (verify ? ciphertext_pad_len : plaintext_pad_len) 4538 : tdata->digest.offset_bytes), 4539 tdata->validCipherLenInBits.len, 4540 tdata->validCipherOffsetInBits.len, 4541 tdata->validAuthLenInBits.len, 4542 0, 4543 op_mode, 0, verify); 4544 4545 if (retval < 0) 4546 return retval; 4547 4548 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4549 ut_params->op); 4550 4551 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4552 4553 ut_params->obuf = (op_mode == IN_PLACE ? 4554 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4555 4556 4557 if (verify) { 4558 if (ut_params->obuf) 4559 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4560 uint8_t *); 4561 else 4562 plaintext = ciphertext; 4563 4564 debug_hexdump(stdout, "plaintext:", plaintext, 4565 (tdata->plaintext.len >> 3) - tdata->digest.len); 4566 debug_hexdump(stdout, "plaintext expected:", 4567 tdata->plaintext.data, 4568 (tdata->plaintext.len >> 3) - tdata->digest.len); 4569 } else { 4570 if (ut_params->obuf) 4571 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4572 uint8_t *); 4573 else 4574 ciphertext = plaintext; 4575 4576 debug_hexdump(stdout, "ciphertext:", ciphertext, 4577 ciphertext_len); 4578 debug_hexdump(stdout, "ciphertext expected:", 4579 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4580 4581 ut_params->digest = rte_pktmbuf_mtod( 4582 ut_params->obuf, uint8_t *) + 4583 (tdata->digest.offset_bytes == 0 ? 4584 plaintext_pad_len : tdata->digest.offset_bytes); 4585 4586 debug_hexdump(stdout, "digest:", ut_params->digest, 4587 tdata->digest.len); 4588 debug_hexdump(stdout, "digest expected:", 4589 tdata->digest.data, tdata->digest.len); 4590 } 4591 4592 /* Validate obuf */ 4593 if (verify) { 4594 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4595 plaintext, 4596 tdata->plaintext.data, 4597 tdata->plaintext.len >> 3, 4598 "KASUMI Plaintext data not as expected"); 4599 } else { 4600 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4601 ciphertext, 4602 tdata->ciphertext.data, 4603 tdata->ciphertext.len >> 3, 4604 "KASUMI Ciphertext data not as expected"); 4605 4606 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4607 ut_params->digest, 4608 tdata->digest.data, 4609 DIGEST_BYTE_LENGTH_KASUMI_F9, 4610 "KASUMI Generated auth tag not as expected"); 4611 } 4612 return 0; 4613 } 4614 4615 static int 4616 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 4617 uint8_t op_mode, uint8_t verify) 4618 { 4619 struct crypto_testsuite_params *ts_params = &testsuite_params; 4620 struct crypto_unittest_params *ut_params = &unittest_params; 4621 4622 int retval; 4623 4624 const uint8_t *plaintext = NULL; 4625 const uint8_t *ciphertext = NULL; 4626 const uint8_t *digest = NULL; 4627 unsigned int plaintext_pad_len; 4628 unsigned int plaintext_len; 4629 unsigned int ciphertext_pad_len; 4630 unsigned int ciphertext_len; 4631 uint8_t buffer[10000]; 4632 uint8_t digest_buffer[10000]; 4633 4634 struct rte_cryptodev_info dev_info; 4635 4636 /* Verify the capabilities */ 4637 struct rte_cryptodev_sym_capability_idx cap_idx; 4638 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4639 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4640 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4641 &cap_idx) == NULL) 4642 return -ENOTSUP; 4643 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4644 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4645 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4646 &cap_idx) == NULL) 4647 return -ENOTSUP; 4648 4649 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4650 4651 uint64_t feat_flags = dev_info.feature_flags; 4652 4653 if (op_mode == IN_PLACE) { 4654 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4655 printf("Device doesn't support in-place scatter-gather " 4656 "in both input and output mbufs.\n"); 4657 return -ENOTSUP; 4658 } 4659 } else { 4660 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4661 printf("Device doesn't support out-of-place scatter-gather " 4662 "in both input and output mbufs.\n"); 4663 return -ENOTSUP; 4664 } 4665 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4666 printf("Device doesn't support digest encrypted.\n"); 4667 return -ENOTSUP; 4668 } 4669 } 4670 4671 /* Create KASUMI session */ 4672 retval = create_wireless_algo_auth_cipher_session( 4673 ts_params->valid_devs[0], 4674 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4675 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4676 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4677 : RTE_CRYPTO_AUTH_OP_GENERATE), 4678 RTE_CRYPTO_AUTH_KASUMI_F9, 4679 RTE_CRYPTO_CIPHER_KASUMI_F8, 4680 tdata->key.data, tdata->key.len, 4681 0, tdata->digest.len, 4682 tdata->cipher_iv.len); 4683 4684 if (retval < 0) 4685 return retval; 4686 4687 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4688 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4689 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4690 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4691 4692 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4693 plaintext_pad_len, 15, 0); 4694 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4695 "Failed to allocate input buffer in mempool"); 4696 4697 if (op_mode == OUT_OF_PLACE) { 4698 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4699 plaintext_pad_len, 15, 0); 4700 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4701 "Failed to allocate output buffer in mempool"); 4702 } 4703 4704 if (verify) { 4705 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4706 tdata->ciphertext.data); 4707 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4708 ciphertext_len, buffer); 4709 debug_hexdump(stdout, "ciphertext:", ciphertext, 4710 ciphertext_len); 4711 } else { 4712 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4713 tdata->plaintext.data); 4714 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4715 plaintext_len, buffer); 4716 debug_hexdump(stdout, "plaintext:", plaintext, 4717 plaintext_len); 4718 } 4719 memset(buffer, 0, sizeof(buffer)); 4720 4721 /* Create KASUMI operation */ 4722 retval = create_wireless_algo_auth_cipher_operation( 4723 tdata->digest.data, tdata->digest.len, 4724 tdata->cipher_iv.data, tdata->cipher_iv.len, 4725 NULL, 0, 4726 (tdata->digest.offset_bytes == 0 ? 4727 (verify ? ciphertext_pad_len : plaintext_pad_len) 4728 : tdata->digest.offset_bytes), 4729 tdata->validCipherLenInBits.len, 4730 tdata->validCipherOffsetInBits.len, 4731 tdata->validAuthLenInBits.len, 4732 0, 4733 op_mode, 1, verify); 4734 4735 if (retval < 0) 4736 return retval; 4737 4738 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4739 ut_params->op); 4740 4741 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4742 4743 ut_params->obuf = (op_mode == IN_PLACE ? 4744 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4745 4746 if (verify) { 4747 if (ut_params->obuf) 4748 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4749 plaintext_len, buffer); 4750 else 4751 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4752 plaintext_len, buffer); 4753 4754 debug_hexdump(stdout, "plaintext:", plaintext, 4755 (tdata->plaintext.len >> 3) - tdata->digest.len); 4756 debug_hexdump(stdout, "plaintext expected:", 4757 tdata->plaintext.data, 4758 (tdata->plaintext.len >> 3) - tdata->digest.len); 4759 } else { 4760 if (ut_params->obuf) 4761 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4762 ciphertext_len, buffer); 4763 else 4764 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4765 ciphertext_len, buffer); 4766 4767 debug_hexdump(stdout, "ciphertext:", ciphertext, 4768 ciphertext_len); 4769 debug_hexdump(stdout, "ciphertext expected:", 4770 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4771 4772 if (ut_params->obuf) 4773 digest = rte_pktmbuf_read(ut_params->obuf, 4774 (tdata->digest.offset_bytes == 0 ? 4775 plaintext_pad_len : tdata->digest.offset_bytes), 4776 tdata->digest.len, digest_buffer); 4777 else 4778 digest = rte_pktmbuf_read(ut_params->ibuf, 4779 (tdata->digest.offset_bytes == 0 ? 4780 plaintext_pad_len : tdata->digest.offset_bytes), 4781 tdata->digest.len, digest_buffer); 4782 4783 debug_hexdump(stdout, "digest:", digest, 4784 tdata->digest.len); 4785 debug_hexdump(stdout, "digest expected:", 4786 tdata->digest.data, tdata->digest.len); 4787 } 4788 4789 /* Validate obuf */ 4790 if (verify) { 4791 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4792 plaintext, 4793 tdata->plaintext.data, 4794 tdata->plaintext.len >> 3, 4795 "KASUMI Plaintext data not as expected"); 4796 } else { 4797 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4798 ciphertext, 4799 tdata->ciphertext.data, 4800 tdata->validDataLenInBits.len, 4801 "KASUMI Ciphertext data not as expected"); 4802 4803 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4804 digest, 4805 tdata->digest.data, 4806 DIGEST_BYTE_LENGTH_KASUMI_F9, 4807 "KASUMI Generated auth tag not as expected"); 4808 } 4809 return 0; 4810 } 4811 4812 static int 4813 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 4814 { 4815 struct crypto_testsuite_params *ts_params = &testsuite_params; 4816 struct crypto_unittest_params *ut_params = &unittest_params; 4817 4818 int retval; 4819 4820 uint8_t *plaintext, *ciphertext; 4821 unsigned plaintext_pad_len; 4822 unsigned plaintext_len; 4823 4824 /* Verify the capabilities */ 4825 struct rte_cryptodev_sym_capability_idx cap_idx; 4826 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4827 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4828 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4829 &cap_idx) == NULL) 4830 return -ENOTSUP; 4831 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4832 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4833 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4834 &cap_idx) == NULL) 4835 return -ENOTSUP; 4836 4837 /* Create KASUMI session */ 4838 retval = create_wireless_algo_cipher_auth_session( 4839 ts_params->valid_devs[0], 4840 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4841 RTE_CRYPTO_AUTH_OP_GENERATE, 4842 RTE_CRYPTO_AUTH_KASUMI_F9, 4843 RTE_CRYPTO_CIPHER_KASUMI_F8, 4844 tdata->key.data, tdata->key.len, 4845 0, tdata->digest.len, 4846 tdata->cipher_iv.len); 4847 if (retval < 0) 4848 return retval; 4849 4850 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4851 4852 /* clear mbuf payload */ 4853 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4854 rte_pktmbuf_tailroom(ut_params->ibuf)); 4855 4856 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4857 /* Append data which is padded to a multiple of */ 4858 /* the algorithms block size */ 4859 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4860 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4861 plaintext_pad_len); 4862 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4863 4864 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4865 4866 /* Create KASUMI operation */ 4867 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4868 tdata->digest.len, NULL, 0, 4869 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4870 tdata->cipher_iv.data, tdata->cipher_iv.len, 4871 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4872 tdata->validCipherOffsetInBits.len, 4873 tdata->validAuthLenInBits.len, 4874 0 4875 ); 4876 if (retval < 0) 4877 return retval; 4878 4879 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4880 ut_params->op); 4881 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4882 4883 if (ut_params->op->sym->m_dst) 4884 ut_params->obuf = ut_params->op->sym->m_dst; 4885 else 4886 ut_params->obuf = ut_params->op->sym->m_src; 4887 4888 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 4889 tdata->validCipherOffsetInBits.len >> 3); 4890 4891 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4892 + plaintext_pad_len; 4893 4894 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4895 (tdata->validCipherOffsetInBits.len >> 3); 4896 /* Validate obuf */ 4897 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4898 ciphertext, 4899 reference_ciphertext, 4900 tdata->validCipherLenInBits.len, 4901 "KASUMI Ciphertext data not as expected"); 4902 4903 /* Validate obuf */ 4904 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4905 ut_params->digest, 4906 tdata->digest.data, 4907 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4908 "KASUMI Generated auth tag not as expected"); 4909 return 0; 4910 } 4911 4912 static int 4913 test_zuc_encryption(const struct wireless_test_data *tdata) 4914 { 4915 struct crypto_testsuite_params *ts_params = &testsuite_params; 4916 struct crypto_unittest_params *ut_params = &unittest_params; 4917 4918 int retval; 4919 uint8_t *plaintext, *ciphertext; 4920 unsigned plaintext_pad_len; 4921 unsigned plaintext_len; 4922 4923 struct rte_cryptodev_sym_capability_idx cap_idx; 4924 4925 /* Check if device supports ZUC EEA3 */ 4926 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4927 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4928 4929 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4930 &cap_idx) == NULL) 4931 return -ENOTSUP; 4932 4933 /* Create ZUC session */ 4934 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4935 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4936 RTE_CRYPTO_CIPHER_ZUC_EEA3, 4937 tdata->key.data, tdata->key.len, 4938 tdata->cipher_iv.len); 4939 if (retval < 0) 4940 return retval; 4941 4942 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4943 4944 /* Clear mbuf payload */ 4945 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4946 rte_pktmbuf_tailroom(ut_params->ibuf)); 4947 4948 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4949 /* Append data which is padded to a multiple */ 4950 /* of the algorithms block size */ 4951 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4952 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4953 plaintext_pad_len); 4954 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4955 4956 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4957 4958 /* Create ZUC operation */ 4959 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4960 tdata->cipher_iv.len, 4961 tdata->plaintext.len, 4962 0); 4963 if (retval < 0) 4964 return retval; 4965 4966 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4967 ut_params->op); 4968 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4969 4970 ut_params->obuf = ut_params->op->sym->m_dst; 4971 if (ut_params->obuf) 4972 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4973 else 4974 ciphertext = plaintext; 4975 4976 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4977 4978 /* Validate obuf */ 4979 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4980 ciphertext, 4981 tdata->ciphertext.data, 4982 tdata->validCipherLenInBits.len, 4983 "ZUC Ciphertext data not as expected"); 4984 return 0; 4985 } 4986 4987 static int 4988 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 4989 { 4990 struct crypto_testsuite_params *ts_params = &testsuite_params; 4991 struct crypto_unittest_params *ut_params = &unittest_params; 4992 4993 int retval; 4994 4995 unsigned int plaintext_pad_len; 4996 unsigned int plaintext_len; 4997 const uint8_t *ciphertext; 4998 uint8_t ciphertext_buffer[2048]; 4999 struct rte_cryptodev_info dev_info; 5000 5001 struct rte_cryptodev_sym_capability_idx cap_idx; 5002 5003 /* Check if device supports ZUC EEA3 */ 5004 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5005 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5006 5007 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5008 &cap_idx) == NULL) 5009 return -ENOTSUP; 5010 5011 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5012 5013 uint64_t feat_flags = dev_info.feature_flags; 5014 5015 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5016 printf("Device doesn't support in-place scatter-gather. " 5017 "Test Skipped.\n"); 5018 return -ENOTSUP; 5019 } 5020 5021 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5022 5023 /* Append data which is padded to a multiple */ 5024 /* of the algorithms block size */ 5025 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5026 5027 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5028 plaintext_pad_len, 10, 0); 5029 5030 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5031 tdata->plaintext.data); 5032 5033 /* Create ZUC session */ 5034 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5035 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5036 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5037 tdata->key.data, tdata->key.len, 5038 tdata->cipher_iv.len); 5039 if (retval < 0) 5040 return retval; 5041 5042 /* Clear mbuf payload */ 5043 5044 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 5045 5046 /* Create ZUC operation */ 5047 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5048 tdata->cipher_iv.len, tdata->plaintext.len, 5049 0); 5050 if (retval < 0) 5051 return retval; 5052 5053 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5054 ut_params->op); 5055 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5056 5057 ut_params->obuf = ut_params->op->sym->m_dst; 5058 if (ut_params->obuf) 5059 ciphertext = rte_pktmbuf_read(ut_params->obuf, 5060 0, plaintext_len, ciphertext_buffer); 5061 else 5062 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 5063 0, plaintext_len, ciphertext_buffer); 5064 5065 /* Validate obuf */ 5066 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5067 5068 /* Validate obuf */ 5069 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5070 ciphertext, 5071 tdata->ciphertext.data, 5072 tdata->validCipherLenInBits.len, 5073 "ZUC Ciphertext data not as expected"); 5074 5075 return 0; 5076 } 5077 5078 static int 5079 test_zuc_authentication(const struct wireless_test_data *tdata) 5080 { 5081 struct crypto_testsuite_params *ts_params = &testsuite_params; 5082 struct crypto_unittest_params *ut_params = &unittest_params; 5083 5084 int retval; 5085 unsigned plaintext_pad_len; 5086 unsigned plaintext_len; 5087 uint8_t *plaintext; 5088 5089 struct rte_cryptodev_sym_capability_idx cap_idx; 5090 5091 /* QAT PMD supports byte-aligned data only */ 5092 if ((tdata->validAuthLenInBits.len % 8 != 0) && 5093 (gbl_driver_id == rte_cryptodev_driver_id_get( 5094 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)))) 5095 return -ENOTSUP; 5096 5097 /* Check if device supports ZUC EIA3 */ 5098 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5099 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5100 5101 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5102 &cap_idx) == NULL) 5103 return -ENOTSUP; 5104 5105 /* Create ZUC session */ 5106 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 5107 tdata->key.data, tdata->key.len, 5108 tdata->auth_iv.len, tdata->digest.len, 5109 RTE_CRYPTO_AUTH_OP_GENERATE, 5110 RTE_CRYPTO_AUTH_ZUC_EIA3); 5111 if (retval < 0) 5112 return retval; 5113 5114 /* alloc mbuf and set payload */ 5115 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5116 5117 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5118 rte_pktmbuf_tailroom(ut_params->ibuf)); 5119 5120 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5121 /* Append data which is padded to a multiple of */ 5122 /* the algorithms block size */ 5123 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5124 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5125 plaintext_pad_len); 5126 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5127 5128 /* Create ZUC operation */ 5129 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 5130 tdata->auth_iv.data, tdata->auth_iv.len, 5131 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5132 tdata->validAuthLenInBits.len, 5133 0); 5134 if (retval < 0) 5135 return retval; 5136 5137 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5138 ut_params->op); 5139 ut_params->obuf = ut_params->op->sym->m_src; 5140 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5141 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5142 + plaintext_pad_len; 5143 5144 /* Validate obuf */ 5145 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5146 ut_params->digest, 5147 tdata->digest.data, 5148 tdata->digest.len, 5149 "ZUC Generated auth tag not as expected"); 5150 5151 return 0; 5152 } 5153 5154 static int 5155 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 5156 uint8_t op_mode, uint8_t verify) 5157 { 5158 struct crypto_testsuite_params *ts_params = &testsuite_params; 5159 struct crypto_unittest_params *ut_params = &unittest_params; 5160 5161 int retval; 5162 5163 uint8_t *plaintext = NULL, *ciphertext = NULL; 5164 unsigned int plaintext_pad_len; 5165 unsigned int plaintext_len; 5166 unsigned int ciphertext_pad_len; 5167 unsigned int ciphertext_len; 5168 5169 struct rte_cryptodev_info dev_info; 5170 struct rte_cryptodev_sym_capability_idx cap_idx; 5171 5172 /* Check if device supports ZUC EIA3 */ 5173 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5174 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5175 5176 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5177 &cap_idx) == NULL) 5178 return -ENOTSUP; 5179 5180 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5181 5182 uint64_t feat_flags = dev_info.feature_flags; 5183 5184 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5185 printf("Device doesn't support digest encrypted.\n"); 5186 return -ENOTSUP; 5187 } 5188 5189 /* Create ZUC session */ 5190 retval = create_wireless_algo_auth_cipher_session( 5191 ts_params->valid_devs[0], 5192 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5193 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5194 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5195 : RTE_CRYPTO_AUTH_OP_GENERATE), 5196 RTE_CRYPTO_AUTH_ZUC_EIA3, 5197 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5198 tdata->key.data, tdata->key.len, 5199 tdata->auth_iv.len, tdata->digest.len, 5200 tdata->cipher_iv.len); 5201 5202 if (retval < 0) 5203 return retval; 5204 5205 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5206 if (op_mode == OUT_OF_PLACE) 5207 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5208 5209 /* clear mbuf payload */ 5210 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5211 rte_pktmbuf_tailroom(ut_params->ibuf)); 5212 if (op_mode == OUT_OF_PLACE) 5213 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5214 rte_pktmbuf_tailroom(ut_params->obuf)); 5215 5216 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5217 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5218 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5219 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5220 5221 if (verify) { 5222 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5223 ciphertext_pad_len); 5224 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5225 if (op_mode == OUT_OF_PLACE) 5226 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5227 debug_hexdump(stdout, "ciphertext:", ciphertext, 5228 ciphertext_len); 5229 } else { 5230 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5231 plaintext_pad_len); 5232 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5233 if (op_mode == OUT_OF_PLACE) 5234 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5235 debug_hexdump(stdout, "plaintext:", plaintext, 5236 plaintext_len); 5237 } 5238 5239 /* Create ZUC operation */ 5240 retval = create_wireless_algo_auth_cipher_operation( 5241 tdata->digest.data, tdata->digest.len, 5242 tdata->cipher_iv.data, tdata->cipher_iv.len, 5243 tdata->auth_iv.data, tdata->auth_iv.len, 5244 (tdata->digest.offset_bytes == 0 ? 5245 (verify ? ciphertext_pad_len : plaintext_pad_len) 5246 : tdata->digest.offset_bytes), 5247 tdata->validCipherLenInBits.len, 5248 tdata->validCipherOffsetInBits.len, 5249 tdata->validAuthLenInBits.len, 5250 0, 5251 op_mode, 0, verify); 5252 5253 if (retval < 0) 5254 return retval; 5255 5256 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5257 ut_params->op); 5258 5259 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5260 5261 ut_params->obuf = (op_mode == IN_PLACE ? 5262 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5263 5264 5265 if (verify) { 5266 if (ut_params->obuf) 5267 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5268 uint8_t *); 5269 else 5270 plaintext = ciphertext; 5271 5272 debug_hexdump(stdout, "plaintext:", plaintext, 5273 (tdata->plaintext.len >> 3) - tdata->digest.len); 5274 debug_hexdump(stdout, "plaintext expected:", 5275 tdata->plaintext.data, 5276 (tdata->plaintext.len >> 3) - tdata->digest.len); 5277 } else { 5278 if (ut_params->obuf) 5279 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5280 uint8_t *); 5281 else 5282 ciphertext = plaintext; 5283 5284 debug_hexdump(stdout, "ciphertext:", ciphertext, 5285 ciphertext_len); 5286 debug_hexdump(stdout, "ciphertext expected:", 5287 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5288 5289 ut_params->digest = rte_pktmbuf_mtod( 5290 ut_params->obuf, uint8_t *) + 5291 (tdata->digest.offset_bytes == 0 ? 5292 plaintext_pad_len : tdata->digest.offset_bytes); 5293 5294 debug_hexdump(stdout, "digest:", ut_params->digest, 5295 tdata->digest.len); 5296 debug_hexdump(stdout, "digest expected:", 5297 tdata->digest.data, tdata->digest.len); 5298 } 5299 5300 /* Validate obuf */ 5301 if (verify) { 5302 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5303 plaintext, 5304 tdata->plaintext.data, 5305 tdata->plaintext.len >> 3, 5306 "ZUC Plaintext data not as expected"); 5307 } else { 5308 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5309 ciphertext, 5310 tdata->ciphertext.data, 5311 tdata->ciphertext.len >> 3, 5312 "ZUC Ciphertext data not as expected"); 5313 5314 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5315 ut_params->digest, 5316 tdata->digest.data, 5317 DIGEST_BYTE_LENGTH_KASUMI_F9, 5318 "ZUC Generated auth tag not as expected"); 5319 } 5320 return 0; 5321 } 5322 5323 static int 5324 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 5325 uint8_t op_mode, uint8_t verify) 5326 { 5327 struct crypto_testsuite_params *ts_params = &testsuite_params; 5328 struct crypto_unittest_params *ut_params = &unittest_params; 5329 5330 int retval; 5331 5332 const uint8_t *plaintext = NULL; 5333 const uint8_t *ciphertext = NULL; 5334 const uint8_t *digest = NULL; 5335 unsigned int plaintext_pad_len; 5336 unsigned int plaintext_len; 5337 unsigned int ciphertext_pad_len; 5338 unsigned int ciphertext_len; 5339 uint8_t buffer[10000]; 5340 uint8_t digest_buffer[10000]; 5341 5342 struct rte_cryptodev_info dev_info; 5343 struct rte_cryptodev_sym_capability_idx cap_idx; 5344 5345 /* Check if device supports ZUC EIA3 */ 5346 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5347 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5348 5349 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5350 &cap_idx) == NULL) 5351 return -ENOTSUP; 5352 5353 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5354 5355 uint64_t feat_flags = dev_info.feature_flags; 5356 5357 if (op_mode == IN_PLACE) { 5358 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5359 printf("Device doesn't support in-place scatter-gather " 5360 "in both input and output mbufs.\n"); 5361 return -ENOTSUP; 5362 } 5363 } else { 5364 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5365 printf("Device doesn't support out-of-place scatter-gather " 5366 "in both input and output mbufs.\n"); 5367 return -ENOTSUP; 5368 } 5369 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5370 printf("Device doesn't support digest encrypted.\n"); 5371 return -ENOTSUP; 5372 } 5373 } 5374 5375 /* Create ZUC session */ 5376 retval = create_wireless_algo_auth_cipher_session( 5377 ts_params->valid_devs[0], 5378 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5379 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5380 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5381 : RTE_CRYPTO_AUTH_OP_GENERATE), 5382 RTE_CRYPTO_AUTH_ZUC_EIA3, 5383 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5384 tdata->key.data, tdata->key.len, 5385 tdata->auth_iv.len, tdata->digest.len, 5386 tdata->cipher_iv.len); 5387 5388 if (retval < 0) 5389 return retval; 5390 5391 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5392 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5393 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5394 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5395 5396 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5397 plaintext_pad_len, 15, 0); 5398 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5399 "Failed to allocate input buffer in mempool"); 5400 5401 if (op_mode == OUT_OF_PLACE) { 5402 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5403 plaintext_pad_len, 15, 0); 5404 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5405 "Failed to allocate output buffer in mempool"); 5406 } 5407 5408 if (verify) { 5409 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5410 tdata->ciphertext.data); 5411 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5412 ciphertext_len, buffer); 5413 debug_hexdump(stdout, "ciphertext:", ciphertext, 5414 ciphertext_len); 5415 } else { 5416 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5417 tdata->plaintext.data); 5418 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5419 plaintext_len, buffer); 5420 debug_hexdump(stdout, "plaintext:", plaintext, 5421 plaintext_len); 5422 } 5423 memset(buffer, 0, sizeof(buffer)); 5424 5425 /* Create ZUC operation */ 5426 retval = create_wireless_algo_auth_cipher_operation( 5427 tdata->digest.data, tdata->digest.len, 5428 tdata->cipher_iv.data, tdata->cipher_iv.len, 5429 NULL, 0, 5430 (tdata->digest.offset_bytes == 0 ? 5431 (verify ? ciphertext_pad_len : plaintext_pad_len) 5432 : tdata->digest.offset_bytes), 5433 tdata->validCipherLenInBits.len, 5434 tdata->validCipherOffsetInBits.len, 5435 tdata->validAuthLenInBits.len, 5436 0, 5437 op_mode, 1, verify); 5438 5439 if (retval < 0) 5440 return retval; 5441 5442 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5443 ut_params->op); 5444 5445 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5446 5447 ut_params->obuf = (op_mode == IN_PLACE ? 5448 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5449 5450 if (verify) { 5451 if (ut_params->obuf) 5452 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5453 plaintext_len, buffer); 5454 else 5455 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5456 plaintext_len, buffer); 5457 5458 debug_hexdump(stdout, "plaintext:", plaintext, 5459 (tdata->plaintext.len >> 3) - tdata->digest.len); 5460 debug_hexdump(stdout, "plaintext expected:", 5461 tdata->plaintext.data, 5462 (tdata->plaintext.len >> 3) - tdata->digest.len); 5463 } else { 5464 if (ut_params->obuf) 5465 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5466 ciphertext_len, buffer); 5467 else 5468 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5469 ciphertext_len, buffer); 5470 5471 debug_hexdump(stdout, "ciphertext:", ciphertext, 5472 ciphertext_len); 5473 debug_hexdump(stdout, "ciphertext expected:", 5474 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5475 5476 if (ut_params->obuf) 5477 digest = rte_pktmbuf_read(ut_params->obuf, 5478 (tdata->digest.offset_bytes == 0 ? 5479 plaintext_pad_len : tdata->digest.offset_bytes), 5480 tdata->digest.len, digest_buffer); 5481 else 5482 digest = rte_pktmbuf_read(ut_params->ibuf, 5483 (tdata->digest.offset_bytes == 0 ? 5484 plaintext_pad_len : tdata->digest.offset_bytes), 5485 tdata->digest.len, digest_buffer); 5486 5487 debug_hexdump(stdout, "digest:", digest, 5488 tdata->digest.len); 5489 debug_hexdump(stdout, "digest expected:", 5490 tdata->digest.data, tdata->digest.len); 5491 } 5492 5493 /* Validate obuf */ 5494 if (verify) { 5495 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5496 plaintext, 5497 tdata->plaintext.data, 5498 tdata->plaintext.len >> 3, 5499 "ZUC Plaintext data not as expected"); 5500 } else { 5501 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5502 ciphertext, 5503 tdata->ciphertext.data, 5504 tdata->validDataLenInBits.len, 5505 "ZUC Ciphertext data not as expected"); 5506 5507 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5508 digest, 5509 tdata->digest.data, 5510 DIGEST_BYTE_LENGTH_KASUMI_F9, 5511 "ZUC Generated auth tag not as expected"); 5512 } 5513 return 0; 5514 } 5515 5516 static int 5517 test_kasumi_encryption_test_case_1(void) 5518 { 5519 return test_kasumi_encryption(&kasumi_test_case_1); 5520 } 5521 5522 static int 5523 test_kasumi_encryption_test_case_1_sgl(void) 5524 { 5525 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 5526 } 5527 5528 static int 5529 test_kasumi_encryption_test_case_1_oop(void) 5530 { 5531 return test_kasumi_encryption_oop(&kasumi_test_case_1); 5532 } 5533 5534 static int 5535 test_kasumi_encryption_test_case_1_oop_sgl(void) 5536 { 5537 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 5538 } 5539 5540 static int 5541 test_kasumi_encryption_test_case_2(void) 5542 { 5543 return test_kasumi_encryption(&kasumi_test_case_2); 5544 } 5545 5546 static int 5547 test_kasumi_encryption_test_case_3(void) 5548 { 5549 return test_kasumi_encryption(&kasumi_test_case_3); 5550 } 5551 5552 static int 5553 test_kasumi_encryption_test_case_4(void) 5554 { 5555 return test_kasumi_encryption(&kasumi_test_case_4); 5556 } 5557 5558 static int 5559 test_kasumi_encryption_test_case_5(void) 5560 { 5561 return test_kasumi_encryption(&kasumi_test_case_5); 5562 } 5563 5564 static int 5565 test_kasumi_decryption_test_case_1(void) 5566 { 5567 return test_kasumi_decryption(&kasumi_test_case_1); 5568 } 5569 5570 static int 5571 test_kasumi_decryption_test_case_1_oop(void) 5572 { 5573 return test_kasumi_decryption_oop(&kasumi_test_case_1); 5574 } 5575 5576 static int 5577 test_kasumi_decryption_test_case_2(void) 5578 { 5579 return test_kasumi_decryption(&kasumi_test_case_2); 5580 } 5581 5582 static int 5583 test_kasumi_decryption_test_case_3(void) 5584 { 5585 return test_kasumi_decryption(&kasumi_test_case_3); 5586 } 5587 5588 static int 5589 test_kasumi_decryption_test_case_4(void) 5590 { 5591 return test_kasumi_decryption(&kasumi_test_case_4); 5592 } 5593 5594 static int 5595 test_kasumi_decryption_test_case_5(void) 5596 { 5597 return test_kasumi_decryption(&kasumi_test_case_5); 5598 } 5599 static int 5600 test_snow3g_encryption_test_case_1(void) 5601 { 5602 return test_snow3g_encryption(&snow3g_test_case_1); 5603 } 5604 5605 static int 5606 test_snow3g_encryption_test_case_1_oop(void) 5607 { 5608 return test_snow3g_encryption_oop(&snow3g_test_case_1); 5609 } 5610 5611 static int 5612 test_snow3g_encryption_test_case_1_oop_sgl(void) 5613 { 5614 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 5615 } 5616 5617 5618 static int 5619 test_snow3g_encryption_test_case_1_offset_oop(void) 5620 { 5621 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 5622 } 5623 5624 static int 5625 test_snow3g_encryption_test_case_2(void) 5626 { 5627 return test_snow3g_encryption(&snow3g_test_case_2); 5628 } 5629 5630 static int 5631 test_snow3g_encryption_test_case_3(void) 5632 { 5633 return test_snow3g_encryption(&snow3g_test_case_3); 5634 } 5635 5636 static int 5637 test_snow3g_encryption_test_case_4(void) 5638 { 5639 return test_snow3g_encryption(&snow3g_test_case_4); 5640 } 5641 5642 static int 5643 test_snow3g_encryption_test_case_5(void) 5644 { 5645 return test_snow3g_encryption(&snow3g_test_case_5); 5646 } 5647 5648 static int 5649 test_snow3g_decryption_test_case_1(void) 5650 { 5651 return test_snow3g_decryption(&snow3g_test_case_1); 5652 } 5653 5654 static int 5655 test_snow3g_decryption_test_case_1_oop(void) 5656 { 5657 return test_snow3g_decryption_oop(&snow3g_test_case_1); 5658 } 5659 5660 static int 5661 test_snow3g_decryption_test_case_2(void) 5662 { 5663 return test_snow3g_decryption(&snow3g_test_case_2); 5664 } 5665 5666 static int 5667 test_snow3g_decryption_test_case_3(void) 5668 { 5669 return test_snow3g_decryption(&snow3g_test_case_3); 5670 } 5671 5672 static int 5673 test_snow3g_decryption_test_case_4(void) 5674 { 5675 return test_snow3g_decryption(&snow3g_test_case_4); 5676 } 5677 5678 static int 5679 test_snow3g_decryption_test_case_5(void) 5680 { 5681 return test_snow3g_decryption(&snow3g_test_case_5); 5682 } 5683 5684 /* 5685 * Function prepares snow3g_hash_test_data from snow3g_test_data. 5686 * Pattern digest from snow3g_test_data must be allocated as 5687 * 4 last bytes in plaintext. 5688 */ 5689 static void 5690 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 5691 struct snow3g_hash_test_data *output) 5692 { 5693 if ((pattern != NULL) && (output != NULL)) { 5694 output->key.len = pattern->key.len; 5695 5696 memcpy(output->key.data, 5697 pattern->key.data, pattern->key.len); 5698 5699 output->auth_iv.len = pattern->auth_iv.len; 5700 5701 memcpy(output->auth_iv.data, 5702 pattern->auth_iv.data, pattern->auth_iv.len); 5703 5704 output->plaintext.len = pattern->plaintext.len; 5705 5706 memcpy(output->plaintext.data, 5707 pattern->plaintext.data, pattern->plaintext.len >> 3); 5708 5709 output->digest.len = pattern->digest.len; 5710 5711 memcpy(output->digest.data, 5712 &pattern->plaintext.data[pattern->digest.offset_bytes], 5713 pattern->digest.len); 5714 5715 output->validAuthLenInBits.len = 5716 pattern->validAuthLenInBits.len; 5717 } 5718 } 5719 5720 /* 5721 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 5722 */ 5723 static int 5724 test_snow3g_decryption_with_digest_test_case_1(void) 5725 { 5726 struct snow3g_hash_test_data snow3g_hash_data; 5727 5728 /* 5729 * Function prepare data for hash veryfication test case. 5730 * Digest is allocated in 4 last bytes in plaintext, pattern. 5731 */ 5732 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 5733 5734 return test_snow3g_decryption(&snow3g_test_case_7) & 5735 test_snow3g_authentication_verify(&snow3g_hash_data); 5736 } 5737 5738 static int 5739 test_snow3g_cipher_auth_test_case_1(void) 5740 { 5741 return test_snow3g_cipher_auth(&snow3g_test_case_3); 5742 } 5743 5744 static int 5745 test_snow3g_auth_cipher_test_case_1(void) 5746 { 5747 return test_snow3g_auth_cipher( 5748 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 5749 } 5750 5751 static int 5752 test_snow3g_auth_cipher_test_case_2(void) 5753 { 5754 return test_snow3g_auth_cipher( 5755 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 5756 } 5757 5758 static int 5759 test_snow3g_auth_cipher_test_case_2_oop(void) 5760 { 5761 return test_snow3g_auth_cipher( 5762 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 5763 } 5764 5765 static int 5766 test_snow3g_auth_cipher_part_digest_enc(void) 5767 { 5768 return test_snow3g_auth_cipher( 5769 &snow3g_auth_cipher_partial_digest_encryption, 5770 IN_PLACE, 0); 5771 } 5772 5773 static int 5774 test_snow3g_auth_cipher_part_digest_enc_oop(void) 5775 { 5776 return test_snow3g_auth_cipher( 5777 &snow3g_auth_cipher_partial_digest_encryption, 5778 OUT_OF_PLACE, 0); 5779 } 5780 5781 static int 5782 test_snow3g_auth_cipher_test_case_3_sgl(void) 5783 { 5784 return test_snow3g_auth_cipher_sgl( 5785 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 5786 } 5787 5788 static int 5789 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 5790 { 5791 return test_snow3g_auth_cipher_sgl( 5792 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 5793 } 5794 5795 static int 5796 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 5797 { 5798 return test_snow3g_auth_cipher_sgl( 5799 &snow3g_auth_cipher_partial_digest_encryption, 5800 IN_PLACE, 0); 5801 } 5802 5803 static int 5804 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 5805 { 5806 return test_snow3g_auth_cipher_sgl( 5807 &snow3g_auth_cipher_partial_digest_encryption, 5808 OUT_OF_PLACE, 0); 5809 } 5810 5811 static int 5812 test_snow3g_auth_cipher_verify_test_case_1(void) 5813 { 5814 return test_snow3g_auth_cipher( 5815 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 5816 } 5817 5818 static int 5819 test_snow3g_auth_cipher_verify_test_case_2(void) 5820 { 5821 return test_snow3g_auth_cipher( 5822 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 5823 } 5824 5825 static int 5826 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 5827 { 5828 return test_snow3g_auth_cipher( 5829 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 5830 } 5831 5832 static int 5833 test_snow3g_auth_cipher_verify_part_digest_enc(void) 5834 { 5835 return test_snow3g_auth_cipher( 5836 &snow3g_auth_cipher_partial_digest_encryption, 5837 IN_PLACE, 1); 5838 } 5839 5840 static int 5841 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 5842 { 5843 return test_snow3g_auth_cipher( 5844 &snow3g_auth_cipher_partial_digest_encryption, 5845 OUT_OF_PLACE, 1); 5846 } 5847 5848 static int 5849 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 5850 { 5851 return test_snow3g_auth_cipher_sgl( 5852 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 5853 } 5854 5855 static int 5856 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 5857 { 5858 return test_snow3g_auth_cipher_sgl( 5859 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 5860 } 5861 5862 static int 5863 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 5864 { 5865 return test_snow3g_auth_cipher_sgl( 5866 &snow3g_auth_cipher_partial_digest_encryption, 5867 IN_PLACE, 1); 5868 } 5869 5870 static int 5871 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 5872 { 5873 return test_snow3g_auth_cipher_sgl( 5874 &snow3g_auth_cipher_partial_digest_encryption, 5875 OUT_OF_PLACE, 1); 5876 } 5877 5878 static int 5879 test_snow3g_auth_cipher_with_digest_test_case_1(void) 5880 { 5881 return test_snow3g_auth_cipher( 5882 &snow3g_test_case_7, IN_PLACE, 0); 5883 } 5884 5885 static int 5886 test_kasumi_auth_cipher_test_case_1(void) 5887 { 5888 return test_kasumi_auth_cipher( 5889 &kasumi_test_case_3, IN_PLACE, 0); 5890 } 5891 5892 static int 5893 test_kasumi_auth_cipher_test_case_2(void) 5894 { 5895 return test_kasumi_auth_cipher( 5896 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 5897 } 5898 5899 static int 5900 test_kasumi_auth_cipher_test_case_2_oop(void) 5901 { 5902 return test_kasumi_auth_cipher( 5903 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 5904 } 5905 5906 static int 5907 test_kasumi_auth_cipher_test_case_2_sgl(void) 5908 { 5909 return test_kasumi_auth_cipher_sgl( 5910 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 5911 } 5912 5913 static int 5914 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 5915 { 5916 return test_kasumi_auth_cipher_sgl( 5917 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 5918 } 5919 5920 static int 5921 test_kasumi_auth_cipher_verify_test_case_1(void) 5922 { 5923 return test_kasumi_auth_cipher( 5924 &kasumi_test_case_3, IN_PLACE, 1); 5925 } 5926 5927 static int 5928 test_kasumi_auth_cipher_verify_test_case_2(void) 5929 { 5930 return test_kasumi_auth_cipher( 5931 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 5932 } 5933 5934 static int 5935 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 5936 { 5937 return test_kasumi_auth_cipher( 5938 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 5939 } 5940 5941 static int 5942 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 5943 { 5944 return test_kasumi_auth_cipher_sgl( 5945 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 5946 } 5947 5948 static int 5949 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 5950 { 5951 return test_kasumi_auth_cipher_sgl( 5952 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 5953 } 5954 5955 static int 5956 test_kasumi_cipher_auth_test_case_1(void) 5957 { 5958 return test_kasumi_cipher_auth(&kasumi_test_case_6); 5959 } 5960 5961 static int 5962 test_zuc_encryption_test_case_1(void) 5963 { 5964 return test_zuc_encryption(&zuc_test_case_cipher_193b); 5965 } 5966 5967 static int 5968 test_zuc_encryption_test_case_2(void) 5969 { 5970 return test_zuc_encryption(&zuc_test_case_cipher_800b); 5971 } 5972 5973 static int 5974 test_zuc_encryption_test_case_3(void) 5975 { 5976 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 5977 } 5978 5979 static int 5980 test_zuc_encryption_test_case_4(void) 5981 { 5982 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 5983 } 5984 5985 static int 5986 test_zuc_encryption_test_case_5(void) 5987 { 5988 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 5989 } 5990 5991 static int 5992 test_zuc_encryption_test_case_6_sgl(void) 5993 { 5994 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 5995 } 5996 5997 static int 5998 test_zuc_hash_generate_test_case_1(void) 5999 { 6000 return test_zuc_authentication(&zuc_test_case_auth_1b); 6001 } 6002 6003 static int 6004 test_zuc_hash_generate_test_case_2(void) 6005 { 6006 return test_zuc_authentication(&zuc_test_case_auth_90b); 6007 } 6008 6009 static int 6010 test_zuc_hash_generate_test_case_3(void) 6011 { 6012 return test_zuc_authentication(&zuc_test_case_auth_577b); 6013 } 6014 6015 static int 6016 test_zuc_hash_generate_test_case_4(void) 6017 { 6018 return test_zuc_authentication(&zuc_test_case_auth_2079b); 6019 } 6020 6021 static int 6022 test_zuc_hash_generate_test_case_5(void) 6023 { 6024 return test_zuc_authentication(&zuc_test_auth_5670b); 6025 } 6026 6027 static int 6028 test_zuc_hash_generate_test_case_6(void) 6029 { 6030 return test_zuc_authentication(&zuc_test_case_auth_128b); 6031 } 6032 6033 static int 6034 test_zuc_hash_generate_test_case_7(void) 6035 { 6036 /* This test is not for SW ZUC PMD */ 6037 if (gbl_driver_id == rte_cryptodev_driver_id_get( 6038 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) 6039 return -ENOTSUP; 6040 6041 return test_zuc_authentication(&zuc_test_case_auth_2080b); 6042 } 6043 6044 static int 6045 test_zuc_hash_generate_test_case_8(void) 6046 { 6047 return test_zuc_authentication(&zuc_test_case_auth_584b); 6048 } 6049 6050 static int 6051 test_zuc_cipher_auth_test_case_1(void) 6052 { 6053 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 6054 } 6055 6056 static int 6057 test_zuc_cipher_auth_test_case_2(void) 6058 { 6059 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 6060 } 6061 6062 static int 6063 test_zuc_auth_cipher_test_case_1(void) 6064 { 6065 /* This test is not for SW ZUC PMD */ 6066 if (gbl_driver_id == rte_cryptodev_driver_id_get( 6067 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) 6068 return -ENOTSUP; 6069 6070 return test_zuc_auth_cipher( 6071 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6072 } 6073 6074 static int 6075 test_zuc_auth_cipher_test_case_1_oop(void) 6076 { 6077 return test_zuc_auth_cipher( 6078 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6079 } 6080 6081 static int 6082 test_zuc_auth_cipher_test_case_1_sgl(void) 6083 { 6084 return test_zuc_auth_cipher_sgl( 6085 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6086 } 6087 6088 static int 6089 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 6090 { 6091 return test_zuc_auth_cipher_sgl( 6092 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6093 } 6094 6095 static int 6096 test_zuc_auth_cipher_verify_test_case_1(void) 6097 { 6098 return test_zuc_auth_cipher( 6099 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6100 } 6101 6102 static int 6103 test_zuc_auth_cipher_verify_test_case_1_oop(void) 6104 { 6105 return test_zuc_auth_cipher( 6106 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6107 } 6108 6109 static int 6110 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 6111 { 6112 return test_zuc_auth_cipher_sgl( 6113 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6114 } 6115 6116 static int 6117 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 6118 { 6119 return test_zuc_auth_cipher_sgl( 6120 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6121 } 6122 6123 static int 6124 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 6125 { 6126 uint8_t dev_id = testsuite_params.valid_devs[0]; 6127 6128 struct rte_cryptodev_sym_capability_idx cap_idx; 6129 6130 /* Check if device supports particular cipher algorithm */ 6131 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6132 cap_idx.algo.cipher = tdata->cipher_algo; 6133 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6134 return -ENOTSUP; 6135 6136 /* Check if device supports particular hash algorithm */ 6137 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6138 cap_idx.algo.auth = tdata->auth_algo; 6139 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6140 return -ENOTSUP; 6141 6142 return 0; 6143 } 6144 6145 static int 6146 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 6147 uint8_t op_mode, uint8_t verify) 6148 { 6149 struct crypto_testsuite_params *ts_params = &testsuite_params; 6150 struct crypto_unittest_params *ut_params = &unittest_params; 6151 6152 int retval; 6153 6154 uint8_t *plaintext = NULL, *ciphertext = NULL; 6155 unsigned int plaintext_pad_len; 6156 unsigned int plaintext_len; 6157 unsigned int ciphertext_pad_len; 6158 unsigned int ciphertext_len; 6159 6160 struct rte_cryptodev_info dev_info; 6161 struct rte_crypto_op *op; 6162 6163 /* Check if device supports particular algorithms separately */ 6164 if (test_mixed_check_if_unsupported(tdata)) 6165 return -ENOTSUP; 6166 6167 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6168 6169 uint64_t feat_flags = dev_info.feature_flags; 6170 6171 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6172 printf("Device doesn't support digest encrypted.\n"); 6173 return -ENOTSUP; 6174 } 6175 6176 /* Create the session */ 6177 if (verify) 6178 retval = create_wireless_algo_cipher_auth_session( 6179 ts_params->valid_devs[0], 6180 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6181 RTE_CRYPTO_AUTH_OP_VERIFY, 6182 tdata->auth_algo, 6183 tdata->cipher_algo, 6184 tdata->auth_key.data, tdata->auth_key.len, 6185 tdata->auth_iv.len, tdata->digest_enc.len, 6186 tdata->cipher_iv.len); 6187 else 6188 retval = create_wireless_algo_auth_cipher_session( 6189 ts_params->valid_devs[0], 6190 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6191 RTE_CRYPTO_AUTH_OP_GENERATE, 6192 tdata->auth_algo, 6193 tdata->cipher_algo, 6194 tdata->auth_key.data, tdata->auth_key.len, 6195 tdata->auth_iv.len, tdata->digest_enc.len, 6196 tdata->cipher_iv.len); 6197 if (retval < 0) 6198 return retval; 6199 6200 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6201 if (op_mode == OUT_OF_PLACE) 6202 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6203 6204 /* clear mbuf payload */ 6205 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6206 rte_pktmbuf_tailroom(ut_params->ibuf)); 6207 if (op_mode == OUT_OF_PLACE) 6208 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6209 rte_pktmbuf_tailroom(ut_params->obuf)); 6210 6211 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6212 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6213 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6214 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6215 6216 if (verify) { 6217 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6218 ciphertext_pad_len); 6219 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6220 if (op_mode == OUT_OF_PLACE) 6221 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6222 debug_hexdump(stdout, "ciphertext:", ciphertext, 6223 ciphertext_len); 6224 } else { 6225 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6226 plaintext_pad_len); 6227 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6228 if (op_mode == OUT_OF_PLACE) 6229 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6230 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6231 } 6232 6233 /* Create the operation */ 6234 retval = create_wireless_algo_auth_cipher_operation( 6235 tdata->digest_enc.data, tdata->digest_enc.len, 6236 tdata->cipher_iv.data, tdata->cipher_iv.len, 6237 tdata->auth_iv.data, tdata->auth_iv.len, 6238 (tdata->digest_enc.offset == 0 ? 6239 plaintext_pad_len 6240 : tdata->digest_enc.offset), 6241 tdata->validCipherLen.len_bits, 6242 tdata->cipher.offset_bits, 6243 tdata->validAuthLen.len_bits, 6244 tdata->auth.offset_bits, 6245 op_mode, 0, verify); 6246 6247 if (retval < 0) 6248 return retval; 6249 6250 op = process_crypto_request(ts_params->valid_devs[0], 6251 ut_params->op); 6252 6253 /* Check if the op failed because the device doesn't */ 6254 /* support this particular combination of algorithms */ 6255 if (op == NULL && ut_params->op->status == 6256 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6257 printf("Device doesn't support this mixed combination. " 6258 "Test Skipped.\n"); 6259 return -ENOTSUP; 6260 } 6261 ut_params->op = op; 6262 6263 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6264 6265 ut_params->obuf = (op_mode == IN_PLACE ? 6266 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6267 6268 if (verify) { 6269 if (ut_params->obuf) 6270 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6271 uint8_t *); 6272 else 6273 plaintext = ciphertext + 6274 (tdata->cipher.offset_bits >> 3); 6275 6276 debug_hexdump(stdout, "plaintext:", plaintext, 6277 tdata->plaintext.len_bits >> 3); 6278 debug_hexdump(stdout, "plaintext expected:", 6279 tdata->plaintext.data, 6280 tdata->plaintext.len_bits >> 3); 6281 } else { 6282 if (ut_params->obuf) 6283 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6284 uint8_t *); 6285 else 6286 ciphertext = plaintext; 6287 6288 debug_hexdump(stdout, "ciphertext:", ciphertext, 6289 ciphertext_len); 6290 debug_hexdump(stdout, "ciphertext expected:", 6291 tdata->ciphertext.data, 6292 tdata->ciphertext.len_bits >> 3); 6293 6294 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6295 + (tdata->digest_enc.offset == 0 ? 6296 plaintext_pad_len : tdata->digest_enc.offset); 6297 6298 debug_hexdump(stdout, "digest:", ut_params->digest, 6299 tdata->digest_enc.len); 6300 debug_hexdump(stdout, "digest expected:", 6301 tdata->digest_enc.data, 6302 tdata->digest_enc.len); 6303 } 6304 6305 /* Validate obuf */ 6306 if (verify) { 6307 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6308 plaintext, 6309 tdata->plaintext.data, 6310 tdata->plaintext.len_bits >> 3, 6311 "Plaintext data not as expected"); 6312 } else { 6313 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6314 ciphertext, 6315 tdata->ciphertext.data, 6316 tdata->validDataLen.len_bits, 6317 "Ciphertext data not as expected"); 6318 6319 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6320 ut_params->digest, 6321 tdata->digest_enc.data, 6322 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6323 "Generated auth tag not as expected"); 6324 } 6325 6326 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6327 "crypto op processing failed"); 6328 6329 return 0; 6330 } 6331 6332 static int 6333 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 6334 uint8_t op_mode, uint8_t verify) 6335 { 6336 struct crypto_testsuite_params *ts_params = &testsuite_params; 6337 struct crypto_unittest_params *ut_params = &unittest_params; 6338 6339 int retval; 6340 6341 const uint8_t *plaintext = NULL; 6342 const uint8_t *ciphertext = NULL; 6343 const uint8_t *digest = NULL; 6344 unsigned int plaintext_pad_len; 6345 unsigned int plaintext_len; 6346 unsigned int ciphertext_pad_len; 6347 unsigned int ciphertext_len; 6348 uint8_t buffer[10000]; 6349 uint8_t digest_buffer[10000]; 6350 6351 struct rte_cryptodev_info dev_info; 6352 struct rte_crypto_op *op; 6353 6354 /* Check if device supports particular algorithms */ 6355 if (test_mixed_check_if_unsupported(tdata)) 6356 return -ENOTSUP; 6357 6358 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6359 6360 uint64_t feat_flags = dev_info.feature_flags; 6361 6362 if (op_mode == IN_PLACE) { 6363 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6364 printf("Device doesn't support in-place scatter-gather " 6365 "in both input and output mbufs.\n"); 6366 return -ENOTSUP; 6367 } 6368 } else { 6369 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6370 printf("Device doesn't support out-of-place scatter-gather " 6371 "in both input and output mbufs.\n"); 6372 return -ENOTSUP; 6373 } 6374 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6375 printf("Device doesn't support digest encrypted.\n"); 6376 return -ENOTSUP; 6377 } 6378 } 6379 6380 /* Create the session */ 6381 if (verify) 6382 retval = create_wireless_algo_cipher_auth_session( 6383 ts_params->valid_devs[0], 6384 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6385 RTE_CRYPTO_AUTH_OP_VERIFY, 6386 tdata->auth_algo, 6387 tdata->cipher_algo, 6388 tdata->auth_key.data, tdata->auth_key.len, 6389 tdata->auth_iv.len, tdata->digest_enc.len, 6390 tdata->cipher_iv.len); 6391 else 6392 retval = create_wireless_algo_auth_cipher_session( 6393 ts_params->valid_devs[0], 6394 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6395 RTE_CRYPTO_AUTH_OP_GENERATE, 6396 tdata->auth_algo, 6397 tdata->cipher_algo, 6398 tdata->auth_key.data, tdata->auth_key.len, 6399 tdata->auth_iv.len, tdata->digest_enc.len, 6400 tdata->cipher_iv.len); 6401 if (retval < 0) 6402 return retval; 6403 6404 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6405 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6406 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6407 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6408 6409 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6410 ciphertext_pad_len, 15, 0); 6411 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6412 "Failed to allocate input buffer in mempool"); 6413 6414 if (op_mode == OUT_OF_PLACE) { 6415 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6416 plaintext_pad_len, 15, 0); 6417 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6418 "Failed to allocate output buffer in mempool"); 6419 } 6420 6421 if (verify) { 6422 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6423 tdata->ciphertext.data); 6424 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6425 ciphertext_len, buffer); 6426 debug_hexdump(stdout, "ciphertext:", ciphertext, 6427 ciphertext_len); 6428 } else { 6429 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6430 tdata->plaintext.data); 6431 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6432 plaintext_len, buffer); 6433 debug_hexdump(stdout, "plaintext:", plaintext, 6434 plaintext_len); 6435 } 6436 memset(buffer, 0, sizeof(buffer)); 6437 6438 /* Create the operation */ 6439 retval = create_wireless_algo_auth_cipher_operation( 6440 tdata->digest_enc.data, tdata->digest_enc.len, 6441 tdata->cipher_iv.data, tdata->cipher_iv.len, 6442 tdata->auth_iv.data, tdata->auth_iv.len, 6443 (tdata->digest_enc.offset == 0 ? 6444 plaintext_pad_len 6445 : tdata->digest_enc.offset), 6446 tdata->validCipherLen.len_bits, 6447 tdata->cipher.offset_bits, 6448 tdata->validAuthLen.len_bits, 6449 tdata->auth.offset_bits, 6450 op_mode, 1, verify); 6451 6452 if (retval < 0) 6453 return retval; 6454 6455 op = process_crypto_request(ts_params->valid_devs[0], 6456 ut_params->op); 6457 6458 /* Check if the op failed because the device doesn't */ 6459 /* support this particular combination of algorithms */ 6460 if (op == NULL && ut_params->op->status == 6461 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6462 printf("Device doesn't support this mixed combination. " 6463 "Test Skipped.\n"); 6464 return -ENOTSUP; 6465 } 6466 6467 ut_params->op = op; 6468 6469 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6470 6471 ut_params->obuf = (op_mode == IN_PLACE ? 6472 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6473 6474 if (verify) { 6475 if (ut_params->obuf) 6476 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6477 plaintext_len, buffer); 6478 else 6479 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6480 plaintext_len, buffer); 6481 6482 debug_hexdump(stdout, "plaintext:", plaintext, 6483 (tdata->plaintext.len_bits >> 3) - 6484 tdata->digest_enc.len); 6485 debug_hexdump(stdout, "plaintext expected:", 6486 tdata->plaintext.data, 6487 (tdata->plaintext.len_bits >> 3) - 6488 tdata->digest_enc.len); 6489 } else { 6490 if (ut_params->obuf) 6491 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6492 ciphertext_len, buffer); 6493 else 6494 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6495 ciphertext_len, buffer); 6496 6497 debug_hexdump(stdout, "ciphertext:", ciphertext, 6498 ciphertext_len); 6499 debug_hexdump(stdout, "ciphertext expected:", 6500 tdata->ciphertext.data, 6501 tdata->ciphertext.len_bits >> 3); 6502 6503 if (ut_params->obuf) 6504 digest = rte_pktmbuf_read(ut_params->obuf, 6505 (tdata->digest_enc.offset == 0 ? 6506 plaintext_pad_len : 6507 tdata->digest_enc.offset), 6508 tdata->digest_enc.len, digest_buffer); 6509 else 6510 digest = rte_pktmbuf_read(ut_params->ibuf, 6511 (tdata->digest_enc.offset == 0 ? 6512 plaintext_pad_len : 6513 tdata->digest_enc.offset), 6514 tdata->digest_enc.len, digest_buffer); 6515 6516 debug_hexdump(stdout, "digest:", digest, 6517 tdata->digest_enc.len); 6518 debug_hexdump(stdout, "digest expected:", 6519 tdata->digest_enc.data, tdata->digest_enc.len); 6520 } 6521 6522 /* Validate obuf */ 6523 if (verify) { 6524 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6525 plaintext, 6526 tdata->plaintext.data, 6527 tdata->plaintext.len_bits >> 3, 6528 "Plaintext data not as expected"); 6529 } else { 6530 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6531 ciphertext, 6532 tdata->ciphertext.data, 6533 tdata->validDataLen.len_bits, 6534 "Ciphertext data not as expected"); 6535 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6536 digest, 6537 tdata->digest_enc.data, 6538 tdata->digest_enc.len, 6539 "Generated auth tag not as expected"); 6540 } 6541 6542 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6543 "crypto op processing failed"); 6544 6545 return 0; 6546 } 6547 6548 /** AUTH AES CMAC + CIPHER AES CTR */ 6549 6550 static int 6551 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 6552 { 6553 return test_mixed_auth_cipher( 6554 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 6555 } 6556 6557 static int 6558 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 6559 { 6560 return test_mixed_auth_cipher( 6561 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 6562 } 6563 6564 static int 6565 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 6566 { 6567 return test_mixed_auth_cipher_sgl( 6568 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 6569 } 6570 6571 static int 6572 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 6573 { 6574 return test_mixed_auth_cipher_sgl( 6575 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 6576 } 6577 6578 static int 6579 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 6580 { 6581 return test_mixed_auth_cipher( 6582 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 6583 } 6584 6585 static int 6586 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 6587 { 6588 return test_mixed_auth_cipher( 6589 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 6590 } 6591 6592 static int 6593 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 6594 { 6595 return test_mixed_auth_cipher_sgl( 6596 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 6597 } 6598 6599 static int 6600 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 6601 { 6602 return test_mixed_auth_cipher_sgl( 6603 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 6604 } 6605 6606 /** MIXED AUTH + CIPHER */ 6607 6608 static int 6609 test_auth_zuc_cipher_snow_test_case_1(void) 6610 { 6611 return test_mixed_auth_cipher( 6612 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 6613 } 6614 6615 static int 6616 test_verify_auth_zuc_cipher_snow_test_case_1(void) 6617 { 6618 return test_mixed_auth_cipher( 6619 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 6620 } 6621 6622 static int 6623 test_auth_aes_cmac_cipher_snow_test_case_1(void) 6624 { 6625 return test_mixed_auth_cipher( 6626 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 6627 } 6628 6629 static int 6630 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 6631 { 6632 return test_mixed_auth_cipher( 6633 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 6634 } 6635 6636 static int 6637 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 6638 { 6639 return test_mixed_auth_cipher( 6640 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 6641 } 6642 6643 static int 6644 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 6645 { 6646 return test_mixed_auth_cipher( 6647 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 6648 } 6649 6650 static int 6651 test_auth_snow_cipher_aes_ctr_test_case_1(void) 6652 { 6653 return test_mixed_auth_cipher( 6654 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 6655 } 6656 6657 static int 6658 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 6659 { 6660 return test_mixed_auth_cipher( 6661 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 6662 } 6663 6664 static int 6665 test_auth_snow_cipher_zuc_test_case_1(void) 6666 { 6667 return test_mixed_auth_cipher( 6668 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 6669 } 6670 6671 static int 6672 test_verify_auth_snow_cipher_zuc_test_case_1(void) 6673 { 6674 return test_mixed_auth_cipher( 6675 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 6676 } 6677 6678 static int 6679 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 6680 { 6681 return test_mixed_auth_cipher( 6682 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 6683 } 6684 6685 static int 6686 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 6687 { 6688 return test_mixed_auth_cipher( 6689 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 6690 } 6691 6692 static int 6693 test_auth_null_cipher_snow_test_case_1(void) 6694 { 6695 return test_mixed_auth_cipher( 6696 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 6697 } 6698 6699 static int 6700 test_verify_auth_null_cipher_snow_test_case_1(void) 6701 { 6702 return test_mixed_auth_cipher( 6703 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 6704 } 6705 6706 static int 6707 test_auth_null_cipher_zuc_test_case_1(void) 6708 { 6709 return test_mixed_auth_cipher( 6710 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 6711 } 6712 6713 static int 6714 test_verify_auth_null_cipher_zuc_test_case_1(void) 6715 { 6716 return test_mixed_auth_cipher( 6717 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 6718 } 6719 6720 static int 6721 test_auth_snow_cipher_null_test_case_1(void) 6722 { 6723 return test_mixed_auth_cipher( 6724 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 6725 } 6726 6727 static int 6728 test_verify_auth_snow_cipher_null_test_case_1(void) 6729 { 6730 return test_mixed_auth_cipher( 6731 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 6732 } 6733 6734 static int 6735 test_auth_zuc_cipher_null_test_case_1(void) 6736 { 6737 return test_mixed_auth_cipher( 6738 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 6739 } 6740 6741 static int 6742 test_verify_auth_zuc_cipher_null_test_case_1(void) 6743 { 6744 return test_mixed_auth_cipher( 6745 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 6746 } 6747 6748 static int 6749 test_auth_null_cipher_aes_ctr_test_case_1(void) 6750 { 6751 return test_mixed_auth_cipher( 6752 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 6753 } 6754 6755 static int 6756 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 6757 { 6758 return test_mixed_auth_cipher( 6759 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 6760 } 6761 6762 static int 6763 test_auth_aes_cmac_cipher_null_test_case_1(void) 6764 { 6765 return test_mixed_auth_cipher( 6766 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 6767 } 6768 6769 static int 6770 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 6771 { 6772 return test_mixed_auth_cipher( 6773 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 6774 } 6775 6776 /* ***** AEAD algorithm Tests ***** */ 6777 6778 static int 6779 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 6780 enum rte_crypto_aead_operation op, 6781 const uint8_t *key, const uint8_t key_len, 6782 const uint16_t aad_len, const uint8_t auth_len, 6783 uint8_t iv_len) 6784 { 6785 uint8_t aead_key[key_len]; 6786 6787 struct crypto_testsuite_params *ts_params = &testsuite_params; 6788 struct crypto_unittest_params *ut_params = &unittest_params; 6789 6790 memcpy(aead_key, key, key_len); 6791 6792 /* Setup AEAD Parameters */ 6793 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 6794 ut_params->aead_xform.next = NULL; 6795 ut_params->aead_xform.aead.algo = algo; 6796 ut_params->aead_xform.aead.op = op; 6797 ut_params->aead_xform.aead.key.data = aead_key; 6798 ut_params->aead_xform.aead.key.length = key_len; 6799 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 6800 ut_params->aead_xform.aead.iv.length = iv_len; 6801 ut_params->aead_xform.aead.digest_length = auth_len; 6802 ut_params->aead_xform.aead.aad_length = aad_len; 6803 6804 debug_hexdump(stdout, "key:", key, key_len); 6805 6806 /* Create Crypto session*/ 6807 ut_params->sess = rte_cryptodev_sym_session_create( 6808 ts_params->session_mpool); 6809 6810 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 6811 &ut_params->aead_xform, 6812 ts_params->session_priv_mpool); 6813 6814 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 6815 6816 return 0; 6817 } 6818 6819 static int 6820 create_aead_xform(struct rte_crypto_op *op, 6821 enum rte_crypto_aead_algorithm algo, 6822 enum rte_crypto_aead_operation aead_op, 6823 uint8_t *key, const uint8_t key_len, 6824 const uint8_t aad_len, const uint8_t auth_len, 6825 uint8_t iv_len) 6826 { 6827 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 6828 "failed to allocate space for crypto transform"); 6829 6830 struct rte_crypto_sym_op *sym_op = op->sym; 6831 6832 /* Setup AEAD Parameters */ 6833 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 6834 sym_op->xform->next = NULL; 6835 sym_op->xform->aead.algo = algo; 6836 sym_op->xform->aead.op = aead_op; 6837 sym_op->xform->aead.key.data = key; 6838 sym_op->xform->aead.key.length = key_len; 6839 sym_op->xform->aead.iv.offset = IV_OFFSET; 6840 sym_op->xform->aead.iv.length = iv_len; 6841 sym_op->xform->aead.digest_length = auth_len; 6842 sym_op->xform->aead.aad_length = aad_len; 6843 6844 debug_hexdump(stdout, "key:", key, key_len); 6845 6846 return 0; 6847 } 6848 6849 static int 6850 create_aead_operation(enum rte_crypto_aead_operation op, 6851 const struct aead_test_data *tdata) 6852 { 6853 struct crypto_testsuite_params *ts_params = &testsuite_params; 6854 struct crypto_unittest_params *ut_params = &unittest_params; 6855 6856 uint8_t *plaintext, *ciphertext; 6857 unsigned int aad_pad_len, plaintext_pad_len; 6858 6859 /* Generate Crypto op data structure */ 6860 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 6861 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 6862 TEST_ASSERT_NOT_NULL(ut_params->op, 6863 "Failed to allocate symmetric crypto operation struct"); 6864 6865 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 6866 6867 /* Append aad data */ 6868 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 6869 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 6870 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6871 aad_pad_len); 6872 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 6873 "no room to append aad"); 6874 6875 sym_op->aead.aad.phys_addr = 6876 rte_pktmbuf_iova(ut_params->ibuf); 6877 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 6878 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 6879 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 6880 tdata->aad.len); 6881 6882 /* Append IV at the end of the crypto operation*/ 6883 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 6884 uint8_t *, IV_OFFSET); 6885 6886 /* Copy IV 1 byte after the IV pointer, according to the API */ 6887 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 6888 debug_hexdump(stdout, "iv:", iv_ptr, 6889 tdata->iv.len); 6890 } else { 6891 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 6892 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6893 aad_pad_len); 6894 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 6895 "no room to append aad"); 6896 6897 sym_op->aead.aad.phys_addr = 6898 rte_pktmbuf_iova(ut_params->ibuf); 6899 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 6900 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 6901 tdata->aad.len); 6902 6903 /* Append IV at the end of the crypto operation*/ 6904 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 6905 uint8_t *, IV_OFFSET); 6906 6907 if (tdata->iv.len == 0) { 6908 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 6909 debug_hexdump(stdout, "iv:", iv_ptr, 6910 AES_GCM_J0_LENGTH); 6911 } else { 6912 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 6913 debug_hexdump(stdout, "iv:", iv_ptr, 6914 tdata->iv.len); 6915 } 6916 } 6917 6918 /* Append plaintext/ciphertext */ 6919 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 6920 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 6921 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6922 plaintext_pad_len); 6923 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 6924 6925 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 6926 debug_hexdump(stdout, "plaintext:", plaintext, 6927 tdata->plaintext.len); 6928 6929 if (ut_params->obuf) { 6930 ciphertext = (uint8_t *)rte_pktmbuf_append( 6931 ut_params->obuf, 6932 plaintext_pad_len + aad_pad_len); 6933 TEST_ASSERT_NOT_NULL(ciphertext, 6934 "no room to append ciphertext"); 6935 6936 memset(ciphertext + aad_pad_len, 0, 6937 tdata->ciphertext.len); 6938 } 6939 } else { 6940 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 6941 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6942 plaintext_pad_len); 6943 TEST_ASSERT_NOT_NULL(ciphertext, 6944 "no room to append ciphertext"); 6945 6946 memcpy(ciphertext, tdata->ciphertext.data, 6947 tdata->ciphertext.len); 6948 debug_hexdump(stdout, "ciphertext:", ciphertext, 6949 tdata->ciphertext.len); 6950 6951 if (ut_params->obuf) { 6952 plaintext = (uint8_t *)rte_pktmbuf_append( 6953 ut_params->obuf, 6954 plaintext_pad_len + aad_pad_len); 6955 TEST_ASSERT_NOT_NULL(plaintext, 6956 "no room to append plaintext"); 6957 6958 memset(plaintext + aad_pad_len, 0, 6959 tdata->plaintext.len); 6960 } 6961 } 6962 6963 /* Append digest data */ 6964 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 6965 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 6966 ut_params->obuf ? ut_params->obuf : 6967 ut_params->ibuf, 6968 tdata->auth_tag.len); 6969 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 6970 "no room to append digest"); 6971 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 6972 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 6973 ut_params->obuf ? ut_params->obuf : 6974 ut_params->ibuf, 6975 plaintext_pad_len + 6976 aad_pad_len); 6977 } else { 6978 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 6979 ut_params->ibuf, tdata->auth_tag.len); 6980 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 6981 "no room to append digest"); 6982 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 6983 ut_params->ibuf, 6984 plaintext_pad_len + aad_pad_len); 6985 6986 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 6987 tdata->auth_tag.len); 6988 debug_hexdump(stdout, "digest:", 6989 sym_op->aead.digest.data, 6990 tdata->auth_tag.len); 6991 } 6992 6993 sym_op->aead.data.length = tdata->plaintext.len; 6994 sym_op->aead.data.offset = aad_pad_len; 6995 6996 return 0; 6997 } 6998 6999 static int 7000 test_authenticated_encryption(const struct aead_test_data *tdata) 7001 { 7002 struct crypto_testsuite_params *ts_params = &testsuite_params; 7003 struct crypto_unittest_params *ut_params = &unittest_params; 7004 7005 int retval; 7006 uint8_t *ciphertext, *auth_tag; 7007 uint16_t plaintext_pad_len; 7008 uint32_t i; 7009 7010 /* Verify the capabilities */ 7011 struct rte_cryptodev_sym_capability_idx cap_idx; 7012 const struct rte_cryptodev_symmetric_capability *capability; 7013 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7014 cap_idx.algo.aead = tdata->algo; 7015 capability = rte_cryptodev_sym_capability_get( 7016 ts_params->valid_devs[0], &cap_idx); 7017 if (capability == NULL) 7018 return -ENOTSUP; 7019 if (rte_cryptodev_sym_capability_check_aead( 7020 capability, tdata->key.len, tdata->auth_tag.len, 7021 tdata->aad.len, tdata->iv.len)) 7022 return -ENOTSUP; 7023 7024 /* Create AEAD session */ 7025 retval = create_aead_session(ts_params->valid_devs[0], 7026 tdata->algo, 7027 RTE_CRYPTO_AEAD_OP_ENCRYPT, 7028 tdata->key.data, tdata->key.len, 7029 tdata->aad.len, tdata->auth_tag.len, 7030 tdata->iv.len); 7031 if (retval < 0) 7032 return retval; 7033 7034 if (tdata->aad.len > MBUF_SIZE) { 7035 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7036 /* Populate full size of add data */ 7037 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7038 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7039 } else 7040 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7041 7042 /* clear mbuf payload */ 7043 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7044 rte_pktmbuf_tailroom(ut_params->ibuf)); 7045 7046 /* Create AEAD operation */ 7047 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 7048 if (retval < 0) 7049 return retval; 7050 7051 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7052 7053 ut_params->op->sym->m_src = ut_params->ibuf; 7054 7055 /* Process crypto operation */ 7056 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7057 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7058 else 7059 TEST_ASSERT_NOT_NULL( 7060 process_crypto_request(ts_params->valid_devs[0], 7061 ut_params->op), "failed to process sym crypto op"); 7062 7063 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7064 "crypto op processing failed"); 7065 7066 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7067 7068 if (ut_params->op->sym->m_dst) { 7069 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7070 uint8_t *); 7071 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7072 uint8_t *, plaintext_pad_len); 7073 } else { 7074 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7075 uint8_t *, 7076 ut_params->op->sym->cipher.data.offset); 7077 auth_tag = ciphertext + plaintext_pad_len; 7078 } 7079 7080 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 7081 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 7082 7083 /* Validate obuf */ 7084 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7085 ciphertext, 7086 tdata->ciphertext.data, 7087 tdata->ciphertext.len, 7088 "Ciphertext data not as expected"); 7089 7090 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7091 auth_tag, 7092 tdata->auth_tag.data, 7093 tdata->auth_tag.len, 7094 "Generated auth tag not as expected"); 7095 7096 return 0; 7097 7098 } 7099 7100 #ifdef RTE_LIBRTE_SECURITY 7101 /* Basic algorithm run function for async inplace mode. 7102 * Creates a session from input parameters and runs one operation 7103 * on input_vec. Checks the output of the crypto operation against 7104 * output_vec. 7105 */ 7106 static int 7107 test_pdcp_proto(int i, int oop, 7108 enum rte_crypto_cipher_operation opc, 7109 enum rte_crypto_auth_operation opa, 7110 uint8_t *input_vec, 7111 unsigned int input_vec_len, 7112 uint8_t *output_vec, 7113 unsigned int output_vec_len) 7114 { 7115 struct crypto_testsuite_params *ts_params = &testsuite_params; 7116 struct crypto_unittest_params *ut_params = &unittest_params; 7117 uint8_t *plaintext; 7118 int ret = TEST_SUCCESS; 7119 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7120 rte_cryptodev_get_sec_ctx( 7121 ts_params->valid_devs[0]); 7122 7123 /* Verify the capabilities */ 7124 struct rte_security_capability_idx sec_cap_idx; 7125 7126 sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 7127 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7128 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7129 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7130 return -ENOTSUP; 7131 7132 /* Generate test mbuf data */ 7133 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7134 7135 /* clear mbuf payload */ 7136 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7137 rte_pktmbuf_tailroom(ut_params->ibuf)); 7138 7139 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7140 input_vec_len); 7141 memcpy(plaintext, input_vec, input_vec_len); 7142 7143 /* Out of place support */ 7144 if (oop) { 7145 /* 7146 * For out-op-place we need to alloc another mbuf 7147 */ 7148 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7149 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 7150 } 7151 7152 /* Set crypto type as IPSEC */ 7153 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 7154 7155 /* Setup Cipher Parameters */ 7156 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7157 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 7158 ut_params->cipher_xform.cipher.op = opc; 7159 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 7160 ut_params->cipher_xform.cipher.key.length = 7161 pdcp_test_params[i].cipher_key_len; 7162 ut_params->cipher_xform.cipher.iv.length = 0; 7163 7164 /* Setup HMAC Parameters if ICV header is required */ 7165 if (pdcp_test_params[i].auth_alg != 0) { 7166 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7167 ut_params->auth_xform.next = NULL; 7168 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 7169 ut_params->auth_xform.auth.op = opa; 7170 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 7171 ut_params->auth_xform.auth.key.length = 7172 pdcp_test_params[i].auth_key_len; 7173 7174 ut_params->cipher_xform.next = &ut_params->auth_xform; 7175 } else { 7176 ut_params->cipher_xform.next = NULL; 7177 } 7178 7179 struct rte_security_session_conf sess_conf = { 7180 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 7181 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7182 {.pdcp = { 7183 .bearer = pdcp_test_bearer[i], 7184 .domain = pdcp_test_params[i].domain, 7185 .pkt_dir = pdcp_test_packet_direction[i], 7186 .sn_size = pdcp_test_data_sn_size[i], 7187 .hfn = pdcp_test_hfn[i], 7188 .hfn_threshold = pdcp_test_hfn_threshold[i], 7189 } }, 7190 .crypto_xform = &ut_params->cipher_xform 7191 }; 7192 7193 /* Create security session */ 7194 ut_params->sec_session = rte_security_session_create(ctx, 7195 &sess_conf, ts_params->session_priv_mpool); 7196 7197 if (!ut_params->sec_session) { 7198 printf("TestCase %s()-%d line %d failed %s: ", 7199 __func__, i, __LINE__, "Failed to allocate session"); 7200 ret = TEST_FAILED; 7201 goto on_err; 7202 } 7203 7204 /* Generate crypto op data structure */ 7205 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7206 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7207 if (!ut_params->op) { 7208 printf("TestCase %s()-%d line %d failed %s: ", 7209 __func__, i, __LINE__, 7210 "Failed to allocate symmetric crypto operation struct"); 7211 ret = TEST_FAILED; 7212 goto on_err; 7213 } 7214 7215 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7216 7217 /* set crypto operation source mbuf */ 7218 ut_params->op->sym->m_src = ut_params->ibuf; 7219 if (oop) 7220 ut_params->op->sym->m_dst = ut_params->obuf; 7221 7222 /* Process crypto operation */ 7223 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7224 == NULL) { 7225 printf("TestCase %s()-%d line %d failed %s: ", 7226 __func__, i, __LINE__, 7227 "failed to process sym crypto op"); 7228 ret = TEST_FAILED; 7229 goto on_err; 7230 } 7231 7232 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7233 printf("TestCase %s()-%d line %d failed %s: ", 7234 __func__, i, __LINE__, "crypto op processing failed"); 7235 ret = TEST_FAILED; 7236 goto on_err; 7237 } 7238 7239 /* Validate obuf */ 7240 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7241 uint8_t *); 7242 if (oop) { 7243 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7244 uint8_t *); 7245 } 7246 7247 if (memcmp(ciphertext, output_vec, output_vec_len)) { 7248 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7249 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 7250 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 7251 ret = TEST_FAILED; 7252 goto on_err; 7253 } 7254 7255 on_err: 7256 rte_crypto_op_free(ut_params->op); 7257 ut_params->op = NULL; 7258 7259 if (ut_params->sec_session) 7260 rte_security_session_destroy(ctx, ut_params->sec_session); 7261 ut_params->sec_session = NULL; 7262 7263 rte_pktmbuf_free(ut_params->ibuf); 7264 ut_params->ibuf = NULL; 7265 if (oop) { 7266 rte_pktmbuf_free(ut_params->obuf); 7267 ut_params->obuf = NULL; 7268 } 7269 7270 return ret; 7271 } 7272 7273 static int 7274 test_pdcp_proto_SGL(int i, int oop, 7275 enum rte_crypto_cipher_operation opc, 7276 enum rte_crypto_auth_operation opa, 7277 uint8_t *input_vec, 7278 unsigned int input_vec_len, 7279 uint8_t *output_vec, 7280 unsigned int output_vec_len, 7281 uint32_t fragsz, 7282 uint32_t fragsz_oop) 7283 { 7284 struct crypto_testsuite_params *ts_params = &testsuite_params; 7285 struct crypto_unittest_params *ut_params = &unittest_params; 7286 uint8_t *plaintext; 7287 struct rte_mbuf *buf, *buf_oop = NULL; 7288 int ret = TEST_SUCCESS; 7289 int to_trn = 0; 7290 int to_trn_tbl[16]; 7291 int segs = 1; 7292 unsigned int trn_data = 0; 7293 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7294 rte_cryptodev_get_sec_ctx( 7295 ts_params->valid_devs[0]); 7296 7297 /* Verify the capabilities */ 7298 struct rte_security_capability_idx sec_cap_idx; 7299 7300 sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 7301 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7302 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7303 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7304 return -ENOTSUP; 7305 7306 if (fragsz > input_vec_len) 7307 fragsz = input_vec_len; 7308 7309 uint16_t plaintext_len = fragsz; 7310 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 7311 7312 if (fragsz_oop > output_vec_len) 7313 frag_size_oop = output_vec_len; 7314 7315 int ecx = 0; 7316 if (input_vec_len % fragsz != 0) { 7317 if (input_vec_len / fragsz + 1 > 16) 7318 return 1; 7319 } else if (input_vec_len / fragsz > 16) 7320 return 1; 7321 7322 /* Out of place support */ 7323 if (oop) { 7324 /* 7325 * For out-op-place we need to alloc another mbuf 7326 */ 7327 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7328 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 7329 buf_oop = ut_params->obuf; 7330 } 7331 7332 /* Generate test mbuf data */ 7333 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7334 7335 /* clear mbuf payload */ 7336 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7337 rte_pktmbuf_tailroom(ut_params->ibuf)); 7338 7339 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7340 plaintext_len); 7341 memcpy(plaintext, input_vec, plaintext_len); 7342 trn_data += plaintext_len; 7343 7344 buf = ut_params->ibuf; 7345 7346 /* 7347 * Loop until no more fragments 7348 */ 7349 7350 while (trn_data < input_vec_len) { 7351 ++segs; 7352 to_trn = (input_vec_len - trn_data < fragsz) ? 7353 (input_vec_len - trn_data) : fragsz; 7354 7355 to_trn_tbl[ecx++] = to_trn; 7356 7357 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7358 buf = buf->next; 7359 7360 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 7361 rte_pktmbuf_tailroom(buf)); 7362 7363 /* OOP */ 7364 if (oop && !fragsz_oop) { 7365 buf_oop->next = 7366 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7367 buf_oop = buf_oop->next; 7368 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7369 0, rte_pktmbuf_tailroom(buf_oop)); 7370 rte_pktmbuf_append(buf_oop, to_trn); 7371 } 7372 7373 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 7374 to_trn); 7375 7376 memcpy(plaintext, input_vec + trn_data, to_trn); 7377 trn_data += to_trn; 7378 } 7379 7380 ut_params->ibuf->nb_segs = segs; 7381 7382 segs = 1; 7383 if (fragsz_oop && oop) { 7384 to_trn = 0; 7385 ecx = 0; 7386 7387 trn_data = frag_size_oop; 7388 while (trn_data < output_vec_len) { 7389 ++segs; 7390 to_trn = 7391 (output_vec_len - trn_data < 7392 frag_size_oop) ? 7393 (output_vec_len - trn_data) : 7394 frag_size_oop; 7395 7396 to_trn_tbl[ecx++] = to_trn; 7397 7398 buf_oop->next = 7399 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7400 buf_oop = buf_oop->next; 7401 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7402 0, rte_pktmbuf_tailroom(buf_oop)); 7403 rte_pktmbuf_append(buf_oop, to_trn); 7404 7405 trn_data += to_trn; 7406 } 7407 ut_params->obuf->nb_segs = segs; 7408 } 7409 7410 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 7411 7412 /* Setup Cipher Parameters */ 7413 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7414 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 7415 ut_params->cipher_xform.cipher.op = opc; 7416 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 7417 ut_params->cipher_xform.cipher.key.length = 7418 pdcp_test_params[i].cipher_key_len; 7419 ut_params->cipher_xform.cipher.iv.length = 0; 7420 7421 /* Setup HMAC Parameters if ICV header is required */ 7422 if (pdcp_test_params[i].auth_alg != 0) { 7423 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7424 ut_params->auth_xform.next = NULL; 7425 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 7426 ut_params->auth_xform.auth.op = opa; 7427 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 7428 ut_params->auth_xform.auth.key.length = 7429 pdcp_test_params[i].auth_key_len; 7430 7431 ut_params->cipher_xform.next = &ut_params->auth_xform; 7432 } else { 7433 ut_params->cipher_xform.next = NULL; 7434 } 7435 7436 struct rte_security_session_conf sess_conf = { 7437 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 7438 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7439 {.pdcp = { 7440 .bearer = pdcp_test_bearer[i], 7441 .domain = pdcp_test_params[i].domain, 7442 .pkt_dir = pdcp_test_packet_direction[i], 7443 .sn_size = pdcp_test_data_sn_size[i], 7444 .hfn = pdcp_test_hfn[i], 7445 .hfn_threshold = pdcp_test_hfn_threshold[i], 7446 } }, 7447 .crypto_xform = &ut_params->cipher_xform 7448 }; 7449 7450 /* Create security session */ 7451 ut_params->sec_session = rte_security_session_create(ctx, 7452 &sess_conf, ts_params->session_priv_mpool); 7453 7454 if (!ut_params->sec_session) { 7455 printf("TestCase %s()-%d line %d failed %s: ", 7456 __func__, i, __LINE__, "Failed to allocate session"); 7457 ret = TEST_FAILED; 7458 goto on_err; 7459 } 7460 7461 /* Generate crypto op data structure */ 7462 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7463 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7464 if (!ut_params->op) { 7465 printf("TestCase %s()-%d line %d failed %s: ", 7466 __func__, i, __LINE__, 7467 "Failed to allocate symmetric crypto operation struct"); 7468 ret = TEST_FAILED; 7469 goto on_err; 7470 } 7471 7472 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7473 7474 /* set crypto operation source mbuf */ 7475 ut_params->op->sym->m_src = ut_params->ibuf; 7476 if (oop) 7477 ut_params->op->sym->m_dst = ut_params->obuf; 7478 7479 /* Process crypto operation */ 7480 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7481 == NULL) { 7482 printf("TestCase %s()-%d line %d failed %s: ", 7483 __func__, i, __LINE__, 7484 "failed to process sym crypto op"); 7485 ret = TEST_FAILED; 7486 goto on_err; 7487 } 7488 7489 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7490 printf("TestCase %s()-%d line %d failed %s: ", 7491 __func__, i, __LINE__, "crypto op processing failed"); 7492 ret = TEST_FAILED; 7493 goto on_err; 7494 } 7495 7496 /* Validate obuf */ 7497 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7498 uint8_t *); 7499 if (oop) { 7500 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7501 uint8_t *); 7502 } 7503 if (fragsz_oop) 7504 fragsz = frag_size_oop; 7505 if (memcmp(ciphertext, output_vec, fragsz)) { 7506 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7507 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 7508 rte_hexdump(stdout, "reference", output_vec, fragsz); 7509 ret = TEST_FAILED; 7510 goto on_err; 7511 } 7512 7513 buf = ut_params->op->sym->m_src->next; 7514 if (oop) 7515 buf = ut_params->op->sym->m_dst->next; 7516 7517 unsigned int off = fragsz; 7518 7519 ecx = 0; 7520 while (buf) { 7521 ciphertext = rte_pktmbuf_mtod(buf, 7522 uint8_t *); 7523 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 7524 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7525 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 7526 rte_hexdump(stdout, "reference", output_vec + off, 7527 to_trn_tbl[ecx]); 7528 ret = TEST_FAILED; 7529 goto on_err; 7530 } 7531 off += to_trn_tbl[ecx++]; 7532 buf = buf->next; 7533 } 7534 on_err: 7535 rte_crypto_op_free(ut_params->op); 7536 ut_params->op = NULL; 7537 7538 if (ut_params->sec_session) 7539 rte_security_session_destroy(ctx, ut_params->sec_session); 7540 ut_params->sec_session = NULL; 7541 7542 rte_pktmbuf_free(ut_params->ibuf); 7543 ut_params->ibuf = NULL; 7544 if (oop) { 7545 rte_pktmbuf_free(ut_params->obuf); 7546 ut_params->obuf = NULL; 7547 } 7548 7549 return ret; 7550 } 7551 7552 int 7553 test_pdcp_proto_cplane_encap(int i) 7554 { 7555 return test_pdcp_proto(i, 0, 7556 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7557 RTE_CRYPTO_AUTH_OP_GENERATE, 7558 pdcp_test_data_in[i], 7559 pdcp_test_data_in_len[i], 7560 pdcp_test_data_out[i], 7561 pdcp_test_data_in_len[i]+4); 7562 } 7563 7564 int 7565 test_pdcp_proto_uplane_encap(int i) 7566 { 7567 return test_pdcp_proto(i, 0, 7568 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7569 RTE_CRYPTO_AUTH_OP_GENERATE, 7570 pdcp_test_data_in[i], 7571 pdcp_test_data_in_len[i], 7572 pdcp_test_data_out[i], 7573 pdcp_test_data_in_len[i]); 7574 7575 } 7576 7577 int 7578 test_pdcp_proto_uplane_encap_with_int(int i) 7579 { 7580 return test_pdcp_proto(i, 0, 7581 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7582 RTE_CRYPTO_AUTH_OP_GENERATE, 7583 pdcp_test_data_in[i], 7584 pdcp_test_data_in_len[i], 7585 pdcp_test_data_out[i], 7586 pdcp_test_data_in_len[i] + 4); 7587 } 7588 7589 int 7590 test_pdcp_proto_cplane_decap(int i) 7591 { 7592 return test_pdcp_proto(i, 0, 7593 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7594 RTE_CRYPTO_AUTH_OP_VERIFY, 7595 pdcp_test_data_out[i], 7596 pdcp_test_data_in_len[i] + 4, 7597 pdcp_test_data_in[i], 7598 pdcp_test_data_in_len[i]); 7599 } 7600 7601 int 7602 test_pdcp_proto_uplane_decap(int i) 7603 { 7604 return test_pdcp_proto(i, 0, 7605 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7606 RTE_CRYPTO_AUTH_OP_VERIFY, 7607 pdcp_test_data_out[i], 7608 pdcp_test_data_in_len[i], 7609 pdcp_test_data_in[i], 7610 pdcp_test_data_in_len[i]); 7611 } 7612 7613 int 7614 test_pdcp_proto_uplane_decap_with_int(int i) 7615 { 7616 return test_pdcp_proto(i, 0, 7617 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7618 RTE_CRYPTO_AUTH_OP_VERIFY, 7619 pdcp_test_data_out[i], 7620 pdcp_test_data_in_len[i] + 4, 7621 pdcp_test_data_in[i], 7622 pdcp_test_data_in_len[i]); 7623 } 7624 7625 static int 7626 test_PDCP_PROTO_SGL_in_place_32B(void) 7627 { 7628 /* i can be used for running any PDCP case 7629 * In this case it is uplane 12-bit AES-SNOW DL encap 7630 */ 7631 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 7632 return test_pdcp_proto_SGL(i, IN_PLACE, 7633 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7634 RTE_CRYPTO_AUTH_OP_GENERATE, 7635 pdcp_test_data_in[i], 7636 pdcp_test_data_in_len[i], 7637 pdcp_test_data_out[i], 7638 pdcp_test_data_in_len[i]+4, 7639 32, 0); 7640 } 7641 static int 7642 test_PDCP_PROTO_SGL_oop_32B_128B(void) 7643 { 7644 /* i can be used for running any PDCP case 7645 * In this case it is uplane 18-bit NULL-NULL DL encap 7646 */ 7647 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 7648 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 7649 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7650 RTE_CRYPTO_AUTH_OP_GENERATE, 7651 pdcp_test_data_in[i], 7652 pdcp_test_data_in_len[i], 7653 pdcp_test_data_out[i], 7654 pdcp_test_data_in_len[i]+4, 7655 32, 128); 7656 } 7657 static int 7658 test_PDCP_PROTO_SGL_oop_32B_40B(void) 7659 { 7660 /* i can be used for running any PDCP case 7661 * In this case it is uplane 18-bit AES DL encap 7662 */ 7663 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 7664 + DOWNLINK; 7665 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 7666 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7667 RTE_CRYPTO_AUTH_OP_GENERATE, 7668 pdcp_test_data_in[i], 7669 pdcp_test_data_in_len[i], 7670 pdcp_test_data_out[i], 7671 pdcp_test_data_in_len[i], 7672 32, 40); 7673 } 7674 static int 7675 test_PDCP_PROTO_SGL_oop_128B_32B(void) 7676 { 7677 /* i can be used for running any PDCP case 7678 * In this case it is cplane 12-bit AES-ZUC DL encap 7679 */ 7680 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 7681 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 7682 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7683 RTE_CRYPTO_AUTH_OP_GENERATE, 7684 pdcp_test_data_in[i], 7685 pdcp_test_data_in_len[i], 7686 pdcp_test_data_out[i], 7687 pdcp_test_data_in_len[i]+4, 7688 128, 32); 7689 } 7690 #endif 7691 7692 static int 7693 test_AES_GCM_authenticated_encryption_test_case_1(void) 7694 { 7695 return test_authenticated_encryption(&gcm_test_case_1); 7696 } 7697 7698 static int 7699 test_AES_GCM_authenticated_encryption_test_case_2(void) 7700 { 7701 return test_authenticated_encryption(&gcm_test_case_2); 7702 } 7703 7704 static int 7705 test_AES_GCM_authenticated_encryption_test_case_3(void) 7706 { 7707 return test_authenticated_encryption(&gcm_test_case_3); 7708 } 7709 7710 static int 7711 test_AES_GCM_authenticated_encryption_test_case_4(void) 7712 { 7713 return test_authenticated_encryption(&gcm_test_case_4); 7714 } 7715 7716 static int 7717 test_AES_GCM_authenticated_encryption_test_case_5(void) 7718 { 7719 return test_authenticated_encryption(&gcm_test_case_5); 7720 } 7721 7722 static int 7723 test_AES_GCM_authenticated_encryption_test_case_6(void) 7724 { 7725 return test_authenticated_encryption(&gcm_test_case_6); 7726 } 7727 7728 static int 7729 test_AES_GCM_authenticated_encryption_test_case_7(void) 7730 { 7731 return test_authenticated_encryption(&gcm_test_case_7); 7732 } 7733 7734 static int 7735 test_AES_GCM_authenticated_encryption_test_case_8(void) 7736 { 7737 return test_authenticated_encryption(&gcm_test_case_8); 7738 } 7739 7740 static int 7741 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 7742 { 7743 return test_authenticated_encryption(&gcm_J0_test_case_1); 7744 } 7745 7746 static int 7747 test_AES_GCM_auth_encryption_test_case_192_1(void) 7748 { 7749 return test_authenticated_encryption(&gcm_test_case_192_1); 7750 } 7751 7752 static int 7753 test_AES_GCM_auth_encryption_test_case_192_2(void) 7754 { 7755 return test_authenticated_encryption(&gcm_test_case_192_2); 7756 } 7757 7758 static int 7759 test_AES_GCM_auth_encryption_test_case_192_3(void) 7760 { 7761 return test_authenticated_encryption(&gcm_test_case_192_3); 7762 } 7763 7764 static int 7765 test_AES_GCM_auth_encryption_test_case_192_4(void) 7766 { 7767 return test_authenticated_encryption(&gcm_test_case_192_4); 7768 } 7769 7770 static int 7771 test_AES_GCM_auth_encryption_test_case_192_5(void) 7772 { 7773 return test_authenticated_encryption(&gcm_test_case_192_5); 7774 } 7775 7776 static int 7777 test_AES_GCM_auth_encryption_test_case_192_6(void) 7778 { 7779 return test_authenticated_encryption(&gcm_test_case_192_6); 7780 } 7781 7782 static int 7783 test_AES_GCM_auth_encryption_test_case_192_7(void) 7784 { 7785 return test_authenticated_encryption(&gcm_test_case_192_7); 7786 } 7787 7788 static int 7789 test_AES_GCM_auth_encryption_test_case_256_1(void) 7790 { 7791 return test_authenticated_encryption(&gcm_test_case_256_1); 7792 } 7793 7794 static int 7795 test_AES_GCM_auth_encryption_test_case_256_2(void) 7796 { 7797 return test_authenticated_encryption(&gcm_test_case_256_2); 7798 } 7799 7800 static int 7801 test_AES_GCM_auth_encryption_test_case_256_3(void) 7802 { 7803 return test_authenticated_encryption(&gcm_test_case_256_3); 7804 } 7805 7806 static int 7807 test_AES_GCM_auth_encryption_test_case_256_4(void) 7808 { 7809 return test_authenticated_encryption(&gcm_test_case_256_4); 7810 } 7811 7812 static int 7813 test_AES_GCM_auth_encryption_test_case_256_5(void) 7814 { 7815 return test_authenticated_encryption(&gcm_test_case_256_5); 7816 } 7817 7818 static int 7819 test_AES_GCM_auth_encryption_test_case_256_6(void) 7820 { 7821 return test_authenticated_encryption(&gcm_test_case_256_6); 7822 } 7823 7824 static int 7825 test_AES_GCM_auth_encryption_test_case_256_7(void) 7826 { 7827 return test_authenticated_encryption(&gcm_test_case_256_7); 7828 } 7829 7830 static int 7831 test_AES_GCM_auth_encryption_test_case_aad_1(void) 7832 { 7833 return test_authenticated_encryption(&gcm_test_case_aad_1); 7834 } 7835 7836 static int 7837 test_AES_GCM_auth_encryption_test_case_aad_2(void) 7838 { 7839 return test_authenticated_encryption(&gcm_test_case_aad_2); 7840 } 7841 7842 static int 7843 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 7844 { 7845 struct aead_test_data tdata; 7846 int res; 7847 7848 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7849 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7850 tdata.iv.data[0] += 1; 7851 res = test_authenticated_encryption(&tdata); 7852 if (res == -ENOTSUP) 7853 return res; 7854 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7855 return TEST_SUCCESS; 7856 } 7857 7858 static int 7859 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 7860 { 7861 struct aead_test_data tdata; 7862 int res; 7863 7864 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7865 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7866 tdata.plaintext.data[0] += 1; 7867 res = test_authenticated_encryption(&tdata); 7868 if (res == -ENOTSUP) 7869 return res; 7870 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7871 return TEST_SUCCESS; 7872 } 7873 7874 static int 7875 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 7876 { 7877 struct aead_test_data tdata; 7878 int res; 7879 7880 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7881 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7882 tdata.ciphertext.data[0] += 1; 7883 res = test_authenticated_encryption(&tdata); 7884 if (res == -ENOTSUP) 7885 return res; 7886 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7887 return TEST_SUCCESS; 7888 } 7889 7890 static int 7891 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 7892 { 7893 struct aead_test_data tdata; 7894 int res; 7895 7896 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7897 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7898 tdata.aad.len += 1; 7899 res = test_authenticated_encryption(&tdata); 7900 if (res == -ENOTSUP) 7901 return res; 7902 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7903 return TEST_SUCCESS; 7904 } 7905 7906 static int 7907 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 7908 { 7909 struct aead_test_data tdata; 7910 uint8_t aad[gcm_test_case_7.aad.len]; 7911 int res; 7912 7913 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7914 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7915 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 7916 aad[0] += 1; 7917 tdata.aad.data = aad; 7918 res = test_authenticated_encryption(&tdata); 7919 if (res == -ENOTSUP) 7920 return res; 7921 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7922 return TEST_SUCCESS; 7923 } 7924 7925 static int 7926 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 7927 { 7928 struct aead_test_data tdata; 7929 int res; 7930 7931 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 7932 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 7933 tdata.auth_tag.data[0] += 1; 7934 res = test_authenticated_encryption(&tdata); 7935 if (res == -ENOTSUP) 7936 return res; 7937 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 7938 return TEST_SUCCESS; 7939 } 7940 7941 static int 7942 test_authenticated_decryption(const struct aead_test_data *tdata) 7943 { 7944 struct crypto_testsuite_params *ts_params = &testsuite_params; 7945 struct crypto_unittest_params *ut_params = &unittest_params; 7946 7947 int retval; 7948 uint8_t *plaintext; 7949 uint32_t i; 7950 7951 /* Verify the capabilities */ 7952 struct rte_cryptodev_sym_capability_idx cap_idx; 7953 const struct rte_cryptodev_symmetric_capability *capability; 7954 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7955 cap_idx.algo.aead = tdata->algo; 7956 capability = rte_cryptodev_sym_capability_get( 7957 ts_params->valid_devs[0], &cap_idx); 7958 if (capability == NULL) 7959 return -ENOTSUP; 7960 if (rte_cryptodev_sym_capability_check_aead( 7961 capability, tdata->key.len, tdata->auth_tag.len, 7962 tdata->aad.len, tdata->iv.len)) 7963 return -ENOTSUP; 7964 7965 /* Create AEAD session */ 7966 retval = create_aead_session(ts_params->valid_devs[0], 7967 tdata->algo, 7968 RTE_CRYPTO_AEAD_OP_DECRYPT, 7969 tdata->key.data, tdata->key.len, 7970 tdata->aad.len, tdata->auth_tag.len, 7971 tdata->iv.len); 7972 if (retval < 0) 7973 return retval; 7974 7975 /* alloc mbuf and set payload */ 7976 if (tdata->aad.len > MBUF_SIZE) { 7977 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7978 /* Populate full size of add data */ 7979 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7980 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7981 } else 7982 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7983 7984 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7985 rte_pktmbuf_tailroom(ut_params->ibuf)); 7986 7987 /* Create AEAD operation */ 7988 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 7989 if (retval < 0) 7990 return retval; 7991 7992 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7993 7994 ut_params->op->sym->m_src = ut_params->ibuf; 7995 7996 /* Process crypto operation */ 7997 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7998 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7999 else 8000 TEST_ASSERT_NOT_NULL( 8001 process_crypto_request(ts_params->valid_devs[0], 8002 ut_params->op), "failed to process sym crypto op"); 8003 8004 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8005 "crypto op processing failed"); 8006 8007 if (ut_params->op->sym->m_dst) 8008 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8009 uint8_t *); 8010 else 8011 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8012 uint8_t *, 8013 ut_params->op->sym->cipher.data.offset); 8014 8015 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 8016 8017 /* Validate obuf */ 8018 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8019 plaintext, 8020 tdata->plaintext.data, 8021 tdata->plaintext.len, 8022 "Plaintext data not as expected"); 8023 8024 TEST_ASSERT_EQUAL(ut_params->op->status, 8025 RTE_CRYPTO_OP_STATUS_SUCCESS, 8026 "Authentication failed"); 8027 8028 return 0; 8029 } 8030 8031 static int 8032 test_AES_GCM_authenticated_decryption_test_case_1(void) 8033 { 8034 return test_authenticated_decryption(&gcm_test_case_1); 8035 } 8036 8037 static int 8038 test_AES_GCM_authenticated_decryption_test_case_2(void) 8039 { 8040 return test_authenticated_decryption(&gcm_test_case_2); 8041 } 8042 8043 static int 8044 test_AES_GCM_authenticated_decryption_test_case_3(void) 8045 { 8046 return test_authenticated_decryption(&gcm_test_case_3); 8047 } 8048 8049 static int 8050 test_AES_GCM_authenticated_decryption_test_case_4(void) 8051 { 8052 return test_authenticated_decryption(&gcm_test_case_4); 8053 } 8054 8055 static int 8056 test_AES_GCM_authenticated_decryption_test_case_5(void) 8057 { 8058 return test_authenticated_decryption(&gcm_test_case_5); 8059 } 8060 8061 static int 8062 test_AES_GCM_authenticated_decryption_test_case_6(void) 8063 { 8064 return test_authenticated_decryption(&gcm_test_case_6); 8065 } 8066 8067 static int 8068 test_AES_GCM_authenticated_decryption_test_case_7(void) 8069 { 8070 return test_authenticated_decryption(&gcm_test_case_7); 8071 } 8072 8073 static int 8074 test_AES_GCM_authenticated_decryption_test_case_8(void) 8075 { 8076 return test_authenticated_decryption(&gcm_test_case_8); 8077 } 8078 8079 static int 8080 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 8081 { 8082 return test_authenticated_decryption(&gcm_J0_test_case_1); 8083 } 8084 8085 static int 8086 test_AES_GCM_auth_decryption_test_case_192_1(void) 8087 { 8088 return test_authenticated_decryption(&gcm_test_case_192_1); 8089 } 8090 8091 static int 8092 test_AES_GCM_auth_decryption_test_case_192_2(void) 8093 { 8094 return test_authenticated_decryption(&gcm_test_case_192_2); 8095 } 8096 8097 static int 8098 test_AES_GCM_auth_decryption_test_case_192_3(void) 8099 { 8100 return test_authenticated_decryption(&gcm_test_case_192_3); 8101 } 8102 8103 static int 8104 test_AES_GCM_auth_decryption_test_case_192_4(void) 8105 { 8106 return test_authenticated_decryption(&gcm_test_case_192_4); 8107 } 8108 8109 static int 8110 test_AES_GCM_auth_decryption_test_case_192_5(void) 8111 { 8112 return test_authenticated_decryption(&gcm_test_case_192_5); 8113 } 8114 8115 static int 8116 test_AES_GCM_auth_decryption_test_case_192_6(void) 8117 { 8118 return test_authenticated_decryption(&gcm_test_case_192_6); 8119 } 8120 8121 static int 8122 test_AES_GCM_auth_decryption_test_case_192_7(void) 8123 { 8124 return test_authenticated_decryption(&gcm_test_case_192_7); 8125 } 8126 8127 static int 8128 test_AES_GCM_auth_decryption_test_case_256_1(void) 8129 { 8130 return test_authenticated_decryption(&gcm_test_case_256_1); 8131 } 8132 8133 static int 8134 test_AES_GCM_auth_decryption_test_case_256_2(void) 8135 { 8136 return test_authenticated_decryption(&gcm_test_case_256_2); 8137 } 8138 8139 static int 8140 test_AES_GCM_auth_decryption_test_case_256_3(void) 8141 { 8142 return test_authenticated_decryption(&gcm_test_case_256_3); 8143 } 8144 8145 static int 8146 test_AES_GCM_auth_decryption_test_case_256_4(void) 8147 { 8148 return test_authenticated_decryption(&gcm_test_case_256_4); 8149 } 8150 8151 static int 8152 test_AES_GCM_auth_decryption_test_case_256_5(void) 8153 { 8154 return test_authenticated_decryption(&gcm_test_case_256_5); 8155 } 8156 8157 static int 8158 test_AES_GCM_auth_decryption_test_case_256_6(void) 8159 { 8160 return test_authenticated_decryption(&gcm_test_case_256_6); 8161 } 8162 8163 static int 8164 test_AES_GCM_auth_decryption_test_case_256_7(void) 8165 { 8166 return test_authenticated_decryption(&gcm_test_case_256_7); 8167 } 8168 8169 static int 8170 test_AES_GCM_auth_decryption_test_case_aad_1(void) 8171 { 8172 return test_authenticated_decryption(&gcm_test_case_aad_1); 8173 } 8174 8175 static int 8176 test_AES_GCM_auth_decryption_test_case_aad_2(void) 8177 { 8178 return test_authenticated_decryption(&gcm_test_case_aad_2); 8179 } 8180 8181 static int 8182 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 8183 { 8184 struct aead_test_data tdata; 8185 int res; 8186 8187 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8188 tdata.iv.data[0] += 1; 8189 res = test_authenticated_decryption(&tdata); 8190 if (res == -ENOTSUP) 8191 return res; 8192 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 8193 return TEST_SUCCESS; 8194 } 8195 8196 static int 8197 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 8198 { 8199 struct aead_test_data tdata; 8200 int res; 8201 8202 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 8203 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8204 tdata.plaintext.data[0] += 1; 8205 res = test_authenticated_decryption(&tdata); 8206 if (res == -ENOTSUP) 8207 return res; 8208 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 8209 return TEST_SUCCESS; 8210 } 8211 8212 static int 8213 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 8214 { 8215 struct aead_test_data tdata; 8216 int res; 8217 8218 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8219 tdata.ciphertext.data[0] += 1; 8220 res = test_authenticated_decryption(&tdata); 8221 if (res == -ENOTSUP) 8222 return res; 8223 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 8224 return TEST_SUCCESS; 8225 } 8226 8227 static int 8228 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 8229 { 8230 struct aead_test_data tdata; 8231 int res; 8232 8233 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8234 tdata.aad.len += 1; 8235 res = test_authenticated_decryption(&tdata); 8236 if (res == -ENOTSUP) 8237 return res; 8238 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 8239 return TEST_SUCCESS; 8240 } 8241 8242 static int 8243 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 8244 { 8245 struct aead_test_data tdata; 8246 uint8_t aad[gcm_test_case_7.aad.len]; 8247 int res; 8248 8249 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8250 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 8251 aad[0] += 1; 8252 tdata.aad.data = aad; 8253 res = test_authenticated_decryption(&tdata); 8254 if (res == -ENOTSUP) 8255 return res; 8256 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 8257 return TEST_SUCCESS; 8258 } 8259 8260 static int 8261 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 8262 { 8263 struct aead_test_data tdata; 8264 int res; 8265 8266 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 8267 tdata.auth_tag.data[0] += 1; 8268 res = test_authenticated_decryption(&tdata); 8269 if (res == -ENOTSUP) 8270 return res; 8271 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 8272 return TEST_SUCCESS; 8273 } 8274 8275 static int 8276 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 8277 { 8278 struct crypto_testsuite_params *ts_params = &testsuite_params; 8279 struct crypto_unittest_params *ut_params = &unittest_params; 8280 8281 int retval; 8282 uint8_t *ciphertext, *auth_tag; 8283 uint16_t plaintext_pad_len; 8284 8285 /* Verify the capabilities */ 8286 struct rte_cryptodev_sym_capability_idx cap_idx; 8287 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8288 cap_idx.algo.aead = tdata->algo; 8289 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8290 &cap_idx) == NULL) 8291 return -ENOTSUP; 8292 8293 /* not supported with CPU crypto */ 8294 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8295 return -ENOTSUP; 8296 8297 /* Create AEAD session */ 8298 retval = create_aead_session(ts_params->valid_devs[0], 8299 tdata->algo, 8300 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8301 tdata->key.data, tdata->key.len, 8302 tdata->aad.len, tdata->auth_tag.len, 8303 tdata->iv.len); 8304 if (retval < 0) 8305 return retval; 8306 8307 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8308 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8309 8310 /* clear mbuf payload */ 8311 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8312 rte_pktmbuf_tailroom(ut_params->ibuf)); 8313 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8314 rte_pktmbuf_tailroom(ut_params->obuf)); 8315 8316 /* Create AEAD operation */ 8317 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8318 if (retval < 0) 8319 return retval; 8320 8321 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8322 8323 ut_params->op->sym->m_src = ut_params->ibuf; 8324 ut_params->op->sym->m_dst = ut_params->obuf; 8325 8326 /* Process crypto operation */ 8327 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 8328 ut_params->op), "failed to process sym crypto op"); 8329 8330 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8331 "crypto op processing failed"); 8332 8333 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8334 8335 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 8336 ut_params->op->sym->cipher.data.offset); 8337 auth_tag = ciphertext + plaintext_pad_len; 8338 8339 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8340 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8341 8342 /* Validate obuf */ 8343 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8344 ciphertext, 8345 tdata->ciphertext.data, 8346 tdata->ciphertext.len, 8347 "Ciphertext data not as expected"); 8348 8349 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8350 auth_tag, 8351 tdata->auth_tag.data, 8352 tdata->auth_tag.len, 8353 "Generated auth tag not as expected"); 8354 8355 return 0; 8356 8357 } 8358 8359 static int 8360 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 8361 { 8362 return test_authenticated_encryption_oop(&gcm_test_case_5); 8363 } 8364 8365 static int 8366 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 8367 { 8368 struct crypto_testsuite_params *ts_params = &testsuite_params; 8369 struct crypto_unittest_params *ut_params = &unittest_params; 8370 8371 int retval; 8372 uint8_t *plaintext; 8373 8374 /* Verify the capabilities */ 8375 struct rte_cryptodev_sym_capability_idx cap_idx; 8376 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8377 cap_idx.algo.aead = tdata->algo; 8378 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8379 &cap_idx) == NULL) 8380 return -ENOTSUP; 8381 8382 /* not supported with CPU crypto */ 8383 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8384 return -ENOTSUP; 8385 8386 /* Create AEAD session */ 8387 retval = create_aead_session(ts_params->valid_devs[0], 8388 tdata->algo, 8389 RTE_CRYPTO_AEAD_OP_DECRYPT, 8390 tdata->key.data, tdata->key.len, 8391 tdata->aad.len, tdata->auth_tag.len, 8392 tdata->iv.len); 8393 if (retval < 0) 8394 return retval; 8395 8396 /* alloc mbuf and set payload */ 8397 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8398 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8399 8400 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8401 rte_pktmbuf_tailroom(ut_params->ibuf)); 8402 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8403 rte_pktmbuf_tailroom(ut_params->obuf)); 8404 8405 /* Create AEAD operation */ 8406 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 8407 if (retval < 0) 8408 return retval; 8409 8410 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8411 8412 ut_params->op->sym->m_src = ut_params->ibuf; 8413 ut_params->op->sym->m_dst = ut_params->obuf; 8414 8415 /* Process crypto operation */ 8416 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 8417 ut_params->op), "failed to process sym crypto op"); 8418 8419 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8420 "crypto op processing failed"); 8421 8422 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 8423 ut_params->op->sym->cipher.data.offset); 8424 8425 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 8426 8427 /* Validate obuf */ 8428 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8429 plaintext, 8430 tdata->plaintext.data, 8431 tdata->plaintext.len, 8432 "Plaintext data not as expected"); 8433 8434 TEST_ASSERT_EQUAL(ut_params->op->status, 8435 RTE_CRYPTO_OP_STATUS_SUCCESS, 8436 "Authentication failed"); 8437 return 0; 8438 } 8439 8440 static int 8441 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 8442 { 8443 return test_authenticated_decryption_oop(&gcm_test_case_5); 8444 } 8445 8446 static int 8447 test_authenticated_encryption_sessionless( 8448 const struct aead_test_data *tdata) 8449 { 8450 struct crypto_testsuite_params *ts_params = &testsuite_params; 8451 struct crypto_unittest_params *ut_params = &unittest_params; 8452 8453 int retval; 8454 uint8_t *ciphertext, *auth_tag; 8455 uint16_t plaintext_pad_len; 8456 uint8_t key[tdata->key.len + 1]; 8457 8458 /* This test is for AESNI MB and AESNI GCM PMDs only */ 8459 if ((gbl_driver_id != rte_cryptodev_driver_id_get( 8460 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) && 8461 (gbl_driver_id != rte_cryptodev_driver_id_get( 8462 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)))) 8463 return -ENOTSUP; 8464 8465 /* not supported with CPU crypto */ 8466 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8467 return -ENOTSUP; 8468 8469 /* Verify the capabilities */ 8470 struct rte_cryptodev_sym_capability_idx cap_idx; 8471 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8472 cap_idx.algo.aead = tdata->algo; 8473 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8474 &cap_idx) == NULL) 8475 return -ENOTSUP; 8476 8477 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8478 8479 /* clear mbuf payload */ 8480 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8481 rte_pktmbuf_tailroom(ut_params->ibuf)); 8482 8483 /* Create AEAD operation */ 8484 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8485 if (retval < 0) 8486 return retval; 8487 8488 /* Create GCM xform */ 8489 memcpy(key, tdata->key.data, tdata->key.len); 8490 retval = create_aead_xform(ut_params->op, 8491 tdata->algo, 8492 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8493 key, tdata->key.len, 8494 tdata->aad.len, tdata->auth_tag.len, 8495 tdata->iv.len); 8496 if (retval < 0) 8497 return retval; 8498 8499 ut_params->op->sym->m_src = ut_params->ibuf; 8500 8501 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 8502 RTE_CRYPTO_OP_SESSIONLESS, 8503 "crypto op session type not sessionless"); 8504 8505 /* Process crypto operation */ 8506 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 8507 ut_params->op), "failed to process sym crypto op"); 8508 8509 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 8510 8511 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8512 "crypto op status not success"); 8513 8514 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8515 8516 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 8517 ut_params->op->sym->cipher.data.offset); 8518 auth_tag = ciphertext + plaintext_pad_len; 8519 8520 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8521 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8522 8523 /* Validate obuf */ 8524 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8525 ciphertext, 8526 tdata->ciphertext.data, 8527 tdata->ciphertext.len, 8528 "Ciphertext data not as expected"); 8529 8530 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8531 auth_tag, 8532 tdata->auth_tag.data, 8533 tdata->auth_tag.len, 8534 "Generated auth tag not as expected"); 8535 8536 return 0; 8537 8538 } 8539 8540 static int 8541 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 8542 { 8543 return test_authenticated_encryption_sessionless( 8544 &gcm_test_case_5); 8545 } 8546 8547 static int 8548 test_authenticated_decryption_sessionless( 8549 const struct aead_test_data *tdata) 8550 { 8551 struct crypto_testsuite_params *ts_params = &testsuite_params; 8552 struct crypto_unittest_params *ut_params = &unittest_params; 8553 8554 int retval; 8555 uint8_t *plaintext; 8556 uint8_t key[tdata->key.len + 1]; 8557 8558 /* This test is for AESNI MB and AESNI GCM PMDs only */ 8559 if ((gbl_driver_id != rte_cryptodev_driver_id_get( 8560 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) && 8561 (gbl_driver_id != rte_cryptodev_driver_id_get( 8562 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)))) 8563 return -ENOTSUP; 8564 8565 /* not supported with CPU crypto */ 8566 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8567 return -ENOTSUP; 8568 8569 /* Verify the capabilities */ 8570 struct rte_cryptodev_sym_capability_idx cap_idx; 8571 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8572 cap_idx.algo.aead = tdata->algo; 8573 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8574 &cap_idx) == NULL) 8575 return -ENOTSUP; 8576 8577 /* alloc mbuf and set payload */ 8578 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8579 8580 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8581 rte_pktmbuf_tailroom(ut_params->ibuf)); 8582 8583 /* Create AEAD operation */ 8584 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 8585 if (retval < 0) 8586 return retval; 8587 8588 /* Create AEAD xform */ 8589 memcpy(key, tdata->key.data, tdata->key.len); 8590 retval = create_aead_xform(ut_params->op, 8591 tdata->algo, 8592 RTE_CRYPTO_AEAD_OP_DECRYPT, 8593 key, tdata->key.len, 8594 tdata->aad.len, tdata->auth_tag.len, 8595 tdata->iv.len); 8596 if (retval < 0) 8597 return retval; 8598 8599 ut_params->op->sym->m_src = ut_params->ibuf; 8600 8601 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 8602 RTE_CRYPTO_OP_SESSIONLESS, 8603 "crypto op session type not sessionless"); 8604 8605 /* Process crypto operation */ 8606 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 8607 ut_params->op), "failed to process sym crypto op"); 8608 8609 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 8610 8611 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8612 "crypto op status not success"); 8613 8614 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 8615 ut_params->op->sym->cipher.data.offset); 8616 8617 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 8618 8619 /* Validate obuf */ 8620 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8621 plaintext, 8622 tdata->plaintext.data, 8623 tdata->plaintext.len, 8624 "Plaintext data not as expected"); 8625 8626 TEST_ASSERT_EQUAL(ut_params->op->status, 8627 RTE_CRYPTO_OP_STATUS_SUCCESS, 8628 "Authentication failed"); 8629 return 0; 8630 } 8631 8632 static int 8633 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 8634 { 8635 return test_authenticated_decryption_sessionless( 8636 &gcm_test_case_5); 8637 } 8638 8639 static int 8640 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 8641 { 8642 return test_authenticated_encryption(&ccm_test_case_128_1); 8643 } 8644 8645 static int 8646 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 8647 { 8648 return test_authenticated_encryption(&ccm_test_case_128_2); 8649 } 8650 8651 static int 8652 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 8653 { 8654 return test_authenticated_encryption(&ccm_test_case_128_3); 8655 } 8656 8657 static int 8658 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 8659 { 8660 return test_authenticated_decryption(&ccm_test_case_128_1); 8661 } 8662 8663 static int 8664 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 8665 { 8666 return test_authenticated_decryption(&ccm_test_case_128_2); 8667 } 8668 8669 static int 8670 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 8671 { 8672 return test_authenticated_decryption(&ccm_test_case_128_3); 8673 } 8674 8675 static int 8676 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 8677 { 8678 return test_authenticated_encryption(&ccm_test_case_192_1); 8679 } 8680 8681 static int 8682 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 8683 { 8684 return test_authenticated_encryption(&ccm_test_case_192_2); 8685 } 8686 8687 static int 8688 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 8689 { 8690 return test_authenticated_encryption(&ccm_test_case_192_3); 8691 } 8692 8693 static int 8694 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 8695 { 8696 return test_authenticated_decryption(&ccm_test_case_192_1); 8697 } 8698 8699 static int 8700 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 8701 { 8702 return test_authenticated_decryption(&ccm_test_case_192_2); 8703 } 8704 8705 static int 8706 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 8707 { 8708 return test_authenticated_decryption(&ccm_test_case_192_3); 8709 } 8710 8711 static int 8712 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 8713 { 8714 return test_authenticated_encryption(&ccm_test_case_256_1); 8715 } 8716 8717 static int 8718 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 8719 { 8720 return test_authenticated_encryption(&ccm_test_case_256_2); 8721 } 8722 8723 static int 8724 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 8725 { 8726 return test_authenticated_encryption(&ccm_test_case_256_3); 8727 } 8728 8729 static int 8730 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 8731 { 8732 return test_authenticated_decryption(&ccm_test_case_256_1); 8733 } 8734 8735 static int 8736 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 8737 { 8738 return test_authenticated_decryption(&ccm_test_case_256_2); 8739 } 8740 8741 static int 8742 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 8743 { 8744 return test_authenticated_decryption(&ccm_test_case_256_3); 8745 } 8746 8747 static int 8748 test_stats(void) 8749 { 8750 struct crypto_testsuite_params *ts_params = &testsuite_params; 8751 struct rte_cryptodev_stats stats; 8752 struct rte_cryptodev *dev; 8753 cryptodev_stats_get_t temp_pfn; 8754 8755 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8756 return -ENOTSUP; 8757 8758 /* Verify the capabilities */ 8759 struct rte_cryptodev_sym_capability_idx cap_idx; 8760 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8761 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 8762 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8763 &cap_idx) == NULL) 8764 return -ENOTSUP; 8765 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8766 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 8767 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8768 &cap_idx) == NULL) 8769 return -ENOTSUP; 8770 8771 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 8772 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 8773 &stats) == -ENODEV), 8774 "rte_cryptodev_stats_get invalid dev failed"); 8775 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 8776 "rte_cryptodev_stats_get invalid Param failed"); 8777 dev = &rte_cryptodevs[ts_params->valid_devs[0]]; 8778 temp_pfn = dev->dev_ops->stats_get; 8779 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0; 8780 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 8781 == -ENOTSUP), 8782 "rte_cryptodev_stats_get invalid Param failed"); 8783 dev->dev_ops->stats_get = temp_pfn; 8784 8785 /* Test expected values */ 8786 ut_setup(); 8787 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 8788 ut_teardown(); 8789 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 8790 &stats), 8791 "rte_cryptodev_stats_get failed"); 8792 TEST_ASSERT((stats.enqueued_count == 1), 8793 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8794 TEST_ASSERT((stats.dequeued_count == 1), 8795 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8796 TEST_ASSERT((stats.enqueue_err_count == 0), 8797 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8798 TEST_ASSERT((stats.dequeue_err_count == 0), 8799 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8800 8801 /* invalid device but should ignore and not reset device stats*/ 8802 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 8803 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 8804 &stats), 8805 "rte_cryptodev_stats_get failed"); 8806 TEST_ASSERT((stats.enqueued_count == 1), 8807 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8808 8809 /* check that a valid reset clears stats */ 8810 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 8811 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 8812 &stats), 8813 "rte_cryptodev_stats_get failed"); 8814 TEST_ASSERT((stats.enqueued_count == 0), 8815 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8816 TEST_ASSERT((stats.dequeued_count == 0), 8817 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 8818 8819 return TEST_SUCCESS; 8820 } 8821 8822 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 8823 struct crypto_unittest_params *ut_params, 8824 enum rte_crypto_auth_operation op, 8825 const struct HMAC_MD5_vector *test_case) 8826 { 8827 uint8_t key[64]; 8828 8829 memcpy(key, test_case->key.data, test_case->key.len); 8830 8831 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8832 ut_params->auth_xform.next = NULL; 8833 ut_params->auth_xform.auth.op = op; 8834 8835 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 8836 8837 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 8838 ut_params->auth_xform.auth.key.length = test_case->key.len; 8839 ut_params->auth_xform.auth.key.data = key; 8840 8841 ut_params->sess = rte_cryptodev_sym_session_create( 8842 ts_params->session_mpool); 8843 8844 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 8845 ut_params->sess, &ut_params->auth_xform, 8846 ts_params->session_priv_mpool); 8847 8848 if (ut_params->sess == NULL) 8849 return TEST_FAILED; 8850 8851 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8852 8853 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8854 rte_pktmbuf_tailroom(ut_params->ibuf)); 8855 8856 return 0; 8857 } 8858 8859 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 8860 const struct HMAC_MD5_vector *test_case, 8861 uint8_t **plaintext) 8862 { 8863 uint16_t plaintext_pad_len; 8864 8865 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8866 8867 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 8868 16); 8869 8870 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8871 plaintext_pad_len); 8872 memcpy(*plaintext, test_case->plaintext.data, 8873 test_case->plaintext.len); 8874 8875 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 8876 ut_params->ibuf, MD5_DIGEST_LEN); 8877 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 8878 "no room to append digest"); 8879 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 8880 ut_params->ibuf, plaintext_pad_len); 8881 8882 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 8883 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 8884 test_case->auth_tag.len); 8885 } 8886 8887 sym_op->auth.data.offset = 0; 8888 sym_op->auth.data.length = test_case->plaintext.len; 8889 8890 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8891 ut_params->op->sym->m_src = ut_params->ibuf; 8892 8893 return 0; 8894 } 8895 8896 static int 8897 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 8898 { 8899 uint16_t plaintext_pad_len; 8900 uint8_t *plaintext, *auth_tag; 8901 8902 struct crypto_testsuite_params *ts_params = &testsuite_params; 8903 struct crypto_unittest_params *ut_params = &unittest_params; 8904 8905 /* Verify the capabilities */ 8906 struct rte_cryptodev_sym_capability_idx cap_idx; 8907 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8908 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 8909 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8910 &cap_idx) == NULL) 8911 return -ENOTSUP; 8912 8913 if (MD5_HMAC_create_session(ts_params, ut_params, 8914 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 8915 return TEST_FAILED; 8916 8917 /* Generate Crypto op data structure */ 8918 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8919 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8920 TEST_ASSERT_NOT_NULL(ut_params->op, 8921 "Failed to allocate symmetric crypto operation struct"); 8922 8923 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 8924 16); 8925 8926 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 8927 return TEST_FAILED; 8928 8929 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8930 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 8931 ut_params->op); 8932 else 8933 TEST_ASSERT_NOT_NULL( 8934 process_crypto_request(ts_params->valid_devs[0], 8935 ut_params->op), 8936 "failed to process sym crypto op"); 8937 8938 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8939 "crypto op processing failed"); 8940 8941 if (ut_params->op->sym->m_dst) { 8942 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8943 uint8_t *, plaintext_pad_len); 8944 } else { 8945 auth_tag = plaintext + plaintext_pad_len; 8946 } 8947 8948 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8949 auth_tag, 8950 test_case->auth_tag.data, 8951 test_case->auth_tag.len, 8952 "HMAC_MD5 generated tag not as expected"); 8953 8954 return TEST_SUCCESS; 8955 } 8956 8957 static int 8958 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 8959 { 8960 uint8_t *plaintext; 8961 8962 struct crypto_testsuite_params *ts_params = &testsuite_params; 8963 struct crypto_unittest_params *ut_params = &unittest_params; 8964 8965 /* Verify the capabilities */ 8966 struct rte_cryptodev_sym_capability_idx cap_idx; 8967 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8968 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 8969 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 8970 &cap_idx) == NULL) 8971 return -ENOTSUP; 8972 8973 if (MD5_HMAC_create_session(ts_params, ut_params, 8974 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 8975 return TEST_FAILED; 8976 } 8977 8978 /* Generate Crypto op data structure */ 8979 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8980 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8981 TEST_ASSERT_NOT_NULL(ut_params->op, 8982 "Failed to allocate symmetric crypto operation struct"); 8983 8984 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 8985 return TEST_FAILED; 8986 8987 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8988 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 8989 ut_params->op); 8990 else 8991 TEST_ASSERT_NOT_NULL( 8992 process_crypto_request(ts_params->valid_devs[0], 8993 ut_params->op), 8994 "failed to process sym crypto op"); 8995 8996 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8997 "HMAC_MD5 crypto op processing failed"); 8998 8999 return TEST_SUCCESS; 9000 } 9001 9002 static int 9003 test_MD5_HMAC_generate_case_1(void) 9004 { 9005 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 9006 } 9007 9008 static int 9009 test_MD5_HMAC_verify_case_1(void) 9010 { 9011 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 9012 } 9013 9014 static int 9015 test_MD5_HMAC_generate_case_2(void) 9016 { 9017 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 9018 } 9019 9020 static int 9021 test_MD5_HMAC_verify_case_2(void) 9022 { 9023 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 9024 } 9025 9026 static int 9027 test_multi_session(void) 9028 { 9029 struct crypto_testsuite_params *ts_params = &testsuite_params; 9030 struct crypto_unittest_params *ut_params = &unittest_params; 9031 9032 struct rte_cryptodev_info dev_info; 9033 struct rte_cryptodev_sym_session **sessions; 9034 9035 uint16_t i; 9036 9037 /* Verify the capabilities */ 9038 struct rte_cryptodev_sym_capability_idx cap_idx; 9039 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9040 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 9041 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9042 &cap_idx) == NULL) 9043 return -ENOTSUP; 9044 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9045 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 9046 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9047 &cap_idx) == NULL) 9048 return -ENOTSUP; 9049 9050 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 9051 aes_cbc_key, hmac_sha512_key); 9052 9053 9054 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9055 9056 sessions = rte_malloc(NULL, 9057 (sizeof(struct rte_cryptodev_sym_session *) * 9058 MAX_NB_SESSIONS) + 1, 0); 9059 9060 /* Create multiple crypto sessions*/ 9061 for (i = 0; i < MAX_NB_SESSIONS; i++) { 9062 9063 sessions[i] = rte_cryptodev_sym_session_create( 9064 ts_params->session_mpool); 9065 9066 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9067 sessions[i], &ut_params->auth_xform, 9068 ts_params->session_priv_mpool); 9069 TEST_ASSERT_NOT_NULL(sessions[i], 9070 "Session creation failed at session number %u", 9071 i); 9072 9073 /* Attempt to send a request on each session */ 9074 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 9075 sessions[i], 9076 ut_params, 9077 ts_params, 9078 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 9079 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 9080 aes_cbc_iv), 9081 "Failed to perform decrypt on request number %u.", i); 9082 /* free crypto operation structure */ 9083 if (ut_params->op) 9084 rte_crypto_op_free(ut_params->op); 9085 9086 /* 9087 * free mbuf - both obuf and ibuf are usually the same, 9088 * so check if they point at the same address is necessary, 9089 * to avoid freeing the mbuf twice. 9090 */ 9091 if (ut_params->obuf) { 9092 rte_pktmbuf_free(ut_params->obuf); 9093 if (ut_params->ibuf == ut_params->obuf) 9094 ut_params->ibuf = 0; 9095 ut_params->obuf = 0; 9096 } 9097 if (ut_params->ibuf) { 9098 rte_pktmbuf_free(ut_params->ibuf); 9099 ut_params->ibuf = 0; 9100 } 9101 } 9102 9103 /* Next session create should fail */ 9104 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9105 sessions[i], &ut_params->auth_xform, 9106 ts_params->session_priv_mpool); 9107 TEST_ASSERT_NULL(sessions[i], 9108 "Session creation succeeded unexpectedly!"); 9109 9110 for (i = 0; i < MAX_NB_SESSIONS; i++) { 9111 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 9112 sessions[i]); 9113 rte_cryptodev_sym_session_free(sessions[i]); 9114 } 9115 9116 rte_free(sessions); 9117 9118 return TEST_SUCCESS; 9119 } 9120 9121 struct multi_session_params { 9122 struct crypto_unittest_params ut_params; 9123 uint8_t *cipher_key; 9124 uint8_t *hmac_key; 9125 const uint8_t *cipher; 9126 const uint8_t *digest; 9127 uint8_t *iv; 9128 }; 9129 9130 #define MB_SESSION_NUMBER 3 9131 9132 static int 9133 test_multi_session_random_usage(void) 9134 { 9135 struct crypto_testsuite_params *ts_params = &testsuite_params; 9136 struct rte_cryptodev_info dev_info; 9137 struct rte_cryptodev_sym_session **sessions; 9138 uint32_t i, j; 9139 struct multi_session_params ut_paramz[] = { 9140 9141 { 9142 .cipher_key = ms_aes_cbc_key0, 9143 .hmac_key = ms_hmac_key0, 9144 .cipher = ms_aes_cbc_cipher0, 9145 .digest = ms_hmac_digest0, 9146 .iv = ms_aes_cbc_iv0 9147 }, 9148 { 9149 .cipher_key = ms_aes_cbc_key1, 9150 .hmac_key = ms_hmac_key1, 9151 .cipher = ms_aes_cbc_cipher1, 9152 .digest = ms_hmac_digest1, 9153 .iv = ms_aes_cbc_iv1 9154 }, 9155 { 9156 .cipher_key = ms_aes_cbc_key2, 9157 .hmac_key = ms_hmac_key2, 9158 .cipher = ms_aes_cbc_cipher2, 9159 .digest = ms_hmac_digest2, 9160 .iv = ms_aes_cbc_iv2 9161 }, 9162 9163 }; 9164 9165 /* Verify the capabilities */ 9166 struct rte_cryptodev_sym_capability_idx cap_idx; 9167 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9168 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 9169 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9170 &cap_idx) == NULL) 9171 return -ENOTSUP; 9172 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9173 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 9174 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9175 &cap_idx) == NULL) 9176 return -ENOTSUP; 9177 9178 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9179 9180 sessions = rte_malloc(NULL, 9181 (sizeof(struct rte_cryptodev_sym_session *) 9182 * MAX_NB_SESSIONS) + 1, 0); 9183 9184 for (i = 0; i < MB_SESSION_NUMBER; i++) { 9185 sessions[i] = rte_cryptodev_sym_session_create( 9186 ts_params->session_mpool); 9187 9188 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 9189 sizeof(struct crypto_unittest_params)); 9190 9191 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 9192 &ut_paramz[i].ut_params, 9193 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 9194 9195 /* Create multiple crypto sessions*/ 9196 rte_cryptodev_sym_session_init( 9197 ts_params->valid_devs[0], 9198 sessions[i], 9199 &ut_paramz[i].ut_params.auth_xform, 9200 ts_params->session_priv_mpool); 9201 9202 TEST_ASSERT_NOT_NULL(sessions[i], 9203 "Session creation failed at session number %u", 9204 i); 9205 9206 } 9207 9208 srand(time(NULL)); 9209 for (i = 0; i < 40000; i++) { 9210 9211 j = rand() % MB_SESSION_NUMBER; 9212 9213 TEST_ASSERT_SUCCESS( 9214 test_AES_CBC_HMAC_SHA512_decrypt_perform( 9215 sessions[j], 9216 &ut_paramz[j].ut_params, 9217 ts_params, ut_paramz[j].cipher, 9218 ut_paramz[j].digest, 9219 ut_paramz[j].iv), 9220 "Failed to perform decrypt on request number %u.", i); 9221 9222 if (ut_paramz[j].ut_params.op) 9223 rte_crypto_op_free(ut_paramz[j].ut_params.op); 9224 9225 /* 9226 * free mbuf - both obuf and ibuf are usually the same, 9227 * so check if they point at the same address is necessary, 9228 * to avoid freeing the mbuf twice. 9229 */ 9230 if (ut_paramz[j].ut_params.obuf) { 9231 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 9232 if (ut_paramz[j].ut_params.ibuf 9233 == ut_paramz[j].ut_params.obuf) 9234 ut_paramz[j].ut_params.ibuf = 0; 9235 ut_paramz[j].ut_params.obuf = 0; 9236 } 9237 if (ut_paramz[j].ut_params.ibuf) { 9238 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 9239 ut_paramz[j].ut_params.ibuf = 0; 9240 } 9241 } 9242 9243 for (i = 0; i < MB_SESSION_NUMBER; i++) { 9244 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 9245 sessions[i]); 9246 rte_cryptodev_sym_session_free(sessions[i]); 9247 } 9248 9249 rte_free(sessions); 9250 9251 return TEST_SUCCESS; 9252 } 9253 9254 static int 9255 test_null_cipher_only_operation(void) 9256 { 9257 struct crypto_testsuite_params *ts_params = &testsuite_params; 9258 struct crypto_unittest_params *ut_params = &unittest_params; 9259 9260 /* Verify the capabilities */ 9261 struct rte_cryptodev_sym_capability_idx cap_idx; 9262 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9263 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL; 9264 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9265 &cap_idx) == NULL) 9266 return -ENOTSUP; 9267 9268 /* Generate test mbuf data and space for digest */ 9269 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 9270 catch_22_quote, QUOTE_512_BYTES, 0); 9271 9272 /* Setup Cipher Parameters */ 9273 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9274 ut_params->cipher_xform.next = NULL; 9275 9276 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 9277 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9278 9279 ut_params->sess = rte_cryptodev_sym_session_create( 9280 ts_params->session_mpool); 9281 9282 /* Create Crypto session*/ 9283 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9284 ut_params->sess, 9285 &ut_params->cipher_xform, 9286 ts_params->session_priv_mpool); 9287 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9288 9289 /* Generate Crypto op data structure */ 9290 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9291 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9292 TEST_ASSERT_NOT_NULL(ut_params->op, 9293 "Failed to allocate symmetric crypto operation struct"); 9294 9295 /* Set crypto operation data parameters */ 9296 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9297 9298 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 9299 9300 /* set crypto operation source mbuf */ 9301 sym_op->m_src = ut_params->ibuf; 9302 9303 sym_op->cipher.data.offset = 0; 9304 sym_op->cipher.data.length = QUOTE_512_BYTES; 9305 9306 /* Process crypto operation */ 9307 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9308 ut_params->op); 9309 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 9310 9311 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9312 "crypto operation processing failed"); 9313 9314 /* Validate obuf */ 9315 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9316 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 9317 catch_22_quote, 9318 QUOTE_512_BYTES, 9319 "Ciphertext data not as expected"); 9320 9321 return TEST_SUCCESS; 9322 } 9323 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 9324 0xab, 0xab, 0xab, 0xab, 9325 0xab, 0xab, 0xab, 0xab, 9326 0xab, 0xab, 0xab, 0xab}; 9327 static int 9328 test_null_auth_only_operation(void) 9329 { 9330 struct crypto_testsuite_params *ts_params = &testsuite_params; 9331 struct crypto_unittest_params *ut_params = &unittest_params; 9332 uint8_t *digest; 9333 9334 /* Verify the capabilities */ 9335 struct rte_cryptodev_sym_capability_idx cap_idx; 9336 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9337 cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL; 9338 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9339 &cap_idx) == NULL) 9340 return -ENOTSUP; 9341 9342 /* Generate test mbuf data and space for digest */ 9343 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 9344 catch_22_quote, QUOTE_512_BYTES, 0); 9345 9346 /* create a pointer for digest, but don't expect anything to be written 9347 * here in a NULL auth algo so no mbuf append done. 9348 */ 9349 digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9350 QUOTE_512_BYTES); 9351 /* prefill the memory pointed to by digest */ 9352 memcpy(digest, orig_data, sizeof(orig_data)); 9353 9354 /* Setup HMAC Parameters */ 9355 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9356 ut_params->auth_xform.next = NULL; 9357 9358 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 9359 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 9360 9361 ut_params->sess = rte_cryptodev_sym_session_create( 9362 ts_params->session_mpool); 9363 9364 /* Create Crypto session*/ 9365 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9366 ut_params->sess, &ut_params->auth_xform, 9367 ts_params->session_priv_mpool); 9368 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9369 9370 /* Generate Crypto op data structure */ 9371 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9372 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9373 TEST_ASSERT_NOT_NULL(ut_params->op, 9374 "Failed to allocate symmetric crypto operation struct"); 9375 9376 /* Set crypto operation data parameters */ 9377 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9378 9379 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 9380 9381 sym_op->m_src = ut_params->ibuf; 9382 9383 sym_op->auth.data.offset = 0; 9384 sym_op->auth.data.length = QUOTE_512_BYTES; 9385 sym_op->auth.digest.data = digest; 9386 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf, 9387 QUOTE_512_BYTES); 9388 9389 /* Process crypto operation */ 9390 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9391 ut_params->op); 9392 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 9393 9394 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9395 "crypto operation processing failed"); 9396 /* Make sure memory pointed to by digest hasn't been overwritten */ 9397 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9398 orig_data, 9399 digest, 9400 sizeof(orig_data), 9401 "Memory at digest ptr overwritten unexpectedly"); 9402 9403 return TEST_SUCCESS; 9404 } 9405 9406 9407 static int 9408 test_null_cipher_auth_operation(void) 9409 { 9410 struct crypto_testsuite_params *ts_params = &testsuite_params; 9411 struct crypto_unittest_params *ut_params = &unittest_params; 9412 uint8_t *digest; 9413 9414 /* Verify the capabilities */ 9415 struct rte_cryptodev_sym_capability_idx cap_idx; 9416 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9417 cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL; 9418 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9419 &cap_idx) == NULL) 9420 return -ENOTSUP; 9421 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9422 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL; 9423 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9424 &cap_idx) == NULL) 9425 return -ENOTSUP; 9426 9427 /* Generate test mbuf data and space for digest */ 9428 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 9429 catch_22_quote, QUOTE_512_BYTES, 0); 9430 9431 /* create a pointer for digest, but don't expect anything to be written 9432 * here in a NULL auth algo so no mbuf append done. 9433 */ 9434 digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9435 QUOTE_512_BYTES); 9436 /* prefill the memory pointed to by digest */ 9437 memcpy(digest, orig_data, sizeof(orig_data)); 9438 9439 /* Setup Cipher Parameters */ 9440 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9441 ut_params->cipher_xform.next = &ut_params->auth_xform; 9442 9443 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 9444 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9445 9446 /* Setup HMAC Parameters */ 9447 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9448 ut_params->auth_xform.next = NULL; 9449 9450 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 9451 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 9452 9453 ut_params->sess = rte_cryptodev_sym_session_create( 9454 ts_params->session_mpool); 9455 9456 /* Create Crypto session*/ 9457 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9458 ut_params->sess, &ut_params->cipher_xform, 9459 ts_params->session_priv_mpool); 9460 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9461 9462 /* Generate Crypto op data structure */ 9463 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9464 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9465 TEST_ASSERT_NOT_NULL(ut_params->op, 9466 "Failed to allocate symmetric crypto operation struct"); 9467 9468 /* Set crypto operation data parameters */ 9469 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9470 9471 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 9472 9473 sym_op->m_src = ut_params->ibuf; 9474 9475 sym_op->cipher.data.offset = 0; 9476 sym_op->cipher.data.length = QUOTE_512_BYTES; 9477 9478 sym_op->auth.data.offset = 0; 9479 sym_op->auth.data.length = QUOTE_512_BYTES; 9480 sym_op->auth.digest.data = digest; 9481 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf, 9482 QUOTE_512_BYTES); 9483 9484 /* Process crypto operation */ 9485 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9486 ut_params->op); 9487 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 9488 9489 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9490 "crypto operation processing failed"); 9491 9492 /* Validate obuf */ 9493 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9494 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 9495 catch_22_quote, 9496 QUOTE_512_BYTES, 9497 "Ciphertext data not as expected"); 9498 /* Make sure memory pointed to by digest hasn't been overwritten */ 9499 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9500 orig_data, 9501 digest, 9502 sizeof(orig_data), 9503 "Memory at digest ptr overwritten unexpectedly"); 9504 9505 return TEST_SUCCESS; 9506 } 9507 9508 static int 9509 test_null_auth_cipher_operation(void) 9510 { 9511 struct crypto_testsuite_params *ts_params = &testsuite_params; 9512 struct crypto_unittest_params *ut_params = &unittest_params; 9513 uint8_t *digest; 9514 9515 /* Verify the capabilities */ 9516 struct rte_cryptodev_sym_capability_idx cap_idx; 9517 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9518 cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL; 9519 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9520 &cap_idx) == NULL) 9521 return -ENOTSUP; 9522 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9523 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL; 9524 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9525 &cap_idx) == NULL) 9526 return -ENOTSUP; 9527 9528 /* Generate test mbuf data */ 9529 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 9530 catch_22_quote, QUOTE_512_BYTES, 0); 9531 9532 /* create a pointer for digest, but don't expect anything to be written 9533 * here in a NULL auth algo so no mbuf append done. 9534 */ 9535 digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9536 QUOTE_512_BYTES); 9537 /* prefill the memory pointed to by digest */ 9538 memcpy(digest, orig_data, sizeof(orig_data)); 9539 9540 /* Setup Cipher Parameters */ 9541 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9542 ut_params->cipher_xform.next = NULL; 9543 9544 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 9545 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9546 9547 /* Setup HMAC Parameters */ 9548 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9549 ut_params->auth_xform.next = &ut_params->cipher_xform; 9550 9551 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 9552 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 9553 9554 ut_params->sess = rte_cryptodev_sym_session_create( 9555 ts_params->session_mpool); 9556 9557 /* Create Crypto session*/ 9558 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9559 ut_params->sess, &ut_params->cipher_xform, 9560 ts_params->session_priv_mpool); 9561 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9562 9563 /* Generate Crypto op data structure */ 9564 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9565 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9566 TEST_ASSERT_NOT_NULL(ut_params->op, 9567 "Failed to allocate symmetric crypto operation struct"); 9568 9569 /* Set crypto operation data parameters */ 9570 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9571 9572 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 9573 9574 sym_op->m_src = ut_params->ibuf; 9575 9576 sym_op->cipher.data.offset = 0; 9577 sym_op->cipher.data.length = QUOTE_512_BYTES; 9578 9579 sym_op->auth.data.offset = 0; 9580 sym_op->auth.data.length = QUOTE_512_BYTES; 9581 sym_op->auth.digest.data = digest; 9582 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf, 9583 QUOTE_512_BYTES); 9584 9585 /* Process crypto operation */ 9586 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9587 ut_params->op); 9588 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 9589 9590 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9591 "crypto operation processing failed"); 9592 9593 /* Validate obuf */ 9594 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9595 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *), 9596 catch_22_quote, 9597 QUOTE_512_BYTES, 9598 "Ciphertext data not as expected"); 9599 /* Make sure memory pointed to by digest hasn't been overwritten */ 9600 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9601 orig_data, 9602 digest, 9603 sizeof(orig_data), 9604 "Memory at digest ptr overwritten unexpectedly"); 9605 9606 return TEST_SUCCESS; 9607 } 9608 9609 9610 static int 9611 test_null_invalid_operation(void) 9612 { 9613 struct crypto_testsuite_params *ts_params = &testsuite_params; 9614 struct crypto_unittest_params *ut_params = &unittest_params; 9615 int ret; 9616 9617 /* This test is for NULL PMD only */ 9618 if (gbl_driver_id != rte_cryptodev_driver_id_get( 9619 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 9620 return -ENOTSUP; 9621 9622 /* Setup Cipher Parameters */ 9623 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9624 ut_params->cipher_xform.next = NULL; 9625 9626 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 9627 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9628 9629 ut_params->sess = rte_cryptodev_sym_session_create( 9630 ts_params->session_mpool); 9631 9632 /* Create Crypto session*/ 9633 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9634 ut_params->sess, &ut_params->cipher_xform, 9635 ts_params->session_priv_mpool); 9636 TEST_ASSERT(ret < 0, 9637 "Session creation succeeded unexpectedly"); 9638 9639 9640 /* Setup HMAC Parameters */ 9641 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9642 ut_params->auth_xform.next = NULL; 9643 9644 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 9645 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 9646 9647 ut_params->sess = rte_cryptodev_sym_session_create( 9648 ts_params->session_mpool); 9649 9650 /* Create Crypto session*/ 9651 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9652 ut_params->sess, &ut_params->auth_xform, 9653 ts_params->session_priv_mpool); 9654 TEST_ASSERT(ret < 0, 9655 "Session creation succeeded unexpectedly"); 9656 9657 return TEST_SUCCESS; 9658 } 9659 9660 9661 #define NULL_BURST_LENGTH (32) 9662 9663 static int 9664 test_null_burst_operation(void) 9665 { 9666 struct crypto_testsuite_params *ts_params = &testsuite_params; 9667 struct crypto_unittest_params *ut_params = &unittest_params; 9668 9669 unsigned i, burst_len = NULL_BURST_LENGTH; 9670 9671 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 9672 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 9673 9674 /* This test is for NULL PMD only */ 9675 if (gbl_driver_id != rte_cryptodev_driver_id_get( 9676 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 9677 return -ENOTSUP; 9678 9679 /* Setup Cipher Parameters */ 9680 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9681 ut_params->cipher_xform.next = &ut_params->auth_xform; 9682 9683 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 9684 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9685 9686 /* Setup HMAC Parameters */ 9687 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9688 ut_params->auth_xform.next = NULL; 9689 9690 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 9691 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 9692 9693 ut_params->sess = rte_cryptodev_sym_session_create( 9694 ts_params->session_mpool); 9695 9696 /* Create Crypto session*/ 9697 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 9698 ut_params->sess, &ut_params->cipher_xform, 9699 ts_params->session_priv_mpool); 9700 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9701 9702 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 9703 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 9704 burst_len, "failed to generate burst of crypto ops"); 9705 9706 /* Generate an operation for each mbuf in burst */ 9707 for (i = 0; i < burst_len; i++) { 9708 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9709 9710 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 9711 9712 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 9713 sizeof(unsigned)); 9714 *data = i; 9715 9716 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 9717 9718 burst[i]->sym->m_src = m; 9719 } 9720 9721 /* Process crypto operation */ 9722 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 9723 0, burst, burst_len), 9724 burst_len, 9725 "Error enqueuing burst"); 9726 9727 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 9728 0, burst_dequeued, burst_len), 9729 burst_len, 9730 "Error dequeuing burst"); 9731 9732 9733 for (i = 0; i < burst_len; i++) { 9734 TEST_ASSERT_EQUAL( 9735 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 9736 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 9737 uint32_t *), 9738 "data not as expected"); 9739 9740 rte_pktmbuf_free(burst[i]->sym->m_src); 9741 rte_crypto_op_free(burst[i]); 9742 } 9743 9744 return TEST_SUCCESS; 9745 } 9746 9747 static void 9748 generate_gmac_large_plaintext(uint8_t *data) 9749 { 9750 uint16_t i; 9751 9752 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 9753 memcpy(&data[i], &data[0], 32); 9754 } 9755 9756 static int 9757 create_gmac_operation(enum rte_crypto_auth_operation op, 9758 const struct gmac_test_data *tdata) 9759 { 9760 struct crypto_testsuite_params *ts_params = &testsuite_params; 9761 struct crypto_unittest_params *ut_params = &unittest_params; 9762 struct rte_crypto_sym_op *sym_op; 9763 9764 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9765 9766 /* Generate Crypto op data structure */ 9767 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9768 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9769 TEST_ASSERT_NOT_NULL(ut_params->op, 9770 "Failed to allocate symmetric crypto operation struct"); 9771 9772 sym_op = ut_params->op->sym; 9773 9774 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 9775 ut_params->ibuf, tdata->gmac_tag.len); 9776 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 9777 "no room to append digest"); 9778 9779 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 9780 ut_params->ibuf, plaintext_pad_len); 9781 9782 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 9783 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 9784 tdata->gmac_tag.len); 9785 debug_hexdump(stdout, "digest:", 9786 sym_op->auth.digest.data, 9787 tdata->gmac_tag.len); 9788 } 9789 9790 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 9791 uint8_t *, IV_OFFSET); 9792 9793 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 9794 9795 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 9796 9797 sym_op->cipher.data.length = 0; 9798 sym_op->cipher.data.offset = 0; 9799 9800 sym_op->auth.data.offset = 0; 9801 sym_op->auth.data.length = tdata->plaintext.len; 9802 9803 return 0; 9804 } 9805 9806 static int create_gmac_session(uint8_t dev_id, 9807 const struct gmac_test_data *tdata, 9808 enum rte_crypto_auth_operation auth_op) 9809 { 9810 uint8_t auth_key[tdata->key.len]; 9811 9812 struct crypto_testsuite_params *ts_params = &testsuite_params; 9813 struct crypto_unittest_params *ut_params = &unittest_params; 9814 9815 memcpy(auth_key, tdata->key.data, tdata->key.len); 9816 9817 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9818 ut_params->auth_xform.next = NULL; 9819 9820 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 9821 ut_params->auth_xform.auth.op = auth_op; 9822 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 9823 ut_params->auth_xform.auth.key.length = tdata->key.len; 9824 ut_params->auth_xform.auth.key.data = auth_key; 9825 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 9826 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 9827 9828 9829 ut_params->sess = rte_cryptodev_sym_session_create( 9830 ts_params->session_mpool); 9831 9832 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 9833 &ut_params->auth_xform, 9834 ts_params->session_priv_mpool); 9835 9836 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 9837 9838 return 0; 9839 } 9840 9841 static int 9842 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 9843 { 9844 struct crypto_testsuite_params *ts_params = &testsuite_params; 9845 struct crypto_unittest_params *ut_params = &unittest_params; 9846 9847 int retval; 9848 9849 uint8_t *auth_tag, *plaintext; 9850 uint16_t plaintext_pad_len; 9851 9852 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 9853 "No GMAC length in the source data"); 9854 9855 /* Verify the capabilities */ 9856 struct rte_cryptodev_sym_capability_idx cap_idx; 9857 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9858 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 9859 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9860 &cap_idx) == NULL) 9861 return -ENOTSUP; 9862 9863 retval = create_gmac_session(ts_params->valid_devs[0], 9864 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 9865 9866 if (retval < 0) 9867 return retval; 9868 9869 if (tdata->plaintext.len > MBUF_SIZE) 9870 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9871 else 9872 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9873 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 9874 "Failed to allocate input buffer in mempool"); 9875 9876 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9877 rte_pktmbuf_tailroom(ut_params->ibuf)); 9878 9879 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9880 /* 9881 * Runtime generate the large plain text instead of use hard code 9882 * plain text vector. It is done to avoid create huge source file 9883 * with the test vector. 9884 */ 9885 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 9886 generate_gmac_large_plaintext(tdata->plaintext.data); 9887 9888 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9889 plaintext_pad_len); 9890 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 9891 9892 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 9893 debug_hexdump(stdout, "plaintext:", plaintext, 9894 tdata->plaintext.len); 9895 9896 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 9897 tdata); 9898 9899 if (retval < 0) 9900 return retval; 9901 9902 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9903 9904 ut_params->op->sym->m_src = ut_params->ibuf; 9905 9906 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9907 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 9908 ut_params->op); 9909 else 9910 TEST_ASSERT_NOT_NULL( 9911 process_crypto_request(ts_params->valid_devs[0], 9912 ut_params->op), "failed to process sym crypto op"); 9913 9914 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9915 "crypto op processing failed"); 9916 9917 if (ut_params->op->sym->m_dst) { 9918 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 9919 uint8_t *, plaintext_pad_len); 9920 } else { 9921 auth_tag = plaintext + plaintext_pad_len; 9922 } 9923 9924 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 9925 9926 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9927 auth_tag, 9928 tdata->gmac_tag.data, 9929 tdata->gmac_tag.len, 9930 "GMAC Generated auth tag not as expected"); 9931 9932 return 0; 9933 } 9934 9935 static int 9936 test_AES_GMAC_authentication_test_case_1(void) 9937 { 9938 return test_AES_GMAC_authentication(&gmac_test_case_1); 9939 } 9940 9941 static int 9942 test_AES_GMAC_authentication_test_case_2(void) 9943 { 9944 return test_AES_GMAC_authentication(&gmac_test_case_2); 9945 } 9946 9947 static int 9948 test_AES_GMAC_authentication_test_case_3(void) 9949 { 9950 return test_AES_GMAC_authentication(&gmac_test_case_3); 9951 } 9952 9953 static int 9954 test_AES_GMAC_authentication_test_case_4(void) 9955 { 9956 return test_AES_GMAC_authentication(&gmac_test_case_4); 9957 } 9958 9959 static int 9960 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 9961 { 9962 struct crypto_testsuite_params *ts_params = &testsuite_params; 9963 struct crypto_unittest_params *ut_params = &unittest_params; 9964 int retval; 9965 uint32_t plaintext_pad_len; 9966 uint8_t *plaintext; 9967 9968 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 9969 "No GMAC length in the source data"); 9970 9971 /* Verify the capabilities */ 9972 struct rte_cryptodev_sym_capability_idx cap_idx; 9973 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9974 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 9975 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9976 &cap_idx) == NULL) 9977 return -ENOTSUP; 9978 9979 retval = create_gmac_session(ts_params->valid_devs[0], 9980 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 9981 9982 if (retval < 0) 9983 return retval; 9984 9985 if (tdata->plaintext.len > MBUF_SIZE) 9986 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9987 else 9988 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9989 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 9990 "Failed to allocate input buffer in mempool"); 9991 9992 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9993 rte_pktmbuf_tailroom(ut_params->ibuf)); 9994 9995 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9996 9997 /* 9998 * Runtime generate the large plain text instead of use hard code 9999 * plain text vector. It is done to avoid create huge source file 10000 * with the test vector. 10001 */ 10002 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 10003 generate_gmac_large_plaintext(tdata->plaintext.data); 10004 10005 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10006 plaintext_pad_len); 10007 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10008 10009 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 10010 debug_hexdump(stdout, "plaintext:", plaintext, 10011 tdata->plaintext.len); 10012 10013 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 10014 tdata); 10015 10016 if (retval < 0) 10017 return retval; 10018 10019 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10020 10021 ut_params->op->sym->m_src = ut_params->ibuf; 10022 10023 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10024 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10025 ut_params->op); 10026 else 10027 TEST_ASSERT_NOT_NULL( 10028 process_crypto_request(ts_params->valid_devs[0], 10029 ut_params->op), "failed to process sym crypto op"); 10030 10031 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10032 "crypto op processing failed"); 10033 10034 return 0; 10035 10036 } 10037 10038 static int 10039 test_AES_GMAC_authentication_verify_test_case_1(void) 10040 { 10041 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 10042 } 10043 10044 static int 10045 test_AES_GMAC_authentication_verify_test_case_2(void) 10046 { 10047 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 10048 } 10049 10050 static int 10051 test_AES_GMAC_authentication_verify_test_case_3(void) 10052 { 10053 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 10054 } 10055 10056 static int 10057 test_AES_GMAC_authentication_verify_test_case_4(void) 10058 { 10059 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 10060 } 10061 10062 struct test_crypto_vector { 10063 enum rte_crypto_cipher_algorithm crypto_algo; 10064 unsigned int cipher_offset; 10065 unsigned int cipher_len; 10066 10067 struct { 10068 uint8_t data[64]; 10069 unsigned int len; 10070 } cipher_key; 10071 10072 struct { 10073 uint8_t data[64]; 10074 unsigned int len; 10075 } iv; 10076 10077 struct { 10078 const uint8_t *data; 10079 unsigned int len; 10080 } plaintext; 10081 10082 struct { 10083 const uint8_t *data; 10084 unsigned int len; 10085 } ciphertext; 10086 10087 enum rte_crypto_auth_algorithm auth_algo; 10088 unsigned int auth_offset; 10089 10090 struct { 10091 uint8_t data[128]; 10092 unsigned int len; 10093 } auth_key; 10094 10095 struct { 10096 const uint8_t *data; 10097 unsigned int len; 10098 } aad; 10099 10100 struct { 10101 uint8_t data[128]; 10102 unsigned int len; 10103 } digest; 10104 }; 10105 10106 static const struct test_crypto_vector 10107 hmac_sha1_test_crypto_vector = { 10108 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 10109 .plaintext = { 10110 .data = plaintext_hash, 10111 .len = 512 10112 }, 10113 .auth_key = { 10114 .data = { 10115 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 10116 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 10117 0xDE, 0xF4, 0xDE, 0xAD 10118 }, 10119 .len = 20 10120 }, 10121 .digest = { 10122 .data = { 10123 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 10124 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 10125 0x3F, 0x91, 0x64, 0x59 10126 }, 10127 .len = 20 10128 } 10129 }; 10130 10131 static const struct test_crypto_vector 10132 aes128_gmac_test_vector = { 10133 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 10134 .plaintext = { 10135 .data = plaintext_hash, 10136 .len = 512 10137 }, 10138 .iv = { 10139 .data = { 10140 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 10141 0x08, 0x09, 0x0A, 0x0B 10142 }, 10143 .len = 12 10144 }, 10145 .auth_key = { 10146 .data = { 10147 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 10148 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 10149 }, 10150 .len = 16 10151 }, 10152 .digest = { 10153 .data = { 10154 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 10155 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 10156 }, 10157 .len = 16 10158 } 10159 }; 10160 10161 static const struct test_crypto_vector 10162 aes128cbc_hmac_sha1_test_vector = { 10163 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 10164 .cipher_offset = 0, 10165 .cipher_len = 512, 10166 .cipher_key = { 10167 .data = { 10168 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 10169 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 10170 }, 10171 .len = 16 10172 }, 10173 .iv = { 10174 .data = { 10175 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 10176 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 10177 }, 10178 .len = 16 10179 }, 10180 .plaintext = { 10181 .data = plaintext_hash, 10182 .len = 512 10183 }, 10184 .ciphertext = { 10185 .data = ciphertext512_aes128cbc, 10186 .len = 512 10187 }, 10188 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 10189 .auth_offset = 0, 10190 .auth_key = { 10191 .data = { 10192 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 10193 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 10194 0xDE, 0xF4, 0xDE, 0xAD 10195 }, 10196 .len = 20 10197 }, 10198 .digest = { 10199 .data = { 10200 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 10201 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 10202 0x18, 0x8C, 0x1D, 0x32 10203 }, 10204 .len = 20 10205 } 10206 }; 10207 10208 static const struct test_crypto_vector 10209 aes128cbc_hmac_sha1_aad_test_vector = { 10210 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 10211 .cipher_offset = 12, 10212 .cipher_len = 496, 10213 .cipher_key = { 10214 .data = { 10215 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 10216 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 10217 }, 10218 .len = 16 10219 }, 10220 .iv = { 10221 .data = { 10222 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 10223 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 10224 }, 10225 .len = 16 10226 }, 10227 .plaintext = { 10228 .data = plaintext_hash, 10229 .len = 512 10230 }, 10231 .ciphertext = { 10232 .data = ciphertext512_aes128cbc_aad, 10233 .len = 512 10234 }, 10235 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 10236 .auth_offset = 0, 10237 .auth_key = { 10238 .data = { 10239 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 10240 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 10241 0xDE, 0xF4, 0xDE, 0xAD 10242 }, 10243 .len = 20 10244 }, 10245 .digest = { 10246 .data = { 10247 0x1F, 0x6A, 0xD2, 0x8B, 0x4B, 0xB3, 0xC0, 0x9E, 10248 0x86, 0x9B, 0x3A, 0xF2, 0x00, 0x5B, 0x4F, 0x08, 10249 0x62, 0x8D, 0x62, 0x65 10250 }, 10251 .len = 20 10252 } 10253 }; 10254 10255 static void 10256 data_corruption(uint8_t *data) 10257 { 10258 data[0] += 1; 10259 } 10260 10261 static void 10262 tag_corruption(uint8_t *data, unsigned int tag_offset) 10263 { 10264 data[tag_offset] += 1; 10265 } 10266 10267 static int 10268 create_auth_session(struct crypto_unittest_params *ut_params, 10269 uint8_t dev_id, 10270 const struct test_crypto_vector *reference, 10271 enum rte_crypto_auth_operation auth_op) 10272 { 10273 struct crypto_testsuite_params *ts_params = &testsuite_params; 10274 uint8_t auth_key[reference->auth_key.len + 1]; 10275 10276 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 10277 10278 /* Setup Authentication Parameters */ 10279 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10280 ut_params->auth_xform.auth.op = auth_op; 10281 ut_params->auth_xform.next = NULL; 10282 ut_params->auth_xform.auth.algo = reference->auth_algo; 10283 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 10284 ut_params->auth_xform.auth.key.data = auth_key; 10285 ut_params->auth_xform.auth.digest_length = reference->digest.len; 10286 10287 /* Create Crypto session*/ 10288 ut_params->sess = rte_cryptodev_sym_session_create( 10289 ts_params->session_mpool); 10290 10291 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 10292 &ut_params->auth_xform, 10293 ts_params->session_priv_mpool); 10294 10295 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10296 10297 return 0; 10298 } 10299 10300 static int 10301 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 10302 uint8_t dev_id, 10303 const struct test_crypto_vector *reference, 10304 enum rte_crypto_auth_operation auth_op, 10305 enum rte_crypto_cipher_operation cipher_op) 10306 { 10307 struct crypto_testsuite_params *ts_params = &testsuite_params; 10308 uint8_t cipher_key[reference->cipher_key.len + 1]; 10309 uint8_t auth_key[reference->auth_key.len + 1]; 10310 10311 memcpy(cipher_key, reference->cipher_key.data, 10312 reference->cipher_key.len); 10313 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 10314 10315 /* Setup Authentication Parameters */ 10316 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10317 ut_params->auth_xform.auth.op = auth_op; 10318 ut_params->auth_xform.auth.algo = reference->auth_algo; 10319 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 10320 ut_params->auth_xform.auth.key.data = auth_key; 10321 ut_params->auth_xform.auth.digest_length = reference->digest.len; 10322 10323 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 10324 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 10325 ut_params->auth_xform.auth.iv.length = reference->iv.len; 10326 } else { 10327 ut_params->auth_xform.next = &ut_params->cipher_xform; 10328 10329 /* Setup Cipher Parameters */ 10330 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10331 ut_params->cipher_xform.next = NULL; 10332 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 10333 ut_params->cipher_xform.cipher.op = cipher_op; 10334 ut_params->cipher_xform.cipher.key.data = cipher_key; 10335 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 10336 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10337 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 10338 } 10339 10340 /* Create Crypto session*/ 10341 ut_params->sess = rte_cryptodev_sym_session_create( 10342 ts_params->session_mpool); 10343 10344 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 10345 &ut_params->auth_xform, 10346 ts_params->session_priv_mpool); 10347 10348 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10349 10350 return 0; 10351 } 10352 10353 static int 10354 create_auth_operation(struct crypto_testsuite_params *ts_params, 10355 struct crypto_unittest_params *ut_params, 10356 const struct test_crypto_vector *reference, 10357 unsigned int auth_generate) 10358 { 10359 /* Generate Crypto op data structure */ 10360 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10361 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10362 TEST_ASSERT_NOT_NULL(ut_params->op, 10363 "Failed to allocate pktmbuf offload"); 10364 10365 /* Set crypto operation data parameters */ 10366 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10367 10368 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10369 10370 /* set crypto operation source mbuf */ 10371 sym_op->m_src = ut_params->ibuf; 10372 10373 /* digest */ 10374 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10375 ut_params->ibuf, reference->digest.len); 10376 10377 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10378 "no room to append auth tag"); 10379 10380 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10381 ut_params->ibuf, reference->plaintext.len); 10382 10383 if (auth_generate) 10384 memset(sym_op->auth.digest.data, 0, reference->digest.len); 10385 else 10386 memcpy(sym_op->auth.digest.data, 10387 reference->digest.data, 10388 reference->digest.len); 10389 10390 debug_hexdump(stdout, "digest:", 10391 sym_op->auth.digest.data, 10392 reference->digest.len); 10393 10394 sym_op->auth.data.length = reference->plaintext.len; 10395 sym_op->auth.data.offset = 0; 10396 10397 return 0; 10398 } 10399 10400 static int 10401 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 10402 struct crypto_unittest_params *ut_params, 10403 const struct test_crypto_vector *reference, 10404 unsigned int auth_generate) 10405 { 10406 /* Generate Crypto op data structure */ 10407 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10408 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10409 TEST_ASSERT_NOT_NULL(ut_params->op, 10410 "Failed to allocate pktmbuf offload"); 10411 10412 /* Set crypto operation data parameters */ 10413 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10414 10415 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10416 10417 /* set crypto operation source mbuf */ 10418 sym_op->m_src = ut_params->ibuf; 10419 10420 /* digest */ 10421 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10422 ut_params->ibuf, reference->digest.len); 10423 10424 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10425 "no room to append auth tag"); 10426 10427 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10428 ut_params->ibuf, reference->ciphertext.len); 10429 10430 if (auth_generate) 10431 memset(sym_op->auth.digest.data, 0, reference->digest.len); 10432 else 10433 memcpy(sym_op->auth.digest.data, 10434 reference->digest.data, 10435 reference->digest.len); 10436 10437 debug_hexdump(stdout, "digest:", 10438 sym_op->auth.digest.data, 10439 reference->digest.len); 10440 10441 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 10442 reference->iv.data, reference->iv.len); 10443 10444 sym_op->cipher.data.length = 0; 10445 sym_op->cipher.data.offset = 0; 10446 10447 sym_op->auth.data.length = reference->plaintext.len; 10448 sym_op->auth.data.offset = 0; 10449 10450 return 0; 10451 } 10452 10453 static int 10454 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 10455 struct crypto_unittest_params *ut_params, 10456 const struct test_crypto_vector *reference, 10457 unsigned int auth_generate) 10458 { 10459 /* Generate Crypto op data structure */ 10460 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10461 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10462 TEST_ASSERT_NOT_NULL(ut_params->op, 10463 "Failed to allocate pktmbuf offload"); 10464 10465 /* Set crypto operation data parameters */ 10466 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10467 10468 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10469 10470 /* set crypto operation source mbuf */ 10471 sym_op->m_src = ut_params->ibuf; 10472 10473 /* digest */ 10474 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10475 ut_params->ibuf, reference->digest.len); 10476 10477 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10478 "no room to append auth tag"); 10479 10480 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10481 ut_params->ibuf, reference->ciphertext.len); 10482 10483 if (auth_generate) 10484 memset(sym_op->auth.digest.data, 0, reference->digest.len); 10485 else 10486 memcpy(sym_op->auth.digest.data, 10487 reference->digest.data, 10488 reference->digest.len); 10489 10490 debug_hexdump(stdout, "digest:", 10491 sym_op->auth.digest.data, 10492 reference->digest.len); 10493 10494 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 10495 reference->iv.data, reference->iv.len); 10496 10497 sym_op->cipher.data.length = reference->cipher_len; 10498 sym_op->cipher.data.offset = reference->cipher_offset; 10499 10500 sym_op->auth.data.length = reference->plaintext.len; 10501 sym_op->auth.data.offset = reference->auth_offset; 10502 10503 return 0; 10504 } 10505 10506 static int 10507 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 10508 struct crypto_unittest_params *ut_params, 10509 const struct test_crypto_vector *reference) 10510 { 10511 return create_auth_operation(ts_params, ut_params, reference, 0); 10512 } 10513 10514 static int 10515 create_auth_verify_GMAC_operation( 10516 struct crypto_testsuite_params *ts_params, 10517 struct crypto_unittest_params *ut_params, 10518 const struct test_crypto_vector *reference) 10519 { 10520 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 10521 } 10522 10523 static int 10524 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 10525 struct crypto_unittest_params *ut_params, 10526 const struct test_crypto_vector *reference) 10527 { 10528 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 10529 } 10530 10531 static int 10532 test_authentication_verify_fail_when_data_corruption( 10533 struct crypto_testsuite_params *ts_params, 10534 struct crypto_unittest_params *ut_params, 10535 const struct test_crypto_vector *reference, 10536 unsigned int data_corrupted) 10537 { 10538 int retval; 10539 10540 uint8_t *plaintext; 10541 10542 /* Verify the capabilities */ 10543 struct rte_cryptodev_sym_capability_idx cap_idx; 10544 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10545 cap_idx.algo.auth = reference->auth_algo; 10546 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10547 &cap_idx) == NULL) 10548 return -ENOTSUP; 10549 10550 /* Create session */ 10551 retval = create_auth_session(ut_params, 10552 ts_params->valid_devs[0], 10553 reference, 10554 RTE_CRYPTO_AUTH_OP_VERIFY); 10555 if (retval < 0) 10556 return retval; 10557 10558 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10559 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10560 "Failed to allocate input buffer in mempool"); 10561 10562 /* clear mbuf payload */ 10563 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10564 rte_pktmbuf_tailroom(ut_params->ibuf)); 10565 10566 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10567 reference->plaintext.len); 10568 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10569 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 10570 10571 debug_hexdump(stdout, "plaintext:", plaintext, 10572 reference->plaintext.len); 10573 10574 /* Create operation */ 10575 retval = create_auth_verify_operation(ts_params, ut_params, reference); 10576 10577 if (retval < 0) 10578 return retval; 10579 10580 if (data_corrupted) 10581 data_corruption(plaintext); 10582 else 10583 tag_corruption(plaintext, reference->plaintext.len); 10584 10585 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 10586 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10587 ut_params->op); 10588 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 10589 RTE_CRYPTO_OP_STATUS_SUCCESS, 10590 "authentication not failed"); 10591 } else { 10592 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 10593 ut_params->op); 10594 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 10595 } 10596 10597 return 0; 10598 } 10599 10600 static int 10601 test_authentication_verify_GMAC_fail_when_corruption( 10602 struct crypto_testsuite_params *ts_params, 10603 struct crypto_unittest_params *ut_params, 10604 const struct test_crypto_vector *reference, 10605 unsigned int data_corrupted) 10606 { 10607 int retval; 10608 uint8_t *plaintext; 10609 10610 /* Verify the capabilities */ 10611 struct rte_cryptodev_sym_capability_idx cap_idx; 10612 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10613 cap_idx.algo.auth = reference->auth_algo; 10614 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10615 &cap_idx) == NULL) 10616 return -ENOTSUP; 10617 10618 /* Create session */ 10619 retval = create_auth_cipher_session(ut_params, 10620 ts_params->valid_devs[0], 10621 reference, 10622 RTE_CRYPTO_AUTH_OP_VERIFY, 10623 RTE_CRYPTO_CIPHER_OP_DECRYPT); 10624 if (retval < 0) 10625 return retval; 10626 10627 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10628 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10629 "Failed to allocate input buffer in mempool"); 10630 10631 /* clear mbuf payload */ 10632 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10633 rte_pktmbuf_tailroom(ut_params->ibuf)); 10634 10635 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10636 reference->plaintext.len); 10637 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10638 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 10639 10640 debug_hexdump(stdout, "plaintext:", plaintext, 10641 reference->plaintext.len); 10642 10643 /* Create operation */ 10644 retval = create_auth_verify_GMAC_operation(ts_params, 10645 ut_params, 10646 reference); 10647 10648 if (retval < 0) 10649 return retval; 10650 10651 if (data_corrupted) 10652 data_corruption(plaintext); 10653 else 10654 tag_corruption(plaintext, reference->aad.len); 10655 10656 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 10657 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10658 ut_params->op); 10659 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 10660 RTE_CRYPTO_OP_STATUS_SUCCESS, 10661 "authentication not failed"); 10662 } else { 10663 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 10664 ut_params->op); 10665 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 10666 } 10667 10668 return 0; 10669 } 10670 10671 static int 10672 test_authenticated_decryption_fail_when_corruption( 10673 struct crypto_testsuite_params *ts_params, 10674 struct crypto_unittest_params *ut_params, 10675 const struct test_crypto_vector *reference, 10676 unsigned int data_corrupted) 10677 { 10678 int retval; 10679 10680 uint8_t *ciphertext; 10681 10682 /* Verify the capabilities */ 10683 struct rte_cryptodev_sym_capability_idx cap_idx; 10684 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10685 cap_idx.algo.auth = reference->auth_algo; 10686 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10687 &cap_idx) == NULL) 10688 return -ENOTSUP; 10689 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10690 cap_idx.algo.cipher = reference->crypto_algo; 10691 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10692 &cap_idx) == NULL) 10693 return -ENOTSUP; 10694 10695 /* Create session */ 10696 retval = create_auth_cipher_session(ut_params, 10697 ts_params->valid_devs[0], 10698 reference, 10699 RTE_CRYPTO_AUTH_OP_VERIFY, 10700 RTE_CRYPTO_CIPHER_OP_DECRYPT); 10701 if (retval < 0) 10702 return retval; 10703 10704 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10705 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10706 "Failed to allocate input buffer in mempool"); 10707 10708 /* clear mbuf payload */ 10709 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10710 rte_pktmbuf_tailroom(ut_params->ibuf)); 10711 10712 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10713 reference->ciphertext.len); 10714 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 10715 memcpy(ciphertext, reference->ciphertext.data, 10716 reference->ciphertext.len); 10717 10718 /* Create operation */ 10719 retval = create_cipher_auth_verify_operation(ts_params, 10720 ut_params, 10721 reference); 10722 10723 if (retval < 0) 10724 return retval; 10725 10726 if (data_corrupted) 10727 data_corruption(ciphertext); 10728 else 10729 tag_corruption(ciphertext, reference->ciphertext.len); 10730 10731 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 10732 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10733 ut_params->op); 10734 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 10735 RTE_CRYPTO_OP_STATUS_SUCCESS, 10736 "authentication not failed"); 10737 } else { 10738 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 10739 ut_params->op); 10740 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 10741 } 10742 10743 return 0; 10744 } 10745 10746 static int 10747 test_authenticated_encryt_with_esn( 10748 struct crypto_testsuite_params *ts_params, 10749 struct crypto_unittest_params *ut_params, 10750 const struct test_crypto_vector *reference) 10751 { 10752 int retval; 10753 10754 uint8_t *authciphertext, *plaintext, *auth_tag; 10755 uint16_t plaintext_pad_len; 10756 uint8_t cipher_key[reference->cipher_key.len + 1]; 10757 uint8_t auth_key[reference->auth_key.len + 1]; 10758 10759 /* Verify the capabilities */ 10760 struct rte_cryptodev_sym_capability_idx cap_idx; 10761 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10762 cap_idx.algo.auth = reference->auth_algo; 10763 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10764 &cap_idx) == NULL) 10765 return -ENOTSUP; 10766 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10767 cap_idx.algo.cipher = reference->crypto_algo; 10768 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10769 &cap_idx) == NULL) 10770 return -ENOTSUP; 10771 10772 /* Create session */ 10773 memcpy(cipher_key, reference->cipher_key.data, 10774 reference->cipher_key.len); 10775 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 10776 10777 /* Setup Cipher Parameters */ 10778 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10779 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 10780 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10781 ut_params->cipher_xform.cipher.key.data = cipher_key; 10782 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 10783 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10784 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 10785 10786 ut_params->cipher_xform.next = &ut_params->auth_xform; 10787 10788 /* Setup Authentication Parameters */ 10789 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10790 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10791 ut_params->auth_xform.auth.algo = reference->auth_algo; 10792 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 10793 ut_params->auth_xform.auth.key.data = auth_key; 10794 ut_params->auth_xform.auth.digest_length = reference->digest.len; 10795 ut_params->auth_xform.next = NULL; 10796 10797 /* Create Crypto session*/ 10798 ut_params->sess = rte_cryptodev_sym_session_create( 10799 ts_params->session_mpool); 10800 10801 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10802 ut_params->sess, 10803 &ut_params->cipher_xform, 10804 ts_params->session_priv_mpool); 10805 10806 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10807 10808 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10809 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10810 "Failed to allocate input buffer in mempool"); 10811 10812 /* clear mbuf payload */ 10813 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10814 rte_pktmbuf_tailroom(ut_params->ibuf)); 10815 10816 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10817 reference->plaintext.len); 10818 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10819 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 10820 10821 /* Create operation */ 10822 retval = create_cipher_auth_operation(ts_params, 10823 ut_params, 10824 reference, 0); 10825 10826 if (retval < 0) 10827 return retval; 10828 10829 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10830 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10831 ut_params->op); 10832 else 10833 ut_params->op = process_crypto_request( 10834 ts_params->valid_devs[0], ut_params->op); 10835 10836 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 10837 10838 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10839 "crypto op processing failed"); 10840 10841 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 10842 10843 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10844 ut_params->op->sym->auth.data.offset); 10845 auth_tag = authciphertext + plaintext_pad_len; 10846 debug_hexdump(stdout, "ciphertext:", authciphertext, 10847 reference->ciphertext.len); 10848 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 10849 10850 /* Validate obuf */ 10851 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10852 authciphertext, 10853 reference->ciphertext.data, 10854 reference->ciphertext.len, 10855 "Ciphertext data not as expected"); 10856 10857 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10858 auth_tag, 10859 reference->digest.data, 10860 reference->digest.len, 10861 "Generated digest not as expected"); 10862 10863 return TEST_SUCCESS; 10864 10865 } 10866 10867 static int 10868 test_authenticated_decrypt_with_esn( 10869 struct crypto_testsuite_params *ts_params, 10870 struct crypto_unittest_params *ut_params, 10871 const struct test_crypto_vector *reference) 10872 { 10873 int retval; 10874 10875 uint8_t *ciphertext; 10876 uint8_t cipher_key[reference->cipher_key.len + 1]; 10877 uint8_t auth_key[reference->auth_key.len + 1]; 10878 10879 /* Verify the capabilities */ 10880 struct rte_cryptodev_sym_capability_idx cap_idx; 10881 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10882 cap_idx.algo.auth = reference->auth_algo; 10883 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10884 &cap_idx) == NULL) 10885 return -ENOTSUP; 10886 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10887 cap_idx.algo.cipher = reference->crypto_algo; 10888 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10889 &cap_idx) == NULL) 10890 return -ENOTSUP; 10891 10892 /* Create session */ 10893 memcpy(cipher_key, reference->cipher_key.data, 10894 reference->cipher_key.len); 10895 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 10896 10897 /* Setup Authentication Parameters */ 10898 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10899 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 10900 ut_params->auth_xform.auth.algo = reference->auth_algo; 10901 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 10902 ut_params->auth_xform.auth.key.data = auth_key; 10903 ut_params->auth_xform.auth.digest_length = reference->digest.len; 10904 ut_params->auth_xform.next = &ut_params->cipher_xform; 10905 10906 /* Setup Cipher Parameters */ 10907 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10908 ut_params->cipher_xform.next = NULL; 10909 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 10910 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 10911 ut_params->cipher_xform.cipher.key.data = cipher_key; 10912 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 10913 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10914 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 10915 10916 /* Create Crypto session*/ 10917 ut_params->sess = rte_cryptodev_sym_session_create( 10918 ts_params->session_mpool); 10919 10920 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10921 ut_params->sess, 10922 &ut_params->auth_xform, 10923 ts_params->session_priv_mpool); 10924 10925 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10926 10927 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10928 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10929 "Failed to allocate input buffer in mempool"); 10930 10931 /* clear mbuf payload */ 10932 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10933 rte_pktmbuf_tailroom(ut_params->ibuf)); 10934 10935 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10936 reference->ciphertext.len); 10937 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 10938 memcpy(ciphertext, reference->ciphertext.data, 10939 reference->ciphertext.len); 10940 10941 /* Create operation */ 10942 retval = create_cipher_auth_verify_operation(ts_params, 10943 ut_params, 10944 reference); 10945 10946 if (retval < 0) 10947 return retval; 10948 10949 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10950 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10951 ut_params->op); 10952 else 10953 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 10954 ut_params->op); 10955 10956 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10957 TEST_ASSERT_EQUAL(ut_params->op->status, 10958 RTE_CRYPTO_OP_STATUS_SUCCESS, 10959 "crypto op processing passed"); 10960 10961 ut_params->obuf = ut_params->op->sym->m_src; 10962 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 10963 10964 return 0; 10965 } 10966 10967 static int 10968 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 10969 const struct aead_test_data *tdata, 10970 void *digest_mem, uint64_t digest_phys) 10971 { 10972 struct crypto_testsuite_params *ts_params = &testsuite_params; 10973 struct crypto_unittest_params *ut_params = &unittest_params; 10974 10975 const unsigned int auth_tag_len = tdata->auth_tag.len; 10976 const unsigned int iv_len = tdata->iv.len; 10977 unsigned int aad_len = tdata->aad.len; 10978 unsigned int aad_len_pad = 0; 10979 10980 /* Generate Crypto op data structure */ 10981 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10982 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10983 TEST_ASSERT_NOT_NULL(ut_params->op, 10984 "Failed to allocate symmetric crypto operation struct"); 10985 10986 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10987 10988 sym_op->aead.digest.data = digest_mem; 10989 10990 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 10991 "no room to append digest"); 10992 10993 sym_op->aead.digest.phys_addr = digest_phys; 10994 10995 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 10996 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 10997 auth_tag_len); 10998 debug_hexdump(stdout, "digest:", 10999 sym_op->aead.digest.data, 11000 auth_tag_len); 11001 } 11002 11003 /* Append aad data */ 11004 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 11005 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11006 uint8_t *, IV_OFFSET); 11007 11008 /* Copy IV 1 byte after the IV pointer, according to the API */ 11009 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 11010 11011 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 11012 11013 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 11014 ut_params->ibuf, aad_len); 11015 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 11016 "no room to prepend aad"); 11017 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 11018 ut_params->ibuf); 11019 11020 memset(sym_op->aead.aad.data, 0, aad_len); 11021 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 11022 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 11023 11024 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 11025 debug_hexdump(stdout, "aad:", 11026 sym_op->aead.aad.data, aad_len); 11027 } else { 11028 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11029 uint8_t *, IV_OFFSET); 11030 11031 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 11032 11033 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 11034 11035 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 11036 ut_params->ibuf, aad_len_pad); 11037 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 11038 "no room to prepend aad"); 11039 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 11040 ut_params->ibuf); 11041 11042 memset(sym_op->aead.aad.data, 0, aad_len); 11043 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 11044 11045 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 11046 debug_hexdump(stdout, "aad:", 11047 sym_op->aead.aad.data, aad_len); 11048 } 11049 11050 sym_op->aead.data.length = tdata->plaintext.len; 11051 sym_op->aead.data.offset = aad_len_pad; 11052 11053 return 0; 11054 } 11055 11056 #define SGL_MAX_NO 16 11057 11058 static int 11059 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 11060 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 11061 { 11062 struct crypto_testsuite_params *ts_params = &testsuite_params; 11063 struct crypto_unittest_params *ut_params = &unittest_params; 11064 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 11065 int retval; 11066 int to_trn = 0; 11067 int to_trn_tbl[SGL_MAX_NO]; 11068 int segs = 1; 11069 unsigned int trn_data = 0; 11070 uint8_t *plaintext, *ciphertext, *auth_tag; 11071 struct rte_cryptodev_info dev_info; 11072 11073 /* Verify the capabilities */ 11074 struct rte_cryptodev_sym_capability_idx cap_idx; 11075 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11076 cap_idx.algo.aead = tdata->algo; 11077 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11078 &cap_idx) == NULL) 11079 return -ENOTSUP; 11080 11081 /* OOP not supported with CPU crypto */ 11082 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11083 return -ENOTSUP; 11084 11085 /* Detailed check for the particular SGL support flag */ 11086 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11087 if (!oop) { 11088 unsigned int sgl_in = fragsz < tdata->plaintext.len; 11089 if (sgl_in && (!(dev_info.feature_flags & 11090 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 11091 return -ENOTSUP; 11092 } else { 11093 unsigned int sgl_in = fragsz < tdata->plaintext.len; 11094 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 11095 tdata->plaintext.len; 11096 if (sgl_in && !sgl_out) { 11097 if (!(dev_info.feature_flags & 11098 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 11099 return -ENOTSUP; 11100 } else if (!sgl_in && sgl_out) { 11101 if (!(dev_info.feature_flags & 11102 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 11103 return -ENOTSUP; 11104 } else if (sgl_in && sgl_out) { 11105 if (!(dev_info.feature_flags & 11106 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 11107 return -ENOTSUP; 11108 } 11109 } 11110 11111 if (fragsz > tdata->plaintext.len) 11112 fragsz = tdata->plaintext.len; 11113 11114 uint16_t plaintext_len = fragsz; 11115 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 11116 11117 if (fragsz_oop > tdata->plaintext.len) 11118 frag_size_oop = tdata->plaintext.len; 11119 11120 int ecx = 0; 11121 void *digest_mem = NULL; 11122 11123 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 11124 11125 if (tdata->plaintext.len % fragsz != 0) { 11126 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 11127 return 1; 11128 } else { 11129 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 11130 return 1; 11131 } 11132 11133 /* 11134 * For out-op-place we need to alloc another mbuf 11135 */ 11136 if (oop) { 11137 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11138 rte_pktmbuf_append(ut_params->obuf, 11139 frag_size_oop + prepend_len); 11140 buf_oop = ut_params->obuf; 11141 } 11142 11143 /* Create AEAD session */ 11144 retval = create_aead_session(ts_params->valid_devs[0], 11145 tdata->algo, 11146 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11147 tdata->key.data, tdata->key.len, 11148 tdata->aad.len, tdata->auth_tag.len, 11149 tdata->iv.len); 11150 if (retval < 0) 11151 return retval; 11152 11153 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11154 11155 /* clear mbuf payload */ 11156 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11157 rte_pktmbuf_tailroom(ut_params->ibuf)); 11158 11159 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11160 plaintext_len); 11161 11162 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 11163 11164 trn_data += plaintext_len; 11165 11166 buf = ut_params->ibuf; 11167 11168 /* 11169 * Loop until no more fragments 11170 */ 11171 11172 while (trn_data < tdata->plaintext.len) { 11173 ++segs; 11174 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 11175 (tdata->plaintext.len - trn_data) : fragsz; 11176 11177 to_trn_tbl[ecx++] = to_trn; 11178 11179 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11180 buf = buf->next; 11181 11182 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 11183 rte_pktmbuf_tailroom(buf)); 11184 11185 /* OOP */ 11186 if (oop && !fragsz_oop) { 11187 buf_last_oop = buf_oop->next = 11188 rte_pktmbuf_alloc(ts_params->mbuf_pool); 11189 buf_oop = buf_oop->next; 11190 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 11191 0, rte_pktmbuf_tailroom(buf_oop)); 11192 rte_pktmbuf_append(buf_oop, to_trn); 11193 } 11194 11195 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 11196 to_trn); 11197 11198 memcpy(plaintext, tdata->plaintext.data + trn_data, 11199 to_trn); 11200 trn_data += to_trn; 11201 if (trn_data == tdata->plaintext.len) { 11202 if (oop) { 11203 if (!fragsz_oop) 11204 digest_mem = rte_pktmbuf_append(buf_oop, 11205 tdata->auth_tag.len); 11206 } else 11207 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 11208 tdata->auth_tag.len); 11209 } 11210 } 11211 11212 uint64_t digest_phys = 0; 11213 11214 ut_params->ibuf->nb_segs = segs; 11215 11216 segs = 1; 11217 if (fragsz_oop && oop) { 11218 to_trn = 0; 11219 ecx = 0; 11220 11221 if (frag_size_oop == tdata->plaintext.len) { 11222 digest_mem = rte_pktmbuf_append(ut_params->obuf, 11223 tdata->auth_tag.len); 11224 11225 digest_phys = rte_pktmbuf_iova_offset( 11226 ut_params->obuf, 11227 tdata->plaintext.len + prepend_len); 11228 } 11229 11230 trn_data = frag_size_oop; 11231 while (trn_data < tdata->plaintext.len) { 11232 ++segs; 11233 to_trn = 11234 (tdata->plaintext.len - trn_data < 11235 frag_size_oop) ? 11236 (tdata->plaintext.len - trn_data) : 11237 frag_size_oop; 11238 11239 to_trn_tbl[ecx++] = to_trn; 11240 11241 buf_last_oop = buf_oop->next = 11242 rte_pktmbuf_alloc(ts_params->mbuf_pool); 11243 buf_oop = buf_oop->next; 11244 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 11245 0, rte_pktmbuf_tailroom(buf_oop)); 11246 rte_pktmbuf_append(buf_oop, to_trn); 11247 11248 trn_data += to_trn; 11249 11250 if (trn_data == tdata->plaintext.len) { 11251 digest_mem = rte_pktmbuf_append(buf_oop, 11252 tdata->auth_tag.len); 11253 } 11254 } 11255 11256 ut_params->obuf->nb_segs = segs; 11257 } 11258 11259 /* 11260 * Place digest at the end of the last buffer 11261 */ 11262 if (!digest_phys) 11263 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 11264 if (oop && buf_last_oop) 11265 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 11266 11267 if (!digest_mem && !oop) { 11268 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11269 + tdata->auth_tag.len); 11270 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 11271 tdata->plaintext.len); 11272 } 11273 11274 /* Create AEAD operation */ 11275 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 11276 tdata, digest_mem, digest_phys); 11277 11278 if (retval < 0) 11279 return retval; 11280 11281 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11282 11283 ut_params->op->sym->m_src = ut_params->ibuf; 11284 if (oop) 11285 ut_params->op->sym->m_dst = ut_params->obuf; 11286 11287 /* Process crypto operation */ 11288 if (oop == IN_PLACE && 11289 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11290 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 11291 else 11292 TEST_ASSERT_NOT_NULL( 11293 process_crypto_request(ts_params->valid_devs[0], 11294 ut_params->op), "failed to process sym crypto op"); 11295 11296 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11297 "crypto op processing failed"); 11298 11299 11300 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 11301 uint8_t *, prepend_len); 11302 if (oop) { 11303 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11304 uint8_t *, prepend_len); 11305 } 11306 11307 if (fragsz_oop) 11308 fragsz = fragsz_oop; 11309 11310 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11311 ciphertext, 11312 tdata->ciphertext.data, 11313 fragsz, 11314 "Ciphertext data not as expected"); 11315 11316 buf = ut_params->op->sym->m_src->next; 11317 if (oop) 11318 buf = ut_params->op->sym->m_dst->next; 11319 11320 unsigned int off = fragsz; 11321 11322 ecx = 0; 11323 while (buf) { 11324 ciphertext = rte_pktmbuf_mtod(buf, 11325 uint8_t *); 11326 11327 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11328 ciphertext, 11329 tdata->ciphertext.data + off, 11330 to_trn_tbl[ecx], 11331 "Ciphertext data not as expected"); 11332 11333 off += to_trn_tbl[ecx++]; 11334 buf = buf->next; 11335 } 11336 11337 auth_tag = digest_mem; 11338 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11339 auth_tag, 11340 tdata->auth_tag.data, 11341 tdata->auth_tag.len, 11342 "Generated auth tag not as expected"); 11343 11344 return 0; 11345 } 11346 11347 static int 11348 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 11349 { 11350 return test_authenticated_encryption_SGL( 11351 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 11352 } 11353 11354 static int 11355 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 11356 { 11357 return test_authenticated_encryption_SGL( 11358 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 11359 } 11360 11361 static int 11362 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 11363 { 11364 return test_authenticated_encryption_SGL( 11365 &gcm_test_case_8, OUT_OF_PLACE, 400, 11366 gcm_test_case_8.plaintext.len); 11367 } 11368 11369 static int 11370 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 11371 { 11372 /* This test is not for OPENSSL PMD */ 11373 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11374 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 11375 return -ENOTSUP; 11376 11377 return test_authenticated_encryption_SGL( 11378 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 11379 } 11380 11381 static int 11382 test_authentication_verify_fail_when_data_corrupted( 11383 struct crypto_testsuite_params *ts_params, 11384 struct crypto_unittest_params *ut_params, 11385 const struct test_crypto_vector *reference) 11386 { 11387 return test_authentication_verify_fail_when_data_corruption( 11388 ts_params, ut_params, reference, 1); 11389 } 11390 11391 static int 11392 test_authentication_verify_fail_when_tag_corrupted( 11393 struct crypto_testsuite_params *ts_params, 11394 struct crypto_unittest_params *ut_params, 11395 const struct test_crypto_vector *reference) 11396 { 11397 return test_authentication_verify_fail_when_data_corruption( 11398 ts_params, ut_params, reference, 0); 11399 } 11400 11401 static int 11402 test_authentication_verify_GMAC_fail_when_data_corrupted( 11403 struct crypto_testsuite_params *ts_params, 11404 struct crypto_unittest_params *ut_params, 11405 const struct test_crypto_vector *reference) 11406 { 11407 return test_authentication_verify_GMAC_fail_when_corruption( 11408 ts_params, ut_params, reference, 1); 11409 } 11410 11411 static int 11412 test_authentication_verify_GMAC_fail_when_tag_corrupted( 11413 struct crypto_testsuite_params *ts_params, 11414 struct crypto_unittest_params *ut_params, 11415 const struct test_crypto_vector *reference) 11416 { 11417 return test_authentication_verify_GMAC_fail_when_corruption( 11418 ts_params, ut_params, reference, 0); 11419 } 11420 11421 static int 11422 test_authenticated_decryption_fail_when_data_corrupted( 11423 struct crypto_testsuite_params *ts_params, 11424 struct crypto_unittest_params *ut_params, 11425 const struct test_crypto_vector *reference) 11426 { 11427 return test_authenticated_decryption_fail_when_corruption( 11428 ts_params, ut_params, reference, 1); 11429 } 11430 11431 static int 11432 test_authenticated_decryption_fail_when_tag_corrupted( 11433 struct crypto_testsuite_params *ts_params, 11434 struct crypto_unittest_params *ut_params, 11435 const struct test_crypto_vector *reference) 11436 { 11437 return test_authenticated_decryption_fail_when_corruption( 11438 ts_params, ut_params, reference, 0); 11439 } 11440 11441 static int 11442 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 11443 { 11444 return test_authentication_verify_fail_when_data_corrupted( 11445 &testsuite_params, &unittest_params, 11446 &hmac_sha1_test_crypto_vector); 11447 } 11448 11449 static int 11450 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 11451 { 11452 return test_authentication_verify_fail_when_tag_corrupted( 11453 &testsuite_params, &unittest_params, 11454 &hmac_sha1_test_crypto_vector); 11455 } 11456 11457 static int 11458 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 11459 { 11460 return test_authentication_verify_GMAC_fail_when_data_corrupted( 11461 &testsuite_params, &unittest_params, 11462 &aes128_gmac_test_vector); 11463 } 11464 11465 static int 11466 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 11467 { 11468 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 11469 &testsuite_params, &unittest_params, 11470 &aes128_gmac_test_vector); 11471 } 11472 11473 static int 11474 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 11475 { 11476 return test_authenticated_decryption_fail_when_data_corrupted( 11477 &testsuite_params, 11478 &unittest_params, 11479 &aes128cbc_hmac_sha1_test_vector); 11480 } 11481 11482 static int 11483 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 11484 { 11485 return test_authenticated_decryption_fail_when_tag_corrupted( 11486 &testsuite_params, 11487 &unittest_params, 11488 &aes128cbc_hmac_sha1_test_vector); 11489 } 11490 11491 static int 11492 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 11493 { 11494 return test_authenticated_encryt_with_esn( 11495 &testsuite_params, 11496 &unittest_params, 11497 &aes128cbc_hmac_sha1_aad_test_vector); 11498 } 11499 11500 static int 11501 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 11502 { 11503 return test_authenticated_decrypt_with_esn( 11504 &testsuite_params, 11505 &unittest_params, 11506 &aes128cbc_hmac_sha1_aad_test_vector); 11507 } 11508 11509 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 11510 11511 /* global AESNI slave IDs for the scheduler test */ 11512 uint8_t aesni_ids[2]; 11513 11514 static int 11515 test_scheduler_attach_slave_op(void) 11516 { 11517 struct crypto_testsuite_params *ts_params = &testsuite_params; 11518 uint8_t sched_id = ts_params->valid_devs[0]; 11519 uint32_t nb_devs, i, nb_devs_attached = 0; 11520 int ret; 11521 char vdev_name[32]; 11522 11523 /* create 2 AESNI_MB if necessary */ 11524 nb_devs = rte_cryptodev_device_count_by_driver( 11525 rte_cryptodev_driver_id_get( 11526 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 11527 if (nb_devs < 2) { 11528 for (i = nb_devs; i < 2; i++) { 11529 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 11530 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 11531 i); 11532 ret = rte_vdev_init(vdev_name, NULL); 11533 11534 TEST_ASSERT(ret == 0, 11535 "Failed to create instance %u of" 11536 " pmd : %s", 11537 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 11538 } 11539 } 11540 11541 /* attach 2 AESNI_MB cdevs */ 11542 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 11543 i++) { 11544 struct rte_cryptodev_info info; 11545 unsigned int session_size; 11546 11547 rte_cryptodev_info_get(i, &info); 11548 if (info.driver_id != rte_cryptodev_driver_id_get( 11549 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 11550 continue; 11551 11552 session_size = rte_cryptodev_sym_get_private_session_size(i); 11553 /* 11554 * Create the session mempool again, since now there are new devices 11555 * to use the mempool. 11556 */ 11557 if (ts_params->session_mpool) { 11558 rte_mempool_free(ts_params->session_mpool); 11559 ts_params->session_mpool = NULL; 11560 } 11561 if (ts_params->session_priv_mpool) { 11562 rte_mempool_free(ts_params->session_priv_mpool); 11563 ts_params->session_priv_mpool = NULL; 11564 } 11565 11566 if (info.sym.max_nb_sessions != 0 && 11567 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 11568 RTE_LOG(ERR, USER1, 11569 "Device does not support " 11570 "at least %u sessions\n", 11571 MAX_NB_SESSIONS); 11572 return TEST_FAILED; 11573 } 11574 /* 11575 * Create mempool with maximum number of sessions, 11576 * to include the session headers 11577 */ 11578 if (ts_params->session_mpool == NULL) { 11579 ts_params->session_mpool = 11580 rte_cryptodev_sym_session_pool_create( 11581 "test_sess_mp", 11582 MAX_NB_SESSIONS, 0, 0, 0, 11583 SOCKET_ID_ANY); 11584 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 11585 "session mempool allocation failed"); 11586 } 11587 11588 /* 11589 * Create mempool with maximum number of sessions, 11590 * to include device specific session private data 11591 */ 11592 if (ts_params->session_priv_mpool == NULL) { 11593 ts_params->session_priv_mpool = rte_mempool_create( 11594 "test_sess_mp_priv", 11595 MAX_NB_SESSIONS, 11596 session_size, 11597 0, 0, NULL, NULL, NULL, 11598 NULL, SOCKET_ID_ANY, 11599 0); 11600 11601 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 11602 "session mempool allocation failed"); 11603 } 11604 11605 ts_params->qp_conf.mp_session = ts_params->session_mpool; 11606 ts_params->qp_conf.mp_session_private = 11607 ts_params->session_priv_mpool; 11608 11609 ret = rte_cryptodev_scheduler_slave_attach(sched_id, 11610 (uint8_t)i); 11611 11612 TEST_ASSERT(ret == 0, 11613 "Failed to attach device %u of pmd : %s", i, 11614 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 11615 11616 aesni_ids[nb_devs_attached] = (uint8_t)i; 11617 11618 nb_devs_attached++; 11619 } 11620 11621 return 0; 11622 } 11623 11624 static int 11625 test_scheduler_detach_slave_op(void) 11626 { 11627 struct crypto_testsuite_params *ts_params = &testsuite_params; 11628 uint8_t sched_id = ts_params->valid_devs[0]; 11629 uint32_t i; 11630 int ret; 11631 11632 for (i = 0; i < 2; i++) { 11633 ret = rte_cryptodev_scheduler_slave_detach(sched_id, 11634 aesni_ids[i]); 11635 TEST_ASSERT(ret == 0, 11636 "Failed to detach device %u", aesni_ids[i]); 11637 } 11638 11639 return 0; 11640 } 11641 11642 static int 11643 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 11644 { 11645 struct crypto_testsuite_params *ts_params = &testsuite_params; 11646 uint8_t sched_id = ts_params->valid_devs[0]; 11647 /* set mode */ 11648 return rte_cryptodev_scheduler_mode_set(sched_id, 11649 scheduler_mode); 11650 } 11651 11652 static int 11653 test_scheduler_mode_roundrobin_op(void) 11654 { 11655 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 11656 0, "Failed to set roundrobin mode"); 11657 return 0; 11658 11659 } 11660 11661 static int 11662 test_scheduler_mode_multicore_op(void) 11663 { 11664 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 11665 0, "Failed to set multicore mode"); 11666 11667 return 0; 11668 } 11669 11670 static int 11671 test_scheduler_mode_failover_op(void) 11672 { 11673 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 11674 0, "Failed to set failover mode"); 11675 11676 return 0; 11677 } 11678 11679 static int 11680 test_scheduler_mode_pkt_size_distr_op(void) 11681 { 11682 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 11683 0, "Failed to set pktsize mode"); 11684 11685 return 0; 11686 } 11687 11688 static struct unit_test_suite cryptodev_scheduler_testsuite = { 11689 .suite_name = "Crypto Device Scheduler Unit Test Suite", 11690 .setup = testsuite_setup, 11691 .teardown = testsuite_teardown, 11692 .unit_test_cases = { 11693 /* Multi Core */ 11694 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 11695 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op), 11696 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 11697 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 11698 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 11699 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 11700 11701 /* Round Robin */ 11702 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 11703 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op), 11704 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 11705 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 11706 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 11707 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 11708 11709 /* Fail over */ 11710 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 11711 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op), 11712 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 11713 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 11714 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 11715 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 11716 11717 /* PKT SIZE */ 11718 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 11719 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op), 11720 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 11721 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 11722 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 11723 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 11724 11725 TEST_CASES_END() /**< NULL terminate unit test array */ 11726 } 11727 }; 11728 11729 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */ 11730 11731 static struct unit_test_suite cryptodev_testsuite = { 11732 .suite_name = "Crypto Unit Test Suite", 11733 .setup = testsuite_setup, 11734 .teardown = testsuite_teardown, 11735 .unit_test_cases = { 11736 TEST_CASE_ST(ut_setup, ut_teardown, 11737 test_device_configure_invalid_dev_id), 11738 TEST_CASE_ST(ut_setup, ut_teardown, 11739 test_device_configure_invalid_queue_pair_ids), 11740 TEST_CASE_ST(ut_setup, ut_teardown, 11741 test_queue_pair_descriptor_setup), 11742 11743 TEST_CASE_ST(ut_setup, ut_teardown, 11744 test_multi_session), 11745 TEST_CASE_ST(ut_setup, ut_teardown, 11746 test_multi_session_random_usage), 11747 11748 TEST_CASE_ST(ut_setup, ut_teardown, 11749 test_null_invalid_operation), 11750 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 11751 11752 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 11753 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 11754 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 11755 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 11756 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all), 11757 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all), 11758 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all), 11759 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 11760 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 11761 11762 /** AES CCM Authenticated Encryption 128 bits key */ 11763 TEST_CASE_ST(ut_setup, ut_teardown, 11764 test_AES_CCM_authenticated_encryption_test_case_128_1), 11765 TEST_CASE_ST(ut_setup, ut_teardown, 11766 test_AES_CCM_authenticated_encryption_test_case_128_2), 11767 TEST_CASE_ST(ut_setup, ut_teardown, 11768 test_AES_CCM_authenticated_encryption_test_case_128_3), 11769 11770 /** AES CCM Authenticated Decryption 128 bits key*/ 11771 TEST_CASE_ST(ut_setup, ut_teardown, 11772 test_AES_CCM_authenticated_decryption_test_case_128_1), 11773 TEST_CASE_ST(ut_setup, ut_teardown, 11774 test_AES_CCM_authenticated_decryption_test_case_128_2), 11775 TEST_CASE_ST(ut_setup, ut_teardown, 11776 test_AES_CCM_authenticated_decryption_test_case_128_3), 11777 11778 /** AES CCM Authenticated Encryption 192 bits key */ 11779 TEST_CASE_ST(ut_setup, ut_teardown, 11780 test_AES_CCM_authenticated_encryption_test_case_192_1), 11781 TEST_CASE_ST(ut_setup, ut_teardown, 11782 test_AES_CCM_authenticated_encryption_test_case_192_2), 11783 TEST_CASE_ST(ut_setup, ut_teardown, 11784 test_AES_CCM_authenticated_encryption_test_case_192_3), 11785 11786 /** AES CCM Authenticated Decryption 192 bits key*/ 11787 TEST_CASE_ST(ut_setup, ut_teardown, 11788 test_AES_CCM_authenticated_decryption_test_case_192_1), 11789 TEST_CASE_ST(ut_setup, ut_teardown, 11790 test_AES_CCM_authenticated_decryption_test_case_192_2), 11791 TEST_CASE_ST(ut_setup, ut_teardown, 11792 test_AES_CCM_authenticated_decryption_test_case_192_3), 11793 11794 /** AES CCM Authenticated Encryption 256 bits key */ 11795 TEST_CASE_ST(ut_setup, ut_teardown, 11796 test_AES_CCM_authenticated_encryption_test_case_256_1), 11797 TEST_CASE_ST(ut_setup, ut_teardown, 11798 test_AES_CCM_authenticated_encryption_test_case_256_2), 11799 TEST_CASE_ST(ut_setup, ut_teardown, 11800 test_AES_CCM_authenticated_encryption_test_case_256_3), 11801 11802 /** AES CCM Authenticated Decryption 256 bits key*/ 11803 TEST_CASE_ST(ut_setup, ut_teardown, 11804 test_AES_CCM_authenticated_decryption_test_case_256_1), 11805 TEST_CASE_ST(ut_setup, ut_teardown, 11806 test_AES_CCM_authenticated_decryption_test_case_256_2), 11807 TEST_CASE_ST(ut_setup, ut_teardown, 11808 test_AES_CCM_authenticated_decryption_test_case_256_3), 11809 11810 /** AES GCM Authenticated Encryption */ 11811 TEST_CASE_ST(ut_setup, ut_teardown, 11812 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 11813 TEST_CASE_ST(ut_setup, ut_teardown, 11814 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 11815 TEST_CASE_ST(ut_setup, ut_teardown, 11816 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 11817 TEST_CASE_ST(ut_setup, ut_teardown, 11818 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 11819 TEST_CASE_ST(ut_setup, ut_teardown, 11820 test_AES_GCM_authenticated_encryption_test_case_1), 11821 TEST_CASE_ST(ut_setup, ut_teardown, 11822 test_AES_GCM_authenticated_encryption_test_case_2), 11823 TEST_CASE_ST(ut_setup, ut_teardown, 11824 test_AES_GCM_authenticated_encryption_test_case_3), 11825 TEST_CASE_ST(ut_setup, ut_teardown, 11826 test_AES_GCM_authenticated_encryption_test_case_4), 11827 TEST_CASE_ST(ut_setup, ut_teardown, 11828 test_AES_GCM_authenticated_encryption_test_case_5), 11829 TEST_CASE_ST(ut_setup, ut_teardown, 11830 test_AES_GCM_authenticated_encryption_test_case_6), 11831 TEST_CASE_ST(ut_setup, ut_teardown, 11832 test_AES_GCM_authenticated_encryption_test_case_7), 11833 TEST_CASE_ST(ut_setup, ut_teardown, 11834 test_AES_GCM_authenticated_encryption_test_case_8), 11835 TEST_CASE_ST(ut_setup, ut_teardown, 11836 test_AES_GCM_J0_authenticated_encryption_test_case_1), 11837 11838 /** AES GCM Authenticated Decryption */ 11839 TEST_CASE_ST(ut_setup, ut_teardown, 11840 test_AES_GCM_authenticated_decryption_test_case_1), 11841 TEST_CASE_ST(ut_setup, ut_teardown, 11842 test_AES_GCM_authenticated_decryption_test_case_2), 11843 TEST_CASE_ST(ut_setup, ut_teardown, 11844 test_AES_GCM_authenticated_decryption_test_case_3), 11845 TEST_CASE_ST(ut_setup, ut_teardown, 11846 test_AES_GCM_authenticated_decryption_test_case_4), 11847 TEST_CASE_ST(ut_setup, ut_teardown, 11848 test_AES_GCM_authenticated_decryption_test_case_5), 11849 TEST_CASE_ST(ut_setup, ut_teardown, 11850 test_AES_GCM_authenticated_decryption_test_case_6), 11851 TEST_CASE_ST(ut_setup, ut_teardown, 11852 test_AES_GCM_authenticated_decryption_test_case_7), 11853 TEST_CASE_ST(ut_setup, ut_teardown, 11854 test_AES_GCM_authenticated_decryption_test_case_8), 11855 TEST_CASE_ST(ut_setup, ut_teardown, 11856 test_AES_GCM_J0_authenticated_decryption_test_case_1), 11857 11858 /** AES GCM Authenticated Encryption 192 bits key */ 11859 TEST_CASE_ST(ut_setup, ut_teardown, 11860 test_AES_GCM_auth_encryption_test_case_192_1), 11861 TEST_CASE_ST(ut_setup, ut_teardown, 11862 test_AES_GCM_auth_encryption_test_case_192_2), 11863 TEST_CASE_ST(ut_setup, ut_teardown, 11864 test_AES_GCM_auth_encryption_test_case_192_3), 11865 TEST_CASE_ST(ut_setup, ut_teardown, 11866 test_AES_GCM_auth_encryption_test_case_192_4), 11867 TEST_CASE_ST(ut_setup, ut_teardown, 11868 test_AES_GCM_auth_encryption_test_case_192_5), 11869 TEST_CASE_ST(ut_setup, ut_teardown, 11870 test_AES_GCM_auth_encryption_test_case_192_6), 11871 TEST_CASE_ST(ut_setup, ut_teardown, 11872 test_AES_GCM_auth_encryption_test_case_192_7), 11873 11874 /** AES GCM Authenticated Decryption 192 bits key */ 11875 TEST_CASE_ST(ut_setup, ut_teardown, 11876 test_AES_GCM_auth_decryption_test_case_192_1), 11877 TEST_CASE_ST(ut_setup, ut_teardown, 11878 test_AES_GCM_auth_decryption_test_case_192_2), 11879 TEST_CASE_ST(ut_setup, ut_teardown, 11880 test_AES_GCM_auth_decryption_test_case_192_3), 11881 TEST_CASE_ST(ut_setup, ut_teardown, 11882 test_AES_GCM_auth_decryption_test_case_192_4), 11883 TEST_CASE_ST(ut_setup, ut_teardown, 11884 test_AES_GCM_auth_decryption_test_case_192_5), 11885 TEST_CASE_ST(ut_setup, ut_teardown, 11886 test_AES_GCM_auth_decryption_test_case_192_6), 11887 TEST_CASE_ST(ut_setup, ut_teardown, 11888 test_AES_GCM_auth_decryption_test_case_192_7), 11889 11890 /** AES GCM Authenticated Encryption 256 bits key */ 11891 TEST_CASE_ST(ut_setup, ut_teardown, 11892 test_AES_GCM_auth_encryption_test_case_256_1), 11893 TEST_CASE_ST(ut_setup, ut_teardown, 11894 test_AES_GCM_auth_encryption_test_case_256_2), 11895 TEST_CASE_ST(ut_setup, ut_teardown, 11896 test_AES_GCM_auth_encryption_test_case_256_3), 11897 TEST_CASE_ST(ut_setup, ut_teardown, 11898 test_AES_GCM_auth_encryption_test_case_256_4), 11899 TEST_CASE_ST(ut_setup, ut_teardown, 11900 test_AES_GCM_auth_encryption_test_case_256_5), 11901 TEST_CASE_ST(ut_setup, ut_teardown, 11902 test_AES_GCM_auth_encryption_test_case_256_6), 11903 TEST_CASE_ST(ut_setup, ut_teardown, 11904 test_AES_GCM_auth_encryption_test_case_256_7), 11905 11906 /** AES GCM Authenticated Decryption 256 bits key */ 11907 TEST_CASE_ST(ut_setup, ut_teardown, 11908 test_AES_GCM_auth_decryption_test_case_256_1), 11909 TEST_CASE_ST(ut_setup, ut_teardown, 11910 test_AES_GCM_auth_decryption_test_case_256_2), 11911 TEST_CASE_ST(ut_setup, ut_teardown, 11912 test_AES_GCM_auth_decryption_test_case_256_3), 11913 TEST_CASE_ST(ut_setup, ut_teardown, 11914 test_AES_GCM_auth_decryption_test_case_256_4), 11915 TEST_CASE_ST(ut_setup, ut_teardown, 11916 test_AES_GCM_auth_decryption_test_case_256_5), 11917 TEST_CASE_ST(ut_setup, ut_teardown, 11918 test_AES_GCM_auth_decryption_test_case_256_6), 11919 TEST_CASE_ST(ut_setup, ut_teardown, 11920 test_AES_GCM_auth_decryption_test_case_256_7), 11921 11922 /** AES GCM Authenticated Encryption big aad size */ 11923 TEST_CASE_ST(ut_setup, ut_teardown, 11924 test_AES_GCM_auth_encryption_test_case_aad_1), 11925 TEST_CASE_ST(ut_setup, ut_teardown, 11926 test_AES_GCM_auth_encryption_test_case_aad_2), 11927 11928 /** AES GCM Authenticated Decryption big aad size */ 11929 TEST_CASE_ST(ut_setup, ut_teardown, 11930 test_AES_GCM_auth_decryption_test_case_aad_1), 11931 TEST_CASE_ST(ut_setup, ut_teardown, 11932 test_AES_GCM_auth_decryption_test_case_aad_2), 11933 11934 /** Out of place tests */ 11935 TEST_CASE_ST(ut_setup, ut_teardown, 11936 test_AES_GCM_authenticated_encryption_oop_test_case_1), 11937 TEST_CASE_ST(ut_setup, ut_teardown, 11938 test_AES_GCM_authenticated_decryption_oop_test_case_1), 11939 11940 /** Session-less tests */ 11941 TEST_CASE_ST(ut_setup, ut_teardown, 11942 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 11943 TEST_CASE_ST(ut_setup, ut_teardown, 11944 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 11945 11946 /** AES GMAC Authentication */ 11947 TEST_CASE_ST(ut_setup, ut_teardown, 11948 test_AES_GMAC_authentication_test_case_1), 11949 TEST_CASE_ST(ut_setup, ut_teardown, 11950 test_AES_GMAC_authentication_verify_test_case_1), 11951 TEST_CASE_ST(ut_setup, ut_teardown, 11952 test_AES_GMAC_authentication_test_case_2), 11953 TEST_CASE_ST(ut_setup, ut_teardown, 11954 test_AES_GMAC_authentication_verify_test_case_2), 11955 TEST_CASE_ST(ut_setup, ut_teardown, 11956 test_AES_GMAC_authentication_test_case_3), 11957 TEST_CASE_ST(ut_setup, ut_teardown, 11958 test_AES_GMAC_authentication_verify_test_case_3), 11959 TEST_CASE_ST(ut_setup, ut_teardown, 11960 test_AES_GMAC_authentication_test_case_4), 11961 TEST_CASE_ST(ut_setup, ut_teardown, 11962 test_AES_GMAC_authentication_verify_test_case_4), 11963 11964 /** SNOW 3G encrypt only (UEA2) */ 11965 TEST_CASE_ST(ut_setup, ut_teardown, 11966 test_snow3g_encryption_test_case_1), 11967 TEST_CASE_ST(ut_setup, ut_teardown, 11968 test_snow3g_encryption_test_case_2), 11969 TEST_CASE_ST(ut_setup, ut_teardown, 11970 test_snow3g_encryption_test_case_3), 11971 TEST_CASE_ST(ut_setup, ut_teardown, 11972 test_snow3g_encryption_test_case_4), 11973 TEST_CASE_ST(ut_setup, ut_teardown, 11974 test_snow3g_encryption_test_case_5), 11975 11976 TEST_CASE_ST(ut_setup, ut_teardown, 11977 test_snow3g_encryption_test_case_1_oop), 11978 TEST_CASE_ST(ut_setup, ut_teardown, 11979 test_snow3g_encryption_test_case_1_oop_sgl), 11980 TEST_CASE_ST(ut_setup, ut_teardown, 11981 test_snow3g_encryption_test_case_1_offset_oop), 11982 TEST_CASE_ST(ut_setup, ut_teardown, 11983 test_snow3g_decryption_test_case_1_oop), 11984 11985 /** SNOW 3G generate auth, then encrypt (UEA2) */ 11986 TEST_CASE_ST(ut_setup, ut_teardown, 11987 test_snow3g_auth_cipher_test_case_1), 11988 TEST_CASE_ST(ut_setup, ut_teardown, 11989 test_snow3g_auth_cipher_test_case_2), 11990 TEST_CASE_ST(ut_setup, ut_teardown, 11991 test_snow3g_auth_cipher_test_case_2_oop), 11992 TEST_CASE_ST(ut_setup, ut_teardown, 11993 test_snow3g_auth_cipher_part_digest_enc), 11994 TEST_CASE_ST(ut_setup, ut_teardown, 11995 test_snow3g_auth_cipher_part_digest_enc_oop), 11996 TEST_CASE_ST(ut_setup, ut_teardown, 11997 test_snow3g_auth_cipher_test_case_3_sgl), 11998 TEST_CASE_ST(ut_setup, ut_teardown, 11999 test_snow3g_auth_cipher_test_case_3_oop_sgl), 12000 TEST_CASE_ST(ut_setup, ut_teardown, 12001 test_snow3g_auth_cipher_part_digest_enc_sgl), 12002 TEST_CASE_ST(ut_setup, ut_teardown, 12003 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 12004 12005 /** SNOW 3G decrypt (UEA2), then verify auth */ 12006 TEST_CASE_ST(ut_setup, ut_teardown, 12007 test_snow3g_auth_cipher_verify_test_case_1), 12008 TEST_CASE_ST(ut_setup, ut_teardown, 12009 test_snow3g_auth_cipher_verify_test_case_2), 12010 TEST_CASE_ST(ut_setup, ut_teardown, 12011 test_snow3g_auth_cipher_verify_test_case_2_oop), 12012 TEST_CASE_ST(ut_setup, ut_teardown, 12013 test_snow3g_auth_cipher_verify_part_digest_enc), 12014 TEST_CASE_ST(ut_setup, ut_teardown, 12015 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 12016 TEST_CASE_ST(ut_setup, ut_teardown, 12017 test_snow3g_auth_cipher_verify_test_case_3_sgl), 12018 TEST_CASE_ST(ut_setup, ut_teardown, 12019 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 12020 TEST_CASE_ST(ut_setup, ut_teardown, 12021 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 12022 TEST_CASE_ST(ut_setup, ut_teardown, 12023 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 12024 12025 /** SNOW 3G decrypt only (UEA2) */ 12026 TEST_CASE_ST(ut_setup, ut_teardown, 12027 test_snow3g_decryption_test_case_1), 12028 TEST_CASE_ST(ut_setup, ut_teardown, 12029 test_snow3g_decryption_test_case_2), 12030 TEST_CASE_ST(ut_setup, ut_teardown, 12031 test_snow3g_decryption_test_case_3), 12032 TEST_CASE_ST(ut_setup, ut_teardown, 12033 test_snow3g_decryption_test_case_4), 12034 TEST_CASE_ST(ut_setup, ut_teardown, 12035 test_snow3g_decryption_test_case_5), 12036 TEST_CASE_ST(ut_setup, ut_teardown, 12037 test_snow3g_decryption_with_digest_test_case_1), 12038 TEST_CASE_ST(ut_setup, ut_teardown, 12039 test_snow3g_hash_generate_test_case_1), 12040 TEST_CASE_ST(ut_setup, ut_teardown, 12041 test_snow3g_hash_generate_test_case_2), 12042 TEST_CASE_ST(ut_setup, ut_teardown, 12043 test_snow3g_hash_generate_test_case_3), 12044 /* Tests with buffers which length is not byte-aligned */ 12045 TEST_CASE_ST(ut_setup, ut_teardown, 12046 test_snow3g_hash_generate_test_case_4), 12047 TEST_CASE_ST(ut_setup, ut_teardown, 12048 test_snow3g_hash_generate_test_case_5), 12049 TEST_CASE_ST(ut_setup, ut_teardown, 12050 test_snow3g_hash_generate_test_case_6), 12051 TEST_CASE_ST(ut_setup, ut_teardown, 12052 test_snow3g_hash_verify_test_case_1), 12053 TEST_CASE_ST(ut_setup, ut_teardown, 12054 test_snow3g_hash_verify_test_case_2), 12055 TEST_CASE_ST(ut_setup, ut_teardown, 12056 test_snow3g_hash_verify_test_case_3), 12057 /* Tests with buffers which length is not byte-aligned */ 12058 TEST_CASE_ST(ut_setup, ut_teardown, 12059 test_snow3g_hash_verify_test_case_4), 12060 TEST_CASE_ST(ut_setup, ut_teardown, 12061 test_snow3g_hash_verify_test_case_5), 12062 TEST_CASE_ST(ut_setup, ut_teardown, 12063 test_snow3g_hash_verify_test_case_6), 12064 TEST_CASE_ST(ut_setup, ut_teardown, 12065 test_snow3g_cipher_auth_test_case_1), 12066 TEST_CASE_ST(ut_setup, ut_teardown, 12067 test_snow3g_auth_cipher_with_digest_test_case_1), 12068 12069 /** ZUC encrypt only (EEA3) */ 12070 TEST_CASE_ST(ut_setup, ut_teardown, 12071 test_zuc_encryption_test_case_1), 12072 TEST_CASE_ST(ut_setup, ut_teardown, 12073 test_zuc_encryption_test_case_2), 12074 TEST_CASE_ST(ut_setup, ut_teardown, 12075 test_zuc_encryption_test_case_3), 12076 TEST_CASE_ST(ut_setup, ut_teardown, 12077 test_zuc_encryption_test_case_4), 12078 TEST_CASE_ST(ut_setup, ut_teardown, 12079 test_zuc_encryption_test_case_5), 12080 TEST_CASE_ST(ut_setup, ut_teardown, 12081 test_zuc_encryption_test_case_6_sgl), 12082 12083 /** ZUC authenticate (EIA3) */ 12084 TEST_CASE_ST(ut_setup, ut_teardown, 12085 test_zuc_hash_generate_test_case_1), 12086 TEST_CASE_ST(ut_setup, ut_teardown, 12087 test_zuc_hash_generate_test_case_2), 12088 TEST_CASE_ST(ut_setup, ut_teardown, 12089 test_zuc_hash_generate_test_case_3), 12090 TEST_CASE_ST(ut_setup, ut_teardown, 12091 test_zuc_hash_generate_test_case_4), 12092 TEST_CASE_ST(ut_setup, ut_teardown, 12093 test_zuc_hash_generate_test_case_5), 12094 TEST_CASE_ST(ut_setup, ut_teardown, 12095 test_zuc_hash_generate_test_case_6), 12096 TEST_CASE_ST(ut_setup, ut_teardown, 12097 test_zuc_hash_generate_test_case_7), 12098 TEST_CASE_ST(ut_setup, ut_teardown, 12099 test_zuc_hash_generate_test_case_8), 12100 12101 /** ZUC alg-chain (EEA3/EIA3) */ 12102 TEST_CASE_ST(ut_setup, ut_teardown, 12103 test_zuc_cipher_auth_test_case_1), 12104 TEST_CASE_ST(ut_setup, ut_teardown, 12105 test_zuc_cipher_auth_test_case_2), 12106 12107 /** ZUC generate auth, then encrypt (EEA3) */ 12108 TEST_CASE_ST(ut_setup, ut_teardown, 12109 test_zuc_auth_cipher_test_case_1), 12110 TEST_CASE_ST(ut_setup, ut_teardown, 12111 test_zuc_auth_cipher_test_case_1_oop), 12112 TEST_CASE_ST(ut_setup, ut_teardown, 12113 test_zuc_auth_cipher_test_case_1_sgl), 12114 TEST_CASE_ST(ut_setup, ut_teardown, 12115 test_zuc_auth_cipher_test_case_1_oop_sgl), 12116 12117 /** ZUC decrypt (EEA3), then verify auth */ 12118 TEST_CASE_ST(ut_setup, ut_teardown, 12119 test_zuc_auth_cipher_verify_test_case_1), 12120 TEST_CASE_ST(ut_setup, ut_teardown, 12121 test_zuc_auth_cipher_verify_test_case_1_oop), 12122 TEST_CASE_ST(ut_setup, ut_teardown, 12123 test_zuc_auth_cipher_verify_test_case_1_sgl), 12124 TEST_CASE_ST(ut_setup, ut_teardown, 12125 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 12126 12127 /** HMAC_MD5 Authentication */ 12128 TEST_CASE_ST(ut_setup, ut_teardown, 12129 test_MD5_HMAC_generate_case_1), 12130 TEST_CASE_ST(ut_setup, ut_teardown, 12131 test_MD5_HMAC_verify_case_1), 12132 TEST_CASE_ST(ut_setup, ut_teardown, 12133 test_MD5_HMAC_generate_case_2), 12134 TEST_CASE_ST(ut_setup, ut_teardown, 12135 test_MD5_HMAC_verify_case_2), 12136 12137 /** KASUMI hash only (UIA1) */ 12138 TEST_CASE_ST(ut_setup, ut_teardown, 12139 test_kasumi_hash_generate_test_case_1), 12140 TEST_CASE_ST(ut_setup, ut_teardown, 12141 test_kasumi_hash_generate_test_case_2), 12142 TEST_CASE_ST(ut_setup, ut_teardown, 12143 test_kasumi_hash_generate_test_case_3), 12144 TEST_CASE_ST(ut_setup, ut_teardown, 12145 test_kasumi_hash_generate_test_case_4), 12146 TEST_CASE_ST(ut_setup, ut_teardown, 12147 test_kasumi_hash_generate_test_case_5), 12148 TEST_CASE_ST(ut_setup, ut_teardown, 12149 test_kasumi_hash_generate_test_case_6), 12150 12151 TEST_CASE_ST(ut_setup, ut_teardown, 12152 test_kasumi_hash_verify_test_case_1), 12153 TEST_CASE_ST(ut_setup, ut_teardown, 12154 test_kasumi_hash_verify_test_case_2), 12155 TEST_CASE_ST(ut_setup, ut_teardown, 12156 test_kasumi_hash_verify_test_case_3), 12157 TEST_CASE_ST(ut_setup, ut_teardown, 12158 test_kasumi_hash_verify_test_case_4), 12159 TEST_CASE_ST(ut_setup, ut_teardown, 12160 test_kasumi_hash_verify_test_case_5), 12161 12162 /** KASUMI encrypt only (UEA1) */ 12163 TEST_CASE_ST(ut_setup, ut_teardown, 12164 test_kasumi_encryption_test_case_1), 12165 TEST_CASE_ST(ut_setup, ut_teardown, 12166 test_kasumi_encryption_test_case_1_sgl), 12167 TEST_CASE_ST(ut_setup, ut_teardown, 12168 test_kasumi_encryption_test_case_1_oop), 12169 TEST_CASE_ST(ut_setup, ut_teardown, 12170 test_kasumi_encryption_test_case_1_oop_sgl), 12171 TEST_CASE_ST(ut_setup, ut_teardown, 12172 test_kasumi_encryption_test_case_2), 12173 TEST_CASE_ST(ut_setup, ut_teardown, 12174 test_kasumi_encryption_test_case_3), 12175 TEST_CASE_ST(ut_setup, ut_teardown, 12176 test_kasumi_encryption_test_case_4), 12177 TEST_CASE_ST(ut_setup, ut_teardown, 12178 test_kasumi_encryption_test_case_5), 12179 12180 /** KASUMI decrypt only (UEA1) */ 12181 TEST_CASE_ST(ut_setup, ut_teardown, 12182 test_kasumi_decryption_test_case_1), 12183 TEST_CASE_ST(ut_setup, ut_teardown, 12184 test_kasumi_decryption_test_case_2), 12185 TEST_CASE_ST(ut_setup, ut_teardown, 12186 test_kasumi_decryption_test_case_3), 12187 TEST_CASE_ST(ut_setup, ut_teardown, 12188 test_kasumi_decryption_test_case_4), 12189 TEST_CASE_ST(ut_setup, ut_teardown, 12190 test_kasumi_decryption_test_case_5), 12191 TEST_CASE_ST(ut_setup, ut_teardown, 12192 test_kasumi_decryption_test_case_1_oop), 12193 12194 TEST_CASE_ST(ut_setup, ut_teardown, 12195 test_kasumi_cipher_auth_test_case_1), 12196 12197 /** KASUMI generate auth, then encrypt (F8) */ 12198 TEST_CASE_ST(ut_setup, ut_teardown, 12199 test_kasumi_auth_cipher_test_case_1), 12200 TEST_CASE_ST(ut_setup, ut_teardown, 12201 test_kasumi_auth_cipher_test_case_2), 12202 TEST_CASE_ST(ut_setup, ut_teardown, 12203 test_kasumi_auth_cipher_test_case_2_oop), 12204 TEST_CASE_ST(ut_setup, ut_teardown, 12205 test_kasumi_auth_cipher_test_case_2_sgl), 12206 TEST_CASE_ST(ut_setup, ut_teardown, 12207 test_kasumi_auth_cipher_test_case_2_oop_sgl), 12208 12209 /** KASUMI decrypt (F8), then verify auth */ 12210 TEST_CASE_ST(ut_setup, ut_teardown, 12211 test_kasumi_auth_cipher_verify_test_case_1), 12212 TEST_CASE_ST(ut_setup, ut_teardown, 12213 test_kasumi_auth_cipher_verify_test_case_2), 12214 TEST_CASE_ST(ut_setup, ut_teardown, 12215 test_kasumi_auth_cipher_verify_test_case_2_oop), 12216 TEST_CASE_ST(ut_setup, ut_teardown, 12217 test_kasumi_auth_cipher_verify_test_case_2_sgl), 12218 TEST_CASE_ST(ut_setup, ut_teardown, 12219 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 12220 12221 /** ESN Testcase */ 12222 TEST_CASE_ST(ut_setup, ut_teardown, 12223 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 12224 TEST_CASE_ST(ut_setup, ut_teardown, 12225 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 12226 12227 /** Negative tests */ 12228 TEST_CASE_ST(ut_setup, ut_teardown, 12229 authentication_verify_HMAC_SHA1_fail_data_corrupt), 12230 TEST_CASE_ST(ut_setup, ut_teardown, 12231 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 12232 TEST_CASE_ST(ut_setup, ut_teardown, 12233 test_AES_GCM_auth_encryption_fail_iv_corrupt), 12234 TEST_CASE_ST(ut_setup, ut_teardown, 12235 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 12236 TEST_CASE_ST(ut_setup, ut_teardown, 12237 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 12238 TEST_CASE_ST(ut_setup, ut_teardown, 12239 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 12240 TEST_CASE_ST(ut_setup, ut_teardown, 12241 test_AES_GCM_auth_encryption_fail_aad_corrupt), 12242 TEST_CASE_ST(ut_setup, ut_teardown, 12243 test_AES_GCM_auth_encryption_fail_tag_corrupt), 12244 TEST_CASE_ST(ut_setup, ut_teardown, 12245 test_AES_GCM_auth_decryption_fail_iv_corrupt), 12246 TEST_CASE_ST(ut_setup, ut_teardown, 12247 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 12248 TEST_CASE_ST(ut_setup, ut_teardown, 12249 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 12250 TEST_CASE_ST(ut_setup, ut_teardown, 12251 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 12252 TEST_CASE_ST(ut_setup, ut_teardown, 12253 test_AES_GCM_auth_decryption_fail_aad_corrupt), 12254 TEST_CASE_ST(ut_setup, ut_teardown, 12255 test_AES_GCM_auth_decryption_fail_tag_corrupt), 12256 TEST_CASE_ST(ut_setup, ut_teardown, 12257 authentication_verify_AES128_GMAC_fail_data_corrupt), 12258 TEST_CASE_ST(ut_setup, ut_teardown, 12259 authentication_verify_AES128_GMAC_fail_tag_corrupt), 12260 TEST_CASE_ST(ut_setup, ut_teardown, 12261 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12262 TEST_CASE_ST(ut_setup, ut_teardown, 12263 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12264 12265 /** Mixed CIPHER + HASH algorithms */ 12266 /** AUTH AES CMAC + CIPHER AES CTR */ 12267 TEST_CASE_ST(ut_setup, ut_teardown, 12268 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 12269 TEST_CASE_ST(ut_setup, ut_teardown, 12270 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 12271 TEST_CASE_ST(ut_setup, ut_teardown, 12272 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 12273 TEST_CASE_ST(ut_setup, ut_teardown, 12274 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 12275 TEST_CASE_ST(ut_setup, ut_teardown, 12276 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 12277 TEST_CASE_ST(ut_setup, ut_teardown, 12278 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 12279 TEST_CASE_ST(ut_setup, ut_teardown, 12280 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 12281 TEST_CASE_ST(ut_setup, ut_teardown, 12282 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 12283 12284 /** AUTH ZUC + CIPHER SNOW3G */ 12285 TEST_CASE_ST(ut_setup, ut_teardown, 12286 test_auth_zuc_cipher_snow_test_case_1), 12287 TEST_CASE_ST(ut_setup, ut_teardown, 12288 test_verify_auth_zuc_cipher_snow_test_case_1), 12289 /** AUTH AES CMAC + CIPHER SNOW3G */ 12290 TEST_CASE_ST(ut_setup, ut_teardown, 12291 test_auth_aes_cmac_cipher_snow_test_case_1), 12292 TEST_CASE_ST(ut_setup, ut_teardown, 12293 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 12294 /** AUTH ZUC + CIPHER AES CTR */ 12295 TEST_CASE_ST(ut_setup, ut_teardown, 12296 test_auth_zuc_cipher_aes_ctr_test_case_1), 12297 TEST_CASE_ST(ut_setup, ut_teardown, 12298 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 12299 /** AUTH SNOW3G + CIPHER AES CTR */ 12300 TEST_CASE_ST(ut_setup, ut_teardown, 12301 test_auth_snow_cipher_aes_ctr_test_case_1), 12302 TEST_CASE_ST(ut_setup, ut_teardown, 12303 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 12304 /** AUTH SNOW3G + CIPHER ZUC */ 12305 TEST_CASE_ST(ut_setup, ut_teardown, 12306 test_auth_snow_cipher_zuc_test_case_1), 12307 TEST_CASE_ST(ut_setup, ut_teardown, 12308 test_verify_auth_snow_cipher_zuc_test_case_1), 12309 /** AUTH AES CMAC + CIPHER ZUC */ 12310 TEST_CASE_ST(ut_setup, ut_teardown, 12311 test_auth_aes_cmac_cipher_zuc_test_case_1), 12312 TEST_CASE_ST(ut_setup, ut_teardown, 12313 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 12314 12315 /** AUTH NULL + CIPHER SNOW3G */ 12316 TEST_CASE_ST(ut_setup, ut_teardown, 12317 test_auth_null_cipher_snow_test_case_1), 12318 TEST_CASE_ST(ut_setup, ut_teardown, 12319 test_verify_auth_null_cipher_snow_test_case_1), 12320 /** AUTH NULL + CIPHER ZUC */ 12321 TEST_CASE_ST(ut_setup, ut_teardown, 12322 test_auth_null_cipher_zuc_test_case_1), 12323 TEST_CASE_ST(ut_setup, ut_teardown, 12324 test_verify_auth_null_cipher_zuc_test_case_1), 12325 /** AUTH SNOW3G + CIPHER NULL */ 12326 TEST_CASE_ST(ut_setup, ut_teardown, 12327 test_auth_snow_cipher_null_test_case_1), 12328 TEST_CASE_ST(ut_setup, ut_teardown, 12329 test_verify_auth_snow_cipher_null_test_case_1), 12330 /** AUTH ZUC + CIPHER NULL */ 12331 TEST_CASE_ST(ut_setup, ut_teardown, 12332 test_auth_zuc_cipher_null_test_case_1), 12333 TEST_CASE_ST(ut_setup, ut_teardown, 12334 test_verify_auth_zuc_cipher_null_test_case_1), 12335 /** AUTH NULL + CIPHER AES CTR */ 12336 TEST_CASE_ST(ut_setup, ut_teardown, 12337 test_auth_null_cipher_aes_ctr_test_case_1), 12338 TEST_CASE_ST(ut_setup, ut_teardown, 12339 test_verify_auth_null_cipher_aes_ctr_test_case_1), 12340 /** AUTH AES CMAC + CIPHER NULL */ 12341 TEST_CASE_ST(ut_setup, ut_teardown, 12342 test_auth_aes_cmac_cipher_null_test_case_1), 12343 TEST_CASE_ST(ut_setup, ut_teardown, 12344 test_verify_auth_aes_cmac_cipher_null_test_case_1), 12345 12346 TEST_CASES_END() /**< NULL terminate unit test array */ 12347 } 12348 }; 12349 12350 static struct unit_test_suite cryptodev_virtio_testsuite = { 12351 .suite_name = "Crypto VIRTIO Unit Test Suite", 12352 .setup = testsuite_setup, 12353 .teardown = testsuite_teardown, 12354 .unit_test_cases = { 12355 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12356 12357 TEST_CASES_END() /**< NULL terminate unit test array */ 12358 } 12359 }; 12360 12361 static struct unit_test_suite cryptodev_caam_jr_testsuite = { 12362 .suite_name = "Crypto CAAM JR Unit Test Suite", 12363 .setup = testsuite_setup, 12364 .teardown = testsuite_teardown, 12365 .unit_test_cases = { 12366 TEST_CASE_ST(ut_setup, ut_teardown, 12367 test_device_configure_invalid_dev_id), 12368 TEST_CASE_ST(ut_setup, ut_teardown, 12369 test_multi_session), 12370 12371 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12372 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12373 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12374 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12375 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12376 12377 TEST_CASES_END() /**< NULL terminate unit test array */ 12378 } 12379 }; 12380 12381 static struct unit_test_suite cryptodev_dpaa_sec_testsuite = { 12382 .suite_name = "Crypto DPAA_SEC Unit Test Suite", 12383 .setup = testsuite_setup, 12384 .teardown = testsuite_teardown, 12385 .unit_test_cases = { 12386 TEST_CASE_ST(ut_setup, ut_teardown, 12387 test_device_configure_invalid_dev_id), 12388 TEST_CASE_ST(ut_setup, ut_teardown, 12389 test_multi_session), 12390 12391 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12392 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12393 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12394 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12395 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12396 12397 #ifdef RTE_LIBRTE_SECURITY 12398 TEST_CASE_ST(ut_setup, ut_teardown, 12399 test_PDCP_PROTO_cplane_encap_all), 12400 12401 TEST_CASE_ST(ut_setup, ut_teardown, 12402 test_PDCP_PROTO_cplane_decap_all), 12403 12404 TEST_CASE_ST(ut_setup, ut_teardown, 12405 test_PDCP_PROTO_uplane_encap_all), 12406 12407 TEST_CASE_ST(ut_setup, ut_teardown, 12408 test_PDCP_PROTO_uplane_decap_all), 12409 12410 TEST_CASE_ST(ut_setup, ut_teardown, 12411 test_PDCP_PROTO_SGL_in_place_32B), 12412 TEST_CASE_ST(ut_setup, ut_teardown, 12413 test_PDCP_PROTO_SGL_oop_32B_128B), 12414 TEST_CASE_ST(ut_setup, ut_teardown, 12415 test_PDCP_PROTO_SGL_oop_32B_40B), 12416 TEST_CASE_ST(ut_setup, ut_teardown, 12417 test_PDCP_PROTO_SGL_oop_128B_32B), 12418 #endif 12419 /** AES GCM Authenticated Encryption */ 12420 TEST_CASE_ST(ut_setup, ut_teardown, 12421 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 12422 TEST_CASE_ST(ut_setup, ut_teardown, 12423 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 12424 TEST_CASE_ST(ut_setup, ut_teardown, 12425 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 12426 TEST_CASE_ST(ut_setup, ut_teardown, 12427 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 12428 TEST_CASE_ST(ut_setup, ut_teardown, 12429 test_AES_GCM_authenticated_encryption_test_case_1), 12430 TEST_CASE_ST(ut_setup, ut_teardown, 12431 test_AES_GCM_authenticated_encryption_test_case_2), 12432 TEST_CASE_ST(ut_setup, ut_teardown, 12433 test_AES_GCM_authenticated_encryption_test_case_3), 12434 TEST_CASE_ST(ut_setup, ut_teardown, 12435 test_AES_GCM_authenticated_encryption_test_case_4), 12436 TEST_CASE_ST(ut_setup, ut_teardown, 12437 test_AES_GCM_authenticated_encryption_test_case_5), 12438 TEST_CASE_ST(ut_setup, ut_teardown, 12439 test_AES_GCM_authenticated_encryption_test_case_6), 12440 TEST_CASE_ST(ut_setup, ut_teardown, 12441 test_AES_GCM_authenticated_encryption_test_case_7), 12442 TEST_CASE_ST(ut_setup, ut_teardown, 12443 test_AES_GCM_authenticated_encryption_test_case_8), 12444 12445 /** AES GCM Authenticated Decryption */ 12446 TEST_CASE_ST(ut_setup, ut_teardown, 12447 test_AES_GCM_authenticated_decryption_test_case_1), 12448 TEST_CASE_ST(ut_setup, ut_teardown, 12449 test_AES_GCM_authenticated_decryption_test_case_2), 12450 TEST_CASE_ST(ut_setup, ut_teardown, 12451 test_AES_GCM_authenticated_decryption_test_case_3), 12452 TEST_CASE_ST(ut_setup, ut_teardown, 12453 test_AES_GCM_authenticated_decryption_test_case_4), 12454 TEST_CASE_ST(ut_setup, ut_teardown, 12455 test_AES_GCM_authenticated_decryption_test_case_5), 12456 TEST_CASE_ST(ut_setup, ut_teardown, 12457 test_AES_GCM_authenticated_decryption_test_case_6), 12458 TEST_CASE_ST(ut_setup, ut_teardown, 12459 test_AES_GCM_authenticated_decryption_test_case_7), 12460 TEST_CASE_ST(ut_setup, ut_teardown, 12461 test_AES_GCM_authenticated_decryption_test_case_8), 12462 12463 /** AES GCM Authenticated Encryption 192 bits key */ 12464 TEST_CASE_ST(ut_setup, ut_teardown, 12465 test_AES_GCM_auth_encryption_test_case_192_1), 12466 TEST_CASE_ST(ut_setup, ut_teardown, 12467 test_AES_GCM_auth_encryption_test_case_192_2), 12468 TEST_CASE_ST(ut_setup, ut_teardown, 12469 test_AES_GCM_auth_encryption_test_case_192_3), 12470 TEST_CASE_ST(ut_setup, ut_teardown, 12471 test_AES_GCM_auth_encryption_test_case_192_4), 12472 TEST_CASE_ST(ut_setup, ut_teardown, 12473 test_AES_GCM_auth_encryption_test_case_192_5), 12474 TEST_CASE_ST(ut_setup, ut_teardown, 12475 test_AES_GCM_auth_encryption_test_case_192_6), 12476 TEST_CASE_ST(ut_setup, ut_teardown, 12477 test_AES_GCM_auth_encryption_test_case_192_7), 12478 12479 /** AES GCM Authenticated Decryption 192 bits key */ 12480 TEST_CASE_ST(ut_setup, ut_teardown, 12481 test_AES_GCM_auth_decryption_test_case_192_1), 12482 TEST_CASE_ST(ut_setup, ut_teardown, 12483 test_AES_GCM_auth_decryption_test_case_192_2), 12484 TEST_CASE_ST(ut_setup, ut_teardown, 12485 test_AES_GCM_auth_decryption_test_case_192_3), 12486 TEST_CASE_ST(ut_setup, ut_teardown, 12487 test_AES_GCM_auth_decryption_test_case_192_4), 12488 TEST_CASE_ST(ut_setup, ut_teardown, 12489 test_AES_GCM_auth_decryption_test_case_192_5), 12490 TEST_CASE_ST(ut_setup, ut_teardown, 12491 test_AES_GCM_auth_decryption_test_case_192_6), 12492 TEST_CASE_ST(ut_setup, ut_teardown, 12493 test_AES_GCM_auth_decryption_test_case_192_7), 12494 12495 /** AES GCM Authenticated Encryption 256 bits key */ 12496 TEST_CASE_ST(ut_setup, ut_teardown, 12497 test_AES_GCM_auth_encryption_test_case_256_1), 12498 TEST_CASE_ST(ut_setup, ut_teardown, 12499 test_AES_GCM_auth_encryption_test_case_256_2), 12500 TEST_CASE_ST(ut_setup, ut_teardown, 12501 test_AES_GCM_auth_encryption_test_case_256_3), 12502 TEST_CASE_ST(ut_setup, ut_teardown, 12503 test_AES_GCM_auth_encryption_test_case_256_4), 12504 TEST_CASE_ST(ut_setup, ut_teardown, 12505 test_AES_GCM_auth_encryption_test_case_256_5), 12506 TEST_CASE_ST(ut_setup, ut_teardown, 12507 test_AES_GCM_auth_encryption_test_case_256_6), 12508 TEST_CASE_ST(ut_setup, ut_teardown, 12509 test_AES_GCM_auth_encryption_test_case_256_7), 12510 12511 /** AES GCM Authenticated Decryption 256 bits key */ 12512 TEST_CASE_ST(ut_setup, ut_teardown, 12513 test_AES_GCM_auth_decryption_test_case_256_1), 12514 TEST_CASE_ST(ut_setup, ut_teardown, 12515 test_AES_GCM_auth_decryption_test_case_256_2), 12516 TEST_CASE_ST(ut_setup, ut_teardown, 12517 test_AES_GCM_auth_decryption_test_case_256_3), 12518 TEST_CASE_ST(ut_setup, ut_teardown, 12519 test_AES_GCM_auth_decryption_test_case_256_4), 12520 TEST_CASE_ST(ut_setup, ut_teardown, 12521 test_AES_GCM_auth_decryption_test_case_256_5), 12522 TEST_CASE_ST(ut_setup, ut_teardown, 12523 test_AES_GCM_auth_decryption_test_case_256_6), 12524 TEST_CASE_ST(ut_setup, ut_teardown, 12525 test_AES_GCM_auth_decryption_test_case_256_7), 12526 12527 /** Out of place tests */ 12528 TEST_CASE_ST(ut_setup, ut_teardown, 12529 test_AES_GCM_authenticated_encryption_oop_test_case_1), 12530 TEST_CASE_ST(ut_setup, ut_teardown, 12531 test_AES_GCM_authenticated_decryption_oop_test_case_1), 12532 12533 /** SNOW 3G encrypt only (UEA2) */ 12534 TEST_CASE_ST(ut_setup, ut_teardown, 12535 test_snow3g_encryption_test_case_1), 12536 TEST_CASE_ST(ut_setup, ut_teardown, 12537 test_snow3g_encryption_test_case_2), 12538 TEST_CASE_ST(ut_setup, ut_teardown, 12539 test_snow3g_encryption_test_case_3), 12540 TEST_CASE_ST(ut_setup, ut_teardown, 12541 test_snow3g_encryption_test_case_4), 12542 TEST_CASE_ST(ut_setup, ut_teardown, 12543 test_snow3g_encryption_test_case_5), 12544 12545 TEST_CASE_ST(ut_setup, ut_teardown, 12546 test_snow3g_encryption_test_case_1_oop), 12547 TEST_CASE_ST(ut_setup, ut_teardown, 12548 test_snow3g_encryption_test_case_1_oop_sgl), 12549 TEST_CASE_ST(ut_setup, ut_teardown, 12550 test_snow3g_decryption_test_case_1_oop), 12551 12552 /** SNOW 3G decrypt only (UEA2) */ 12553 TEST_CASE_ST(ut_setup, ut_teardown, 12554 test_snow3g_decryption_test_case_1), 12555 TEST_CASE_ST(ut_setup, ut_teardown, 12556 test_snow3g_decryption_test_case_2), 12557 TEST_CASE_ST(ut_setup, ut_teardown, 12558 test_snow3g_decryption_test_case_3), 12559 TEST_CASE_ST(ut_setup, ut_teardown, 12560 test_snow3g_decryption_test_case_4), 12561 TEST_CASE_ST(ut_setup, ut_teardown, 12562 test_snow3g_decryption_test_case_5), 12563 12564 TEST_CASE_ST(ut_setup, ut_teardown, 12565 test_snow3g_hash_generate_test_case_1), 12566 TEST_CASE_ST(ut_setup, ut_teardown, 12567 test_snow3g_hash_generate_test_case_2), 12568 TEST_CASE_ST(ut_setup, ut_teardown, 12569 test_snow3g_hash_generate_test_case_3), 12570 TEST_CASE_ST(ut_setup, ut_teardown, 12571 test_snow3g_hash_verify_test_case_1), 12572 TEST_CASE_ST(ut_setup, ut_teardown, 12573 test_snow3g_hash_verify_test_case_2), 12574 TEST_CASE_ST(ut_setup, ut_teardown, 12575 test_snow3g_hash_verify_test_case_3), 12576 12577 /** ZUC encrypt only (EEA3) */ 12578 TEST_CASE_ST(ut_setup, ut_teardown, 12579 test_zuc_encryption_test_case_1), 12580 TEST_CASE_ST(ut_setup, ut_teardown, 12581 test_zuc_encryption_test_case_2), 12582 TEST_CASE_ST(ut_setup, ut_teardown, 12583 test_zuc_encryption_test_case_3), 12584 TEST_CASE_ST(ut_setup, ut_teardown, 12585 test_zuc_encryption_test_case_4), 12586 TEST_CASE_ST(ut_setup, ut_teardown, 12587 test_zuc_encryption_test_case_5), 12588 12589 /** ZUC authenticate (EIA3) */ 12590 TEST_CASE_ST(ut_setup, ut_teardown, 12591 test_zuc_hash_generate_test_case_6), 12592 TEST_CASE_ST(ut_setup, ut_teardown, 12593 test_zuc_hash_generate_test_case_7), 12594 TEST_CASE_ST(ut_setup, ut_teardown, 12595 test_zuc_hash_generate_test_case_8), 12596 12597 /** Negative tests */ 12598 TEST_CASE_ST(ut_setup, ut_teardown, 12599 test_AES_GCM_auth_encryption_fail_iv_corrupt), 12600 TEST_CASE_ST(ut_setup, ut_teardown, 12601 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 12602 TEST_CASE_ST(ut_setup, ut_teardown, 12603 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 12604 TEST_CASE_ST(ut_setup, ut_teardown, 12605 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 12606 TEST_CASE_ST(ut_setup, ut_teardown, 12607 test_AES_GCM_auth_encryption_fail_aad_corrupt), 12608 TEST_CASE_ST(ut_setup, ut_teardown, 12609 test_AES_GCM_auth_encryption_fail_tag_corrupt), 12610 TEST_CASE_ST(ut_setup, ut_teardown, 12611 test_AES_GCM_auth_decryption_fail_iv_corrupt), 12612 TEST_CASE_ST(ut_setup, ut_teardown, 12613 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 12614 TEST_CASE_ST(ut_setup, ut_teardown, 12615 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 12616 TEST_CASE_ST(ut_setup, ut_teardown, 12617 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 12618 TEST_CASE_ST(ut_setup, ut_teardown, 12619 test_AES_GCM_auth_decryption_fail_aad_corrupt), 12620 TEST_CASE_ST(ut_setup, ut_teardown, 12621 test_AES_GCM_auth_decryption_fail_tag_corrupt), 12622 TEST_CASE_ST(ut_setup, ut_teardown, 12623 authentication_verify_HMAC_SHA1_fail_data_corrupt), 12624 TEST_CASE_ST(ut_setup, ut_teardown, 12625 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 12626 TEST_CASE_ST(ut_setup, ut_teardown, 12627 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12628 TEST_CASE_ST(ut_setup, ut_teardown, 12629 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12630 12631 /* ESN Testcase */ 12632 TEST_CASE_ST(ut_setup, ut_teardown, 12633 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 12634 TEST_CASE_ST(ut_setup, ut_teardown, 12635 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 12636 12637 TEST_CASES_END() /**< NULL terminate unit test array */ 12638 } 12639 }; 12640 12641 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite = { 12642 .suite_name = "Crypto DPAA2_SEC Unit Test Suite", 12643 .setup = testsuite_setup, 12644 .teardown = testsuite_teardown, 12645 .unit_test_cases = { 12646 TEST_CASE_ST(ut_setup, ut_teardown, 12647 test_device_configure_invalid_dev_id), 12648 TEST_CASE_ST(ut_setup, ut_teardown, 12649 test_multi_session), 12650 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12651 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12652 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12653 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12654 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12655 12656 #ifdef RTE_LIBRTE_SECURITY 12657 TEST_CASE_ST(ut_setup, ut_teardown, 12658 test_PDCP_PROTO_cplane_encap_all), 12659 12660 TEST_CASE_ST(ut_setup, ut_teardown, 12661 test_PDCP_PROTO_cplane_decap_all), 12662 12663 TEST_CASE_ST(ut_setup, ut_teardown, 12664 test_PDCP_PROTO_uplane_encap_all), 12665 12666 TEST_CASE_ST(ut_setup, ut_teardown, 12667 test_PDCP_PROTO_uplane_decap_all), 12668 12669 TEST_CASE_ST(ut_setup, ut_teardown, 12670 test_PDCP_PROTO_SGL_in_place_32B), 12671 TEST_CASE_ST(ut_setup, ut_teardown, 12672 test_PDCP_PROTO_SGL_oop_32B_128B), 12673 TEST_CASE_ST(ut_setup, ut_teardown, 12674 test_PDCP_PROTO_SGL_oop_32B_40B), 12675 TEST_CASE_ST(ut_setup, ut_teardown, 12676 test_PDCP_PROTO_SGL_oop_128B_32B), 12677 #endif 12678 /** AES GCM Authenticated Encryption */ 12679 TEST_CASE_ST(ut_setup, ut_teardown, 12680 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 12681 TEST_CASE_ST(ut_setup, ut_teardown, 12682 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 12683 TEST_CASE_ST(ut_setup, ut_teardown, 12684 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 12685 TEST_CASE_ST(ut_setup, ut_teardown, 12686 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 12687 TEST_CASE_ST(ut_setup, ut_teardown, 12688 test_AES_GCM_authenticated_encryption_test_case_1), 12689 TEST_CASE_ST(ut_setup, ut_teardown, 12690 test_AES_GCM_authenticated_encryption_test_case_2), 12691 TEST_CASE_ST(ut_setup, ut_teardown, 12692 test_AES_GCM_authenticated_encryption_test_case_3), 12693 TEST_CASE_ST(ut_setup, ut_teardown, 12694 test_AES_GCM_authenticated_encryption_test_case_4), 12695 TEST_CASE_ST(ut_setup, ut_teardown, 12696 test_AES_GCM_authenticated_encryption_test_case_5), 12697 TEST_CASE_ST(ut_setup, ut_teardown, 12698 test_AES_GCM_authenticated_encryption_test_case_6), 12699 TEST_CASE_ST(ut_setup, ut_teardown, 12700 test_AES_GCM_authenticated_encryption_test_case_7), 12701 TEST_CASE_ST(ut_setup, ut_teardown, 12702 test_AES_GCM_authenticated_encryption_test_case_8), 12703 12704 /** AES GCM Authenticated Decryption */ 12705 TEST_CASE_ST(ut_setup, ut_teardown, 12706 test_AES_GCM_authenticated_decryption_test_case_1), 12707 TEST_CASE_ST(ut_setup, ut_teardown, 12708 test_AES_GCM_authenticated_decryption_test_case_2), 12709 TEST_CASE_ST(ut_setup, ut_teardown, 12710 test_AES_GCM_authenticated_decryption_test_case_3), 12711 TEST_CASE_ST(ut_setup, ut_teardown, 12712 test_AES_GCM_authenticated_decryption_test_case_4), 12713 TEST_CASE_ST(ut_setup, ut_teardown, 12714 test_AES_GCM_authenticated_decryption_test_case_5), 12715 TEST_CASE_ST(ut_setup, ut_teardown, 12716 test_AES_GCM_authenticated_decryption_test_case_6), 12717 TEST_CASE_ST(ut_setup, ut_teardown, 12718 test_AES_GCM_authenticated_decryption_test_case_7), 12719 TEST_CASE_ST(ut_setup, ut_teardown, 12720 test_AES_GCM_authenticated_decryption_test_case_8), 12721 12722 /** AES GCM Authenticated Encryption 192 bits key */ 12723 TEST_CASE_ST(ut_setup, ut_teardown, 12724 test_AES_GCM_auth_encryption_test_case_192_1), 12725 TEST_CASE_ST(ut_setup, ut_teardown, 12726 test_AES_GCM_auth_encryption_test_case_192_2), 12727 TEST_CASE_ST(ut_setup, ut_teardown, 12728 test_AES_GCM_auth_encryption_test_case_192_3), 12729 TEST_CASE_ST(ut_setup, ut_teardown, 12730 test_AES_GCM_auth_encryption_test_case_192_4), 12731 TEST_CASE_ST(ut_setup, ut_teardown, 12732 test_AES_GCM_auth_encryption_test_case_192_5), 12733 TEST_CASE_ST(ut_setup, ut_teardown, 12734 test_AES_GCM_auth_encryption_test_case_192_6), 12735 TEST_CASE_ST(ut_setup, ut_teardown, 12736 test_AES_GCM_auth_encryption_test_case_192_7), 12737 12738 /** AES GCM Authenticated Decryption 192 bits key */ 12739 TEST_CASE_ST(ut_setup, ut_teardown, 12740 test_AES_GCM_auth_decryption_test_case_192_1), 12741 TEST_CASE_ST(ut_setup, ut_teardown, 12742 test_AES_GCM_auth_decryption_test_case_192_2), 12743 TEST_CASE_ST(ut_setup, ut_teardown, 12744 test_AES_GCM_auth_decryption_test_case_192_3), 12745 TEST_CASE_ST(ut_setup, ut_teardown, 12746 test_AES_GCM_auth_decryption_test_case_192_4), 12747 TEST_CASE_ST(ut_setup, ut_teardown, 12748 test_AES_GCM_auth_decryption_test_case_192_5), 12749 TEST_CASE_ST(ut_setup, ut_teardown, 12750 test_AES_GCM_auth_decryption_test_case_192_6), 12751 TEST_CASE_ST(ut_setup, ut_teardown, 12752 test_AES_GCM_auth_decryption_test_case_192_7), 12753 12754 /** AES GCM Authenticated Encryption 256 bits key */ 12755 TEST_CASE_ST(ut_setup, ut_teardown, 12756 test_AES_GCM_auth_encryption_test_case_256_1), 12757 TEST_CASE_ST(ut_setup, ut_teardown, 12758 test_AES_GCM_auth_encryption_test_case_256_2), 12759 TEST_CASE_ST(ut_setup, ut_teardown, 12760 test_AES_GCM_auth_encryption_test_case_256_3), 12761 TEST_CASE_ST(ut_setup, ut_teardown, 12762 test_AES_GCM_auth_encryption_test_case_256_4), 12763 TEST_CASE_ST(ut_setup, ut_teardown, 12764 test_AES_GCM_auth_encryption_test_case_256_5), 12765 TEST_CASE_ST(ut_setup, ut_teardown, 12766 test_AES_GCM_auth_encryption_test_case_256_6), 12767 TEST_CASE_ST(ut_setup, ut_teardown, 12768 test_AES_GCM_auth_encryption_test_case_256_7), 12769 12770 /** AES GCM Authenticated Decryption 256 bits key */ 12771 TEST_CASE_ST(ut_setup, ut_teardown, 12772 test_AES_GCM_auth_decryption_test_case_256_1), 12773 TEST_CASE_ST(ut_setup, ut_teardown, 12774 test_AES_GCM_auth_decryption_test_case_256_2), 12775 TEST_CASE_ST(ut_setup, ut_teardown, 12776 test_AES_GCM_auth_decryption_test_case_256_3), 12777 TEST_CASE_ST(ut_setup, ut_teardown, 12778 test_AES_GCM_auth_decryption_test_case_256_4), 12779 TEST_CASE_ST(ut_setup, ut_teardown, 12780 test_AES_GCM_auth_decryption_test_case_256_5), 12781 TEST_CASE_ST(ut_setup, ut_teardown, 12782 test_AES_GCM_auth_decryption_test_case_256_6), 12783 TEST_CASE_ST(ut_setup, ut_teardown, 12784 test_AES_GCM_auth_decryption_test_case_256_7), 12785 12786 /** Out of place tests */ 12787 TEST_CASE_ST(ut_setup, ut_teardown, 12788 test_AES_GCM_authenticated_encryption_oop_test_case_1), 12789 TEST_CASE_ST(ut_setup, ut_teardown, 12790 test_AES_GCM_authenticated_decryption_oop_test_case_1), 12791 12792 /** SNOW 3G encrypt only (UEA2) */ 12793 TEST_CASE_ST(ut_setup, ut_teardown, 12794 test_snow3g_encryption_test_case_1), 12795 TEST_CASE_ST(ut_setup, ut_teardown, 12796 test_snow3g_encryption_test_case_2), 12797 TEST_CASE_ST(ut_setup, ut_teardown, 12798 test_snow3g_encryption_test_case_3), 12799 TEST_CASE_ST(ut_setup, ut_teardown, 12800 test_snow3g_encryption_test_case_4), 12801 TEST_CASE_ST(ut_setup, ut_teardown, 12802 test_snow3g_encryption_test_case_5), 12803 12804 TEST_CASE_ST(ut_setup, ut_teardown, 12805 test_snow3g_encryption_test_case_1_oop), 12806 TEST_CASE_ST(ut_setup, ut_teardown, 12807 test_snow3g_encryption_test_case_1_oop_sgl), 12808 TEST_CASE_ST(ut_setup, ut_teardown, 12809 test_snow3g_decryption_test_case_1_oop), 12810 12811 /** SNOW 3G decrypt only (UEA2) */ 12812 TEST_CASE_ST(ut_setup, ut_teardown, 12813 test_snow3g_decryption_test_case_1), 12814 TEST_CASE_ST(ut_setup, ut_teardown, 12815 test_snow3g_decryption_test_case_2), 12816 TEST_CASE_ST(ut_setup, ut_teardown, 12817 test_snow3g_decryption_test_case_3), 12818 TEST_CASE_ST(ut_setup, ut_teardown, 12819 test_snow3g_decryption_test_case_4), 12820 TEST_CASE_ST(ut_setup, ut_teardown, 12821 test_snow3g_decryption_test_case_5), 12822 12823 TEST_CASE_ST(ut_setup, ut_teardown, 12824 test_snow3g_hash_generate_test_case_1), 12825 TEST_CASE_ST(ut_setup, ut_teardown, 12826 test_snow3g_hash_generate_test_case_2), 12827 TEST_CASE_ST(ut_setup, ut_teardown, 12828 test_snow3g_hash_generate_test_case_3), 12829 TEST_CASE_ST(ut_setup, ut_teardown, 12830 test_snow3g_hash_verify_test_case_1), 12831 TEST_CASE_ST(ut_setup, ut_teardown, 12832 test_snow3g_hash_verify_test_case_2), 12833 TEST_CASE_ST(ut_setup, ut_teardown, 12834 test_snow3g_hash_verify_test_case_3), 12835 12836 /** ZUC encrypt only (EEA3) */ 12837 TEST_CASE_ST(ut_setup, ut_teardown, 12838 test_zuc_encryption_test_case_1), 12839 TEST_CASE_ST(ut_setup, ut_teardown, 12840 test_zuc_encryption_test_case_2), 12841 TEST_CASE_ST(ut_setup, ut_teardown, 12842 test_zuc_encryption_test_case_3), 12843 TEST_CASE_ST(ut_setup, ut_teardown, 12844 test_zuc_encryption_test_case_4), 12845 TEST_CASE_ST(ut_setup, ut_teardown, 12846 test_zuc_encryption_test_case_5), 12847 12848 /** ZUC authenticate (EIA3) */ 12849 TEST_CASE_ST(ut_setup, ut_teardown, 12850 test_zuc_hash_generate_test_case_6), 12851 TEST_CASE_ST(ut_setup, ut_teardown, 12852 test_zuc_hash_generate_test_case_7), 12853 TEST_CASE_ST(ut_setup, ut_teardown, 12854 test_zuc_hash_generate_test_case_8), 12855 12856 /** HMAC_MD5 Authentication */ 12857 TEST_CASE_ST(ut_setup, ut_teardown, 12858 test_MD5_HMAC_generate_case_1), 12859 TEST_CASE_ST(ut_setup, ut_teardown, 12860 test_MD5_HMAC_verify_case_1), 12861 TEST_CASE_ST(ut_setup, ut_teardown, 12862 test_MD5_HMAC_generate_case_2), 12863 TEST_CASE_ST(ut_setup, ut_teardown, 12864 test_MD5_HMAC_verify_case_2), 12865 12866 /** Negative tests */ 12867 TEST_CASE_ST(ut_setup, ut_teardown, 12868 test_AES_GCM_auth_encryption_fail_iv_corrupt), 12869 TEST_CASE_ST(ut_setup, ut_teardown, 12870 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 12871 TEST_CASE_ST(ut_setup, ut_teardown, 12872 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 12873 TEST_CASE_ST(ut_setup, ut_teardown, 12874 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 12875 TEST_CASE_ST(ut_setup, ut_teardown, 12876 test_AES_GCM_auth_encryption_fail_aad_corrupt), 12877 TEST_CASE_ST(ut_setup, ut_teardown, 12878 test_AES_GCM_auth_encryption_fail_tag_corrupt), 12879 TEST_CASE_ST(ut_setup, ut_teardown, 12880 test_AES_GCM_auth_decryption_fail_iv_corrupt), 12881 TEST_CASE_ST(ut_setup, ut_teardown, 12882 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 12883 TEST_CASE_ST(ut_setup, ut_teardown, 12884 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 12885 TEST_CASE_ST(ut_setup, ut_teardown, 12886 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 12887 TEST_CASE_ST(ut_setup, ut_teardown, 12888 test_AES_GCM_auth_decryption_fail_aad_corrupt), 12889 TEST_CASE_ST(ut_setup, ut_teardown, 12890 test_AES_GCM_auth_decryption_fail_tag_corrupt), 12891 TEST_CASE_ST(ut_setup, ut_teardown, 12892 authentication_verify_HMAC_SHA1_fail_data_corrupt), 12893 TEST_CASE_ST(ut_setup, ut_teardown, 12894 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 12895 TEST_CASE_ST(ut_setup, ut_teardown, 12896 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12897 TEST_CASE_ST(ut_setup, ut_teardown, 12898 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12899 12900 /* ESN Testcase */ 12901 TEST_CASE_ST(ut_setup, ut_teardown, 12902 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 12903 12904 TEST_CASE_ST(ut_setup, ut_teardown, 12905 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 12906 12907 TEST_CASES_END() /**< NULL terminate unit test array */ 12908 } 12909 }; 12910 12911 static struct unit_test_suite cryptodev_armv8_testsuite = { 12912 .suite_name = "Crypto Device ARMv8 Unit Test Suite", 12913 .setup = testsuite_setup, 12914 .teardown = testsuite_teardown, 12915 .unit_test_cases = { 12916 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12917 12918 /** Negative tests */ 12919 TEST_CASE_ST(ut_setup, ut_teardown, 12920 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12921 TEST_CASE_ST(ut_setup, ut_teardown, 12922 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12923 12924 TEST_CASES_END() /**< NULL terminate unit test array */ 12925 } 12926 }; 12927 12928 static struct unit_test_suite cryptodev_mrvl_testsuite = { 12929 .suite_name = "Crypto Device Marvell Component Test Suite", 12930 .setup = testsuite_setup, 12931 .teardown = testsuite_teardown, 12932 .unit_test_cases = { 12933 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 12934 TEST_CASE_ST(ut_setup, ut_teardown, 12935 test_multi_session_random_usage), 12936 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12937 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12938 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12939 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12940 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12941 12942 /** Negative tests */ 12943 TEST_CASE_ST(ut_setup, ut_teardown, 12944 authentication_verify_HMAC_SHA1_fail_data_corrupt), 12945 TEST_CASE_ST(ut_setup, ut_teardown, 12946 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 12947 TEST_CASE_ST(ut_setup, ut_teardown, 12948 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12949 TEST_CASE_ST(ut_setup, ut_teardown, 12950 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12951 12952 TEST_CASES_END() /**< NULL terminate unit test array */ 12953 } 12954 }; 12955 12956 static struct unit_test_suite cryptodev_ccp_testsuite = { 12957 .suite_name = "Crypto Device CCP Unit Test Suite", 12958 .setup = testsuite_setup, 12959 .teardown = testsuite_teardown, 12960 .unit_test_cases = { 12961 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 12962 TEST_CASE_ST(ut_setup, ut_teardown, 12963 test_multi_session_random_usage), 12964 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12965 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12966 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12967 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12968 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12969 12970 /** Negative tests */ 12971 TEST_CASE_ST(ut_setup, ut_teardown, 12972 authentication_verify_HMAC_SHA1_fail_data_corrupt), 12973 TEST_CASE_ST(ut_setup, ut_teardown, 12974 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 12975 TEST_CASE_ST(ut_setup, ut_teardown, 12976 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 12977 TEST_CASE_ST(ut_setup, ut_teardown, 12978 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 12979 12980 TEST_CASES_END() /**< NULL terminate unit test array */ 12981 } 12982 }; 12983 12984 static struct unit_test_suite cryptodev_octeontx_testsuite = { 12985 .suite_name = "Crypto Device OCTEONTX Unit Test Suite", 12986 .setup = testsuite_setup, 12987 .teardown = testsuite_teardown, 12988 .unit_test_cases = { 12989 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12990 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12991 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12992 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12993 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12994 12995 /** AES GCM Authenticated Encryption */ 12996 TEST_CASE_ST(ut_setup, ut_teardown, 12997 test_AES_GCM_authenticated_encryption_test_case_1), 12998 TEST_CASE_ST(ut_setup, ut_teardown, 12999 test_AES_GCM_authenticated_encryption_test_case_2), 13000 TEST_CASE_ST(ut_setup, ut_teardown, 13001 test_AES_GCM_authenticated_encryption_test_case_3), 13002 TEST_CASE_ST(ut_setup, ut_teardown, 13003 test_AES_GCM_authenticated_encryption_test_case_4), 13004 TEST_CASE_ST(ut_setup, ut_teardown, 13005 test_AES_GCM_authenticated_encryption_test_case_5), 13006 TEST_CASE_ST(ut_setup, ut_teardown, 13007 test_AES_GCM_authenticated_encryption_test_case_6), 13008 TEST_CASE_ST(ut_setup, ut_teardown, 13009 test_AES_GCM_authenticated_encryption_test_case_7), 13010 13011 /** AES GCM Authenticated Decryption */ 13012 TEST_CASE_ST(ut_setup, ut_teardown, 13013 test_AES_GCM_authenticated_decryption_test_case_1), 13014 TEST_CASE_ST(ut_setup, ut_teardown, 13015 test_AES_GCM_authenticated_decryption_test_case_2), 13016 TEST_CASE_ST(ut_setup, ut_teardown, 13017 test_AES_GCM_authenticated_decryption_test_case_3), 13018 TEST_CASE_ST(ut_setup, ut_teardown, 13019 test_AES_GCM_authenticated_decryption_test_case_4), 13020 TEST_CASE_ST(ut_setup, ut_teardown, 13021 test_AES_GCM_authenticated_decryption_test_case_5), 13022 TEST_CASE_ST(ut_setup, ut_teardown, 13023 test_AES_GCM_authenticated_decryption_test_case_6), 13024 TEST_CASE_ST(ut_setup, ut_teardown, 13025 test_AES_GCM_authenticated_decryption_test_case_7), 13026 /** AES GMAC Authentication */ 13027 TEST_CASE_ST(ut_setup, ut_teardown, 13028 test_AES_GMAC_authentication_test_case_1), 13029 TEST_CASE_ST(ut_setup, ut_teardown, 13030 test_AES_GMAC_authentication_verify_test_case_1), 13031 TEST_CASE_ST(ut_setup, ut_teardown, 13032 test_AES_GMAC_authentication_test_case_2), 13033 TEST_CASE_ST(ut_setup, ut_teardown, 13034 test_AES_GMAC_authentication_verify_test_case_2), 13035 TEST_CASE_ST(ut_setup, ut_teardown, 13036 test_AES_GMAC_authentication_test_case_3), 13037 TEST_CASE_ST(ut_setup, ut_teardown, 13038 test_AES_GMAC_authentication_verify_test_case_3), 13039 13040 /** SNOW 3G encrypt only (UEA2) */ 13041 TEST_CASE_ST(ut_setup, ut_teardown, 13042 test_snow3g_encryption_test_case_1), 13043 TEST_CASE_ST(ut_setup, ut_teardown, 13044 test_snow3g_encryption_test_case_2), 13045 TEST_CASE_ST(ut_setup, ut_teardown, 13046 test_snow3g_encryption_test_case_3), 13047 TEST_CASE_ST(ut_setup, ut_teardown, 13048 test_snow3g_encryption_test_case_4), 13049 TEST_CASE_ST(ut_setup, ut_teardown, 13050 test_snow3g_encryption_test_case_5), 13051 13052 TEST_CASE_ST(ut_setup, ut_teardown, 13053 test_snow3g_encryption_test_case_1_oop), 13054 TEST_CASE_ST(ut_setup, ut_teardown, 13055 test_snow3g_decryption_test_case_1_oop), 13056 TEST_CASE_ST(ut_setup, ut_teardown, 13057 test_snow3g_encryption_test_case_1_oop_sgl), 13058 13059 /** SNOW 3G decrypt only (UEA2) */ 13060 TEST_CASE_ST(ut_setup, ut_teardown, 13061 test_snow3g_decryption_test_case_1), 13062 TEST_CASE_ST(ut_setup, ut_teardown, 13063 test_snow3g_decryption_test_case_2), 13064 TEST_CASE_ST(ut_setup, ut_teardown, 13065 test_snow3g_decryption_test_case_3), 13066 TEST_CASE_ST(ut_setup, ut_teardown, 13067 test_snow3g_decryption_test_case_4), 13068 TEST_CASE_ST(ut_setup, ut_teardown, 13069 test_snow3g_decryption_test_case_5), 13070 13071 TEST_CASE_ST(ut_setup, ut_teardown, 13072 test_snow3g_hash_generate_test_case_1), 13073 TEST_CASE_ST(ut_setup, ut_teardown, 13074 test_snow3g_hash_generate_test_case_2), 13075 TEST_CASE_ST(ut_setup, ut_teardown, 13076 test_snow3g_hash_generate_test_case_3), 13077 TEST_CASE_ST(ut_setup, ut_teardown, 13078 test_snow3g_hash_verify_test_case_1), 13079 TEST_CASE_ST(ut_setup, ut_teardown, 13080 test_snow3g_hash_verify_test_case_2), 13081 TEST_CASE_ST(ut_setup, ut_teardown, 13082 test_snow3g_hash_verify_test_case_3), 13083 13084 /** ZUC encrypt only (EEA3) */ 13085 TEST_CASE_ST(ut_setup, ut_teardown, 13086 test_zuc_encryption_test_case_1), 13087 TEST_CASE_ST(ut_setup, ut_teardown, 13088 test_zuc_encryption_test_case_2), 13089 TEST_CASE_ST(ut_setup, ut_teardown, 13090 test_zuc_encryption_test_case_3), 13091 TEST_CASE_ST(ut_setup, ut_teardown, 13092 test_zuc_encryption_test_case_4), 13093 TEST_CASE_ST(ut_setup, ut_teardown, 13094 test_zuc_encryption_test_case_5), 13095 TEST_CASE_ST(ut_setup, ut_teardown, 13096 test_zuc_hash_generate_test_case_1), 13097 TEST_CASE_ST(ut_setup, ut_teardown, 13098 test_zuc_hash_generate_test_case_2), 13099 TEST_CASE_ST(ut_setup, ut_teardown, 13100 test_zuc_hash_generate_test_case_3), 13101 TEST_CASE_ST(ut_setup, ut_teardown, 13102 test_zuc_hash_generate_test_case_4), 13103 TEST_CASE_ST(ut_setup, ut_teardown, 13104 test_zuc_hash_generate_test_case_5), 13105 TEST_CASE_ST(ut_setup, ut_teardown, 13106 test_zuc_encryption_test_case_6_sgl), 13107 13108 /** KASUMI encrypt only (UEA1) */ 13109 TEST_CASE_ST(ut_setup, ut_teardown, 13110 test_kasumi_encryption_test_case_1), 13111 TEST_CASE_ST(ut_setup, ut_teardown, 13112 test_kasumi_encryption_test_case_2), 13113 TEST_CASE_ST(ut_setup, ut_teardown, 13114 test_kasumi_encryption_test_case_3), 13115 TEST_CASE_ST(ut_setup, ut_teardown, 13116 test_kasumi_encryption_test_case_4), 13117 TEST_CASE_ST(ut_setup, ut_teardown, 13118 test_kasumi_encryption_test_case_5), 13119 TEST_CASE_ST(ut_setup, ut_teardown, 13120 test_kasumi_encryption_test_case_1_sgl), 13121 TEST_CASE_ST(ut_setup, ut_teardown, 13122 test_kasumi_encryption_test_case_1_oop_sgl), 13123 /** KASUMI decrypt only (UEA1) */ 13124 TEST_CASE_ST(ut_setup, ut_teardown, 13125 test_kasumi_decryption_test_case_1), 13126 TEST_CASE_ST(ut_setup, ut_teardown, 13127 test_kasumi_decryption_test_case_2), 13128 TEST_CASE_ST(ut_setup, ut_teardown, 13129 test_kasumi_decryption_test_case_3), 13130 TEST_CASE_ST(ut_setup, ut_teardown, 13131 test_kasumi_decryption_test_case_4), 13132 TEST_CASE_ST(ut_setup, ut_teardown, 13133 test_kasumi_decryption_test_case_5), 13134 13135 TEST_CASE_ST(ut_setup, ut_teardown, 13136 test_kasumi_encryption_test_case_1_oop), 13137 TEST_CASE_ST(ut_setup, ut_teardown, 13138 test_kasumi_decryption_test_case_1_oop), 13139 13140 /** KASUMI hash only (UIA1) */ 13141 TEST_CASE_ST(ut_setup, ut_teardown, 13142 test_kasumi_hash_generate_test_case_1), 13143 TEST_CASE_ST(ut_setup, ut_teardown, 13144 test_kasumi_hash_generate_test_case_2), 13145 TEST_CASE_ST(ut_setup, ut_teardown, 13146 test_kasumi_hash_generate_test_case_3), 13147 TEST_CASE_ST(ut_setup, ut_teardown, 13148 test_kasumi_hash_generate_test_case_4), 13149 TEST_CASE_ST(ut_setup, ut_teardown, 13150 test_kasumi_hash_generate_test_case_5), 13151 TEST_CASE_ST(ut_setup, ut_teardown, 13152 test_kasumi_hash_generate_test_case_6), 13153 TEST_CASE_ST(ut_setup, ut_teardown, 13154 test_kasumi_hash_verify_test_case_1), 13155 TEST_CASE_ST(ut_setup, ut_teardown, 13156 test_kasumi_hash_verify_test_case_2), 13157 TEST_CASE_ST(ut_setup, ut_teardown, 13158 test_kasumi_hash_verify_test_case_3), 13159 TEST_CASE_ST(ut_setup, ut_teardown, 13160 test_kasumi_hash_verify_test_case_4), 13161 TEST_CASE_ST(ut_setup, ut_teardown, 13162 test_kasumi_hash_verify_test_case_5), 13163 13164 /** NULL tests */ 13165 TEST_CASE_ST(ut_setup, ut_teardown, 13166 test_null_cipher_only_operation), 13167 TEST_CASE_ST(ut_setup, ut_teardown, 13168 test_null_auth_only_operation), 13169 TEST_CASE_ST(ut_setup, ut_teardown, 13170 test_null_cipher_auth_operation), 13171 TEST_CASE_ST(ut_setup, ut_teardown, 13172 test_null_auth_cipher_operation), 13173 13174 /** Negative tests */ 13175 TEST_CASE_ST(ut_setup, ut_teardown, 13176 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13177 TEST_CASE_ST(ut_setup, ut_teardown, 13178 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13179 TEST_CASE_ST(ut_setup, ut_teardown, 13180 authentication_verify_AES128_GMAC_fail_data_corrupt), 13181 TEST_CASE_ST(ut_setup, ut_teardown, 13182 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13183 TEST_CASE_ST(ut_setup, ut_teardown, 13184 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13185 TEST_CASE_ST(ut_setup, ut_teardown, 13186 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13187 TEST_CASES_END() /**< NULL terminate unit test array */ 13188 } 13189 }; 13190 13191 static struct unit_test_suite cryptodev_nitrox_testsuite = { 13192 .suite_name = "Crypto NITROX Unit Test Suite", 13193 .setup = testsuite_setup, 13194 .teardown = testsuite_teardown, 13195 .unit_test_cases = { 13196 TEST_CASE_ST(ut_setup, ut_teardown, 13197 test_device_configure_invalid_dev_id), 13198 TEST_CASE_ST(ut_setup, ut_teardown, 13199 test_device_configure_invalid_queue_pair_ids), 13200 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13201 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13202 13203 TEST_CASES_END() /**< NULL terminate unit test array */ 13204 } 13205 }; 13206 13207 static struct unit_test_suite cryptodev_octeontx2_testsuite = { 13208 .suite_name = "Crypto Device OCTEON TX2 Unit Test Suite", 13209 .setup = testsuite_setup, 13210 .teardown = testsuite_teardown, 13211 .unit_test_cases = { 13212 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13213 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13214 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13215 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13216 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13217 13218 /** AES GCM Authenticated Encryption */ 13219 TEST_CASE_ST(ut_setup, ut_teardown, 13220 test_AES_GCM_authenticated_encryption_test_case_1), 13221 TEST_CASE_ST(ut_setup, ut_teardown, 13222 test_AES_GCM_authenticated_encryption_test_case_2), 13223 TEST_CASE_ST(ut_setup, ut_teardown, 13224 test_AES_GCM_authenticated_encryption_test_case_3), 13225 TEST_CASE_ST(ut_setup, ut_teardown, 13226 test_AES_GCM_authenticated_encryption_test_case_4), 13227 TEST_CASE_ST(ut_setup, ut_teardown, 13228 test_AES_GCM_authenticated_encryption_test_case_5), 13229 TEST_CASE_ST(ut_setup, ut_teardown, 13230 test_AES_GCM_authenticated_encryption_test_case_6), 13231 TEST_CASE_ST(ut_setup, ut_teardown, 13232 test_AES_GCM_authenticated_encryption_test_case_7), 13233 13234 /** AES GCM Authenticated Decryption */ 13235 TEST_CASE_ST(ut_setup, ut_teardown, 13236 test_AES_GCM_authenticated_decryption_test_case_1), 13237 TEST_CASE_ST(ut_setup, ut_teardown, 13238 test_AES_GCM_authenticated_decryption_test_case_2), 13239 TEST_CASE_ST(ut_setup, ut_teardown, 13240 test_AES_GCM_authenticated_decryption_test_case_3), 13241 TEST_CASE_ST(ut_setup, ut_teardown, 13242 test_AES_GCM_authenticated_decryption_test_case_4), 13243 TEST_CASE_ST(ut_setup, ut_teardown, 13244 test_AES_GCM_authenticated_decryption_test_case_5), 13245 TEST_CASE_ST(ut_setup, ut_teardown, 13246 test_AES_GCM_authenticated_decryption_test_case_6), 13247 TEST_CASE_ST(ut_setup, ut_teardown, 13248 test_AES_GCM_authenticated_decryption_test_case_7), 13249 /** AES GMAC Authentication */ 13250 TEST_CASE_ST(ut_setup, ut_teardown, 13251 test_AES_GMAC_authentication_test_case_1), 13252 TEST_CASE_ST(ut_setup, ut_teardown, 13253 test_AES_GMAC_authentication_verify_test_case_1), 13254 TEST_CASE_ST(ut_setup, ut_teardown, 13255 test_AES_GMAC_authentication_test_case_2), 13256 TEST_CASE_ST(ut_setup, ut_teardown, 13257 test_AES_GMAC_authentication_verify_test_case_2), 13258 TEST_CASE_ST(ut_setup, ut_teardown, 13259 test_AES_GMAC_authentication_test_case_3), 13260 TEST_CASE_ST(ut_setup, ut_teardown, 13261 test_AES_GMAC_authentication_verify_test_case_3), 13262 13263 /** SNOW 3G encrypt only (UEA2) */ 13264 TEST_CASE_ST(ut_setup, ut_teardown, 13265 test_snow3g_encryption_test_case_1), 13266 TEST_CASE_ST(ut_setup, ut_teardown, 13267 test_snow3g_encryption_test_case_2), 13268 TEST_CASE_ST(ut_setup, ut_teardown, 13269 test_snow3g_encryption_test_case_3), 13270 TEST_CASE_ST(ut_setup, ut_teardown, 13271 test_snow3g_encryption_test_case_4), 13272 TEST_CASE_ST(ut_setup, ut_teardown, 13273 test_snow3g_encryption_test_case_5), 13274 13275 TEST_CASE_ST(ut_setup, ut_teardown, 13276 test_snow3g_encryption_test_case_1_oop), 13277 TEST_CASE_ST(ut_setup, ut_teardown, 13278 test_snow3g_decryption_test_case_1_oop), 13279 TEST_CASE_ST(ut_setup, ut_teardown, 13280 test_snow3g_encryption_test_case_1_oop_sgl), 13281 13282 /** SNOW 3G decrypt only (UEA2) */ 13283 TEST_CASE_ST(ut_setup, ut_teardown, 13284 test_snow3g_decryption_test_case_1), 13285 TEST_CASE_ST(ut_setup, ut_teardown, 13286 test_snow3g_decryption_test_case_2), 13287 TEST_CASE_ST(ut_setup, ut_teardown, 13288 test_snow3g_decryption_test_case_3), 13289 TEST_CASE_ST(ut_setup, ut_teardown, 13290 test_snow3g_decryption_test_case_4), 13291 TEST_CASE_ST(ut_setup, ut_teardown, 13292 test_snow3g_decryption_test_case_5), 13293 13294 TEST_CASE_ST(ut_setup, ut_teardown, 13295 test_snow3g_hash_generate_test_case_1), 13296 TEST_CASE_ST(ut_setup, ut_teardown, 13297 test_snow3g_hash_generate_test_case_2), 13298 TEST_CASE_ST(ut_setup, ut_teardown, 13299 test_snow3g_hash_generate_test_case_3), 13300 TEST_CASE_ST(ut_setup, ut_teardown, 13301 test_snow3g_hash_verify_test_case_1), 13302 TEST_CASE_ST(ut_setup, ut_teardown, 13303 test_snow3g_hash_verify_test_case_2), 13304 TEST_CASE_ST(ut_setup, ut_teardown, 13305 test_snow3g_hash_verify_test_case_3), 13306 13307 /** ZUC encrypt only (EEA3) */ 13308 TEST_CASE_ST(ut_setup, ut_teardown, 13309 test_zuc_encryption_test_case_1), 13310 TEST_CASE_ST(ut_setup, ut_teardown, 13311 test_zuc_encryption_test_case_2), 13312 TEST_CASE_ST(ut_setup, ut_teardown, 13313 test_zuc_encryption_test_case_3), 13314 TEST_CASE_ST(ut_setup, ut_teardown, 13315 test_zuc_encryption_test_case_4), 13316 TEST_CASE_ST(ut_setup, ut_teardown, 13317 test_zuc_encryption_test_case_5), 13318 TEST_CASE_ST(ut_setup, ut_teardown, 13319 test_zuc_hash_generate_test_case_1), 13320 TEST_CASE_ST(ut_setup, ut_teardown, 13321 test_zuc_hash_generate_test_case_2), 13322 TEST_CASE_ST(ut_setup, ut_teardown, 13323 test_zuc_hash_generate_test_case_3), 13324 TEST_CASE_ST(ut_setup, ut_teardown, 13325 test_zuc_hash_generate_test_case_4), 13326 TEST_CASE_ST(ut_setup, ut_teardown, 13327 test_zuc_hash_generate_test_case_5), 13328 TEST_CASE_ST(ut_setup, ut_teardown, 13329 test_zuc_encryption_test_case_6_sgl), 13330 13331 /** KASUMI encrypt only (UEA1) */ 13332 TEST_CASE_ST(ut_setup, ut_teardown, 13333 test_kasumi_encryption_test_case_1), 13334 TEST_CASE_ST(ut_setup, ut_teardown, 13335 test_kasumi_encryption_test_case_2), 13336 TEST_CASE_ST(ut_setup, ut_teardown, 13337 test_kasumi_encryption_test_case_3), 13338 TEST_CASE_ST(ut_setup, ut_teardown, 13339 test_kasumi_encryption_test_case_4), 13340 TEST_CASE_ST(ut_setup, ut_teardown, 13341 test_kasumi_encryption_test_case_5), 13342 TEST_CASE_ST(ut_setup, ut_teardown, 13343 test_kasumi_encryption_test_case_1_sgl), 13344 TEST_CASE_ST(ut_setup, ut_teardown, 13345 test_kasumi_encryption_test_case_1_oop_sgl), 13346 /** KASUMI decrypt only (UEA1) */ 13347 TEST_CASE_ST(ut_setup, ut_teardown, 13348 test_kasumi_decryption_test_case_1), 13349 TEST_CASE_ST(ut_setup, ut_teardown, 13350 test_kasumi_decryption_test_case_2), 13351 TEST_CASE_ST(ut_setup, ut_teardown, 13352 test_kasumi_decryption_test_case_3), 13353 TEST_CASE_ST(ut_setup, ut_teardown, 13354 test_kasumi_decryption_test_case_4), 13355 TEST_CASE_ST(ut_setup, ut_teardown, 13356 test_kasumi_decryption_test_case_5), 13357 13358 TEST_CASE_ST(ut_setup, ut_teardown, 13359 test_kasumi_encryption_test_case_1_oop), 13360 TEST_CASE_ST(ut_setup, ut_teardown, 13361 test_kasumi_decryption_test_case_1_oop), 13362 13363 /** KASUMI hash only (UIA1) */ 13364 TEST_CASE_ST(ut_setup, ut_teardown, 13365 test_kasumi_hash_generate_test_case_1), 13366 TEST_CASE_ST(ut_setup, ut_teardown, 13367 test_kasumi_hash_generate_test_case_2), 13368 TEST_CASE_ST(ut_setup, ut_teardown, 13369 test_kasumi_hash_generate_test_case_3), 13370 TEST_CASE_ST(ut_setup, ut_teardown, 13371 test_kasumi_hash_generate_test_case_4), 13372 TEST_CASE_ST(ut_setup, ut_teardown, 13373 test_kasumi_hash_generate_test_case_5), 13374 TEST_CASE_ST(ut_setup, ut_teardown, 13375 test_kasumi_hash_generate_test_case_6), 13376 TEST_CASE_ST(ut_setup, ut_teardown, 13377 test_kasumi_hash_verify_test_case_1), 13378 TEST_CASE_ST(ut_setup, ut_teardown, 13379 test_kasumi_hash_verify_test_case_2), 13380 TEST_CASE_ST(ut_setup, ut_teardown, 13381 test_kasumi_hash_verify_test_case_3), 13382 TEST_CASE_ST(ut_setup, ut_teardown, 13383 test_kasumi_hash_verify_test_case_4), 13384 TEST_CASE_ST(ut_setup, ut_teardown, 13385 test_kasumi_hash_verify_test_case_5), 13386 13387 /** NULL tests */ 13388 TEST_CASE_ST(ut_setup, ut_teardown, 13389 test_null_cipher_only_operation), 13390 TEST_CASE_ST(ut_setup, ut_teardown, 13391 test_null_auth_only_operation), 13392 TEST_CASE_ST(ut_setup, ut_teardown, 13393 test_null_cipher_auth_operation), 13394 TEST_CASE_ST(ut_setup, ut_teardown, 13395 test_null_auth_cipher_operation), 13396 13397 /** Negative tests */ 13398 TEST_CASE_ST(ut_setup, ut_teardown, 13399 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13400 TEST_CASE_ST(ut_setup, ut_teardown, 13401 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13402 TEST_CASE_ST(ut_setup, ut_teardown, 13403 authentication_verify_AES128_GMAC_fail_data_corrupt), 13404 TEST_CASE_ST(ut_setup, ut_teardown, 13405 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13406 TEST_CASE_ST(ut_setup, ut_teardown, 13407 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13408 TEST_CASE_ST(ut_setup, ut_teardown, 13409 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13410 TEST_CASES_END() /**< NULL terminate unit test array */ 13411 } 13412 }; 13413 13414 static int 13415 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 13416 { 13417 gbl_driver_id = rte_cryptodev_driver_id_get( 13418 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 13419 13420 if (gbl_driver_id == -1) { 13421 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both " 13422 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM " 13423 "are enabled in config file to run this testsuite.\n"); 13424 return TEST_SKIPPED; 13425 } 13426 13427 return unit_test_suite_runner(&cryptodev_testsuite); 13428 } 13429 13430 static int 13431 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/) 13432 { 13433 gbl_driver_id = rte_cryptodev_driver_id_get( 13434 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 13435 13436 if (gbl_driver_id == -1) { 13437 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if " 13438 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled " 13439 "in config file to run this testsuite.\n"); 13440 return TEST_FAILED; 13441 } 13442 13443 return unit_test_suite_runner(&cryptodev_virtio_testsuite); 13444 } 13445 13446 static int 13447 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 13448 { 13449 gbl_driver_id = rte_cryptodev_driver_id_get( 13450 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13451 13452 if (gbl_driver_id == -1) { 13453 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if " 13454 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled " 13455 "in config file to run this testsuite.\n"); 13456 return TEST_SKIPPED; 13457 } 13458 13459 return unit_test_suite_runner(&cryptodev_testsuite); 13460 } 13461 13462 static int 13463 test_cryptodev_cpu_aesni_mb(void) 13464 { 13465 int32_t rc; 13466 enum rte_security_session_action_type at; 13467 13468 gbl_driver_id = rte_cryptodev_driver_id_get( 13469 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13470 13471 if (gbl_driver_id == -1) { 13472 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if " 13473 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled " 13474 "in config file to run this testsuite.\n"); 13475 return TEST_SKIPPED; 13476 } 13477 13478 at = gbl_action_type; 13479 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 13480 rc = unit_test_suite_runner(&cryptodev_testsuite); 13481 gbl_action_type = at; 13482 return rc; 13483 } 13484 13485 static int 13486 test_cryptodev_openssl(void) 13487 { 13488 gbl_driver_id = rte_cryptodev_driver_id_get( 13489 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 13490 13491 if (gbl_driver_id == -1) { 13492 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if " 13493 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled " 13494 "in config file to run this testsuite.\n"); 13495 return TEST_SKIPPED; 13496 } 13497 13498 return unit_test_suite_runner(&cryptodev_testsuite); 13499 } 13500 13501 static int 13502 test_cryptodev_aesni_gcm(void) 13503 { 13504 gbl_driver_id = rte_cryptodev_driver_id_get( 13505 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 13506 13507 if (gbl_driver_id == -1) { 13508 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if " 13509 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled " 13510 "in config file to run this testsuite.\n"); 13511 return TEST_SKIPPED; 13512 } 13513 13514 return unit_test_suite_runner(&cryptodev_testsuite); 13515 } 13516 13517 static int 13518 test_cryptodev_cpu_aesni_gcm(void) 13519 { 13520 int32_t rc; 13521 enum rte_security_session_action_type at; 13522 13523 gbl_driver_id = rte_cryptodev_driver_id_get( 13524 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 13525 13526 if (gbl_driver_id == -1) { 13527 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if " 13528 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled " 13529 "in config file to run this testsuite.\n"); 13530 return TEST_SKIPPED; 13531 } 13532 13533 at = gbl_action_type; 13534 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 13535 rc = unit_test_suite_runner(&cryptodev_testsuite); 13536 gbl_action_type = at; 13537 return rc; 13538 } 13539 13540 static int 13541 test_cryptodev_null(void) 13542 { 13543 gbl_driver_id = rte_cryptodev_driver_id_get( 13544 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 13545 13546 if (gbl_driver_id == -1) { 13547 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if " 13548 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled " 13549 "in config file to run this testsuite.\n"); 13550 return TEST_SKIPPED; 13551 } 13552 13553 return unit_test_suite_runner(&cryptodev_testsuite); 13554 } 13555 13556 static int 13557 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 13558 { 13559 gbl_driver_id = rte_cryptodev_driver_id_get( 13560 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 13561 13562 if (gbl_driver_id == -1) { 13563 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if " 13564 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled " 13565 "in config file to run this testsuite.\n"); 13566 return TEST_SKIPPED; 13567 } 13568 13569 return unit_test_suite_runner(&cryptodev_testsuite); 13570 } 13571 13572 static int 13573 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 13574 { 13575 gbl_driver_id = rte_cryptodev_driver_id_get( 13576 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 13577 13578 if (gbl_driver_id == -1) { 13579 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if " 13580 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled " 13581 "in config file to run this testsuite.\n"); 13582 return TEST_SKIPPED; 13583 } 13584 13585 return unit_test_suite_runner(&cryptodev_testsuite); 13586 } 13587 13588 static int 13589 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 13590 { 13591 gbl_driver_id = rte_cryptodev_driver_id_get( 13592 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 13593 13594 if (gbl_driver_id == -1) { 13595 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if " 13596 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled " 13597 "in config file to run this testsuite.\n"); 13598 return TEST_SKIPPED; 13599 } 13600 13601 return unit_test_suite_runner(&cryptodev_testsuite); 13602 } 13603 13604 static int 13605 test_cryptodev_armv8(void) 13606 { 13607 gbl_driver_id = rte_cryptodev_driver_id_get( 13608 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 13609 13610 if (gbl_driver_id == -1) { 13611 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if " 13612 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled " 13613 "in config file to run this testsuite.\n"); 13614 return TEST_SKIPPED; 13615 } 13616 13617 return unit_test_suite_runner(&cryptodev_armv8_testsuite); 13618 } 13619 13620 static int 13621 test_cryptodev_mrvl(void) 13622 { 13623 gbl_driver_id = rte_cryptodev_driver_id_get( 13624 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 13625 13626 if (gbl_driver_id == -1) { 13627 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if " 13628 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled " 13629 "in config file to run this testsuite.\n"); 13630 return TEST_SKIPPED; 13631 } 13632 13633 return unit_test_suite_runner(&cryptodev_mrvl_testsuite); 13634 } 13635 13636 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER 13637 13638 static int 13639 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 13640 { 13641 gbl_driver_id = rte_cryptodev_driver_id_get( 13642 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 13643 13644 if (gbl_driver_id == -1) { 13645 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if " 13646 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled " 13647 "in config file to run this testsuite.\n"); 13648 return TEST_SKIPPED; 13649 } 13650 13651 if (rte_cryptodev_driver_id_get( 13652 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 13653 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be" 13654 " enabled in config file to run this testsuite.\n"); 13655 return TEST_SKIPPED; 13656 } 13657 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 13658 } 13659 13660 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 13661 13662 #endif 13663 13664 static int 13665 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/) 13666 { 13667 gbl_driver_id = rte_cryptodev_driver_id_get( 13668 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 13669 13670 if (gbl_driver_id == -1) { 13671 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if " 13672 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled " 13673 "in config file to run this testsuite.\n"); 13674 return TEST_SKIPPED; 13675 } 13676 13677 return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite); 13678 } 13679 13680 static int 13681 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/) 13682 { 13683 gbl_driver_id = rte_cryptodev_driver_id_get( 13684 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 13685 13686 if (gbl_driver_id == -1) { 13687 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if " 13688 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled " 13689 "in config file to run this testsuite.\n"); 13690 return TEST_SKIPPED; 13691 } 13692 13693 return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite); 13694 } 13695 13696 static int 13697 test_cryptodev_ccp(void) 13698 { 13699 gbl_driver_id = rte_cryptodev_driver_id_get( 13700 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 13701 13702 if (gbl_driver_id == -1) { 13703 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if " 13704 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled " 13705 "in config file to run this testsuite.\n"); 13706 return TEST_FAILED; 13707 } 13708 13709 return unit_test_suite_runner(&cryptodev_ccp_testsuite); 13710 } 13711 13712 static int 13713 test_cryptodev_octeontx(void) 13714 { 13715 gbl_driver_id = rte_cryptodev_driver_id_get( 13716 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 13717 if (gbl_driver_id == -1) { 13718 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if " 13719 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is " 13720 "enabled in config file to run this " 13721 "testsuite.\n"); 13722 return TEST_FAILED; 13723 } 13724 return unit_test_suite_runner(&cryptodev_octeontx_testsuite); 13725 } 13726 13727 static int 13728 test_cryptodev_octeontx2(void) 13729 { 13730 gbl_driver_id = rte_cryptodev_driver_id_get( 13731 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 13732 if (gbl_driver_id == -1) { 13733 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded. Check if " 13734 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is " 13735 "enabled in config file to run this " 13736 "testsuite.\n"); 13737 return TEST_FAILED; 13738 } 13739 return unit_test_suite_runner(&cryptodev_octeontx2_testsuite); 13740 } 13741 13742 static int 13743 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/) 13744 { 13745 gbl_driver_id = rte_cryptodev_driver_id_get( 13746 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 13747 13748 if (gbl_driver_id == -1) { 13749 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded. Check if " 13750 "CONFIG_RTE_LIBRTE_PMD_CAAM_JR is enabled " 13751 "in config file to run this testsuite.\n"); 13752 return TEST_FAILED; 13753 } 13754 13755 return unit_test_suite_runner(&cryptodev_caam_jr_testsuite); 13756 } 13757 13758 static int 13759 test_cryptodev_nitrox(void) 13760 { 13761 gbl_driver_id = rte_cryptodev_driver_id_get( 13762 RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 13763 13764 if (gbl_driver_id == -1) { 13765 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded. Check if " 13766 "CONFIG_RTE_LIBRTE_PMD_NITROX is enabled " 13767 "in config file to run this testsuite.\n"); 13768 return TEST_FAILED; 13769 } 13770 13771 return unit_test_suite_runner(&cryptodev_nitrox_testsuite); 13772 } 13773 13774 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 13775 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 13776 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 13777 test_cryptodev_cpu_aesni_mb); 13778 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 13779 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 13780 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 13781 test_cryptodev_cpu_aesni_gcm); 13782 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 13783 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 13784 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 13785 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 13786 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 13787 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 13788 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 13789 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 13790 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 13791 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 13792 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 13793 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 13794 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 13795 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 13796