1 // Copyright 2015 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // THIS CODE IS GENERATED - DO NOT MODIFY! 6 7 #include "tpm_generated.h" 8 9 UINT16 uint8_t_Marshal(uint8_t* source, BYTE** buffer, INT32* size) { 10 uint8_t value_net = *source; 11 if (!size || *size < sizeof(uint8_t)) { 12 return 0; // Nothing has been marshaled. 13 } 14 switch (sizeof(uint8_t)) { 15 case 2: 16 value_net = htobe16(*source); 17 break; 18 case 4: 19 value_net = htobe32(*source); 20 break; 21 case 8: 22 value_net = htobe64(*source); 23 break; 24 default: 25 break; 26 } 27 memcpy(*buffer, &value_net, sizeof(uint8_t)); 28 *buffer += sizeof(uint8_t); 29 *size -= sizeof(uint8_t); 30 return sizeof(uint8_t); 31 } 32 33 TPM_RC uint8_t_Unmarshal(uint8_t* target, BYTE** buffer, INT32* size) { 34 uint8_t value_net = 0; 35 if (!size || *size < sizeof(uint8_t)) { 36 return TPM_RC_INSUFFICIENT; 37 } 38 memcpy(&value_net, *buffer, sizeof(uint8_t)); 39 switch (sizeof(uint8_t)) { 40 case 2: 41 *target = be16toh(value_net); 42 break; 43 case 4: 44 *target = be32toh(value_net); 45 break; 46 case 8: 47 *target = be64toh(value_net); 48 break; 49 default: 50 *target = value_net; 51 } 52 *buffer += sizeof(uint8_t); 53 *size -= sizeof(uint8_t); 54 return TPM_RC_SUCCESS; 55 } 56 57 UINT16 int8_t_Marshal(int8_t* source, BYTE** buffer, INT32* size) { 58 int8_t value_net = *source; 59 if (!size || *size < sizeof(int8_t)) { 60 return 0; // Nothing has been marshaled. 61 } 62 switch (sizeof(int8_t)) { 63 case 2: 64 value_net = htobe16(*source); 65 break; 66 case 4: 67 value_net = htobe32(*source); 68 break; 69 case 8: 70 value_net = htobe64(*source); 71 break; 72 default: 73 break; 74 } 75 memcpy(*buffer, &value_net, sizeof(int8_t)); 76 *buffer += sizeof(int8_t); 77 *size -= sizeof(int8_t); 78 return sizeof(int8_t); 79 } 80 81 TPM_RC int8_t_Unmarshal(int8_t* target, BYTE** buffer, INT32* size) { 82 int8_t value_net = 0; 83 if (!size || *size < sizeof(int8_t)) { 84 return TPM_RC_INSUFFICIENT; 85 } 86 memcpy(&value_net, *buffer, sizeof(int8_t)); 87 switch (sizeof(int8_t)) { 88 case 2: 89 *target = be16toh(value_net); 90 break; 91 case 4: 92 *target = be32toh(value_net); 93 break; 94 case 8: 95 *target = be64toh(value_net); 96 break; 97 default: 98 *target = value_net; 99 } 100 *buffer += sizeof(int8_t); 101 *size -= sizeof(int8_t); 102 return TPM_RC_SUCCESS; 103 } 104 105 UINT16 uint16_t_Marshal(uint16_t* source, BYTE** buffer, INT32* size) { 106 uint16_t value_net = *source; 107 if (!size || *size < sizeof(uint16_t)) { 108 return 0; // Nothing has been marshaled. 109 } 110 switch (sizeof(uint16_t)) { 111 case 2: 112 value_net = htobe16(*source); 113 break; 114 case 4: 115 value_net = htobe32(*source); 116 break; 117 case 8: 118 value_net = htobe64(*source); 119 break; 120 default: 121 break; 122 } 123 memcpy(*buffer, &value_net, sizeof(uint16_t)); 124 *buffer += sizeof(uint16_t); 125 *size -= sizeof(uint16_t); 126 return sizeof(uint16_t); 127 } 128 129 TPM_RC uint16_t_Unmarshal(uint16_t* target, BYTE** buffer, INT32* size) { 130 uint16_t value_net = 0; 131 if (!size || *size < sizeof(uint16_t)) { 132 return TPM_RC_INSUFFICIENT; 133 } 134 memcpy(&value_net, *buffer, sizeof(uint16_t)); 135 switch (sizeof(uint16_t)) { 136 case 2: 137 *target = be16toh(value_net); 138 break; 139 case 4: 140 *target = be32toh(value_net); 141 break; 142 case 8: 143 *target = be64toh(value_net); 144 break; 145 default: 146 *target = value_net; 147 } 148 *buffer += sizeof(uint16_t); 149 *size -= sizeof(uint16_t); 150 return TPM_RC_SUCCESS; 151 } 152 153 UINT16 int16_t_Marshal(int16_t* source, BYTE** buffer, INT32* size) { 154 int16_t value_net = *source; 155 if (!size || *size < sizeof(int16_t)) { 156 return 0; // Nothing has been marshaled. 157 } 158 switch (sizeof(int16_t)) { 159 case 2: 160 value_net = htobe16(*source); 161 break; 162 case 4: 163 value_net = htobe32(*source); 164 break; 165 case 8: 166 value_net = htobe64(*source); 167 break; 168 default: 169 break; 170 } 171 memcpy(*buffer, &value_net, sizeof(int16_t)); 172 *buffer += sizeof(int16_t); 173 *size -= sizeof(int16_t); 174 return sizeof(int16_t); 175 } 176 177 TPM_RC int16_t_Unmarshal(int16_t* target, BYTE** buffer, INT32* size) { 178 int16_t value_net = 0; 179 if (!size || *size < sizeof(int16_t)) { 180 return TPM_RC_INSUFFICIENT; 181 } 182 memcpy(&value_net, *buffer, sizeof(int16_t)); 183 switch (sizeof(int16_t)) { 184 case 2: 185 *target = be16toh(value_net); 186 break; 187 case 4: 188 *target = be32toh(value_net); 189 break; 190 case 8: 191 *target = be64toh(value_net); 192 break; 193 default: 194 *target = value_net; 195 } 196 *buffer += sizeof(int16_t); 197 *size -= sizeof(int16_t); 198 return TPM_RC_SUCCESS; 199 } 200 201 UINT16 uint32_t_Marshal(uint32_t* source, BYTE** buffer, INT32* size) { 202 uint32_t value_net = *source; 203 if (!size || *size < sizeof(uint32_t)) { 204 return 0; // Nothing has been marshaled. 205 } 206 switch (sizeof(uint32_t)) { 207 case 2: 208 value_net = htobe16(*source); 209 break; 210 case 4: 211 value_net = htobe32(*source); 212 break; 213 case 8: 214 value_net = htobe64(*source); 215 break; 216 default: 217 break; 218 } 219 memcpy(*buffer, &value_net, sizeof(uint32_t)); 220 *buffer += sizeof(uint32_t); 221 *size -= sizeof(uint32_t); 222 return sizeof(uint32_t); 223 } 224 225 TPM_RC uint32_t_Unmarshal(uint32_t* target, BYTE** buffer, INT32* size) { 226 uint32_t value_net = 0; 227 if (!size || *size < sizeof(uint32_t)) { 228 return TPM_RC_INSUFFICIENT; 229 } 230 memcpy(&value_net, *buffer, sizeof(uint32_t)); 231 switch (sizeof(uint32_t)) { 232 case 2: 233 *target = be16toh(value_net); 234 break; 235 case 4: 236 *target = be32toh(value_net); 237 break; 238 case 8: 239 *target = be64toh(value_net); 240 break; 241 default: 242 *target = value_net; 243 } 244 *buffer += sizeof(uint32_t); 245 *size -= sizeof(uint32_t); 246 return TPM_RC_SUCCESS; 247 } 248 249 UINT16 int32_t_Marshal(int32_t* source, BYTE** buffer, INT32* size) { 250 int32_t value_net = *source; 251 if (!size || *size < sizeof(int32_t)) { 252 return 0; // Nothing has been marshaled. 253 } 254 switch (sizeof(int32_t)) { 255 case 2: 256 value_net = htobe16(*source); 257 break; 258 case 4: 259 value_net = htobe32(*source); 260 break; 261 case 8: 262 value_net = htobe64(*source); 263 break; 264 default: 265 break; 266 } 267 memcpy(*buffer, &value_net, sizeof(int32_t)); 268 *buffer += sizeof(int32_t); 269 *size -= sizeof(int32_t); 270 return sizeof(int32_t); 271 } 272 273 TPM_RC int32_t_Unmarshal(int32_t* target, BYTE** buffer, INT32* size) { 274 int32_t value_net = 0; 275 if (!size || *size < sizeof(int32_t)) { 276 return TPM_RC_INSUFFICIENT; 277 } 278 memcpy(&value_net, *buffer, sizeof(int32_t)); 279 switch (sizeof(int32_t)) { 280 case 2: 281 *target = be16toh(value_net); 282 break; 283 case 4: 284 *target = be32toh(value_net); 285 break; 286 case 8: 287 *target = be64toh(value_net); 288 break; 289 default: 290 *target = value_net; 291 } 292 *buffer += sizeof(int32_t); 293 *size -= sizeof(int32_t); 294 return TPM_RC_SUCCESS; 295 } 296 297 UINT16 uint64_t_Marshal(uint64_t* source, BYTE** buffer, INT32* size) { 298 uint64_t value_net = *source; 299 if (!size || *size < sizeof(uint64_t)) { 300 return 0; // Nothing has been marshaled. 301 } 302 switch (sizeof(uint64_t)) { 303 case 2: 304 value_net = htobe16(*source); 305 break; 306 case 4: 307 value_net = htobe32(*source); 308 break; 309 case 8: 310 value_net = htobe64(*source); 311 break; 312 default: 313 break; 314 } 315 memcpy(*buffer, &value_net, sizeof(uint64_t)); 316 *buffer += sizeof(uint64_t); 317 *size -= sizeof(uint64_t); 318 return sizeof(uint64_t); 319 } 320 321 TPM_RC uint64_t_Unmarshal(uint64_t* target, BYTE** buffer, INT32* size) { 322 uint64_t value_net = 0; 323 if (!size || *size < sizeof(uint64_t)) { 324 return TPM_RC_INSUFFICIENT; 325 } 326 memcpy(&value_net, *buffer, sizeof(uint64_t)); 327 switch (sizeof(uint64_t)) { 328 case 2: 329 *target = be16toh(value_net); 330 break; 331 case 4: 332 *target = be32toh(value_net); 333 break; 334 case 8: 335 *target = be64toh(value_net); 336 break; 337 default: 338 *target = value_net; 339 } 340 *buffer += sizeof(uint64_t); 341 *size -= sizeof(uint64_t); 342 return TPM_RC_SUCCESS; 343 } 344 345 UINT16 int64_t_Marshal(int64_t* source, BYTE** buffer, INT32* size) { 346 int64_t value_net = *source; 347 if (!size || *size < sizeof(int64_t)) { 348 return 0; // Nothing has been marshaled. 349 } 350 switch (sizeof(int64_t)) { 351 case 2: 352 value_net = htobe16(*source); 353 break; 354 case 4: 355 value_net = htobe32(*source); 356 break; 357 case 8: 358 value_net = htobe64(*source); 359 break; 360 default: 361 break; 362 } 363 memcpy(*buffer, &value_net, sizeof(int64_t)); 364 *buffer += sizeof(int64_t); 365 *size -= sizeof(int64_t); 366 return sizeof(int64_t); 367 } 368 369 TPM_RC int64_t_Unmarshal(int64_t* target, BYTE** buffer, INT32* size) { 370 int64_t value_net = 0; 371 if (!size || *size < sizeof(int64_t)) { 372 return TPM_RC_INSUFFICIENT; 373 } 374 memcpy(&value_net, *buffer, sizeof(int64_t)); 375 switch (sizeof(int64_t)) { 376 case 2: 377 *target = be16toh(value_net); 378 break; 379 case 4: 380 *target = be32toh(value_net); 381 break; 382 case 8: 383 *target = be64toh(value_net); 384 break; 385 default: 386 *target = value_net; 387 } 388 *buffer += sizeof(int64_t); 389 *size -= sizeof(int64_t); 390 return TPM_RC_SUCCESS; 391 } 392 393 UINT16 BYTE_Marshal(BYTE* source, BYTE** buffer, INT32* size) { 394 return uint8_t_Marshal(source, buffer, size); 395 } 396 397 TPM_RC BYTE_Unmarshal(BYTE* target, BYTE** buffer, INT32* size) { 398 return uint8_t_Unmarshal(target, buffer, size); 399 } 400 401 UINT16 INT16_Marshal(INT16* source, BYTE** buffer, INT32* size) { 402 return int16_t_Marshal(source, buffer, size); 403 } 404 405 TPM_RC INT16_Unmarshal(INT16* target, BYTE** buffer, INT32* size) { 406 return int16_t_Unmarshal(target, buffer, size); 407 } 408 409 UINT16 INT32_Marshal(INT32* source, BYTE** buffer, INT32* size) { 410 return int32_t_Marshal(source, buffer, size); 411 } 412 413 TPM_RC INT32_Unmarshal(INT32* target, BYTE** buffer, INT32* size) { 414 return int32_t_Unmarshal(target, buffer, size); 415 } 416 417 UINT16 INT64_Marshal(INT64* source, BYTE** buffer, INT32* size) { 418 return int64_t_Marshal(source, buffer, size); 419 } 420 421 TPM_RC INT64_Unmarshal(INT64* target, BYTE** buffer, INT32* size) { 422 return int64_t_Unmarshal(target, buffer, size); 423 } 424 425 UINT16 INT8_Marshal(INT8* source, BYTE** buffer, INT32* size) { 426 return int8_t_Marshal(source, buffer, size); 427 } 428 429 TPM_RC INT8_Unmarshal(INT8* target, BYTE** buffer, INT32* size) { 430 return int8_t_Unmarshal(target, buffer, size); 431 } 432 433 UINT16 UINT16_Marshal(UINT16* source, BYTE** buffer, INT32* size) { 434 return uint16_t_Marshal(source, buffer, size); 435 } 436 437 TPM_RC UINT16_Unmarshal(UINT16* target, BYTE** buffer, INT32* size) { 438 return uint16_t_Unmarshal(target, buffer, size); 439 } 440 441 UINT16 TPM2B_ATTEST_Marshal(TPM2B_ATTEST* source, BYTE** buffer, INT32* size) { 442 UINT16 total_size = 0; 443 INT32 i; 444 total_size += UINT16_Marshal(&source->t.size, buffer, size); 445 for (i = 0; i < source->t.size; ++i) { 446 total_size += BYTE_Marshal(&source->t.attestationData[i], buffer, size); 447 } 448 return total_size; 449 } 450 451 TPM_RC TPM2B_ATTEST_Unmarshal(TPM2B_ATTEST* target, 452 BYTE** buffer, 453 INT32* size) { 454 TPM_RC result; 455 INT32 i; 456 result = UINT16_Unmarshal(&target->t.size, buffer, size); 457 if (result != TPM_RC_SUCCESS) { 458 return result; 459 } 460 if (target->t.size == 0) { 461 return TPM_RC_SUCCESS; 462 } 463 if (target->t.size > sizeof(TPMS_ATTEST)) { 464 return TPM_RC_SIZE; 465 } 466 for (i = 0; i < target->t.size; ++i) { 467 result = BYTE_Unmarshal(&target->t.attestationData[i], buffer, size); 468 if (result != TPM_RC_SUCCESS) { 469 return result; 470 } 471 } 472 return TPM_RC_SUCCESS; 473 } 474 475 UINT16 TPM2B_DIGEST_Marshal(TPM2B_DIGEST* source, BYTE** buffer, INT32* size) { 476 UINT16 total_size = 0; 477 INT32 i; 478 total_size += UINT16_Marshal(&source->t.size, buffer, size); 479 for (i = 0; i < source->t.size; ++i) { 480 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 481 } 482 return total_size; 483 } 484 485 TPM_RC TPM2B_DIGEST_Unmarshal(TPM2B_DIGEST* target, 486 BYTE** buffer, 487 INT32* size) { 488 TPM_RC result; 489 INT32 i; 490 result = UINT16_Unmarshal(&target->t.size, buffer, size); 491 if (result != TPM_RC_SUCCESS) { 492 return result; 493 } 494 if (target->t.size == 0) { 495 return TPM_RC_SUCCESS; 496 } 497 if (target->t.size > sizeof(TPMU_HA)) { 498 return TPM_RC_SIZE; 499 } 500 for (i = 0; i < target->t.size; ++i) { 501 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 502 if (result != TPM_RC_SUCCESS) { 503 return result; 504 } 505 } 506 return TPM_RC_SUCCESS; 507 } 508 509 UINT16 TPM2B_AUTH_Marshal(TPM2B_AUTH* source, BYTE** buffer, INT32* size) { 510 return TPM2B_DIGEST_Marshal(source, buffer, size); 511 } 512 513 TPM_RC TPM2B_AUTH_Unmarshal(TPM2B_AUTH* target, BYTE** buffer, INT32* size) { 514 return TPM2B_DIGEST_Unmarshal(target, buffer, size); 515 } 516 517 UINT16 TPM2B_CONTEXT_DATA_Marshal(TPM2B_CONTEXT_DATA* source, 518 BYTE** buffer, 519 INT32* size) { 520 UINT16 total_size = 0; 521 INT32 i; 522 total_size += UINT16_Marshal(&source->t.size, buffer, size); 523 for (i = 0; i < source->t.size; ++i) { 524 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 525 } 526 return total_size; 527 } 528 529 TPM_RC TPM2B_CONTEXT_DATA_Unmarshal(TPM2B_CONTEXT_DATA* target, 530 BYTE** buffer, 531 INT32* size) { 532 TPM_RC result; 533 INT32 i; 534 result = UINT16_Unmarshal(&target->t.size, buffer, size); 535 if (result != TPM_RC_SUCCESS) { 536 return result; 537 } 538 if (target->t.size == 0) { 539 return TPM_RC_SUCCESS; 540 } 541 if (target->t.size > sizeof(TPMS_CONTEXT_DATA)) { 542 return TPM_RC_SIZE; 543 } 544 for (i = 0; i < target->t.size; ++i) { 545 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 546 if (result != TPM_RC_SUCCESS) { 547 return result; 548 } 549 } 550 return TPM_RC_SUCCESS; 551 } 552 553 UINT16 TPM2B_CONTEXT_SENSITIVE_Marshal(TPM2B_CONTEXT_SENSITIVE* source, 554 BYTE** buffer, 555 INT32* size) { 556 UINT16 total_size = 0; 557 INT32 i; 558 total_size += UINT16_Marshal(&source->t.size, buffer, size); 559 for (i = 0; i < source->t.size; ++i) { 560 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 561 } 562 return total_size; 563 } 564 565 TPM_RC TPM2B_CONTEXT_SENSITIVE_Unmarshal(TPM2B_CONTEXT_SENSITIVE* target, 566 BYTE** buffer, 567 INT32* size) { 568 TPM_RC result; 569 INT32 i; 570 result = UINT16_Unmarshal(&target->t.size, buffer, size); 571 if (result != TPM_RC_SUCCESS) { 572 return result; 573 } 574 if (target->t.size == 0) { 575 return TPM_RC_SUCCESS; 576 } 577 if (target->t.size > MAX_CONTEXT_SIZE) { 578 return TPM_RC_SIZE; 579 } 580 for (i = 0; i < target->t.size; ++i) { 581 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 582 if (result != TPM_RC_SUCCESS) { 583 return result; 584 } 585 } 586 return TPM_RC_SUCCESS; 587 } 588 589 UINT16 TPM_ALG_ID_Marshal(TPM_ALG_ID* source, BYTE** buffer, INT32* size) { 590 return uint16_t_Marshal(source, buffer, size); 591 } 592 593 TPM_RC TPM_ALG_ID_Unmarshal(TPM_ALG_ID* target, BYTE** buffer, INT32* size) { 594 TPM_RC result; 595 result = uint16_t_Unmarshal(target, buffer, size); 596 if (result != TPM_RC_SUCCESS) { 597 return result; 598 } 599 #ifdef TPM_ALG_ERROR 600 if (*target == TPM_ALG_ERROR) { 601 return TPM_RC_SUCCESS; 602 } 603 #endif 604 #ifdef TPM_ALG_RSA 605 if (*target == TPM_ALG_RSA) { 606 return TPM_RC_SUCCESS; 607 } 608 #endif 609 #ifdef TPM_ALG_SHA 610 if (*target == TPM_ALG_SHA) { 611 return TPM_RC_SUCCESS; 612 } 613 #endif 614 #ifdef TPM_ALG_SHA1 615 if (*target == TPM_ALG_SHA1) { 616 return TPM_RC_SUCCESS; 617 } 618 #endif 619 #ifdef TPM_ALG_HMAC 620 if (*target == TPM_ALG_HMAC) { 621 return TPM_RC_SUCCESS; 622 } 623 #endif 624 #ifdef TPM_ALG_AES 625 if (*target == TPM_ALG_AES) { 626 return TPM_RC_SUCCESS; 627 } 628 #endif 629 #ifdef TPM_ALG_MGF1 630 if (*target == TPM_ALG_MGF1) { 631 return TPM_RC_SUCCESS; 632 } 633 #endif 634 #ifdef TPM_ALG_KEYEDHASH 635 if (*target == TPM_ALG_KEYEDHASH) { 636 return TPM_RC_SUCCESS; 637 } 638 #endif 639 #ifdef TPM_ALG_XOR 640 if (*target == TPM_ALG_XOR) { 641 return TPM_RC_SUCCESS; 642 } 643 #endif 644 #ifdef TPM_ALG_SHA256 645 if (*target == TPM_ALG_SHA256) { 646 return TPM_RC_SUCCESS; 647 } 648 #endif 649 #ifdef TPM_ALG_SHA384 650 if (*target == TPM_ALG_SHA384) { 651 return TPM_RC_SUCCESS; 652 } 653 #endif 654 #ifdef TPM_ALG_SHA512 655 if (*target == TPM_ALG_SHA512) { 656 return TPM_RC_SUCCESS; 657 } 658 #endif 659 #ifdef TPM_ALG_NULL 660 if (*target == TPM_ALG_NULL) { 661 return TPM_RC_SUCCESS; 662 } 663 #endif 664 #ifdef TPM_ALG_SM3_256 665 if (*target == TPM_ALG_SM3_256) { 666 return TPM_RC_SUCCESS; 667 } 668 #endif 669 #ifdef TPM_ALG_SM4 670 if (*target == TPM_ALG_SM4) { 671 return TPM_RC_SUCCESS; 672 } 673 #endif 674 #ifdef TPM_ALG_RSASSA 675 if (*target == TPM_ALG_RSASSA) { 676 return TPM_RC_SUCCESS; 677 } 678 #endif 679 #ifdef TPM_ALG_RSAES 680 if (*target == TPM_ALG_RSAES) { 681 return TPM_RC_SUCCESS; 682 } 683 #endif 684 #ifdef TPM_ALG_RSAPSS 685 if (*target == TPM_ALG_RSAPSS) { 686 return TPM_RC_SUCCESS; 687 } 688 #endif 689 #ifdef TPM_ALG_OAEP 690 if (*target == TPM_ALG_OAEP) { 691 return TPM_RC_SUCCESS; 692 } 693 #endif 694 #ifdef TPM_ALG_ECDSA 695 if (*target == TPM_ALG_ECDSA) { 696 return TPM_RC_SUCCESS; 697 } 698 #endif 699 #ifdef TPM_ALG_ECDH 700 if (*target == TPM_ALG_ECDH) { 701 return TPM_RC_SUCCESS; 702 } 703 #endif 704 #ifdef TPM_ALG_ECDAA 705 if (*target == TPM_ALG_ECDAA) { 706 return TPM_RC_SUCCESS; 707 } 708 #endif 709 #ifdef TPM_ALG_SM2 710 if (*target == TPM_ALG_SM2) { 711 return TPM_RC_SUCCESS; 712 } 713 #endif 714 #ifdef TPM_ALG_ECSCHNORR 715 if (*target == TPM_ALG_ECSCHNORR) { 716 return TPM_RC_SUCCESS; 717 } 718 #endif 719 #ifdef TPM_ALG_ECMQV 720 if (*target == TPM_ALG_ECMQV) { 721 return TPM_RC_SUCCESS; 722 } 723 #endif 724 #ifdef TPM_ALG_KDF1_SP800_56A 725 if (*target == TPM_ALG_KDF1_SP800_56A) { 726 return TPM_RC_SUCCESS; 727 } 728 #endif 729 #ifdef TPM_ALG_KDF2 730 if (*target == TPM_ALG_KDF2) { 731 return TPM_RC_SUCCESS; 732 } 733 #endif 734 #ifdef TPM_ALG_KDF1_SP800_108 735 if (*target == TPM_ALG_KDF1_SP800_108) { 736 return TPM_RC_SUCCESS; 737 } 738 #endif 739 #ifdef TPM_ALG_ECC 740 if (*target == TPM_ALG_ECC) { 741 return TPM_RC_SUCCESS; 742 } 743 #endif 744 #ifdef TPM_ALG_SYMCIPHER 745 if (*target == TPM_ALG_SYMCIPHER) { 746 return TPM_RC_SUCCESS; 747 } 748 #endif 749 #ifdef TPM_ALG_CAMELLIA 750 if (*target == TPM_ALG_CAMELLIA) { 751 return TPM_RC_SUCCESS; 752 } 753 #endif 754 #ifdef TPM_ALG_CTR 755 if (*target == TPM_ALG_CTR) { 756 return TPM_RC_SUCCESS; 757 } 758 #endif 759 #ifdef TPM_ALG_OFB 760 if (*target == TPM_ALG_OFB) { 761 return TPM_RC_SUCCESS; 762 } 763 #endif 764 #ifdef TPM_ALG_CBC 765 if (*target == TPM_ALG_CBC) { 766 return TPM_RC_SUCCESS; 767 } 768 #endif 769 #ifdef TPM_ALG_CFB 770 if (*target == TPM_ALG_CFB) { 771 return TPM_RC_SUCCESS; 772 } 773 #endif 774 #ifdef TPM_ALG_ECB 775 if (*target == TPM_ALG_ECB) { 776 return TPM_RC_SUCCESS; 777 } 778 #endif 779 return TPM_RC_VALUE; 780 } 781 782 UINT16 TPM2B_DATA_Marshal(TPM2B_DATA* source, BYTE** buffer, INT32* size) { 783 UINT16 total_size = 0; 784 INT32 i; 785 total_size += UINT16_Marshal(&source->t.size, buffer, size); 786 for (i = 0; i < source->t.size; ++i) { 787 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 788 } 789 return total_size; 790 } 791 792 TPM_RC TPM2B_DATA_Unmarshal(TPM2B_DATA* target, BYTE** buffer, INT32* size) { 793 TPM_RC result; 794 INT32 i; 795 result = UINT16_Unmarshal(&target->t.size, buffer, size); 796 if (result != TPM_RC_SUCCESS) { 797 return result; 798 } 799 if (target->t.size == 0) { 800 return TPM_RC_SUCCESS; 801 } 802 if (target->t.size > sizeof(TPMT_HA)) { 803 return TPM_RC_SIZE; 804 } 805 for (i = 0; i < target->t.size; ++i) { 806 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 807 if (result != TPM_RC_SUCCESS) { 808 return result; 809 } 810 } 811 return TPM_RC_SUCCESS; 812 } 813 814 UINT16 TPMA_LOCALITY_Marshal(TPMA_LOCALITY* source, 815 BYTE** buffer, 816 INT32* size) { 817 return uint8_t_Marshal((uint8_t*)source, buffer, size); 818 } 819 820 TPM_RC TPMA_LOCALITY_Unmarshal(TPMA_LOCALITY* target, 821 BYTE** buffer, 822 INT32* size) { 823 TPM_RC result; 824 result = uint8_t_Unmarshal((uint8_t*)target, buffer, size); 825 if (result != TPM_RC_SUCCESS) { 826 return result; 827 } 828 return TPM_RC_SUCCESS; 829 } 830 831 UINT16 TPM2B_NAME_Marshal(TPM2B_NAME* source, BYTE** buffer, INT32* size) { 832 UINT16 total_size = 0; 833 INT32 i; 834 total_size += UINT16_Marshal(&source->t.size, buffer, size); 835 for (i = 0; i < source->t.size; ++i) { 836 total_size += BYTE_Marshal(&source->t.name[i], buffer, size); 837 } 838 return total_size; 839 } 840 841 TPM_RC TPM2B_NAME_Unmarshal(TPM2B_NAME* target, BYTE** buffer, INT32* size) { 842 TPM_RC result; 843 INT32 i; 844 result = UINT16_Unmarshal(&target->t.size, buffer, size); 845 if (result != TPM_RC_SUCCESS) { 846 return result; 847 } 848 if (target->t.size == 0) { 849 return TPM_RC_SUCCESS; 850 } 851 if (target->t.size > sizeof(TPMU_NAME)) { 852 return TPM_RC_SIZE; 853 } 854 for (i = 0; i < target->t.size; ++i) { 855 result = BYTE_Unmarshal(&target->t.name[i], buffer, size); 856 if (result != TPM_RC_SUCCESS) { 857 return result; 858 } 859 } 860 return TPM_RC_SUCCESS; 861 } 862 863 UINT16 TPMI_ALG_HASH_Marshal(TPMI_ALG_HASH* source, 864 BYTE** buffer, 865 INT32* size) { 866 return uint16_t_Marshal(source, buffer, size); 867 } 868 869 TPM_RC TPMI_ALG_HASH_Unmarshal(TPMI_ALG_HASH* target, 870 BYTE** buffer, 871 INT32* size, 872 BOOL allow_conditional_value) { 873 TPM_RC result; 874 BOOL has_valid_value = FALSE; 875 result = uint16_t_Unmarshal(target, buffer, size); 876 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 877 return result; 878 } 879 if (*target == TPM_ALG_NULL) { 880 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_HASH; 881 } 882 switch (*target) { 883 #ifdef TPM_ALG_SHA 884 case TPM_ALG_SHA: 885 #endif 886 #ifdef TPM_ALG_SHA1 887 case TPM_ALG_SHA1: 888 #endif 889 #ifdef TPM_ALG_SHA256 890 case TPM_ALG_SHA256: 891 #endif 892 #ifdef TPM_ALG_SHA384 893 case TPM_ALG_SHA384: 894 #endif 895 #ifdef TPM_ALG_SHA512 896 case TPM_ALG_SHA512: 897 #endif 898 #ifdef TPM_ALG_SM3_256 899 case TPM_ALG_SM3_256: 900 #endif 901 has_valid_value = TRUE; 902 break; 903 } 904 if (!has_valid_value) { 905 return TPM_RC_HASH; 906 } 907 return TPM_RC_SUCCESS; 908 } 909 910 UINT16 UINT8_Marshal(UINT8* source, BYTE** buffer, INT32* size) { 911 return uint8_t_Marshal(source, buffer, size); 912 } 913 914 TPM_RC UINT8_Unmarshal(UINT8* target, BYTE** buffer, INT32* size) { 915 return uint8_t_Unmarshal(target, buffer, size); 916 } 917 918 UINT16 TPMS_PCR_SELECTION_Marshal(TPMS_PCR_SELECTION* source, 919 BYTE** buffer, 920 INT32* size) { 921 UINT16 total_size = 0; 922 INT32 i; 923 total_size += TPMI_ALG_HASH_Marshal(&source->hash, buffer, size); 924 total_size += UINT8_Marshal(&source->sizeofSelect, buffer, size); 925 for (i = 0; i < source->sizeofSelect; ++i) { 926 total_size += BYTE_Marshal(&source->pcrSelect[i], buffer, size); 927 } 928 return total_size; 929 } 930 931 TPM_RC TPMS_PCR_SELECTION_Unmarshal(TPMS_PCR_SELECTION* target, 932 BYTE** buffer, 933 INT32* size) { 934 TPM_RC result; 935 INT32 i; 936 result = TPMI_ALG_HASH_Unmarshal(&target->hash, buffer, size, FALSE); 937 if (result != TPM_RC_SUCCESS) { 938 return result; 939 } 940 result = UINT8_Unmarshal(&target->sizeofSelect, buffer, size); 941 if (result != TPM_RC_SUCCESS) { 942 return result; 943 } 944 if (target->sizeofSelect > PCR_SELECT_MAX) { 945 return TPM_RC_VALUE; 946 } 947 if (target->sizeofSelect < PCR_SELECT_MIN) { 948 return TPM_RC_VALUE; 949 } 950 for (i = 0; i < target->sizeofSelect; ++i) { 951 result = BYTE_Unmarshal(&target->pcrSelect[i], buffer, size); 952 if (result != TPM_RC_SUCCESS) { 953 return result; 954 } 955 } 956 return TPM_RC_SUCCESS; 957 } 958 959 UINT16 UINT32_Marshal(UINT32* source, BYTE** buffer, INT32* size) { 960 return uint32_t_Marshal(source, buffer, size); 961 } 962 963 TPM_RC UINT32_Unmarshal(UINT32* target, BYTE** buffer, INT32* size) { 964 return uint32_t_Unmarshal(target, buffer, size); 965 } 966 967 UINT16 TPML_PCR_SELECTION_Marshal(TPML_PCR_SELECTION* source, 968 BYTE** buffer, 969 INT32* size) { 970 UINT16 total_size = 0; 971 INT32 i; 972 total_size += UINT32_Marshal(&source->count, buffer, size); 973 for (i = 0; i < source->count; ++i) { 974 total_size += 975 TPMS_PCR_SELECTION_Marshal(&source->pcrSelections[i], buffer, size); 976 } 977 return total_size; 978 } 979 980 TPM_RC TPML_PCR_SELECTION_Unmarshal(TPML_PCR_SELECTION* target, 981 BYTE** buffer, 982 INT32* size) { 983 TPM_RC result; 984 INT32 i; 985 result = UINT32_Unmarshal(&target->count, buffer, size); 986 if (result != TPM_RC_SUCCESS) { 987 return result; 988 } 989 if (target->count > HASH_COUNT) { 990 return TPM_RC_SIZE; 991 } 992 for (i = 0; i < target->count; ++i) { 993 result = 994 TPMS_PCR_SELECTION_Unmarshal(&target->pcrSelections[i], buffer, size); 995 if (result != TPM_RC_SUCCESS) { 996 return result; 997 } 998 } 999 return TPM_RC_SUCCESS; 1000 } 1001 1002 UINT16 TPMS_CREATION_DATA_Marshal(TPMS_CREATION_DATA* source, 1003 BYTE** buffer, 1004 INT32* size) { 1005 UINT16 total_size = 0; 1006 total_size += TPML_PCR_SELECTION_Marshal(&source->pcrSelect, buffer, size); 1007 total_size += TPM2B_DIGEST_Marshal(&source->pcrDigest, buffer, size); 1008 total_size += TPMA_LOCALITY_Marshal(&source->locality, buffer, size); 1009 total_size += TPM_ALG_ID_Marshal(&source->parentNameAlg, buffer, size); 1010 total_size += TPM2B_NAME_Marshal(&source->parentName, buffer, size); 1011 total_size += TPM2B_NAME_Marshal(&source->parentQualifiedName, buffer, size); 1012 total_size += TPM2B_DATA_Marshal(&source->outsideInfo, buffer, size); 1013 return total_size; 1014 } 1015 1016 TPM_RC TPMS_CREATION_DATA_Unmarshal(TPMS_CREATION_DATA* target, 1017 BYTE** buffer, 1018 INT32* size) { 1019 TPM_RC result; 1020 result = TPML_PCR_SELECTION_Unmarshal(&target->pcrSelect, buffer, size); 1021 if (result != TPM_RC_SUCCESS) { 1022 return result; 1023 } 1024 result = TPM2B_DIGEST_Unmarshal(&target->pcrDigest, buffer, size); 1025 if (result != TPM_RC_SUCCESS) { 1026 return result; 1027 } 1028 result = TPMA_LOCALITY_Unmarshal(&target->locality, buffer, size); 1029 if (result != TPM_RC_SUCCESS) { 1030 return result; 1031 } 1032 result = TPM_ALG_ID_Unmarshal(&target->parentNameAlg, buffer, size); 1033 if (result != TPM_RC_SUCCESS) { 1034 return result; 1035 } 1036 result = TPM2B_NAME_Unmarshal(&target->parentName, buffer, size); 1037 if (result != TPM_RC_SUCCESS) { 1038 return result; 1039 } 1040 result = TPM2B_NAME_Unmarshal(&target->parentQualifiedName, buffer, size); 1041 if (result != TPM_RC_SUCCESS) { 1042 return result; 1043 } 1044 result = TPM2B_DATA_Unmarshal(&target->outsideInfo, buffer, size); 1045 if (result != TPM_RC_SUCCESS) { 1046 return result; 1047 } 1048 return TPM_RC_SUCCESS; 1049 } 1050 1051 UINT16 TPM2B_CREATION_DATA_Marshal(TPM2B_CREATION_DATA* source, 1052 BYTE** buffer, 1053 INT32* size) { 1054 UINT16 total_size = 0; 1055 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1056 total_size += 1057 TPMS_CREATION_DATA_Marshal(&source->t.creationData, buffer, size); 1058 { 1059 BYTE* size_location = *buffer - total_size; 1060 INT32 size_field_size = sizeof(UINT16); 1061 UINT16 payload_size = total_size - (UINT16)size_field_size; 1062 UINT16_Marshal(&payload_size, &size_location, &size_field_size); 1063 } 1064 return total_size; 1065 } 1066 1067 TPM_RC TPM2B_CREATION_DATA_Unmarshal(TPM2B_CREATION_DATA* target, 1068 BYTE** buffer, 1069 INT32* size) { 1070 TPM_RC result; 1071 UINT32 start_size = *size; 1072 UINT32 struct_size; 1073 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1074 if (result != TPM_RC_SUCCESS) { 1075 return result; 1076 } 1077 if (target->t.size == 0) { 1078 return TPM_RC_SIZE; 1079 } 1080 result = TPMS_CREATION_DATA_Unmarshal(&target->t.creationData, buffer, size); 1081 if (result != TPM_RC_SUCCESS) { 1082 return result; 1083 } 1084 struct_size = start_size - *size - sizeof(target->t.size); 1085 if (struct_size != target->t.size) { 1086 return TPM_RC_SIZE; 1087 } 1088 return TPM_RC_SUCCESS; 1089 } 1090 1091 UINT16 TPM2B_DIGEST_VALUES_Marshal(TPM2B_DIGEST_VALUES* source, 1092 BYTE** buffer, 1093 INT32* size) { 1094 UINT16 total_size = 0; 1095 INT32 i; 1096 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1097 for (i = 0; i < source->t.size; ++i) { 1098 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1099 } 1100 return total_size; 1101 } 1102 1103 TPM_RC TPM2B_DIGEST_VALUES_Unmarshal(TPM2B_DIGEST_VALUES* target, 1104 BYTE** buffer, 1105 INT32* size) { 1106 TPM_RC result; 1107 INT32 i; 1108 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1109 if (result != TPM_RC_SUCCESS) { 1110 return result; 1111 } 1112 if (target->t.size == 0) { 1113 return TPM_RC_SUCCESS; 1114 } 1115 if (target->t.size > sizeof(TPML_DIGEST_VALUES)) { 1116 return TPM_RC_SIZE; 1117 } 1118 for (i = 0; i < target->t.size; ++i) { 1119 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1120 if (result != TPM_RC_SUCCESS) { 1121 return result; 1122 } 1123 } 1124 return TPM_RC_SUCCESS; 1125 } 1126 1127 UINT16 TPM2B_ECC_PARAMETER_Marshal(TPM2B_ECC_PARAMETER* source, 1128 BYTE** buffer, 1129 INT32* size) { 1130 UINT16 total_size = 0; 1131 INT32 i; 1132 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1133 for (i = 0; i < source->t.size; ++i) { 1134 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1135 } 1136 return total_size; 1137 } 1138 1139 TPM_RC TPM2B_ECC_PARAMETER_Unmarshal(TPM2B_ECC_PARAMETER* target, 1140 BYTE** buffer, 1141 INT32* size) { 1142 TPM_RC result; 1143 INT32 i; 1144 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1145 if (result != TPM_RC_SUCCESS) { 1146 return result; 1147 } 1148 if (target->t.size == 0) { 1149 return TPM_RC_SUCCESS; 1150 } 1151 if (target->t.size > MAX_ECC_KEY_BYTES) { 1152 return TPM_RC_SIZE; 1153 } 1154 for (i = 0; i < target->t.size; ++i) { 1155 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1156 if (result != TPM_RC_SUCCESS) { 1157 return result; 1158 } 1159 } 1160 return TPM_RC_SUCCESS; 1161 } 1162 1163 UINT16 TPMS_ECC_POINT_Marshal(TPMS_ECC_POINT* source, 1164 BYTE** buffer, 1165 INT32* size) { 1166 UINT16 total_size = 0; 1167 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->x, buffer, size); 1168 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->y, buffer, size); 1169 return total_size; 1170 } 1171 1172 TPM_RC TPMS_ECC_POINT_Unmarshal(TPMS_ECC_POINT* target, 1173 BYTE** buffer, 1174 INT32* size) { 1175 TPM_RC result; 1176 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->x, buffer, size); 1177 if (result != TPM_RC_SUCCESS) { 1178 return result; 1179 } 1180 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->y, buffer, size); 1181 if (result != TPM_RC_SUCCESS) { 1182 return result; 1183 } 1184 return TPM_RC_SUCCESS; 1185 } 1186 1187 UINT16 TPM2B_ECC_POINT_Marshal(TPM2B_ECC_POINT* source, 1188 BYTE** buffer, 1189 INT32* size) { 1190 UINT16 total_size = 0; 1191 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1192 total_size += TPMS_ECC_POINT_Marshal(&source->t.point, buffer, size); 1193 { 1194 BYTE* size_location = *buffer - total_size; 1195 INT32 size_field_size = sizeof(UINT16); 1196 UINT16 payload_size = total_size - (UINT16)size_field_size; 1197 UINT16_Marshal(&payload_size, &size_location, &size_field_size); 1198 } 1199 return total_size; 1200 } 1201 1202 TPM_RC TPM2B_ECC_POINT_Unmarshal(TPM2B_ECC_POINT* target, 1203 BYTE** buffer, 1204 INT32* size) { 1205 TPM_RC result; 1206 UINT32 start_size = *size; 1207 UINT32 struct_size; 1208 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1209 if (result != TPM_RC_SUCCESS) { 1210 return result; 1211 } 1212 if (target->t.size == 0) { 1213 return TPM_RC_SIZE; 1214 } 1215 result = TPMS_ECC_POINT_Unmarshal(&target->t.point, buffer, size); 1216 if (result != TPM_RC_SUCCESS) { 1217 return result; 1218 } 1219 struct_size = start_size - *size - sizeof(target->t.size); 1220 if (struct_size != target->t.size) { 1221 return TPM_RC_SIZE; 1222 } 1223 return TPM_RC_SUCCESS; 1224 } 1225 1226 UINT16 TPM2B_ENCRYPTED_SECRET_Marshal(TPM2B_ENCRYPTED_SECRET* source, 1227 BYTE** buffer, 1228 INT32* size) { 1229 UINT16 total_size = 0; 1230 INT32 i; 1231 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1232 for (i = 0; i < source->t.size; ++i) { 1233 total_size += BYTE_Marshal(&source->t.secret[i], buffer, size); 1234 } 1235 return total_size; 1236 } 1237 1238 TPM_RC TPM2B_ENCRYPTED_SECRET_Unmarshal(TPM2B_ENCRYPTED_SECRET* target, 1239 BYTE** buffer, 1240 INT32* size) { 1241 TPM_RC result; 1242 INT32 i; 1243 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1244 if (result != TPM_RC_SUCCESS) { 1245 return result; 1246 } 1247 if (target->t.size == 0) { 1248 return TPM_RC_SUCCESS; 1249 } 1250 if (target->t.size > sizeof(TPMU_ENCRYPTED_SECRET)) { 1251 return TPM_RC_SIZE; 1252 } 1253 for (i = 0; i < target->t.size; ++i) { 1254 result = BYTE_Unmarshal(&target->t.secret[i], buffer, size); 1255 if (result != TPM_RC_SUCCESS) { 1256 return result; 1257 } 1258 } 1259 return TPM_RC_SUCCESS; 1260 } 1261 1262 UINT16 TPM2B_EVENT_Marshal(TPM2B_EVENT* source, BYTE** buffer, INT32* size) { 1263 UINT16 total_size = 0; 1264 INT32 i; 1265 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1266 for (i = 0; i < source->t.size; ++i) { 1267 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1268 } 1269 return total_size; 1270 } 1271 1272 TPM_RC TPM2B_EVENT_Unmarshal(TPM2B_EVENT* target, BYTE** buffer, INT32* size) { 1273 TPM_RC result; 1274 INT32 i; 1275 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1276 if (result != TPM_RC_SUCCESS) { 1277 return result; 1278 } 1279 if (target->t.size == 0) { 1280 return TPM_RC_SUCCESS; 1281 } 1282 if (target->t.size > 1024) { 1283 return TPM_RC_SIZE; 1284 } 1285 for (i = 0; i < target->t.size; ++i) { 1286 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1287 if (result != TPM_RC_SUCCESS) { 1288 return result; 1289 } 1290 } 1291 return TPM_RC_SUCCESS; 1292 } 1293 1294 UINT16 TPM2B_ID_OBJECT_Marshal(TPM2B_ID_OBJECT* source, 1295 BYTE** buffer, 1296 INT32* size) { 1297 UINT16 total_size = 0; 1298 INT32 i; 1299 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1300 for (i = 0; i < source->t.size; ++i) { 1301 total_size += BYTE_Marshal(&source->t.credential[i], buffer, size); 1302 } 1303 return total_size; 1304 } 1305 1306 TPM_RC TPM2B_ID_OBJECT_Unmarshal(TPM2B_ID_OBJECT* target, 1307 BYTE** buffer, 1308 INT32* size) { 1309 TPM_RC result; 1310 INT32 i; 1311 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1312 if (result != TPM_RC_SUCCESS) { 1313 return result; 1314 } 1315 if (target->t.size == 0) { 1316 return TPM_RC_SUCCESS; 1317 } 1318 if (target->t.size > sizeof(_ID_OBJECT)) { 1319 return TPM_RC_SIZE; 1320 } 1321 for (i = 0; i < target->t.size; ++i) { 1322 result = BYTE_Unmarshal(&target->t.credential[i], buffer, size); 1323 if (result != TPM_RC_SUCCESS) { 1324 return result; 1325 } 1326 } 1327 return TPM_RC_SUCCESS; 1328 } 1329 1330 UINT16 TPM2B_IV_Marshal(TPM2B_IV* source, BYTE** buffer, INT32* size) { 1331 UINT16 total_size = 0; 1332 INT32 i; 1333 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1334 for (i = 0; i < source->t.size; ++i) { 1335 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1336 } 1337 return total_size; 1338 } 1339 1340 TPM_RC TPM2B_IV_Unmarshal(TPM2B_IV* target, BYTE** buffer, INT32* size) { 1341 TPM_RC result; 1342 INT32 i; 1343 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1344 if (result != TPM_RC_SUCCESS) { 1345 return result; 1346 } 1347 if (target->t.size == 0) { 1348 return TPM_RC_SUCCESS; 1349 } 1350 if (target->t.size > MAX_SYM_BLOCK_SIZE) { 1351 return TPM_RC_SIZE; 1352 } 1353 for (i = 0; i < target->t.size; ++i) { 1354 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1355 if (result != TPM_RC_SUCCESS) { 1356 return result; 1357 } 1358 } 1359 return TPM_RC_SUCCESS; 1360 } 1361 1362 UINT16 TPM2B_MAX_BUFFER_Marshal(TPM2B_MAX_BUFFER* source, 1363 BYTE** buffer, 1364 INT32* size) { 1365 UINT16 total_size = 0; 1366 INT32 i; 1367 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1368 for (i = 0; i < source->t.size; ++i) { 1369 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1370 } 1371 return total_size; 1372 } 1373 1374 TPM_RC TPM2B_MAX_BUFFER_Unmarshal(TPM2B_MAX_BUFFER* target, 1375 BYTE** buffer, 1376 INT32* size) { 1377 TPM_RC result; 1378 INT32 i; 1379 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1380 if (result != TPM_RC_SUCCESS) { 1381 return result; 1382 } 1383 if (target->t.size == 0) { 1384 return TPM_RC_SUCCESS; 1385 } 1386 if (target->t.size > MAX_DIGEST_BUFFER) { 1387 return TPM_RC_SIZE; 1388 } 1389 for (i = 0; i < target->t.size; ++i) { 1390 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1391 if (result != TPM_RC_SUCCESS) { 1392 return result; 1393 } 1394 } 1395 return TPM_RC_SUCCESS; 1396 } 1397 1398 UINT16 TPM2B_MAX_NV_BUFFER_Marshal(TPM2B_MAX_NV_BUFFER* source, 1399 BYTE** buffer, 1400 INT32* size) { 1401 UINT16 total_size = 0; 1402 INT32 i; 1403 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1404 for (i = 0; i < source->t.size; ++i) { 1405 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1406 } 1407 return total_size; 1408 } 1409 1410 TPM_RC TPM2B_MAX_NV_BUFFER_Unmarshal(TPM2B_MAX_NV_BUFFER* target, 1411 BYTE** buffer, 1412 INT32* size) { 1413 TPM_RC result; 1414 INT32 i; 1415 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1416 if (result != TPM_RC_SUCCESS) { 1417 return result; 1418 } 1419 if (target->t.size == 0) { 1420 return TPM_RC_SUCCESS; 1421 } 1422 if (target->t.size > MAX_NV_BUFFER_SIZE) { 1423 return TPM_RC_SIZE; 1424 } 1425 for (i = 0; i < target->t.size; ++i) { 1426 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1427 if (result != TPM_RC_SUCCESS) { 1428 return result; 1429 } 1430 } 1431 return TPM_RC_SUCCESS; 1432 } 1433 1434 UINT16 TPM2B_NONCE_Marshal(TPM2B_NONCE* source, BYTE** buffer, INT32* size) { 1435 return TPM2B_DIGEST_Marshal(source, buffer, size); 1436 } 1437 1438 TPM_RC TPM2B_NONCE_Unmarshal(TPM2B_NONCE* target, BYTE** buffer, INT32* size) { 1439 return TPM2B_DIGEST_Unmarshal(target, buffer, size); 1440 } 1441 1442 UINT16 TPMI_RH_NV_INDEX_Marshal(TPMI_RH_NV_INDEX* source, 1443 BYTE** buffer, 1444 INT32* size) { 1445 return uint32_t_Marshal(source, buffer, size); 1446 } 1447 1448 TPM_RC TPMI_RH_NV_INDEX_Unmarshal(TPMI_RH_NV_INDEX* target, 1449 BYTE** buffer, 1450 INT32* size) { 1451 TPM_RC result; 1452 BOOL has_valid_value = FALSE; 1453 result = uint32_t_Unmarshal(target, buffer, size); 1454 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 1455 return result; 1456 } 1457 if ((*target >= NV_INDEX_FIRST) && (*target <= NV_INDEX_LAST)) { 1458 has_valid_value = TRUE; 1459 } 1460 if (!has_valid_value) { 1461 return TPM_RC_VALUE; 1462 } 1463 return TPM_RC_SUCCESS; 1464 } 1465 1466 UINT16 TPMA_NV_Marshal(TPMA_NV* source, BYTE** buffer, INT32* size) { 1467 return uint32_t_Marshal((uint32_t*)source, buffer, size); 1468 } 1469 1470 TPM_RC TPMA_NV_Unmarshal(TPMA_NV* target, BYTE** buffer, INT32* size) { 1471 TPM_RC result; 1472 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 1473 if (result != TPM_RC_SUCCESS) { 1474 return result; 1475 } 1476 if (target->reserved7_9 != 0) { 1477 return TPM_RC_RESERVED_BITS; 1478 } 1479 if (target->reserved20_24 != 0) { 1480 return TPM_RC_RESERVED_BITS; 1481 } 1482 return TPM_RC_SUCCESS; 1483 } 1484 1485 UINT16 TPMS_NV_PUBLIC_Marshal(TPMS_NV_PUBLIC* source, 1486 BYTE** buffer, 1487 INT32* size) { 1488 UINT16 total_size = 0; 1489 total_size += TPMI_RH_NV_INDEX_Marshal(&source->nvIndex, buffer, size); 1490 total_size += TPMI_ALG_HASH_Marshal(&source->nameAlg, buffer, size); 1491 total_size += TPMA_NV_Marshal(&source->attributes, buffer, size); 1492 total_size += TPM2B_DIGEST_Marshal(&source->authPolicy, buffer, size); 1493 total_size += UINT16_Marshal(&source->dataSize, buffer, size); 1494 return total_size; 1495 } 1496 1497 TPM_RC TPMS_NV_PUBLIC_Unmarshal(TPMS_NV_PUBLIC* target, 1498 BYTE** buffer, 1499 INT32* size) { 1500 TPM_RC result; 1501 result = TPMI_RH_NV_INDEX_Unmarshal(&target->nvIndex, buffer, size); 1502 if (result != TPM_RC_SUCCESS) { 1503 return result; 1504 } 1505 result = TPMI_ALG_HASH_Unmarshal(&target->nameAlg, buffer, size, FALSE); 1506 if (result != TPM_RC_SUCCESS) { 1507 return result; 1508 } 1509 result = TPMA_NV_Unmarshal(&target->attributes, buffer, size); 1510 if (result != TPM_RC_SUCCESS) { 1511 return result; 1512 } 1513 result = TPM2B_DIGEST_Unmarshal(&target->authPolicy, buffer, size); 1514 if (result != TPM_RC_SUCCESS) { 1515 return result; 1516 } 1517 result = UINT16_Unmarshal(&target->dataSize, buffer, size); 1518 if (result != TPM_RC_SUCCESS) { 1519 return result; 1520 } 1521 if (target->dataSize > MAX_NV_INDEX_SIZE) { 1522 return TPM_RC_SIZE; 1523 } 1524 return TPM_RC_SUCCESS; 1525 } 1526 1527 UINT16 TPM2B_NV_PUBLIC_Marshal(TPM2B_NV_PUBLIC* source, 1528 BYTE** buffer, 1529 INT32* size) { 1530 UINT16 total_size = 0; 1531 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1532 total_size += TPMS_NV_PUBLIC_Marshal(&source->t.nvPublic, buffer, size); 1533 { 1534 BYTE* size_location = *buffer - total_size; 1535 INT32 size_field_size = sizeof(UINT16); 1536 UINT16 payload_size = total_size - (UINT16)size_field_size; 1537 UINT16_Marshal(&payload_size, &size_location, &size_field_size); 1538 } 1539 return total_size; 1540 } 1541 1542 TPM_RC TPM2B_NV_PUBLIC_Unmarshal(TPM2B_NV_PUBLIC* target, 1543 BYTE** buffer, 1544 INT32* size) { 1545 TPM_RC result; 1546 UINT32 start_size = *size; 1547 UINT32 struct_size; 1548 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1549 if (result != TPM_RC_SUCCESS) { 1550 return result; 1551 } 1552 if (target->t.size == 0) { 1553 return TPM_RC_SIZE; 1554 } 1555 result = TPMS_NV_PUBLIC_Unmarshal(&target->t.nvPublic, buffer, size); 1556 if (result != TPM_RC_SUCCESS) { 1557 return result; 1558 } 1559 struct_size = start_size - *size - sizeof(target->t.size); 1560 if (struct_size != target->t.size) { 1561 return TPM_RC_SIZE; 1562 } 1563 return TPM_RC_SUCCESS; 1564 } 1565 1566 UINT16 TPM2B_OPERAND_Marshal(TPM2B_OPERAND* source, 1567 BYTE** buffer, 1568 INT32* size) { 1569 return TPM2B_DIGEST_Marshal(source, buffer, size); 1570 } 1571 1572 TPM_RC TPM2B_OPERAND_Unmarshal(TPM2B_OPERAND* target, 1573 BYTE** buffer, 1574 INT32* size) { 1575 return TPM2B_DIGEST_Unmarshal(target, buffer, size); 1576 } 1577 1578 UINT16 TPM2B_PRIVATE_Marshal(TPM2B_PRIVATE* source, 1579 BYTE** buffer, 1580 INT32* size) { 1581 UINT16 total_size = 0; 1582 INT32 i; 1583 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1584 for (i = 0; i < source->t.size; ++i) { 1585 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1586 } 1587 return total_size; 1588 } 1589 1590 TPM_RC TPM2B_PRIVATE_Unmarshal(TPM2B_PRIVATE* target, 1591 BYTE** buffer, 1592 INT32* size) { 1593 TPM_RC result; 1594 INT32 i; 1595 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1596 if (result != TPM_RC_SUCCESS) { 1597 return result; 1598 } 1599 if (target->t.size == 0) { 1600 return TPM_RC_SUCCESS; 1601 } 1602 if (target->t.size > sizeof(_PRIVATE)) { 1603 return TPM_RC_SIZE; 1604 } 1605 for (i = 0; i < target->t.size; ++i) { 1606 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1607 if (result != TPM_RC_SUCCESS) { 1608 return result; 1609 } 1610 } 1611 return TPM_RC_SUCCESS; 1612 } 1613 1614 UINT16 TPM2B_PRIVATE_KEY_RSA_Marshal(TPM2B_PRIVATE_KEY_RSA* source, 1615 BYTE** buffer, 1616 INT32* size) { 1617 UINT16 total_size = 0; 1618 INT32 i; 1619 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1620 for (i = 0; i < source->t.size; ++i) { 1621 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1622 } 1623 return total_size; 1624 } 1625 1626 TPM_RC TPM2B_PRIVATE_KEY_RSA_Unmarshal(TPM2B_PRIVATE_KEY_RSA* target, 1627 BYTE** buffer, 1628 INT32* size) { 1629 TPM_RC result; 1630 INT32 i; 1631 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1632 if (result != TPM_RC_SUCCESS) { 1633 return result; 1634 } 1635 if (target->t.size == 0) { 1636 return TPM_RC_SUCCESS; 1637 } 1638 if (target->t.size > MAX_RSA_KEY_BYTES / 2) { 1639 return TPM_RC_SIZE; 1640 } 1641 for (i = 0; i < target->t.size; ++i) { 1642 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1643 if (result != TPM_RC_SUCCESS) { 1644 return result; 1645 } 1646 } 1647 return TPM_RC_SUCCESS; 1648 } 1649 1650 UINT16 TPM2B_PRIVATE_VENDOR_SPECIFIC_Marshal( 1651 TPM2B_PRIVATE_VENDOR_SPECIFIC* source, 1652 BYTE** buffer, 1653 INT32* size) { 1654 UINT16 total_size = 0; 1655 INT32 i; 1656 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1657 for (i = 0; i < source->t.size; ++i) { 1658 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1659 } 1660 return total_size; 1661 } 1662 1663 TPM_RC TPM2B_PRIVATE_VENDOR_SPECIFIC_Unmarshal( 1664 TPM2B_PRIVATE_VENDOR_SPECIFIC* target, 1665 BYTE** buffer, 1666 INT32* size) { 1667 TPM_RC result; 1668 INT32 i; 1669 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1670 if (result != TPM_RC_SUCCESS) { 1671 return result; 1672 } 1673 if (target->t.size == 0) { 1674 return TPM_RC_SUCCESS; 1675 } 1676 if (target->t.size > PRIVATE_VENDOR_SPECIFIC_BYTES) { 1677 return TPM_RC_SIZE; 1678 } 1679 for (i = 0; i < target->t.size; ++i) { 1680 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1681 if (result != TPM_RC_SUCCESS) { 1682 return result; 1683 } 1684 } 1685 return TPM_RC_SUCCESS; 1686 } 1687 1688 UINT16 TPMA_OBJECT_Marshal(TPMA_OBJECT* source, BYTE** buffer, INT32* size) { 1689 return uint32_t_Marshal((uint32_t*)source, buffer, size); 1690 } 1691 1692 TPM_RC TPMA_OBJECT_Unmarshal(TPMA_OBJECT* target, BYTE** buffer, INT32* size) { 1693 TPM_RC result; 1694 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 1695 if (result != TPM_RC_SUCCESS) { 1696 return result; 1697 } 1698 if (target->reserved0 != 0) { 1699 return TPM_RC_RESERVED_BITS; 1700 } 1701 if (target->reserved3 != 0) { 1702 return TPM_RC_RESERVED_BITS; 1703 } 1704 if (target->reserved8_9 != 0) { 1705 return TPM_RC_RESERVED_BITS; 1706 } 1707 if (target->reserved12_15 != 0) { 1708 return TPM_RC_RESERVED_BITS; 1709 } 1710 if (target->reserved19_31 != 0) { 1711 return TPM_RC_RESERVED_BITS; 1712 } 1713 return TPM_RC_SUCCESS; 1714 } 1715 1716 UINT16 TPMI_ALG_PUBLIC_Marshal(TPMI_ALG_PUBLIC* source, 1717 BYTE** buffer, 1718 INT32* size) { 1719 return uint16_t_Marshal(source, buffer, size); 1720 } 1721 1722 TPM_RC TPMI_ALG_PUBLIC_Unmarshal(TPMI_ALG_PUBLIC* target, 1723 BYTE** buffer, 1724 INT32* size) { 1725 TPM_RC result; 1726 BOOL has_valid_value = FALSE; 1727 result = uint16_t_Unmarshal(target, buffer, size); 1728 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 1729 return result; 1730 } 1731 switch (*target) { 1732 #ifdef TPM_ALG_RSA 1733 case TPM_ALG_RSA: 1734 #endif 1735 #ifdef TPM_ALG_KEYEDHASH 1736 case TPM_ALG_KEYEDHASH: 1737 #endif 1738 #ifdef TPM_ALG_ECC 1739 case TPM_ALG_ECC: 1740 #endif 1741 #ifdef TPM_ALG_SYMCIPHER 1742 case TPM_ALG_SYMCIPHER: 1743 #endif 1744 has_valid_value = TRUE; 1745 break; 1746 } 1747 if (!has_valid_value) { 1748 return TPM_RC_TYPE; 1749 } 1750 return TPM_RC_SUCCESS; 1751 } 1752 1753 UINT16 TPM2B_PUBLIC_KEY_RSA_Marshal(TPM2B_PUBLIC_KEY_RSA* source, 1754 BYTE** buffer, 1755 INT32* size) { 1756 UINT16 total_size = 0; 1757 INT32 i; 1758 total_size += UINT16_Marshal(&source->t.size, buffer, size); 1759 for (i = 0; i < source->t.size; ++i) { 1760 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 1761 } 1762 return total_size; 1763 } 1764 1765 TPM_RC TPM2B_PUBLIC_KEY_RSA_Unmarshal(TPM2B_PUBLIC_KEY_RSA* target, 1766 BYTE** buffer, 1767 INT32* size) { 1768 TPM_RC result; 1769 INT32 i; 1770 result = UINT16_Unmarshal(&target->t.size, buffer, size); 1771 if (result != TPM_RC_SUCCESS) { 1772 return result; 1773 } 1774 if (target->t.size == 0) { 1775 return TPM_RC_SUCCESS; 1776 } 1777 if (target->t.size > MAX_RSA_KEY_BYTES) { 1778 return TPM_RC_SIZE; 1779 } 1780 for (i = 0; i < target->t.size; ++i) { 1781 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 1782 if (result != TPM_RC_SUCCESS) { 1783 return result; 1784 } 1785 } 1786 return TPM_RC_SUCCESS; 1787 } 1788 1789 UINT16 TPMU_PUBLIC_ID_Marshal(TPMU_PUBLIC_ID* source, 1790 BYTE** buffer, 1791 INT32* size, 1792 UINT32 selector) { 1793 switch (selector) { 1794 #ifdef TPM_ALG_KEYEDHASH 1795 case TPM_ALG_KEYEDHASH: 1796 return TPM2B_DIGEST_Marshal((TPM2B_DIGEST*)&source->keyedHash, buffer, 1797 size); 1798 #endif 1799 #ifdef TPM_ALG_SYMCIPHER 1800 case TPM_ALG_SYMCIPHER: 1801 return TPM2B_DIGEST_Marshal((TPM2B_DIGEST*)&source->sym, buffer, size); 1802 #endif 1803 #ifdef TPM_ALG_RSA 1804 case TPM_ALG_RSA: 1805 return TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA*)&source->rsa, 1806 buffer, size); 1807 #endif 1808 #ifdef TPM_ALG_ECC 1809 case TPM_ALG_ECC: 1810 return TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT*)&source->ecc, buffer, 1811 size); 1812 #endif 1813 } 1814 return 0; 1815 } 1816 1817 TPM_RC TPMU_PUBLIC_ID_Unmarshal(TPMU_PUBLIC_ID* target, 1818 BYTE** buffer, 1819 INT32* size, 1820 UINT32 selector) { 1821 switch (selector) { 1822 #ifdef TPM_ALG_KEYEDHASH 1823 case TPM_ALG_KEYEDHASH: 1824 return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST*)&target->keyedHash, buffer, 1825 size); 1826 #endif 1827 #ifdef TPM_ALG_SYMCIPHER 1828 case TPM_ALG_SYMCIPHER: 1829 return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST*)&target->sym, buffer, size); 1830 #endif 1831 #ifdef TPM_ALG_RSA 1832 case TPM_ALG_RSA: 1833 return TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA*)&target->rsa, 1834 buffer, size); 1835 #endif 1836 #ifdef TPM_ALG_ECC 1837 case TPM_ALG_ECC: 1838 return TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT*)&target->ecc, buffer, 1839 size); 1840 #endif 1841 } 1842 return TPM_RC_SELECTOR; 1843 } 1844 1845 UINT16 TPM_KEY_BITS_Marshal(TPM_KEY_BITS* source, BYTE** buffer, INT32* size) { 1846 return uint16_t_Marshal(source, buffer, size); 1847 } 1848 1849 TPM_RC TPM_KEY_BITS_Unmarshal(TPM_KEY_BITS* target, 1850 BYTE** buffer, 1851 INT32* size) { 1852 return uint16_t_Unmarshal(target, buffer, size); 1853 } 1854 1855 UINT16 TPMI_AES_KEY_BITS_Marshal(TPMI_AES_KEY_BITS* source, 1856 BYTE** buffer, 1857 INT32* size) { 1858 return TPM_KEY_BITS_Marshal(source, buffer, size); 1859 } 1860 1861 TPM_RC TPMI_AES_KEY_BITS_Unmarshal(TPMI_AES_KEY_BITS* target, 1862 BYTE** buffer, 1863 INT32* size) { 1864 TPM_RC result; 1865 uint16_t supported_values[] = AES_KEY_SIZES_BITS; 1866 size_t length = sizeof(supported_values) / sizeof(supported_values[0]); 1867 size_t i; 1868 BOOL is_supported_value = FALSE; 1869 result = TPM_KEY_BITS_Unmarshal(target, buffer, size); 1870 if (result != TPM_RC_SUCCESS) { 1871 return result; 1872 } 1873 for (i = 0; i < length; ++i) { 1874 if (*target == supported_values[i]) { 1875 is_supported_value = TRUE; 1876 break; 1877 } 1878 } 1879 if (!is_supported_value) { 1880 return TPM_RC_VALUE; 1881 } 1882 return TPM_RC_SUCCESS; 1883 } 1884 1885 UINT16 TPMI_SM4_KEY_BITS_Marshal(TPMI_SM4_KEY_BITS* source, 1886 BYTE** buffer, 1887 INT32* size) { 1888 return TPM_KEY_BITS_Marshal(source, buffer, size); 1889 } 1890 1891 TPM_RC TPMI_SM4_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS* target, 1892 BYTE** buffer, 1893 INT32* size) { 1894 TPM_RC result; 1895 uint16_t supported_values[] = SM4_KEY_SIZES_BITS; 1896 size_t length = sizeof(supported_values) / sizeof(supported_values[0]); 1897 size_t i; 1898 BOOL is_supported_value = FALSE; 1899 result = TPM_KEY_BITS_Unmarshal(target, buffer, size); 1900 if (result != TPM_RC_SUCCESS) { 1901 return result; 1902 } 1903 for (i = 0; i < length; ++i) { 1904 if (*target == supported_values[i]) { 1905 is_supported_value = TRUE; 1906 break; 1907 } 1908 } 1909 if (!is_supported_value) { 1910 return TPM_RC_VALUE; 1911 } 1912 return TPM_RC_SUCCESS; 1913 } 1914 1915 UINT16 TPMI_CAMELLIA_KEY_BITS_Marshal(TPMI_CAMELLIA_KEY_BITS* source, 1916 BYTE** buffer, 1917 INT32* size) { 1918 return TPM_KEY_BITS_Marshal(source, buffer, size); 1919 } 1920 1921 TPM_RC TPMI_CAMELLIA_KEY_BITS_Unmarshal(TPMI_CAMELLIA_KEY_BITS* target, 1922 BYTE** buffer, 1923 INT32* size) { 1924 TPM_RC result; 1925 uint16_t supported_values[] = CAMELLIA_KEY_SIZES_BITS; 1926 size_t length = sizeof(supported_values) / sizeof(supported_values[0]); 1927 size_t i; 1928 BOOL is_supported_value = FALSE; 1929 result = TPM_KEY_BITS_Unmarshal(target, buffer, size); 1930 if (result != TPM_RC_SUCCESS) { 1931 return result; 1932 } 1933 for (i = 0; i < length; ++i) { 1934 if (*target == supported_values[i]) { 1935 is_supported_value = TRUE; 1936 break; 1937 } 1938 } 1939 if (!is_supported_value) { 1940 return TPM_RC_VALUE; 1941 } 1942 return TPM_RC_SUCCESS; 1943 } 1944 1945 UINT16 TPMU_SYM_KEY_BITS_Marshal(TPMU_SYM_KEY_BITS* source, 1946 BYTE** buffer, 1947 INT32* size, 1948 UINT32 selector) { 1949 switch (selector) { 1950 #ifdef TPM_ALG_AES 1951 case TPM_ALG_AES: 1952 return TPMI_AES_KEY_BITS_Marshal((TPMI_AES_KEY_BITS*)&source->aes, buffer, 1953 size); 1954 #endif 1955 #ifdef TPM_ALG_SM4 1956 case TPM_ALG_SM4: 1957 return TPMI_SM4_KEY_BITS_Marshal((TPMI_SM4_KEY_BITS*)&source->sm4, buffer, 1958 size); 1959 #endif 1960 #ifdef TPM_ALG_CAMELLIA 1961 case TPM_ALG_CAMELLIA: 1962 return TPMI_CAMELLIA_KEY_BITS_Marshal( 1963 (TPMI_CAMELLIA_KEY_BITS*)&source->camellia, buffer, size); 1964 #endif 1965 #ifdef TPM_ALG_XOR 1966 case TPM_ALG_XOR: 1967 return TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH*)&source->xor_, buffer, size); 1968 #endif 1969 #ifdef TPM_ALG_NULL 1970 case TPM_ALG_NULL: 1971 return 0; 1972 #endif 1973 } 1974 return 0; 1975 } 1976 1977 TPM_RC TPMU_SYM_KEY_BITS_Unmarshal(TPMU_SYM_KEY_BITS* target, 1978 BYTE** buffer, 1979 INT32* size, 1980 UINT32 selector) { 1981 switch (selector) { 1982 #ifdef TPM_ALG_AES 1983 case TPM_ALG_AES: 1984 return TPMI_AES_KEY_BITS_Unmarshal((TPMI_AES_KEY_BITS*)&target->aes, 1985 buffer, size); 1986 #endif 1987 #ifdef TPM_ALG_SM4 1988 case TPM_ALG_SM4: 1989 return TPMI_SM4_KEY_BITS_Unmarshal((TPMI_SM4_KEY_BITS*)&target->sm4, 1990 buffer, size); 1991 #endif 1992 #ifdef TPM_ALG_CAMELLIA 1993 case TPM_ALG_CAMELLIA: 1994 return TPMI_CAMELLIA_KEY_BITS_Unmarshal( 1995 (TPMI_CAMELLIA_KEY_BITS*)&target->camellia, buffer, size); 1996 #endif 1997 #ifdef TPM_ALG_XOR 1998 case TPM_ALG_XOR: 1999 return TPMI_ALG_HASH_Unmarshal(&target->xor_, buffer, size, FALSE); 2000 #endif 2001 #ifdef TPM_ALG_NULL 2002 case TPM_ALG_NULL: 2003 return TPM_RC_SUCCESS; 2004 #endif 2005 } 2006 return TPM_RC_SELECTOR; 2007 } 2008 2009 UINT16 TPMI_ALG_SYM_MODE_Marshal(TPMI_ALG_SYM_MODE* source, 2010 BYTE** buffer, 2011 INT32* size) { 2012 return uint16_t_Marshal(source, buffer, size); 2013 } 2014 2015 TPM_RC TPMI_ALG_SYM_MODE_Unmarshal(TPMI_ALG_SYM_MODE* target, 2016 BYTE** buffer, 2017 INT32* size, 2018 BOOL allow_conditional_value) { 2019 TPM_RC result; 2020 BOOL has_valid_value = FALSE; 2021 result = uint16_t_Unmarshal(target, buffer, size); 2022 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2023 return result; 2024 } 2025 if (*target == TPM_ALG_NULL) { 2026 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_MODE; 2027 } 2028 switch (*target) { 2029 #ifdef TPM_ALG_CTR 2030 case TPM_ALG_CTR: 2031 #endif 2032 #ifdef TPM_ALG_OFB 2033 case TPM_ALG_OFB: 2034 #endif 2035 #ifdef TPM_ALG_CBC 2036 case TPM_ALG_CBC: 2037 #endif 2038 #ifdef TPM_ALG_CFB 2039 case TPM_ALG_CFB: 2040 #endif 2041 #ifdef TPM_ALG_ECB 2042 case TPM_ALG_ECB: 2043 #endif 2044 has_valid_value = TRUE; 2045 break; 2046 } 2047 if (!has_valid_value) { 2048 return TPM_RC_MODE; 2049 } 2050 return TPM_RC_SUCCESS; 2051 } 2052 2053 UINT16 TPMU_SYM_MODE_Marshal(TPMU_SYM_MODE* source, 2054 BYTE** buffer, 2055 INT32* size, 2056 UINT32 selector) { 2057 switch (selector) { 2058 #ifdef TPM_ALG_AES 2059 case TPM_ALG_AES: 2060 return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE*)&source->aes, buffer, 2061 size); 2062 #endif 2063 #ifdef TPM_ALG_SM4 2064 case TPM_ALG_SM4: 2065 return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE*)&source->sm4, buffer, 2066 size); 2067 #endif 2068 #ifdef TPM_ALG_CAMELLIA 2069 case TPM_ALG_CAMELLIA: 2070 return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE*)&source->camellia, 2071 buffer, size); 2072 #endif 2073 #ifdef TPM_ALG_XOR 2074 case TPM_ALG_XOR: 2075 return 0; 2076 #endif 2077 #ifdef TPM_ALG_NULL 2078 case TPM_ALG_NULL: 2079 return 0; 2080 #endif 2081 } 2082 return 0; 2083 } 2084 2085 TPM_RC TPMU_SYM_MODE_Unmarshal(TPMU_SYM_MODE* target, 2086 BYTE** buffer, 2087 INT32* size, 2088 UINT32 selector) { 2089 switch (selector) { 2090 #ifdef TPM_ALG_AES 2091 case TPM_ALG_AES: 2092 return TPMI_ALG_SYM_MODE_Unmarshal(&target->aes, buffer, size, FALSE); 2093 #endif 2094 #ifdef TPM_ALG_SM4 2095 case TPM_ALG_SM4: 2096 return TPMI_ALG_SYM_MODE_Unmarshal(&target->sm4, buffer, size, FALSE); 2097 #endif 2098 #ifdef TPM_ALG_CAMELLIA 2099 case TPM_ALG_CAMELLIA: 2100 return TPMI_ALG_SYM_MODE_Unmarshal(&target->camellia, buffer, size, 2101 FALSE); 2102 #endif 2103 #ifdef TPM_ALG_XOR 2104 case TPM_ALG_XOR: 2105 return TPM_RC_SUCCESS; 2106 #endif 2107 #ifdef TPM_ALG_NULL 2108 case TPM_ALG_NULL: 2109 return TPM_RC_SUCCESS; 2110 #endif 2111 } 2112 return TPM_RC_SELECTOR; 2113 } 2114 2115 UINT16 TPMI_ALG_SYM_OBJECT_Marshal(TPMI_ALG_SYM_OBJECT* source, 2116 BYTE** buffer, 2117 INT32* size) { 2118 return uint16_t_Marshal(source, buffer, size); 2119 } 2120 2121 TPM_RC TPMI_ALG_SYM_OBJECT_Unmarshal(TPMI_ALG_SYM_OBJECT* target, 2122 BYTE** buffer, 2123 INT32* size, 2124 BOOL allow_conditional_value) { 2125 TPM_RC result; 2126 BOOL has_valid_value = FALSE; 2127 result = uint16_t_Unmarshal(target, buffer, size); 2128 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2129 return result; 2130 } 2131 if (*target == TPM_ALG_NULL) { 2132 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SYMMETRIC; 2133 } 2134 switch (*target) { 2135 #ifdef TPM_ALG_AES 2136 case TPM_ALG_AES: 2137 #endif 2138 #ifdef TPM_ALG_SM4 2139 case TPM_ALG_SM4: 2140 #endif 2141 #ifdef TPM_ALG_CAMELLIA 2142 case TPM_ALG_CAMELLIA: 2143 #endif 2144 has_valid_value = TRUE; 2145 break; 2146 } 2147 if (!has_valid_value) { 2148 return TPM_RC_SYMMETRIC; 2149 } 2150 return TPM_RC_SUCCESS; 2151 } 2152 2153 UINT16 TPMT_SYM_DEF_OBJECT_Marshal(TPMT_SYM_DEF_OBJECT* source, 2154 BYTE** buffer, 2155 INT32* size) { 2156 UINT16 total_size = 0; 2157 total_size += TPMI_ALG_SYM_OBJECT_Marshal(&source->algorithm, buffer, size); 2158 total_size += TPMU_SYM_KEY_BITS_Marshal(&source->keyBits, buffer, size, 2159 source->algorithm); 2160 total_size += 2161 TPMU_SYM_MODE_Marshal(&source->mode, buffer, size, source->algorithm); 2162 return total_size; 2163 } 2164 2165 TPM_RC TPMT_SYM_DEF_OBJECT_Unmarshal(TPMT_SYM_DEF_OBJECT* target, 2166 BYTE** buffer, 2167 INT32* size) { 2168 TPM_RC result; 2169 result = 2170 TPMI_ALG_SYM_OBJECT_Unmarshal(&target->algorithm, buffer, size, TRUE); 2171 if (result != TPM_RC_SUCCESS) { 2172 return result; 2173 } 2174 result = TPMU_SYM_KEY_BITS_Unmarshal(&target->keyBits, buffer, size, 2175 target->algorithm); 2176 if (result != TPM_RC_SUCCESS) { 2177 return result; 2178 } 2179 result = 2180 TPMU_SYM_MODE_Unmarshal(&target->mode, buffer, size, target->algorithm); 2181 if (result != TPM_RC_SUCCESS) { 2182 return result; 2183 } 2184 return TPM_RC_SUCCESS; 2185 } 2186 2187 UINT16 TPMI_ALG_RSA_SCHEME_Marshal(TPMI_ALG_RSA_SCHEME* source, 2188 BYTE** buffer, 2189 INT32* size) { 2190 return uint16_t_Marshal(source, buffer, size); 2191 } 2192 2193 TPM_RC TPMI_ALG_RSA_SCHEME_Unmarshal(TPMI_ALG_RSA_SCHEME* target, 2194 BYTE** buffer, 2195 INT32* size, 2196 BOOL allow_conditional_value) { 2197 TPM_RC result; 2198 BOOL has_valid_value = FALSE; 2199 result = uint16_t_Unmarshal(target, buffer, size); 2200 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2201 return result; 2202 } 2203 if (*target == TPM_ALG_NULL) { 2204 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 2205 } 2206 switch (*target) { 2207 #ifdef TPM_ALG_RSAES 2208 case TPM_ALG_RSAES: 2209 #endif 2210 #ifdef TPM_ALG_OAEP 2211 case TPM_ALG_OAEP: 2212 #endif 2213 #ifdef TPM_ALG_RSASSA 2214 case TPM_ALG_RSASSA: 2215 #endif 2216 #ifdef TPM_ALG_RSAPSS 2217 case TPM_ALG_RSAPSS: 2218 #endif 2219 has_valid_value = TRUE; 2220 break; 2221 } 2222 if (!has_valid_value) { 2223 return TPM_RC_VALUE; 2224 } 2225 return TPM_RC_SUCCESS; 2226 } 2227 2228 UINT16 TPMS_SCHEME_HASH_Marshal(TPMS_SCHEME_HASH* source, 2229 BYTE** buffer, 2230 INT32* size) { 2231 UINT16 total_size = 0; 2232 total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size); 2233 return total_size; 2234 } 2235 2236 TPM_RC TPMS_SCHEME_HASH_Unmarshal(TPMS_SCHEME_HASH* target, 2237 BYTE** buffer, 2238 INT32* size) { 2239 TPM_RC result; 2240 result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, FALSE); 2241 if (result != TPM_RC_SUCCESS) { 2242 return result; 2243 } 2244 return TPM_RC_SUCCESS; 2245 } 2246 2247 UINT16 TPMS_SIG_SCHEME_RSAPSS_Marshal(TPMS_SIG_SCHEME_RSAPSS* source, 2248 BYTE** buffer, 2249 INT32* size) { 2250 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2251 } 2252 2253 TPM_RC TPMS_SIG_SCHEME_RSAPSS_Unmarshal(TPMS_SIG_SCHEME_RSAPSS* target, 2254 BYTE** buffer, 2255 INT32* size) { 2256 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2257 } 2258 2259 UINT16 TPMS_SIG_SCHEME_SM2_Marshal(TPMS_SIG_SCHEME_SM2* source, 2260 BYTE** buffer, 2261 INT32* size) { 2262 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2263 } 2264 2265 TPM_RC TPMS_SIG_SCHEME_SM2_Unmarshal(TPMS_SIG_SCHEME_SM2* target, 2266 BYTE** buffer, 2267 INT32* size) { 2268 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2269 } 2270 2271 UINT16 TPMS_SIG_SCHEME_ECSCHNORR_Marshal(TPMS_SIG_SCHEME_ECSCHNORR* source, 2272 BYTE** buffer, 2273 INT32* size) { 2274 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2275 } 2276 2277 TPM_RC TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal(TPMS_SIG_SCHEME_ECSCHNORR* target, 2278 BYTE** buffer, 2279 INT32* size) { 2280 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2281 } 2282 2283 UINT16 TPMS_SCHEME_ECDAA_Marshal(TPMS_SCHEME_ECDAA* source, 2284 BYTE** buffer, 2285 INT32* size) { 2286 UINT16 total_size = 0; 2287 total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size); 2288 total_size += UINT16_Marshal(&source->count, buffer, size); 2289 return total_size; 2290 } 2291 2292 TPM_RC TPMS_SCHEME_ECDAA_Unmarshal(TPMS_SCHEME_ECDAA* target, 2293 BYTE** buffer, 2294 INT32* size) { 2295 TPM_RC result; 2296 result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, FALSE); 2297 if (result != TPM_RC_SUCCESS) { 2298 return result; 2299 } 2300 result = UINT16_Unmarshal(&target->count, buffer, size); 2301 if (result != TPM_RC_SUCCESS) { 2302 return result; 2303 } 2304 return TPM_RC_SUCCESS; 2305 } 2306 2307 UINT16 TPMS_SIG_SCHEME_ECDAA_Marshal(TPMS_SIG_SCHEME_ECDAA* source, 2308 BYTE** buffer, 2309 INT32* size) { 2310 return TPMS_SCHEME_ECDAA_Marshal(source, buffer, size); 2311 } 2312 2313 TPM_RC TPMS_SIG_SCHEME_ECDAA_Unmarshal(TPMS_SIG_SCHEME_ECDAA* target, 2314 BYTE** buffer, 2315 INT32* size) { 2316 return TPMS_SCHEME_ECDAA_Unmarshal(target, buffer, size); 2317 } 2318 2319 UINT16 TPMS_KEY_SCHEME_ECDH_Marshal(TPMS_KEY_SCHEME_ECDH* source, 2320 BYTE** buffer, 2321 INT32* size) { 2322 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2323 } 2324 2325 TPM_RC TPMS_KEY_SCHEME_ECDH_Unmarshal(TPMS_KEY_SCHEME_ECDH* target, 2326 BYTE** buffer, 2327 INT32* size) { 2328 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2329 } 2330 2331 UINT16 TPMS_KEY_SCHEME_ECMQV_Marshal(TPMS_KEY_SCHEME_ECMQV* source, 2332 BYTE** buffer, 2333 INT32* size) { 2334 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2335 } 2336 2337 TPM_RC TPMS_KEY_SCHEME_ECMQV_Unmarshal(TPMS_KEY_SCHEME_ECMQV* target, 2338 BYTE** buffer, 2339 INT32* size) { 2340 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2341 } 2342 2343 UINT16 TPMS_SIG_SCHEME_RSASSA_Marshal(TPMS_SIG_SCHEME_RSASSA* source, 2344 BYTE** buffer, 2345 INT32* size) { 2346 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2347 } 2348 2349 TPM_RC TPMS_SIG_SCHEME_RSASSA_Unmarshal(TPMS_SIG_SCHEME_RSASSA* target, 2350 BYTE** buffer, 2351 INT32* size) { 2352 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2353 } 2354 2355 UINT16 TPMS_ENC_SCHEME_OAEP_Marshal(TPMS_ENC_SCHEME_OAEP* source, 2356 BYTE** buffer, 2357 INT32* size) { 2358 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2359 } 2360 2361 TPM_RC TPMS_ENC_SCHEME_OAEP_Unmarshal(TPMS_ENC_SCHEME_OAEP* target, 2362 BYTE** buffer, 2363 INT32* size) { 2364 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2365 } 2366 2367 UINT16 TPMS_EMPTY_Marshal(TPMS_EMPTY* source, BYTE** buffer, INT32* size) { 2368 UINT16 total_size = 0; 2369 return total_size; 2370 } 2371 2372 TPM_RC TPMS_EMPTY_Unmarshal(TPMS_EMPTY* target, BYTE** buffer, INT32* size) { 2373 TPM_RC result; 2374 (void)result; 2375 2376 return TPM_RC_SUCCESS; 2377 } 2378 2379 UINT16 TPMS_ENC_SCHEME_RSAES_Marshal(TPMS_ENC_SCHEME_RSAES* source, 2380 BYTE** buffer, 2381 INT32* size) { 2382 return TPMS_EMPTY_Marshal(source, buffer, size); 2383 } 2384 2385 TPM_RC TPMS_ENC_SCHEME_RSAES_Unmarshal(TPMS_ENC_SCHEME_RSAES* target, 2386 BYTE** buffer, 2387 INT32* size) { 2388 return TPMS_EMPTY_Unmarshal(target, buffer, size); 2389 } 2390 2391 UINT16 TPMS_SIG_SCHEME_ECDSA_Marshal(TPMS_SIG_SCHEME_ECDSA* source, 2392 BYTE** buffer, 2393 INT32* size) { 2394 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2395 } 2396 2397 TPM_RC TPMS_SIG_SCHEME_ECDSA_Unmarshal(TPMS_SIG_SCHEME_ECDSA* target, 2398 BYTE** buffer, 2399 INT32* size) { 2400 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2401 } 2402 2403 UINT16 TPMU_ASYM_SCHEME_Marshal(TPMU_ASYM_SCHEME* source, 2404 BYTE** buffer, 2405 INT32* size, 2406 UINT32 selector) { 2407 switch (selector) { 2408 #ifdef TPM_ALG_ECDH 2409 case TPM_ALG_ECDH: 2410 return TPMS_KEY_SCHEME_ECDH_Marshal((TPMS_KEY_SCHEME_ECDH*)&source->ecdh, 2411 buffer, size); 2412 #endif 2413 #ifdef TPM_ALG_ECMQV 2414 case TPM_ALG_ECMQV: 2415 return TPMS_KEY_SCHEME_ECMQV_Marshal( 2416 (TPMS_KEY_SCHEME_ECMQV*)&source->ecmqv, buffer, size); 2417 #endif 2418 #ifdef TPM_ALG_RSASSA 2419 case TPM_ALG_RSASSA: 2420 return TPMS_SIG_SCHEME_RSASSA_Marshal( 2421 (TPMS_SIG_SCHEME_RSASSA*)&source->rsassa, buffer, size); 2422 #endif 2423 #ifdef TPM_ALG_RSAPSS 2424 case TPM_ALG_RSAPSS: 2425 return TPMS_SIG_SCHEME_RSAPSS_Marshal( 2426 (TPMS_SIG_SCHEME_RSAPSS*)&source->rsapss, buffer, size); 2427 #endif 2428 #ifdef TPM_ALG_ECDSA 2429 case TPM_ALG_ECDSA: 2430 return TPMS_SIG_SCHEME_ECDSA_Marshal( 2431 (TPMS_SIG_SCHEME_ECDSA*)&source->ecdsa, buffer, size); 2432 #endif 2433 #ifdef TPM_ALG_ECDAA 2434 case TPM_ALG_ECDAA: 2435 return TPMS_SIG_SCHEME_ECDAA_Marshal( 2436 (TPMS_SIG_SCHEME_ECDAA*)&source->ecdaa, buffer, size); 2437 #endif 2438 #ifdef TPM_ALG_SM2 2439 case TPM_ALG_SM2: 2440 return TPMS_SIG_SCHEME_SM2_Marshal((TPMS_SIG_SCHEME_SM2*)&source->sm2, 2441 buffer, size); 2442 #endif 2443 #ifdef TPM_ALG_ECSCHNORR 2444 case TPM_ALG_ECSCHNORR: 2445 return TPMS_SIG_SCHEME_ECSCHNORR_Marshal( 2446 (TPMS_SIG_SCHEME_ECSCHNORR*)&source->ecschnorr, buffer, size); 2447 #endif 2448 #ifdef TPM_ALG_RSAES 2449 case TPM_ALG_RSAES: 2450 return TPMS_ENC_SCHEME_RSAES_Marshal( 2451 (TPMS_ENC_SCHEME_RSAES*)&source->rsaes, buffer, size); 2452 #endif 2453 #ifdef TPM_ALG_OAEP 2454 case TPM_ALG_OAEP: 2455 return TPMS_ENC_SCHEME_OAEP_Marshal((TPMS_ENC_SCHEME_OAEP*)&source->oaep, 2456 buffer, size); 2457 #endif 2458 #ifdef TPM_ALG_NULL 2459 case TPM_ALG_NULL: 2460 return 0; 2461 #endif 2462 } 2463 return 0; 2464 } 2465 2466 TPM_RC TPMU_ASYM_SCHEME_Unmarshal(TPMU_ASYM_SCHEME* target, 2467 BYTE** buffer, 2468 INT32* size, 2469 UINT32 selector) { 2470 switch (selector) { 2471 #ifdef TPM_ALG_ECDH 2472 case TPM_ALG_ECDH: 2473 return TPMS_KEY_SCHEME_ECDH_Unmarshal( 2474 (TPMS_KEY_SCHEME_ECDH*)&target->ecdh, buffer, size); 2475 #endif 2476 #ifdef TPM_ALG_ECMQV 2477 case TPM_ALG_ECMQV: 2478 return TPMS_KEY_SCHEME_ECMQV_Unmarshal( 2479 (TPMS_KEY_SCHEME_ECMQV*)&target->ecmqv, buffer, size); 2480 #endif 2481 #ifdef TPM_ALG_RSASSA 2482 case TPM_ALG_RSASSA: 2483 return TPMS_SIG_SCHEME_RSASSA_Unmarshal( 2484 (TPMS_SIG_SCHEME_RSASSA*)&target->rsassa, buffer, size); 2485 #endif 2486 #ifdef TPM_ALG_RSAPSS 2487 case TPM_ALG_RSAPSS: 2488 return TPMS_SIG_SCHEME_RSAPSS_Unmarshal( 2489 (TPMS_SIG_SCHEME_RSAPSS*)&target->rsapss, buffer, size); 2490 #endif 2491 #ifdef TPM_ALG_ECDSA 2492 case TPM_ALG_ECDSA: 2493 return TPMS_SIG_SCHEME_ECDSA_Unmarshal( 2494 (TPMS_SIG_SCHEME_ECDSA*)&target->ecdsa, buffer, size); 2495 #endif 2496 #ifdef TPM_ALG_ECDAA 2497 case TPM_ALG_ECDAA: 2498 return TPMS_SIG_SCHEME_ECDAA_Unmarshal( 2499 (TPMS_SIG_SCHEME_ECDAA*)&target->ecdaa, buffer, size); 2500 #endif 2501 #ifdef TPM_ALG_SM2 2502 case TPM_ALG_SM2: 2503 return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2*)&target->sm2, 2504 buffer, size); 2505 #endif 2506 #ifdef TPM_ALG_ECSCHNORR 2507 case TPM_ALG_ECSCHNORR: 2508 return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal( 2509 (TPMS_SIG_SCHEME_ECSCHNORR*)&target->ecschnorr, buffer, size); 2510 #endif 2511 #ifdef TPM_ALG_RSAES 2512 case TPM_ALG_RSAES: 2513 return TPMS_ENC_SCHEME_RSAES_Unmarshal( 2514 (TPMS_ENC_SCHEME_RSAES*)&target->rsaes, buffer, size); 2515 #endif 2516 #ifdef TPM_ALG_OAEP 2517 case TPM_ALG_OAEP: 2518 return TPMS_ENC_SCHEME_OAEP_Unmarshal( 2519 (TPMS_ENC_SCHEME_OAEP*)&target->oaep, buffer, size); 2520 #endif 2521 #ifdef TPM_ALG_NULL 2522 case TPM_ALG_NULL: 2523 return TPM_RC_SUCCESS; 2524 #endif 2525 } 2526 return TPM_RC_SELECTOR; 2527 } 2528 2529 UINT16 TPMT_RSA_SCHEME_Marshal(TPMT_RSA_SCHEME* source, 2530 BYTE** buffer, 2531 INT32* size) { 2532 UINT16 total_size = 0; 2533 total_size += TPMI_ALG_RSA_SCHEME_Marshal(&source->scheme, buffer, size); 2534 total_size += 2535 TPMU_ASYM_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 2536 return total_size; 2537 } 2538 2539 TPM_RC TPMT_RSA_SCHEME_Unmarshal(TPMT_RSA_SCHEME* target, 2540 BYTE** buffer, 2541 INT32* size) { 2542 TPM_RC result; 2543 result = TPMI_ALG_RSA_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE); 2544 if (result != TPM_RC_SUCCESS) { 2545 return result; 2546 } 2547 result = TPMU_ASYM_SCHEME_Unmarshal(&target->details, buffer, size, 2548 target->scheme); 2549 if (result != TPM_RC_SUCCESS) { 2550 return result; 2551 } 2552 return TPM_RC_SUCCESS; 2553 } 2554 2555 UINT16 TPMI_RSA_KEY_BITS_Marshal(TPMI_RSA_KEY_BITS* source, 2556 BYTE** buffer, 2557 INT32* size) { 2558 return uint16_t_Marshal(source, buffer, size); 2559 } 2560 2561 TPM_RC TPMI_RSA_KEY_BITS_Unmarshal(TPMI_RSA_KEY_BITS* target, 2562 BYTE** buffer, 2563 INT32* size) { 2564 TPM_RC result; 2565 uint16_t supported_values[] = RSA_KEY_SIZES_BITS; 2566 size_t length = sizeof(supported_values) / sizeof(supported_values[0]); 2567 size_t i; 2568 BOOL is_supported_value = FALSE; 2569 result = uint16_t_Unmarshal(target, buffer, size); 2570 if (result != TPM_RC_SUCCESS) { 2571 return result; 2572 } 2573 for (i = 0; i < length; ++i) { 2574 if (*target == supported_values[i]) { 2575 is_supported_value = TRUE; 2576 break; 2577 } 2578 } 2579 if (!is_supported_value) { 2580 return TPM_RC_VALUE; 2581 } 2582 return TPM_RC_SUCCESS; 2583 } 2584 2585 UINT16 TPMS_RSA_PARMS_Marshal(TPMS_RSA_PARMS* source, 2586 BYTE** buffer, 2587 INT32* size) { 2588 UINT16 total_size = 0; 2589 total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->symmetric, buffer, size); 2590 total_size += TPMT_RSA_SCHEME_Marshal(&source->scheme, buffer, size); 2591 total_size += TPMI_RSA_KEY_BITS_Marshal(&source->keyBits, buffer, size); 2592 total_size += UINT32_Marshal(&source->exponent, buffer, size); 2593 return total_size; 2594 } 2595 2596 TPM_RC TPMS_RSA_PARMS_Unmarshal(TPMS_RSA_PARMS* target, 2597 BYTE** buffer, 2598 INT32* size) { 2599 TPM_RC result; 2600 result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->symmetric, buffer, size); 2601 if (result != TPM_RC_SUCCESS) { 2602 return result; 2603 } 2604 result = TPMT_RSA_SCHEME_Unmarshal(&target->scheme, buffer, size); 2605 if (result != TPM_RC_SUCCESS) { 2606 return result; 2607 } 2608 result = TPMI_RSA_KEY_BITS_Unmarshal(&target->keyBits, buffer, size); 2609 if (result != TPM_RC_SUCCESS) { 2610 return result; 2611 } 2612 result = UINT32_Unmarshal(&target->exponent, buffer, size); 2613 if (result != TPM_RC_SUCCESS) { 2614 return result; 2615 } 2616 return TPM_RC_SUCCESS; 2617 } 2618 2619 UINT16 TPMS_SYMCIPHER_PARMS_Marshal(TPMS_SYMCIPHER_PARMS* source, 2620 BYTE** buffer, 2621 INT32* size) { 2622 UINT16 total_size = 0; 2623 total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->sym, buffer, size); 2624 return total_size; 2625 } 2626 2627 TPM_RC TPMS_SYMCIPHER_PARMS_Unmarshal(TPMS_SYMCIPHER_PARMS* target, 2628 BYTE** buffer, 2629 INT32* size) { 2630 TPM_RC result; 2631 result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->sym, buffer, size); 2632 if (result != TPM_RC_SUCCESS) { 2633 return result; 2634 } 2635 return TPM_RC_SUCCESS; 2636 } 2637 2638 UINT16 TPMI_ALG_ASYM_SCHEME_Marshal(TPMI_ALG_ASYM_SCHEME* source, 2639 BYTE** buffer, 2640 INT32* size) { 2641 return uint16_t_Marshal(source, buffer, size); 2642 } 2643 2644 TPM_RC TPMI_ALG_ASYM_SCHEME_Unmarshal(TPMI_ALG_ASYM_SCHEME* target, 2645 BYTE** buffer, 2646 INT32* size, 2647 BOOL allow_conditional_value) { 2648 TPM_RC result; 2649 BOOL has_valid_value = FALSE; 2650 result = uint16_t_Unmarshal(target, buffer, size); 2651 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2652 return result; 2653 } 2654 if (*target == TPM_ALG_NULL) { 2655 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 2656 } 2657 switch (*target) { 2658 #ifdef TPM_ALG_ECDH 2659 case TPM_ALG_ECDH: 2660 #endif 2661 #ifdef TPM_ALG_ECMQV 2662 case TPM_ALG_ECMQV: 2663 #endif 2664 #ifdef TPM_ALG_RSASSA 2665 case TPM_ALG_RSASSA: 2666 #endif 2667 #ifdef TPM_ALG_RSAPSS 2668 case TPM_ALG_RSAPSS: 2669 #endif 2670 #ifdef TPM_ALG_ECDSA 2671 case TPM_ALG_ECDSA: 2672 #endif 2673 #ifdef TPM_ALG_ECDAA 2674 case TPM_ALG_ECDAA: 2675 #endif 2676 #ifdef TPM_ALG_SM2 2677 case TPM_ALG_SM2: 2678 #endif 2679 #ifdef TPM_ALG_ECSCHNORR 2680 case TPM_ALG_ECSCHNORR: 2681 #endif 2682 #ifdef TPM_ALG_RSAES 2683 case TPM_ALG_RSAES: 2684 #endif 2685 #ifdef TPM_ALG_OAEP 2686 case TPM_ALG_OAEP: 2687 #endif 2688 has_valid_value = TRUE; 2689 break; 2690 } 2691 if (!has_valid_value) { 2692 return TPM_RC_VALUE; 2693 } 2694 return TPM_RC_SUCCESS; 2695 } 2696 2697 UINT16 TPMT_ASYM_SCHEME_Marshal(TPMT_ASYM_SCHEME* source, 2698 BYTE** buffer, 2699 INT32* size) { 2700 UINT16 total_size = 0; 2701 total_size += TPMI_ALG_ASYM_SCHEME_Marshal(&source->scheme, buffer, size); 2702 total_size += 2703 TPMU_ASYM_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 2704 return total_size; 2705 } 2706 2707 TPM_RC TPMT_ASYM_SCHEME_Unmarshal(TPMT_ASYM_SCHEME* target, 2708 BYTE** buffer, 2709 INT32* size) { 2710 TPM_RC result; 2711 result = TPMI_ALG_ASYM_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE); 2712 if (result != TPM_RC_SUCCESS) { 2713 return result; 2714 } 2715 result = TPMU_ASYM_SCHEME_Unmarshal(&target->details, buffer, size, 2716 target->scheme); 2717 if (result != TPM_RC_SUCCESS) { 2718 return result; 2719 } 2720 return TPM_RC_SUCCESS; 2721 } 2722 2723 UINT16 TPMS_ASYM_PARMS_Marshal(TPMS_ASYM_PARMS* source, 2724 BYTE** buffer, 2725 INT32* size) { 2726 UINT16 total_size = 0; 2727 total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->symmetric, buffer, size); 2728 total_size += TPMT_ASYM_SCHEME_Marshal(&source->scheme, buffer, size); 2729 return total_size; 2730 } 2731 2732 TPM_RC TPMS_ASYM_PARMS_Unmarshal(TPMS_ASYM_PARMS* target, 2733 BYTE** buffer, 2734 INT32* size) { 2735 TPM_RC result; 2736 result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->symmetric, buffer, size); 2737 if (result != TPM_RC_SUCCESS) { 2738 return result; 2739 } 2740 result = TPMT_ASYM_SCHEME_Unmarshal(&target->scheme, buffer, size); 2741 if (result != TPM_RC_SUCCESS) { 2742 return result; 2743 } 2744 return TPM_RC_SUCCESS; 2745 } 2746 2747 UINT16 TPMI_ALG_KDF_Marshal(TPMI_ALG_KDF* source, BYTE** buffer, INT32* size) { 2748 return uint16_t_Marshal(source, buffer, size); 2749 } 2750 2751 TPM_RC TPMI_ALG_KDF_Unmarshal(TPMI_ALG_KDF* target, 2752 BYTE** buffer, 2753 INT32* size, 2754 BOOL allow_conditional_value) { 2755 TPM_RC result; 2756 BOOL has_valid_value = FALSE; 2757 result = uint16_t_Unmarshal(target, buffer, size); 2758 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2759 return result; 2760 } 2761 if (*target == TPM_ALG_NULL) { 2762 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_KDF; 2763 } 2764 switch (*target) { 2765 #ifdef TPM_ALG_MGF1 2766 case TPM_ALG_MGF1: 2767 #endif 2768 #ifdef TPM_ALG_KDF1_SP800_56A 2769 case TPM_ALG_KDF1_SP800_56A: 2770 #endif 2771 #ifdef TPM_ALG_KDF2 2772 case TPM_ALG_KDF2: 2773 #endif 2774 #ifdef TPM_ALG_KDF1_SP800_108 2775 case TPM_ALG_KDF1_SP800_108: 2776 #endif 2777 has_valid_value = TRUE; 2778 break; 2779 } 2780 if (!has_valid_value) { 2781 return TPM_RC_KDF; 2782 } 2783 return TPM_RC_SUCCESS; 2784 } 2785 2786 UINT16 TPMS_SCHEME_KDF1_SP800_108_Marshal(TPMS_SCHEME_KDF1_SP800_108* source, 2787 BYTE** buffer, 2788 INT32* size) { 2789 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2790 } 2791 2792 TPM_RC TPMS_SCHEME_KDF1_SP800_108_Unmarshal(TPMS_SCHEME_KDF1_SP800_108* target, 2793 BYTE** buffer, 2794 INT32* size) { 2795 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2796 } 2797 2798 UINT16 TPMS_SCHEME_KDF2_Marshal(TPMS_SCHEME_KDF2* source, 2799 BYTE** buffer, 2800 INT32* size) { 2801 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2802 } 2803 2804 TPM_RC TPMS_SCHEME_KDF2_Unmarshal(TPMS_SCHEME_KDF2* target, 2805 BYTE** buffer, 2806 INT32* size) { 2807 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2808 } 2809 2810 UINT16 TPMS_SCHEME_KDF1_SP800_56A_Marshal(TPMS_SCHEME_KDF1_SP800_56A* source, 2811 BYTE** buffer, 2812 INT32* size) { 2813 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2814 } 2815 2816 TPM_RC TPMS_SCHEME_KDF1_SP800_56A_Unmarshal(TPMS_SCHEME_KDF1_SP800_56A* target, 2817 BYTE** buffer, 2818 INT32* size) { 2819 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2820 } 2821 2822 UINT16 TPMS_SCHEME_MGF1_Marshal(TPMS_SCHEME_MGF1* source, 2823 BYTE** buffer, 2824 INT32* size) { 2825 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 2826 } 2827 2828 TPM_RC TPMS_SCHEME_MGF1_Unmarshal(TPMS_SCHEME_MGF1* target, 2829 BYTE** buffer, 2830 INT32* size) { 2831 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 2832 } 2833 2834 UINT16 TPMU_KDF_SCHEME_Marshal(TPMU_KDF_SCHEME* source, 2835 BYTE** buffer, 2836 INT32* size, 2837 UINT32 selector) { 2838 switch (selector) { 2839 #ifdef TPM_ALG_MGF1 2840 case TPM_ALG_MGF1: 2841 return TPMS_SCHEME_MGF1_Marshal((TPMS_SCHEME_MGF1*)&source->mgf1, buffer, 2842 size); 2843 #endif 2844 #ifdef TPM_ALG_KDF1_SP800_56A 2845 case TPM_ALG_KDF1_SP800_56A: 2846 return TPMS_SCHEME_KDF1_SP800_56A_Marshal( 2847 (TPMS_SCHEME_KDF1_SP800_56A*)&source->kdf1_sp800_56a, buffer, size); 2848 #endif 2849 #ifdef TPM_ALG_KDF2 2850 case TPM_ALG_KDF2: 2851 return TPMS_SCHEME_KDF2_Marshal((TPMS_SCHEME_KDF2*)&source->kdf2, buffer, 2852 size); 2853 #endif 2854 #ifdef TPM_ALG_KDF1_SP800_108 2855 case TPM_ALG_KDF1_SP800_108: 2856 return TPMS_SCHEME_KDF1_SP800_108_Marshal( 2857 (TPMS_SCHEME_KDF1_SP800_108*)&source->kdf1_sp800_108, buffer, size); 2858 #endif 2859 #ifdef TPM_ALG_NULL 2860 case TPM_ALG_NULL: 2861 return 0; 2862 #endif 2863 } 2864 return 0; 2865 } 2866 2867 TPM_RC TPMU_KDF_SCHEME_Unmarshal(TPMU_KDF_SCHEME* target, 2868 BYTE** buffer, 2869 INT32* size, 2870 UINT32 selector) { 2871 switch (selector) { 2872 #ifdef TPM_ALG_MGF1 2873 case TPM_ALG_MGF1: 2874 return TPMS_SCHEME_MGF1_Unmarshal((TPMS_SCHEME_MGF1*)&target->mgf1, 2875 buffer, size); 2876 #endif 2877 #ifdef TPM_ALG_KDF1_SP800_56A 2878 case TPM_ALG_KDF1_SP800_56A: 2879 return TPMS_SCHEME_KDF1_SP800_56A_Unmarshal( 2880 (TPMS_SCHEME_KDF1_SP800_56A*)&target->kdf1_sp800_56a, buffer, size); 2881 #endif 2882 #ifdef TPM_ALG_KDF2 2883 case TPM_ALG_KDF2: 2884 return TPMS_SCHEME_KDF2_Unmarshal((TPMS_SCHEME_KDF2*)&target->kdf2, 2885 buffer, size); 2886 #endif 2887 #ifdef TPM_ALG_KDF1_SP800_108 2888 case TPM_ALG_KDF1_SP800_108: 2889 return TPMS_SCHEME_KDF1_SP800_108_Unmarshal( 2890 (TPMS_SCHEME_KDF1_SP800_108*)&target->kdf1_sp800_108, buffer, size); 2891 #endif 2892 #ifdef TPM_ALG_NULL 2893 case TPM_ALG_NULL: 2894 return TPM_RC_SUCCESS; 2895 #endif 2896 } 2897 return TPM_RC_SELECTOR; 2898 } 2899 2900 UINT16 TPMT_KDF_SCHEME_Marshal(TPMT_KDF_SCHEME* source, 2901 BYTE** buffer, 2902 INT32* size) { 2903 UINT16 total_size = 0; 2904 total_size += TPMI_ALG_KDF_Marshal(&source->scheme, buffer, size); 2905 total_size += 2906 TPMU_KDF_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 2907 return total_size; 2908 } 2909 2910 TPM_RC TPMT_KDF_SCHEME_Unmarshal(TPMT_KDF_SCHEME* target, 2911 BYTE** buffer, 2912 INT32* size) { 2913 TPM_RC result; 2914 result = TPMI_ALG_KDF_Unmarshal(&target->scheme, buffer, size, TRUE); 2915 if (result != TPM_RC_SUCCESS) { 2916 return result; 2917 } 2918 result = 2919 TPMU_KDF_SCHEME_Unmarshal(&target->details, buffer, size, target->scheme); 2920 if (result != TPM_RC_SUCCESS) { 2921 return result; 2922 } 2923 return TPM_RC_SUCCESS; 2924 } 2925 2926 UINT16 TPMI_ALG_ECC_SCHEME_Marshal(TPMI_ALG_ECC_SCHEME* source, 2927 BYTE** buffer, 2928 INT32* size) { 2929 return uint16_t_Marshal(source, buffer, size); 2930 } 2931 2932 TPM_RC TPMI_ALG_ECC_SCHEME_Unmarshal(TPMI_ALG_ECC_SCHEME* target, 2933 BYTE** buffer, 2934 INT32* size, 2935 BOOL allow_conditional_value) { 2936 TPM_RC result; 2937 BOOL has_valid_value = FALSE; 2938 result = uint16_t_Unmarshal(target, buffer, size); 2939 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 2940 return result; 2941 } 2942 if (*target == TPM_ALG_NULL) { 2943 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SCHEME; 2944 } 2945 switch (*target) { 2946 #ifdef TPM_ALG_ECDSA 2947 case TPM_ALG_ECDSA: 2948 #endif 2949 #ifdef TPM_ALG_ECDAA 2950 case TPM_ALG_ECDAA: 2951 #endif 2952 #ifdef TPM_ALG_SM2 2953 case TPM_ALG_SM2: 2954 #endif 2955 #ifdef TPM_ALG_ECSCHNORR 2956 case TPM_ALG_ECSCHNORR: 2957 #endif 2958 #ifdef TPM_ALG_ECDH 2959 case TPM_ALG_ECDH: 2960 #endif 2961 #ifdef TPM_ALG_ECMQV 2962 case TPM_ALG_ECMQV: 2963 #endif 2964 has_valid_value = TRUE; 2965 break; 2966 } 2967 if (!has_valid_value) { 2968 return TPM_RC_SCHEME; 2969 } 2970 return TPM_RC_SUCCESS; 2971 } 2972 2973 UINT16 TPMT_ECC_SCHEME_Marshal(TPMT_ECC_SCHEME* source, 2974 BYTE** buffer, 2975 INT32* size) { 2976 UINT16 total_size = 0; 2977 total_size += TPMI_ALG_ECC_SCHEME_Marshal(&source->scheme, buffer, size); 2978 total_size += 2979 TPMU_ASYM_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 2980 return total_size; 2981 } 2982 2983 TPM_RC TPMT_ECC_SCHEME_Unmarshal(TPMT_ECC_SCHEME* target, 2984 BYTE** buffer, 2985 INT32* size) { 2986 TPM_RC result; 2987 result = TPMI_ALG_ECC_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE); 2988 if (result != TPM_RC_SUCCESS) { 2989 return result; 2990 } 2991 result = TPMU_ASYM_SCHEME_Unmarshal(&target->details, buffer, size, 2992 target->scheme); 2993 if (result != TPM_RC_SUCCESS) { 2994 return result; 2995 } 2996 return TPM_RC_SUCCESS; 2997 } 2998 2999 UINT16 TPMI_ECC_CURVE_Marshal(TPMI_ECC_CURVE* source, 3000 BYTE** buffer, 3001 INT32* size) { 3002 return uint16_t_Marshal(source, buffer, size); 3003 } 3004 3005 TPM_RC TPMI_ECC_CURVE_Unmarshal(TPMI_ECC_CURVE* target, 3006 BYTE** buffer, 3007 INT32* size) { 3008 TPM_RC result; 3009 uint16_t supported_values[] = ECC_CURVES; 3010 size_t length = sizeof(supported_values) / sizeof(supported_values[0]); 3011 size_t i; 3012 BOOL is_supported_value = FALSE; 3013 result = uint16_t_Unmarshal(target, buffer, size); 3014 if (result != TPM_RC_SUCCESS) { 3015 return result; 3016 } 3017 for (i = 0; i < length; ++i) { 3018 if (*target == supported_values[i]) { 3019 is_supported_value = TRUE; 3020 break; 3021 } 3022 } 3023 if (!is_supported_value) { 3024 return TPM_RC_CURVE; 3025 } 3026 return TPM_RC_SUCCESS; 3027 } 3028 3029 UINT16 TPMS_ECC_PARMS_Marshal(TPMS_ECC_PARMS* source, 3030 BYTE** buffer, 3031 INT32* size) { 3032 UINT16 total_size = 0; 3033 total_size += TPMT_SYM_DEF_OBJECT_Marshal(&source->symmetric, buffer, size); 3034 total_size += TPMT_ECC_SCHEME_Marshal(&source->scheme, buffer, size); 3035 total_size += TPMI_ECC_CURVE_Marshal(&source->curveID, buffer, size); 3036 total_size += TPMT_KDF_SCHEME_Marshal(&source->kdf, buffer, size); 3037 return total_size; 3038 } 3039 3040 TPM_RC TPMS_ECC_PARMS_Unmarshal(TPMS_ECC_PARMS* target, 3041 BYTE** buffer, 3042 INT32* size) { 3043 TPM_RC result; 3044 result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->symmetric, buffer, size); 3045 if (result != TPM_RC_SUCCESS) { 3046 return result; 3047 } 3048 result = TPMT_ECC_SCHEME_Unmarshal(&target->scheme, buffer, size); 3049 if (result != TPM_RC_SUCCESS) { 3050 return result; 3051 } 3052 result = TPMI_ECC_CURVE_Unmarshal(&target->curveID, buffer, size); 3053 if (result != TPM_RC_SUCCESS) { 3054 return result; 3055 } 3056 result = TPMT_KDF_SCHEME_Unmarshal(&target->kdf, buffer, size); 3057 if (result != TPM_RC_SUCCESS) { 3058 return result; 3059 } 3060 return TPM_RC_SUCCESS; 3061 } 3062 3063 UINT16 TPMI_ALG_KEYEDHASH_SCHEME_Marshal(TPMI_ALG_KEYEDHASH_SCHEME* source, 3064 BYTE** buffer, 3065 INT32* size) { 3066 return uint16_t_Marshal(source, buffer, size); 3067 } 3068 3069 TPM_RC TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal(TPMI_ALG_KEYEDHASH_SCHEME* target, 3070 BYTE** buffer, 3071 INT32* size, 3072 BOOL allow_conditional_value) { 3073 TPM_RC result; 3074 BOOL has_valid_value = FALSE; 3075 result = uint16_t_Unmarshal(target, buffer, size); 3076 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3077 return result; 3078 } 3079 if (*target == TPM_ALG_NULL) { 3080 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 3081 } 3082 switch (*target) { 3083 #ifdef TPM_ALG_HMAC 3084 case TPM_ALG_HMAC: 3085 #endif 3086 #ifdef TPM_ALG_XOR 3087 case TPM_ALG_XOR: 3088 #endif 3089 has_valid_value = TRUE; 3090 break; 3091 } 3092 if (!has_valid_value) { 3093 return TPM_RC_VALUE; 3094 } 3095 return TPM_RC_SUCCESS; 3096 } 3097 3098 UINT16 TPMS_SCHEME_HMAC_Marshal(TPMS_SCHEME_HMAC* source, 3099 BYTE** buffer, 3100 INT32* size) { 3101 return TPMS_SCHEME_HASH_Marshal(source, buffer, size); 3102 } 3103 3104 TPM_RC TPMS_SCHEME_HMAC_Unmarshal(TPMS_SCHEME_HMAC* target, 3105 BYTE** buffer, 3106 INT32* size) { 3107 return TPMS_SCHEME_HASH_Unmarshal(target, buffer, size); 3108 } 3109 3110 UINT16 TPMS_SCHEME_XOR_Marshal(TPMS_SCHEME_XOR* source, 3111 BYTE** buffer, 3112 INT32* size) { 3113 UINT16 total_size = 0; 3114 total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size); 3115 total_size += TPMI_ALG_KDF_Marshal(&source->kdf, buffer, size); 3116 return total_size; 3117 } 3118 3119 TPM_RC TPMS_SCHEME_XOR_Unmarshal(TPMS_SCHEME_XOR* target, 3120 BYTE** buffer, 3121 INT32* size) { 3122 TPM_RC result; 3123 result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, TRUE); 3124 if (result != TPM_RC_SUCCESS) { 3125 return result; 3126 } 3127 result = TPMI_ALG_KDF_Unmarshal(&target->kdf, buffer, size, FALSE); 3128 if (result != TPM_RC_SUCCESS) { 3129 return result; 3130 } 3131 return TPM_RC_SUCCESS; 3132 } 3133 3134 UINT16 TPMU_SCHEME_KEYEDHASH_Marshal(TPMU_SCHEME_KEYEDHASH* source, 3135 BYTE** buffer, 3136 INT32* size, 3137 UINT32 selector) { 3138 switch (selector) { 3139 #ifdef TPM_ALG_HMAC 3140 case TPM_ALG_HMAC: 3141 return TPMS_SCHEME_HMAC_Marshal((TPMS_SCHEME_HMAC*)&source->hmac, buffer, 3142 size); 3143 #endif 3144 #ifdef TPM_ALG_XOR 3145 case TPM_ALG_XOR: 3146 return TPMS_SCHEME_XOR_Marshal((TPMS_SCHEME_XOR*)&source->xor_, buffer, 3147 size); 3148 #endif 3149 #ifdef TPM_ALG_NULL 3150 case TPM_ALG_NULL: 3151 return 0; 3152 #endif 3153 } 3154 return 0; 3155 } 3156 3157 TPM_RC TPMU_SCHEME_KEYEDHASH_Unmarshal(TPMU_SCHEME_KEYEDHASH* target, 3158 BYTE** buffer, 3159 INT32* size, 3160 UINT32 selector) { 3161 switch (selector) { 3162 #ifdef TPM_ALG_HMAC 3163 case TPM_ALG_HMAC: 3164 return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC*)&target->hmac, 3165 buffer, size); 3166 #endif 3167 #ifdef TPM_ALG_XOR 3168 case TPM_ALG_XOR: 3169 return TPMS_SCHEME_XOR_Unmarshal((TPMS_SCHEME_XOR*)&target->xor_, buffer, 3170 size); 3171 #endif 3172 #ifdef TPM_ALG_NULL 3173 case TPM_ALG_NULL: 3174 return TPM_RC_SUCCESS; 3175 #endif 3176 } 3177 return TPM_RC_SELECTOR; 3178 } 3179 3180 UINT16 TPMT_KEYEDHASH_SCHEME_Marshal(TPMT_KEYEDHASH_SCHEME* source, 3181 BYTE** buffer, 3182 INT32* size) { 3183 UINT16 total_size = 0; 3184 total_size += 3185 TPMI_ALG_KEYEDHASH_SCHEME_Marshal(&source->scheme, buffer, size); 3186 total_size += TPMU_SCHEME_KEYEDHASH_Marshal(&source->details, buffer, size, 3187 source->scheme); 3188 return total_size; 3189 } 3190 3191 TPM_RC TPMT_KEYEDHASH_SCHEME_Unmarshal(TPMT_KEYEDHASH_SCHEME* target, 3192 BYTE** buffer, 3193 INT32* size) { 3194 TPM_RC result; 3195 result = 3196 TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE); 3197 if (result != TPM_RC_SUCCESS) { 3198 return result; 3199 } 3200 result = TPMU_SCHEME_KEYEDHASH_Unmarshal(&target->details, buffer, size, 3201 target->scheme); 3202 if (result != TPM_RC_SUCCESS) { 3203 return result; 3204 } 3205 return TPM_RC_SUCCESS; 3206 } 3207 3208 UINT16 TPMS_KEYEDHASH_PARMS_Marshal(TPMS_KEYEDHASH_PARMS* source, 3209 BYTE** buffer, 3210 INT32* size) { 3211 UINT16 total_size = 0; 3212 total_size += TPMT_KEYEDHASH_SCHEME_Marshal(&source->scheme, buffer, size); 3213 return total_size; 3214 } 3215 3216 TPM_RC TPMS_KEYEDHASH_PARMS_Unmarshal(TPMS_KEYEDHASH_PARMS* target, 3217 BYTE** buffer, 3218 INT32* size) { 3219 TPM_RC result; 3220 result = TPMT_KEYEDHASH_SCHEME_Unmarshal(&target->scheme, buffer, size); 3221 if (result != TPM_RC_SUCCESS) { 3222 return result; 3223 } 3224 return TPM_RC_SUCCESS; 3225 } 3226 3227 UINT16 TPMU_PUBLIC_PARMS_Marshal(TPMU_PUBLIC_PARMS* source, 3228 BYTE** buffer, 3229 INT32* size, 3230 UINT32 selector) { 3231 switch (selector) { 3232 #ifdef TPM_ALG_KEYEDHASH 3233 case TPM_ALG_KEYEDHASH: 3234 return TPMS_KEYEDHASH_PARMS_Marshal( 3235 (TPMS_KEYEDHASH_PARMS*)&source->keyedHashDetail, buffer, size); 3236 #endif 3237 #ifdef TPM_ALG_SYMCIPHER 3238 case TPM_ALG_SYMCIPHER: 3239 return TPMS_SYMCIPHER_PARMS_Marshal( 3240 (TPMS_SYMCIPHER_PARMS*)&source->symDetail, buffer, size); 3241 #endif 3242 #ifdef TPM_ALG_RSA 3243 case TPM_ALG_RSA: 3244 return TPMS_RSA_PARMS_Marshal((TPMS_RSA_PARMS*)&source->rsaDetail, buffer, 3245 size); 3246 #endif 3247 #ifdef TPM_ALG_ECC 3248 case TPM_ALG_ECC: 3249 return TPMS_ECC_PARMS_Marshal((TPMS_ECC_PARMS*)&source->eccDetail, buffer, 3250 size); 3251 #endif 3252 } 3253 return 0; 3254 } 3255 3256 TPM_RC TPMU_PUBLIC_PARMS_Unmarshal(TPMU_PUBLIC_PARMS* target, 3257 BYTE** buffer, 3258 INT32* size, 3259 UINT32 selector) { 3260 switch (selector) { 3261 #ifdef TPM_ALG_KEYEDHASH 3262 case TPM_ALG_KEYEDHASH: 3263 return TPMS_KEYEDHASH_PARMS_Unmarshal( 3264 (TPMS_KEYEDHASH_PARMS*)&target->keyedHashDetail, buffer, size); 3265 #endif 3266 #ifdef TPM_ALG_SYMCIPHER 3267 case TPM_ALG_SYMCIPHER: 3268 return TPMS_SYMCIPHER_PARMS_Unmarshal( 3269 (TPMS_SYMCIPHER_PARMS*)&target->symDetail, buffer, size); 3270 #endif 3271 #ifdef TPM_ALG_RSA 3272 case TPM_ALG_RSA: 3273 return TPMS_RSA_PARMS_Unmarshal((TPMS_RSA_PARMS*)&target->rsaDetail, 3274 buffer, size); 3275 #endif 3276 #ifdef TPM_ALG_ECC 3277 case TPM_ALG_ECC: 3278 return TPMS_ECC_PARMS_Unmarshal((TPMS_ECC_PARMS*)&target->eccDetail, 3279 buffer, size); 3280 #endif 3281 } 3282 return TPM_RC_SELECTOR; 3283 } 3284 3285 UINT16 TPMT_PUBLIC_Marshal(TPMT_PUBLIC* source, BYTE** buffer, INT32* size) { 3286 UINT16 total_size = 0; 3287 total_size += TPMI_ALG_PUBLIC_Marshal(&source->type, buffer, size); 3288 total_size += TPMI_ALG_HASH_Marshal(&source->nameAlg, buffer, size); 3289 total_size += TPMA_OBJECT_Marshal(&source->objectAttributes, buffer, size); 3290 total_size += TPM2B_DIGEST_Marshal(&source->authPolicy, buffer, size); 3291 total_size += TPMU_PUBLIC_PARMS_Marshal(&source->parameters, buffer, size, 3292 source->type); 3293 total_size += 3294 TPMU_PUBLIC_ID_Marshal(&source->unique, buffer, size, source->type); 3295 return total_size; 3296 } 3297 3298 TPM_RC TPMT_PUBLIC_Unmarshal(TPMT_PUBLIC* target, BYTE** buffer, INT32* size) { 3299 TPM_RC result; 3300 result = TPMI_ALG_PUBLIC_Unmarshal(&target->type, buffer, size); 3301 if (result != TPM_RC_SUCCESS) { 3302 return result; 3303 } 3304 result = TPMI_ALG_HASH_Unmarshal(&target->nameAlg, buffer, size, TRUE); 3305 if (result != TPM_RC_SUCCESS) { 3306 return result; 3307 } 3308 result = TPMA_OBJECT_Unmarshal(&target->objectAttributes, buffer, size); 3309 if (result != TPM_RC_SUCCESS) { 3310 return result; 3311 } 3312 result = TPM2B_DIGEST_Unmarshal(&target->authPolicy, buffer, size); 3313 if (result != TPM_RC_SUCCESS) { 3314 return result; 3315 } 3316 result = TPMU_PUBLIC_PARMS_Unmarshal(&target->parameters, buffer, size, 3317 target->type); 3318 if (result != TPM_RC_SUCCESS) { 3319 return result; 3320 } 3321 result = 3322 TPMU_PUBLIC_ID_Unmarshal(&target->unique, buffer, size, target->type); 3323 if (result != TPM_RC_SUCCESS) { 3324 return result; 3325 } 3326 return TPM_RC_SUCCESS; 3327 } 3328 3329 UINT16 TPM2B_PUBLIC_Marshal(TPM2B_PUBLIC* source, BYTE** buffer, INT32* size) { 3330 UINT16 total_size = 0; 3331 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3332 total_size += TPMT_PUBLIC_Marshal(&source->t.publicArea, buffer, size); 3333 { 3334 BYTE* size_location = *buffer - total_size; 3335 INT32 size_field_size = sizeof(UINT16); 3336 UINT16 payload_size = total_size - (UINT16)size_field_size; 3337 UINT16_Marshal(&payload_size, &size_location, &size_field_size); 3338 } 3339 return total_size; 3340 } 3341 3342 TPM_RC TPM2B_PUBLIC_Unmarshal(TPM2B_PUBLIC* target, 3343 BYTE** buffer, 3344 INT32* size) { 3345 TPM_RC result; 3346 UINT32 start_size = *size; 3347 UINT32 struct_size; 3348 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3349 if (result != TPM_RC_SUCCESS) { 3350 return result; 3351 } 3352 if (target->t.size == 0) { 3353 return TPM_RC_SIZE; 3354 } 3355 result = TPMT_PUBLIC_Unmarshal(&target->t.publicArea, buffer, size); 3356 if (result != TPM_RC_SUCCESS) { 3357 return result; 3358 } 3359 struct_size = start_size - *size - sizeof(target->t.size); 3360 if (struct_size != target->t.size) { 3361 return TPM_RC_SIZE; 3362 } 3363 return TPM_RC_SUCCESS; 3364 } 3365 3366 UINT16 TPM2B_SENSITIVE_DATA_Marshal(TPM2B_SENSITIVE_DATA* source, 3367 BYTE** buffer, 3368 INT32* size) { 3369 UINT16 total_size = 0; 3370 INT32 i; 3371 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3372 for (i = 0; i < source->t.size; ++i) { 3373 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 3374 } 3375 return total_size; 3376 } 3377 3378 TPM_RC TPM2B_SENSITIVE_DATA_Unmarshal(TPM2B_SENSITIVE_DATA* target, 3379 BYTE** buffer, 3380 INT32* size) { 3381 TPM_RC result; 3382 INT32 i; 3383 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3384 if (result != TPM_RC_SUCCESS) { 3385 return result; 3386 } 3387 if (target->t.size == 0) { 3388 return TPM_RC_SUCCESS; 3389 } 3390 if (target->t.size > MAX_SYM_DATA) { 3391 return TPM_RC_SIZE; 3392 } 3393 for (i = 0; i < target->t.size; ++i) { 3394 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 3395 if (result != TPM_RC_SUCCESS) { 3396 return result; 3397 } 3398 } 3399 return TPM_RC_SUCCESS; 3400 } 3401 3402 UINT16 TPM2B_SYM_KEY_Marshal(TPM2B_SYM_KEY* source, 3403 BYTE** buffer, 3404 INT32* size) { 3405 UINT16 total_size = 0; 3406 INT32 i; 3407 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3408 for (i = 0; i < source->t.size; ++i) { 3409 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 3410 } 3411 return total_size; 3412 } 3413 3414 TPM_RC TPM2B_SYM_KEY_Unmarshal(TPM2B_SYM_KEY* target, 3415 BYTE** buffer, 3416 INT32* size) { 3417 TPM_RC result; 3418 INT32 i; 3419 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3420 if (result != TPM_RC_SUCCESS) { 3421 return result; 3422 } 3423 if (target->t.size == 0) { 3424 return TPM_RC_SUCCESS; 3425 } 3426 if (target->t.size > MAX_SYM_KEY_BYTES) { 3427 return TPM_RC_SIZE; 3428 } 3429 for (i = 0; i < target->t.size; ++i) { 3430 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 3431 if (result != TPM_RC_SUCCESS) { 3432 return result; 3433 } 3434 } 3435 return TPM_RC_SUCCESS; 3436 } 3437 3438 UINT16 TPMU_SENSITIVE_COMPOSITE_Marshal(TPMU_SENSITIVE_COMPOSITE* source, 3439 BYTE** buffer, 3440 INT32* size, 3441 UINT32 selector) { 3442 switch (selector) { 3443 #ifdef TPM_ALG_RSA 3444 case TPM_ALG_RSA: 3445 return TPM2B_PRIVATE_KEY_RSA_Marshal((TPM2B_PRIVATE_KEY_RSA*)&source->rsa, 3446 buffer, size); 3447 #endif 3448 #ifdef TPM_ALG_ECC 3449 case TPM_ALG_ECC: 3450 return TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER*)&source->ecc, 3451 buffer, size); 3452 #endif 3453 #ifdef TPM_ALG_KEYEDHASH 3454 case TPM_ALG_KEYEDHASH: 3455 return TPM2B_SENSITIVE_DATA_Marshal((TPM2B_SENSITIVE_DATA*)&source->bits, 3456 buffer, size); 3457 #endif 3458 #ifdef TPM_ALG_SYMCIPHER 3459 case TPM_ALG_SYMCIPHER: 3460 return TPM2B_SYM_KEY_Marshal((TPM2B_SYM_KEY*)&source->sym, buffer, size); 3461 #endif 3462 } 3463 return 0; 3464 } 3465 3466 TPM_RC TPMU_SENSITIVE_COMPOSITE_Unmarshal(TPMU_SENSITIVE_COMPOSITE* target, 3467 BYTE** buffer, 3468 INT32* size, 3469 UINT32 selector) { 3470 switch (selector) { 3471 #ifdef TPM_ALG_RSA 3472 case TPM_ALG_RSA: 3473 return TPM2B_PRIVATE_KEY_RSA_Unmarshal( 3474 (TPM2B_PRIVATE_KEY_RSA*)&target->rsa, buffer, size); 3475 #endif 3476 #ifdef TPM_ALG_ECC 3477 case TPM_ALG_ECC: 3478 return TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER*)&target->ecc, 3479 buffer, size); 3480 #endif 3481 #ifdef TPM_ALG_KEYEDHASH 3482 case TPM_ALG_KEYEDHASH: 3483 return TPM2B_SENSITIVE_DATA_Unmarshal( 3484 (TPM2B_SENSITIVE_DATA*)&target->bits, buffer, size); 3485 #endif 3486 #ifdef TPM_ALG_SYMCIPHER 3487 case TPM_ALG_SYMCIPHER: 3488 return TPM2B_SYM_KEY_Unmarshal((TPM2B_SYM_KEY*)&target->sym, buffer, 3489 size); 3490 #endif 3491 } 3492 return TPM_RC_SELECTOR; 3493 } 3494 3495 UINT16 TPMT_SENSITIVE_Marshal(TPMT_SENSITIVE* source, 3496 BYTE** buffer, 3497 INT32* size) { 3498 UINT16 total_size = 0; 3499 total_size += TPMI_ALG_PUBLIC_Marshal(&source->sensitiveType, buffer, size); 3500 total_size += TPM2B_AUTH_Marshal(&source->authValue, buffer, size); 3501 total_size += TPM2B_DIGEST_Marshal(&source->seedValue, buffer, size); 3502 total_size += TPMU_SENSITIVE_COMPOSITE_Marshal(&source->sensitive, buffer, 3503 size, source->sensitiveType); 3504 return total_size; 3505 } 3506 3507 TPM_RC TPMT_SENSITIVE_Unmarshal(TPMT_SENSITIVE* target, 3508 BYTE** buffer, 3509 INT32* size) { 3510 TPM_RC result; 3511 result = TPMI_ALG_PUBLIC_Unmarshal(&target->sensitiveType, buffer, size); 3512 if (result != TPM_RC_SUCCESS) { 3513 return result; 3514 } 3515 result = TPM2B_AUTH_Unmarshal(&target->authValue, buffer, size); 3516 if (result != TPM_RC_SUCCESS) { 3517 return result; 3518 } 3519 result = TPM2B_DIGEST_Unmarshal(&target->seedValue, buffer, size); 3520 if (result != TPM_RC_SUCCESS) { 3521 return result; 3522 } 3523 result = TPMU_SENSITIVE_COMPOSITE_Unmarshal(&target->sensitive, buffer, size, 3524 target->sensitiveType); 3525 if (result != TPM_RC_SUCCESS) { 3526 return result; 3527 } 3528 return TPM_RC_SUCCESS; 3529 } 3530 3531 UINT16 TPM2B_SENSITIVE_Marshal(TPM2B_SENSITIVE* source, 3532 BYTE** buffer, 3533 INT32* size) { 3534 UINT16 total_size = 0; 3535 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3536 total_size += TPMT_SENSITIVE_Marshal(&source->t.sensitiveArea, buffer, size); 3537 return total_size; 3538 } 3539 3540 TPM_RC TPM2B_SENSITIVE_Unmarshal(TPM2B_SENSITIVE* target, 3541 BYTE** buffer, 3542 INT32* size) { 3543 TPM_RC result; 3544 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3545 if (result != TPM_RC_SUCCESS) { 3546 return result; 3547 } 3548 if (target->t.size == 0) { 3549 return TPM_RC_SUCCESS; 3550 } 3551 result = TPMT_SENSITIVE_Unmarshal(&target->t.sensitiveArea, buffer, size); 3552 if (result != TPM_RC_SUCCESS) { 3553 return result; 3554 } 3555 return TPM_RC_SUCCESS; 3556 } 3557 3558 UINT16 TPMS_SENSITIVE_CREATE_Marshal(TPMS_SENSITIVE_CREATE* source, 3559 BYTE** buffer, 3560 INT32* size) { 3561 UINT16 total_size = 0; 3562 total_size += TPM2B_AUTH_Marshal(&source->userAuth, buffer, size); 3563 total_size += TPM2B_SENSITIVE_DATA_Marshal(&source->data, buffer, size); 3564 return total_size; 3565 } 3566 3567 TPM_RC TPMS_SENSITIVE_CREATE_Unmarshal(TPMS_SENSITIVE_CREATE* target, 3568 BYTE** buffer, 3569 INT32* size) { 3570 TPM_RC result; 3571 result = TPM2B_AUTH_Unmarshal(&target->userAuth, buffer, size); 3572 if (result != TPM_RC_SUCCESS) { 3573 return result; 3574 } 3575 result = TPM2B_SENSITIVE_DATA_Unmarshal(&target->data, buffer, size); 3576 if (result != TPM_RC_SUCCESS) { 3577 return result; 3578 } 3579 return TPM_RC_SUCCESS; 3580 } 3581 3582 UINT16 TPM2B_SENSITIVE_CREATE_Marshal(TPM2B_SENSITIVE_CREATE* source, 3583 BYTE** buffer, 3584 INT32* size) { 3585 UINT16 total_size = 0; 3586 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3587 total_size += 3588 TPMS_SENSITIVE_CREATE_Marshal(&source->t.sensitive, buffer, size); 3589 { 3590 BYTE* size_location = *buffer - total_size; 3591 INT32 size_field_size = sizeof(UINT16); 3592 UINT16 payload_size = total_size - (UINT16)size_field_size; 3593 UINT16_Marshal(&payload_size, &size_location, &size_field_size); 3594 } 3595 return total_size; 3596 } 3597 3598 TPM_RC TPM2B_SENSITIVE_CREATE_Unmarshal(TPM2B_SENSITIVE_CREATE* target, 3599 BYTE** buffer, 3600 INT32* size) { 3601 TPM_RC result; 3602 UINT32 start_size = *size; 3603 UINT32 struct_size; 3604 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3605 if (result != TPM_RC_SUCCESS) { 3606 return result; 3607 } 3608 if (target->t.size == 0) { 3609 return TPM_RC_SIZE; 3610 } 3611 result = TPMS_SENSITIVE_CREATE_Unmarshal(&target->t.sensitive, buffer, size); 3612 if (result != TPM_RC_SUCCESS) { 3613 return result; 3614 } 3615 struct_size = start_size - *size - sizeof(target->t.size); 3616 if (struct_size != target->t.size) { 3617 return TPM_RC_SIZE; 3618 } 3619 return TPM_RC_SUCCESS; 3620 } 3621 3622 UINT16 TPM2B_TIMEOUT_Marshal(TPM2B_TIMEOUT* source, 3623 BYTE** buffer, 3624 INT32* size) { 3625 UINT16 total_size = 0; 3626 INT32 i; 3627 total_size += UINT16_Marshal(&source->t.size, buffer, size); 3628 for (i = 0; i < source->t.size; ++i) { 3629 total_size += BYTE_Marshal(&source->t.buffer[i], buffer, size); 3630 } 3631 return total_size; 3632 } 3633 3634 TPM_RC TPM2B_TIMEOUT_Unmarshal(TPM2B_TIMEOUT* target, 3635 BYTE** buffer, 3636 INT32* size) { 3637 TPM_RC result; 3638 INT32 i; 3639 result = UINT16_Unmarshal(&target->t.size, buffer, size); 3640 if (result != TPM_RC_SUCCESS) { 3641 return result; 3642 } 3643 if (target->t.size == 0) { 3644 return TPM_RC_SUCCESS; 3645 } 3646 if (target->t.size > sizeof(UINT64)) { 3647 return TPM_RC_SIZE; 3648 } 3649 for (i = 0; i < target->t.size; ++i) { 3650 result = BYTE_Unmarshal(&target->t.buffer[i], buffer, size); 3651 if (result != TPM_RC_SUCCESS) { 3652 return result; 3653 } 3654 } 3655 return TPM_RC_SUCCESS; 3656 } 3657 3658 UINT16 TPMA_ALGORITHM_Marshal(TPMA_ALGORITHM* source, 3659 BYTE** buffer, 3660 INT32* size) { 3661 return uint32_t_Marshal((uint32_t*)source, buffer, size); 3662 } 3663 3664 TPM_RC TPMA_ALGORITHM_Unmarshal(TPMA_ALGORITHM* target, 3665 BYTE** buffer, 3666 INT32* size) { 3667 TPM_RC result; 3668 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 3669 if (result != TPM_RC_SUCCESS) { 3670 return result; 3671 } 3672 if (target->reserved4_7 != 0) { 3673 return TPM_RC_RESERVED_BITS; 3674 } 3675 if (target->reserved11_31 != 0) { 3676 return TPM_RC_RESERVED_BITS; 3677 } 3678 return TPM_RC_SUCCESS; 3679 } 3680 3681 UINT16 TPMA_CC_Marshal(TPMA_CC* source, BYTE** buffer, INT32* size) { 3682 return uint32_t_Marshal((uint32_t*)source, buffer, size); 3683 } 3684 3685 TPM_RC TPMA_CC_Unmarshal(TPMA_CC* target, BYTE** buffer, INT32* size) { 3686 TPM_RC result; 3687 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 3688 if (result != TPM_RC_SUCCESS) { 3689 return result; 3690 } 3691 if (target->reserved16_21 != 0) { 3692 return TPM_RC_RESERVED_BITS; 3693 } 3694 return TPM_RC_SUCCESS; 3695 } 3696 3697 UINT16 TPMA_MEMORY_Marshal(TPMA_MEMORY* source, BYTE** buffer, INT32* size) { 3698 return uint32_t_Marshal((uint32_t*)source, buffer, size); 3699 } 3700 3701 TPM_RC TPMA_MEMORY_Unmarshal(TPMA_MEMORY* target, BYTE** buffer, INT32* size) { 3702 TPM_RC result; 3703 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 3704 if (result != TPM_RC_SUCCESS) { 3705 return result; 3706 } 3707 if (target->reserved3_31 != 0) { 3708 return TPM_RC_RESERVED_BITS; 3709 } 3710 return TPM_RC_SUCCESS; 3711 } 3712 3713 UINT16 TPMA_PERMANENT_Marshal(TPMA_PERMANENT* source, 3714 BYTE** buffer, 3715 INT32* size) { 3716 return uint32_t_Marshal((uint32_t*)source, buffer, size); 3717 } 3718 3719 TPM_RC TPMA_PERMANENT_Unmarshal(TPMA_PERMANENT* target, 3720 BYTE** buffer, 3721 INT32* size) { 3722 TPM_RC result; 3723 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 3724 if (result != TPM_RC_SUCCESS) { 3725 return result; 3726 } 3727 if (target->reserved3_7 != 0) { 3728 return TPM_RC_RESERVED_BITS; 3729 } 3730 if (target->reserved11_31 != 0) { 3731 return TPM_RC_RESERVED_BITS; 3732 } 3733 return TPM_RC_SUCCESS; 3734 } 3735 3736 UINT16 TPMA_SESSION_Marshal(TPMA_SESSION* source, BYTE** buffer, INT32* size) { 3737 return uint8_t_Marshal((uint8_t*)source, buffer, size); 3738 } 3739 3740 TPM_RC TPMA_SESSION_Unmarshal(TPMA_SESSION* target, 3741 BYTE** buffer, 3742 INT32* size) { 3743 TPM_RC result; 3744 result = uint8_t_Unmarshal((uint8_t*)target, buffer, size); 3745 if (result != TPM_RC_SUCCESS) { 3746 return result; 3747 } 3748 if (target->reserved3_4 != 0) { 3749 return TPM_RC_RESERVED_BITS; 3750 } 3751 return TPM_RC_SUCCESS; 3752 } 3753 3754 UINT16 TPMA_STARTUP_CLEAR_Marshal(TPMA_STARTUP_CLEAR* source, 3755 BYTE** buffer, 3756 INT32* size) { 3757 return uint32_t_Marshal((uint32_t*)source, buffer, size); 3758 } 3759 3760 TPM_RC TPMA_STARTUP_CLEAR_Unmarshal(TPMA_STARTUP_CLEAR* target, 3761 BYTE** buffer, 3762 INT32* size) { 3763 TPM_RC result; 3764 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 3765 if (result != TPM_RC_SUCCESS) { 3766 return result; 3767 } 3768 if (target->reserved4_30 != 0) { 3769 return TPM_RC_RESERVED_BITS; 3770 } 3771 return TPM_RC_SUCCESS; 3772 } 3773 3774 UINT16 TPMI_ALG_ASYM_Marshal(TPMI_ALG_ASYM* source, 3775 BYTE** buffer, 3776 INT32* size) { 3777 return uint16_t_Marshal(source, buffer, size); 3778 } 3779 3780 TPM_RC TPMI_ALG_ASYM_Unmarshal(TPMI_ALG_ASYM* target, 3781 BYTE** buffer, 3782 INT32* size, 3783 BOOL allow_conditional_value) { 3784 TPM_RC result; 3785 BOOL has_valid_value = FALSE; 3786 result = uint16_t_Unmarshal(target, buffer, size); 3787 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3788 return result; 3789 } 3790 if (*target == TPM_ALG_NULL) { 3791 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_ASYMMETRIC; 3792 } 3793 switch (*target) { 3794 #ifdef TPM_ALG_RSA 3795 case TPM_ALG_RSA: 3796 #endif 3797 #ifdef TPM_ALG_ECC 3798 case TPM_ALG_ECC: 3799 #endif 3800 has_valid_value = TRUE; 3801 break; 3802 } 3803 if (!has_valid_value) { 3804 return TPM_RC_ASYMMETRIC; 3805 } 3806 return TPM_RC_SUCCESS; 3807 } 3808 3809 UINT16 TPMI_ALG_RSA_DECRYPT_Marshal(TPMI_ALG_RSA_DECRYPT* source, 3810 BYTE** buffer, 3811 INT32* size) { 3812 return uint16_t_Marshal(source, buffer, size); 3813 } 3814 3815 TPM_RC TPMI_ALG_RSA_DECRYPT_Unmarshal(TPMI_ALG_RSA_DECRYPT* target, 3816 BYTE** buffer, 3817 INT32* size, 3818 BOOL allow_conditional_value) { 3819 TPM_RC result; 3820 BOOL has_valid_value = FALSE; 3821 result = uint16_t_Unmarshal(target, buffer, size); 3822 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3823 return result; 3824 } 3825 if (*target == TPM_ALG_NULL) { 3826 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 3827 } 3828 switch (*target) { 3829 #ifdef TPM_ALG_RSAES 3830 case TPM_ALG_RSAES: 3831 #endif 3832 #ifdef TPM_ALG_OAEP 3833 case TPM_ALG_OAEP: 3834 #endif 3835 has_valid_value = TRUE; 3836 break; 3837 } 3838 if (!has_valid_value) { 3839 return TPM_RC_VALUE; 3840 } 3841 return TPM_RC_SUCCESS; 3842 } 3843 3844 UINT16 TPMI_ALG_SIG_SCHEME_Marshal(TPMI_ALG_SIG_SCHEME* source, 3845 BYTE** buffer, 3846 INT32* size) { 3847 return uint16_t_Marshal(source, buffer, size); 3848 } 3849 3850 TPM_RC TPMI_ALG_SIG_SCHEME_Unmarshal(TPMI_ALG_SIG_SCHEME* target, 3851 BYTE** buffer, 3852 INT32* size, 3853 BOOL allow_conditional_value) { 3854 TPM_RC result; 3855 BOOL has_valid_value = FALSE; 3856 result = uint16_t_Unmarshal(target, buffer, size); 3857 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3858 return result; 3859 } 3860 if (*target == TPM_ALG_NULL) { 3861 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SCHEME; 3862 } 3863 switch (*target) { 3864 #ifdef TPM_ALG_RSASSA 3865 case TPM_ALG_RSASSA: 3866 #endif 3867 #ifdef TPM_ALG_RSAPSS 3868 case TPM_ALG_RSAPSS: 3869 #endif 3870 #ifdef TPM_ALG_ECDSA 3871 case TPM_ALG_ECDSA: 3872 #endif 3873 #ifdef TPM_ALG_ECDAA 3874 case TPM_ALG_ECDAA: 3875 #endif 3876 #ifdef TPM_ALG_SM2 3877 case TPM_ALG_SM2: 3878 #endif 3879 #ifdef TPM_ALG_ECSCHNORR 3880 case TPM_ALG_ECSCHNORR: 3881 #endif 3882 #ifdef TPM_ALG_HMAC 3883 case TPM_ALG_HMAC: 3884 #endif 3885 has_valid_value = TRUE; 3886 break; 3887 } 3888 if (!has_valid_value) { 3889 return TPM_RC_SCHEME; 3890 } 3891 return TPM_RC_SUCCESS; 3892 } 3893 3894 UINT16 TPMI_ALG_SYM_Marshal(TPMI_ALG_SYM* source, BYTE** buffer, INT32* size) { 3895 return uint16_t_Marshal(source, buffer, size); 3896 } 3897 3898 TPM_RC TPMI_ALG_SYM_Unmarshal(TPMI_ALG_SYM* target, 3899 BYTE** buffer, 3900 INT32* size, 3901 BOOL allow_conditional_value) { 3902 TPM_RC result; 3903 BOOL has_valid_value = FALSE; 3904 result = uint16_t_Unmarshal(target, buffer, size); 3905 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3906 return result; 3907 } 3908 if (*target == TPM_ALG_NULL) { 3909 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SYMMETRIC; 3910 } 3911 switch (*target) { 3912 #ifdef TPM_ALG_AES 3913 case TPM_ALG_AES: 3914 #endif 3915 #ifdef TPM_ALG_SM4 3916 case TPM_ALG_SM4: 3917 #endif 3918 #ifdef TPM_ALG_CAMELLIA 3919 case TPM_ALG_CAMELLIA: 3920 #endif 3921 #ifdef TPM_ALG_XOR 3922 case TPM_ALG_XOR: 3923 #endif 3924 has_valid_value = TRUE; 3925 break; 3926 } 3927 if (!has_valid_value) { 3928 return TPM_RC_SYMMETRIC; 3929 } 3930 return TPM_RC_SUCCESS; 3931 } 3932 3933 UINT16 TPMI_DH_CONTEXT_Marshal(TPMI_DH_CONTEXT* source, 3934 BYTE** buffer, 3935 INT32* size) { 3936 return uint32_t_Marshal(source, buffer, size); 3937 } 3938 3939 TPM_RC TPMI_DH_CONTEXT_Unmarshal(TPMI_DH_CONTEXT* target, 3940 BYTE** buffer, 3941 INT32* size) { 3942 TPM_RC result; 3943 BOOL has_valid_value = FALSE; 3944 result = uint32_t_Unmarshal(target, buffer, size); 3945 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3946 return result; 3947 } 3948 if ((*target >= HMAC_SESSION_FIRST) && (*target <= HMAC_SESSION_LAST)) { 3949 has_valid_value = TRUE; 3950 } 3951 if ((*target >= POLICY_SESSION_FIRST) && (*target <= POLICY_SESSION_LAST)) { 3952 has_valid_value = TRUE; 3953 } 3954 if ((*target >= TRANSIENT_FIRST) && (*target <= TRANSIENT_LAST)) { 3955 has_valid_value = TRUE; 3956 } 3957 if (!has_valid_value) { 3958 return TPM_RC_VALUE; 3959 } 3960 return TPM_RC_SUCCESS; 3961 } 3962 3963 UINT16 TPMI_DH_ENTITY_Marshal(TPMI_DH_ENTITY* source, 3964 BYTE** buffer, 3965 INT32* size) { 3966 return uint32_t_Marshal(source, buffer, size); 3967 } 3968 3969 TPM_RC TPMI_DH_ENTITY_Unmarshal(TPMI_DH_ENTITY* target, 3970 BYTE** buffer, 3971 INT32* size, 3972 BOOL allow_conditional_value) { 3973 TPM_RC result; 3974 BOOL has_valid_value = FALSE; 3975 result = uint32_t_Unmarshal(target, buffer, size); 3976 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 3977 return result; 3978 } 3979 if (*target == TPM_RH_NULL) { 3980 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 3981 } 3982 switch (*target) { 3983 case TPM_RH_OWNER: 3984 case TPM_RH_ENDORSEMENT: 3985 case TPM_RH_PLATFORM: 3986 case TPM_RH_LOCKOUT: 3987 has_valid_value = TRUE; 3988 break; 3989 } 3990 if ((*target >= TRANSIENT_FIRST) && (*target <= TRANSIENT_LAST)) { 3991 has_valid_value = TRUE; 3992 } 3993 if ((*target >= PERSISTENT_FIRST) && (*target <= PERSISTENT_LAST)) { 3994 has_valid_value = TRUE; 3995 } 3996 if ((*target >= NV_INDEX_FIRST) && (*target <= NV_INDEX_LAST)) { 3997 has_valid_value = TRUE; 3998 } 3999 if ((*target >= PCR_FIRST) && (*target <= PCR_LAST)) { 4000 has_valid_value = TRUE; 4001 } 4002 if ((*target >= TPM_RH_AUTH_00) && (*target <= TPM_RH_AUTH_FF)) { 4003 has_valid_value = TRUE; 4004 } 4005 if (!has_valid_value) { 4006 return TPM_RC_VALUE; 4007 } 4008 return TPM_RC_SUCCESS; 4009 } 4010 4011 UINT16 TPMI_DH_OBJECT_Marshal(TPMI_DH_OBJECT* source, 4012 BYTE** buffer, 4013 INT32* size) { 4014 return uint32_t_Marshal(source, buffer, size); 4015 } 4016 4017 TPM_RC TPMI_DH_OBJECT_Unmarshal(TPMI_DH_OBJECT* target, 4018 BYTE** buffer, 4019 INT32* size, 4020 BOOL allow_conditional_value) { 4021 TPM_RC result; 4022 BOOL has_valid_value = FALSE; 4023 result = uint32_t_Unmarshal(target, buffer, size); 4024 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4025 return result; 4026 } 4027 if (*target == TPM_RH_NULL) { 4028 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4029 } 4030 if ((*target >= TRANSIENT_FIRST) && (*target <= TRANSIENT_LAST)) { 4031 has_valid_value = TRUE; 4032 } 4033 if ((*target >= PERSISTENT_FIRST) && (*target <= PERSISTENT_LAST)) { 4034 has_valid_value = TRUE; 4035 } 4036 if (!has_valid_value) { 4037 return TPM_RC_VALUE; 4038 } 4039 return TPM_RC_SUCCESS; 4040 } 4041 4042 UINT16 TPMI_DH_PCR_Marshal(TPMI_DH_PCR* source, BYTE** buffer, INT32* size) { 4043 return uint32_t_Marshal(source, buffer, size); 4044 } 4045 4046 TPM_RC TPMI_DH_PCR_Unmarshal(TPMI_DH_PCR* target, 4047 BYTE** buffer, 4048 INT32* size, 4049 BOOL allow_conditional_value) { 4050 TPM_RC result; 4051 BOOL has_valid_value = FALSE; 4052 result = uint32_t_Unmarshal(target, buffer, size); 4053 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4054 return result; 4055 } 4056 if (*target == TPM_RH_NULL) { 4057 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4058 } 4059 if ((*target >= PCR_FIRST) && (*target <= PCR_LAST)) { 4060 has_valid_value = TRUE; 4061 } 4062 if (!has_valid_value) { 4063 return TPM_RC_VALUE; 4064 } 4065 return TPM_RC_SUCCESS; 4066 } 4067 4068 UINT16 TPMI_DH_PERSISTENT_Marshal(TPMI_DH_PERSISTENT* source, 4069 BYTE** buffer, 4070 INT32* size) { 4071 return uint32_t_Marshal(source, buffer, size); 4072 } 4073 4074 TPM_RC TPMI_DH_PERSISTENT_Unmarshal(TPMI_DH_PERSISTENT* target, 4075 BYTE** buffer, 4076 INT32* size) { 4077 TPM_RC result; 4078 BOOL has_valid_value = FALSE; 4079 result = uint32_t_Unmarshal(target, buffer, size); 4080 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4081 return result; 4082 } 4083 if ((*target >= PERSISTENT_FIRST) && (*target <= PERSISTENT_LAST)) { 4084 has_valid_value = TRUE; 4085 } 4086 if (!has_valid_value) { 4087 return TPM_RC_VALUE; 4088 } 4089 return TPM_RC_SUCCESS; 4090 } 4091 4092 UINT16 TPMI_ECC_KEY_EXCHANGE_Marshal(TPMI_ECC_KEY_EXCHANGE* source, 4093 BYTE** buffer, 4094 INT32* size) { 4095 return uint16_t_Marshal(source, buffer, size); 4096 } 4097 4098 TPM_RC TPMI_ECC_KEY_EXCHANGE_Unmarshal(TPMI_ECC_KEY_EXCHANGE* target, 4099 BYTE** buffer, 4100 INT32* size, 4101 BOOL allow_conditional_value) { 4102 TPM_RC result; 4103 BOOL has_valid_value = FALSE; 4104 result = uint16_t_Unmarshal(target, buffer, size); 4105 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4106 return result; 4107 } 4108 if (*target == TPM_ALG_NULL) { 4109 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_SCHEME; 4110 } 4111 switch (*target) { 4112 #ifdef TPM_ALG_ECDH 4113 case TPM_ALG_ECDH: 4114 #endif 4115 #ifdef TPM_ALG_ECMQV 4116 case TPM_ALG_ECMQV: 4117 #endif 4118 #ifdef TPM_ALG_SM2 4119 case TPM_ALG_SM2: 4120 #endif 4121 has_valid_value = TRUE; 4122 break; 4123 } 4124 if (!has_valid_value) { 4125 return TPM_RC_SCHEME; 4126 } 4127 return TPM_RC_SUCCESS; 4128 } 4129 4130 UINT16 TPMI_RH_CLEAR_Marshal(TPMI_RH_CLEAR* source, 4131 BYTE** buffer, 4132 INT32* size) { 4133 return uint32_t_Marshal(source, buffer, size); 4134 } 4135 4136 TPM_RC TPMI_RH_CLEAR_Unmarshal(TPMI_RH_CLEAR* target, 4137 BYTE** buffer, 4138 INT32* size) { 4139 TPM_RC result; 4140 BOOL has_valid_value = FALSE; 4141 result = uint32_t_Unmarshal(target, buffer, size); 4142 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4143 return result; 4144 } 4145 switch (*target) { 4146 case TPM_RH_LOCKOUT: 4147 case TPM_RH_PLATFORM: 4148 has_valid_value = TRUE; 4149 break; 4150 } 4151 if (!has_valid_value) { 4152 return TPM_RC_VALUE; 4153 } 4154 return TPM_RC_SUCCESS; 4155 } 4156 4157 UINT16 TPMI_RH_ENABLES_Marshal(TPMI_RH_ENABLES* source, 4158 BYTE** buffer, 4159 INT32* size) { 4160 return uint32_t_Marshal(source, buffer, size); 4161 } 4162 4163 TPM_RC TPMI_RH_ENABLES_Unmarshal(TPMI_RH_ENABLES* target, 4164 BYTE** buffer, 4165 INT32* size, 4166 BOOL allow_conditional_value) { 4167 TPM_RC result; 4168 BOOL has_valid_value = FALSE; 4169 result = uint32_t_Unmarshal(target, buffer, size); 4170 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4171 return result; 4172 } 4173 if (*target == TPM_RH_NULL) { 4174 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4175 } 4176 switch (*target) { 4177 case TPM_RH_OWNER: 4178 case TPM_RH_PLATFORM: 4179 case TPM_RH_ENDORSEMENT: 4180 case TPM_RH_PLATFORM_NV: 4181 has_valid_value = TRUE; 4182 break; 4183 } 4184 if (!has_valid_value) { 4185 return TPM_RC_VALUE; 4186 } 4187 return TPM_RC_SUCCESS; 4188 } 4189 4190 UINT16 TPMI_RH_ENDORSEMENT_Marshal(TPMI_RH_ENDORSEMENT* source, 4191 BYTE** buffer, 4192 INT32* size) { 4193 return uint32_t_Marshal(source, buffer, size); 4194 } 4195 4196 TPM_RC TPMI_RH_ENDORSEMENT_Unmarshal(TPMI_RH_ENDORSEMENT* target, 4197 BYTE** buffer, 4198 INT32* size, 4199 BOOL allow_conditional_value) { 4200 TPM_RC result; 4201 BOOL has_valid_value = FALSE; 4202 result = uint32_t_Unmarshal(target, buffer, size); 4203 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4204 return result; 4205 } 4206 if (*target == TPM_RH_NULL) { 4207 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4208 } 4209 switch (*target) { 4210 case TPM_RH_ENDORSEMENT: 4211 has_valid_value = TRUE; 4212 break; 4213 } 4214 if (!has_valid_value) { 4215 return TPM_RC_VALUE; 4216 } 4217 return TPM_RC_SUCCESS; 4218 } 4219 4220 UINT16 TPMI_RH_HIERARCHY_Marshal(TPMI_RH_HIERARCHY* source, 4221 BYTE** buffer, 4222 INT32* size) { 4223 return uint32_t_Marshal(source, buffer, size); 4224 } 4225 4226 TPM_RC TPMI_RH_HIERARCHY_Unmarshal(TPMI_RH_HIERARCHY* target, 4227 BYTE** buffer, 4228 INT32* size, 4229 BOOL allow_conditional_value) { 4230 TPM_RC result; 4231 BOOL has_valid_value = FALSE; 4232 result = uint32_t_Unmarshal(target, buffer, size); 4233 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4234 return result; 4235 } 4236 if (*target == TPM_RH_NULL) { 4237 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4238 } 4239 switch (*target) { 4240 case TPM_RH_OWNER: 4241 case TPM_RH_PLATFORM: 4242 case TPM_RH_ENDORSEMENT: 4243 has_valid_value = TRUE; 4244 break; 4245 } 4246 if (!has_valid_value) { 4247 return TPM_RC_VALUE; 4248 } 4249 return TPM_RC_SUCCESS; 4250 } 4251 4252 UINT16 TPMI_RH_HIERARCHY_AUTH_Marshal(TPMI_RH_HIERARCHY_AUTH* source, 4253 BYTE** buffer, 4254 INT32* size) { 4255 return uint32_t_Marshal(source, buffer, size); 4256 } 4257 4258 TPM_RC TPMI_RH_HIERARCHY_AUTH_Unmarshal(TPMI_RH_HIERARCHY_AUTH* target, 4259 BYTE** buffer, 4260 INT32* size) { 4261 TPM_RC result; 4262 BOOL has_valid_value = FALSE; 4263 result = uint32_t_Unmarshal(target, buffer, size); 4264 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4265 return result; 4266 } 4267 switch (*target) { 4268 case TPM_RH_OWNER: 4269 case TPM_RH_PLATFORM: 4270 case TPM_RH_ENDORSEMENT: 4271 case TPM_RH_LOCKOUT: 4272 has_valid_value = TRUE; 4273 break; 4274 } 4275 if (!has_valid_value) { 4276 return TPM_RC_VALUE; 4277 } 4278 return TPM_RC_SUCCESS; 4279 } 4280 4281 UINT16 TPMI_RH_LOCKOUT_Marshal(TPMI_RH_LOCKOUT* source, 4282 BYTE** buffer, 4283 INT32* size) { 4284 return uint32_t_Marshal(source, buffer, size); 4285 } 4286 4287 TPM_RC TPMI_RH_LOCKOUT_Unmarshal(TPMI_RH_LOCKOUT* target, 4288 BYTE** buffer, 4289 INT32* size) { 4290 TPM_RC result; 4291 BOOL has_valid_value = FALSE; 4292 result = uint32_t_Unmarshal(target, buffer, size); 4293 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4294 return result; 4295 } 4296 switch (*target) { 4297 case TPM_RH_LOCKOUT: 4298 has_valid_value = TRUE; 4299 break; 4300 } 4301 if (!has_valid_value) { 4302 return TPM_RC_VALUE; 4303 } 4304 return TPM_RC_SUCCESS; 4305 } 4306 4307 UINT16 TPMI_RH_NV_AUTH_Marshal(TPMI_RH_NV_AUTH* source, 4308 BYTE** buffer, 4309 INT32* size) { 4310 return uint32_t_Marshal(source, buffer, size); 4311 } 4312 4313 TPM_RC TPMI_RH_NV_AUTH_Unmarshal(TPMI_RH_NV_AUTH* target, 4314 BYTE** buffer, 4315 INT32* size) { 4316 TPM_RC result; 4317 BOOL has_valid_value = FALSE; 4318 result = uint32_t_Unmarshal(target, buffer, size); 4319 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4320 return result; 4321 } 4322 switch (*target) { 4323 case TPM_RH_PLATFORM: 4324 case TPM_RH_OWNER: 4325 has_valid_value = TRUE; 4326 break; 4327 } 4328 if ((*target >= NV_INDEX_FIRST) && (*target <= NV_INDEX_LAST)) { 4329 has_valid_value = TRUE; 4330 } 4331 if (!has_valid_value) { 4332 return TPM_RC_VALUE; 4333 } 4334 return TPM_RC_SUCCESS; 4335 } 4336 4337 UINT16 TPMI_RH_OWNER_Marshal(TPMI_RH_OWNER* source, 4338 BYTE** buffer, 4339 INT32* size) { 4340 return uint32_t_Marshal(source, buffer, size); 4341 } 4342 4343 TPM_RC TPMI_RH_OWNER_Unmarshal(TPMI_RH_OWNER* target, 4344 BYTE** buffer, 4345 INT32* size, 4346 BOOL allow_conditional_value) { 4347 TPM_RC result; 4348 BOOL has_valid_value = FALSE; 4349 result = uint32_t_Unmarshal(target, buffer, size); 4350 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4351 return result; 4352 } 4353 if (*target == TPM_RH_NULL) { 4354 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4355 } 4356 switch (*target) { 4357 case TPM_RH_OWNER: 4358 has_valid_value = TRUE; 4359 break; 4360 } 4361 if (!has_valid_value) { 4362 return TPM_RC_VALUE; 4363 } 4364 return TPM_RC_SUCCESS; 4365 } 4366 4367 UINT16 TPMI_RH_PLATFORM_Marshal(TPMI_RH_PLATFORM* source, 4368 BYTE** buffer, 4369 INT32* size) { 4370 return uint32_t_Marshal(source, buffer, size); 4371 } 4372 4373 TPM_RC TPMI_RH_PLATFORM_Unmarshal(TPMI_RH_PLATFORM* target, 4374 BYTE** buffer, 4375 INT32* size) { 4376 TPM_RC result; 4377 BOOL has_valid_value = FALSE; 4378 result = uint32_t_Unmarshal(target, buffer, size); 4379 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4380 return result; 4381 } 4382 switch (*target) { 4383 case TPM_RH_PLATFORM: 4384 has_valid_value = TRUE; 4385 break; 4386 } 4387 if (!has_valid_value) { 4388 return TPM_RC_VALUE; 4389 } 4390 return TPM_RC_SUCCESS; 4391 } 4392 4393 UINT16 TPMI_RH_PROVISION_Marshal(TPMI_RH_PROVISION* source, 4394 BYTE** buffer, 4395 INT32* size) { 4396 return uint32_t_Marshal(source, buffer, size); 4397 } 4398 4399 TPM_RC TPMI_RH_PROVISION_Unmarshal(TPMI_RH_PROVISION* target, 4400 BYTE** buffer, 4401 INT32* size) { 4402 TPM_RC result; 4403 BOOL has_valid_value = FALSE; 4404 result = uint32_t_Unmarshal(target, buffer, size); 4405 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4406 return result; 4407 } 4408 switch (*target) { 4409 case TPM_RH_OWNER: 4410 case TPM_RH_PLATFORM: 4411 has_valid_value = TRUE; 4412 break; 4413 } 4414 if (!has_valid_value) { 4415 return TPM_RC_VALUE; 4416 } 4417 return TPM_RC_SUCCESS; 4418 } 4419 4420 UINT16 TPMI_SH_AUTH_SESSION_Marshal(TPMI_SH_AUTH_SESSION* source, 4421 BYTE** buffer, 4422 INT32* size) { 4423 return uint32_t_Marshal(source, buffer, size); 4424 } 4425 4426 TPM_RC TPMI_SH_AUTH_SESSION_Unmarshal(TPMI_SH_AUTH_SESSION* target, 4427 BYTE** buffer, 4428 INT32* size, 4429 BOOL allow_conditional_value) { 4430 TPM_RC result; 4431 BOOL has_valid_value = FALSE; 4432 result = uint32_t_Unmarshal(target, buffer, size); 4433 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4434 return result; 4435 } 4436 if (*target == TPM_RS_PW) { 4437 return allow_conditional_value ? TPM_RC_SUCCESS : TPM_RC_VALUE; 4438 } 4439 if ((*target >= HMAC_SESSION_FIRST) && (*target <= HMAC_SESSION_LAST)) { 4440 has_valid_value = TRUE; 4441 } 4442 if ((*target >= POLICY_SESSION_FIRST) && (*target <= POLICY_SESSION_LAST)) { 4443 has_valid_value = TRUE; 4444 } 4445 if (!has_valid_value) { 4446 return TPM_RC_VALUE; 4447 } 4448 return TPM_RC_SUCCESS; 4449 } 4450 4451 UINT16 TPMI_SH_HMAC_Marshal(TPMI_SH_HMAC* source, BYTE** buffer, INT32* size) { 4452 return uint32_t_Marshal(source, buffer, size); 4453 } 4454 4455 TPM_RC TPMI_SH_HMAC_Unmarshal(TPMI_SH_HMAC* target, 4456 BYTE** buffer, 4457 INT32* size) { 4458 TPM_RC result; 4459 BOOL has_valid_value = FALSE; 4460 result = uint32_t_Unmarshal(target, buffer, size); 4461 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4462 return result; 4463 } 4464 if ((*target >= HMAC_SESSION_FIRST) && (*target <= HMAC_SESSION_LAST)) { 4465 has_valid_value = TRUE; 4466 } 4467 if (!has_valid_value) { 4468 return TPM_RC_VALUE; 4469 } 4470 return TPM_RC_SUCCESS; 4471 } 4472 4473 UINT16 TPMI_SH_POLICY_Marshal(TPMI_SH_POLICY* source, 4474 BYTE** buffer, 4475 INT32* size) { 4476 return uint32_t_Marshal(source, buffer, size); 4477 } 4478 4479 TPM_RC TPMI_SH_POLICY_Unmarshal(TPMI_SH_POLICY* target, 4480 BYTE** buffer, 4481 INT32* size) { 4482 TPM_RC result; 4483 BOOL has_valid_value = FALSE; 4484 result = uint32_t_Unmarshal(target, buffer, size); 4485 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4486 return result; 4487 } 4488 if ((*target >= POLICY_SESSION_FIRST) && (*target <= POLICY_SESSION_LAST)) { 4489 has_valid_value = TRUE; 4490 } 4491 if (!has_valid_value) { 4492 return TPM_RC_VALUE; 4493 } 4494 return TPM_RC_SUCCESS; 4495 } 4496 4497 UINT16 TPMI_ST_ATTEST_Marshal(TPMI_ST_ATTEST* source, 4498 BYTE** buffer, 4499 INT32* size) { 4500 return uint16_t_Marshal(source, buffer, size); 4501 } 4502 4503 TPM_RC TPMI_ST_ATTEST_Unmarshal(TPMI_ST_ATTEST* target, 4504 BYTE** buffer, 4505 INT32* size) { 4506 TPM_RC result; 4507 BOOL has_valid_value = FALSE; 4508 result = uint16_t_Unmarshal(target, buffer, size); 4509 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4510 return result; 4511 } 4512 switch (*target) { 4513 case TPM_ST_ATTEST_CERTIFY: 4514 case TPM_ST_ATTEST_QUOTE: 4515 case TPM_ST_ATTEST_SESSION_AUDIT: 4516 case TPM_ST_ATTEST_COMMAND_AUDIT: 4517 case TPM_ST_ATTEST_TIME: 4518 case TPM_ST_ATTEST_CREATION: 4519 case TPM_ST_ATTEST_NV: 4520 has_valid_value = TRUE; 4521 break; 4522 } 4523 if (!has_valid_value) { 4524 return TPM_RC_VALUE; 4525 } 4526 return TPM_RC_SUCCESS; 4527 } 4528 4529 UINT16 TPMI_ST_COMMAND_TAG_Marshal(TPMI_ST_COMMAND_TAG* source, 4530 BYTE** buffer, 4531 INT32* size) { 4532 return uint16_t_Marshal(source, buffer, size); 4533 } 4534 4535 TPM_RC TPMI_ST_COMMAND_TAG_Unmarshal(TPMI_ST_COMMAND_TAG* target, 4536 BYTE** buffer, 4537 INT32* size) { 4538 TPM_RC result; 4539 BOOL has_valid_value = FALSE; 4540 result = uint16_t_Unmarshal(target, buffer, size); 4541 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4542 return result; 4543 } 4544 switch (*target) { 4545 case TPM_ST_NO_SESSIONS: 4546 case TPM_ST_SESSIONS: 4547 has_valid_value = TRUE; 4548 break; 4549 } 4550 if (!has_valid_value) { 4551 return TPM_RC_BAD_TAG; 4552 } 4553 return TPM_RC_SUCCESS; 4554 } 4555 4556 UINT16 TPMI_YES_NO_Marshal(TPMI_YES_NO* source, BYTE** buffer, INT32* size) { 4557 return uint8_t_Marshal(source, buffer, size); 4558 } 4559 4560 TPM_RC TPMI_YES_NO_Unmarshal(TPMI_YES_NO* target, BYTE** buffer, INT32* size) { 4561 TPM_RC result; 4562 BOOL has_valid_value = FALSE; 4563 result = uint8_t_Unmarshal(target, buffer, size); 4564 if ((result != TPM_RC_VALUE) && (result != TPM_RC_SUCCESS)) { 4565 return result; 4566 } 4567 switch (*target) { 4568 case NO: 4569 case YES: 4570 has_valid_value = TRUE; 4571 break; 4572 } 4573 if (!has_valid_value) { 4574 return TPM_RC_VALUE; 4575 } 4576 return TPM_RC_SUCCESS; 4577 } 4578 4579 UINT16 TPML_ALG_Marshal(TPML_ALG* source, BYTE** buffer, INT32* size) { 4580 UINT16 total_size = 0; 4581 INT32 i; 4582 total_size += UINT32_Marshal(&source->count, buffer, size); 4583 for (i = 0; i < source->count; ++i) { 4584 total_size += TPM_ALG_ID_Marshal(&source->algorithms[i], buffer, size); 4585 } 4586 return total_size; 4587 } 4588 4589 TPM_RC TPML_ALG_Unmarshal(TPML_ALG* target, BYTE** buffer, INT32* size) { 4590 TPM_RC result; 4591 INT32 i; 4592 result = UINT32_Unmarshal(&target->count, buffer, size); 4593 if (result != TPM_RC_SUCCESS) { 4594 return result; 4595 } 4596 if (target->count > MAX_ALG_LIST_SIZE) { 4597 return TPM_RC_SIZE; 4598 } 4599 for (i = 0; i < target->count; ++i) { 4600 result = TPM_ALG_ID_Unmarshal(&target->algorithms[i], buffer, size); 4601 if (result != TPM_RC_SUCCESS) { 4602 return result; 4603 } 4604 } 4605 return TPM_RC_SUCCESS; 4606 } 4607 4608 UINT16 TPMS_ALG_PROPERTY_Marshal(TPMS_ALG_PROPERTY* source, 4609 BYTE** buffer, 4610 INT32* size) { 4611 UINT16 total_size = 0; 4612 total_size += TPM_ALG_ID_Marshal(&source->alg, buffer, size); 4613 total_size += TPMA_ALGORITHM_Marshal(&source->algProperties, buffer, size); 4614 return total_size; 4615 } 4616 4617 TPM_RC TPMS_ALG_PROPERTY_Unmarshal(TPMS_ALG_PROPERTY* target, 4618 BYTE** buffer, 4619 INT32* size) { 4620 TPM_RC result; 4621 result = TPM_ALG_ID_Unmarshal(&target->alg, buffer, size); 4622 if (result != TPM_RC_SUCCESS) { 4623 return result; 4624 } 4625 result = TPMA_ALGORITHM_Unmarshal(&target->algProperties, buffer, size); 4626 if (result != TPM_RC_SUCCESS) { 4627 return result; 4628 } 4629 return TPM_RC_SUCCESS; 4630 } 4631 4632 UINT16 TPML_ALG_PROPERTY_Marshal(TPML_ALG_PROPERTY* source, 4633 BYTE** buffer, 4634 INT32* size) { 4635 UINT16 total_size = 0; 4636 INT32 i; 4637 total_size += UINT32_Marshal(&source->count, buffer, size); 4638 for (i = 0; i < source->count; ++i) { 4639 total_size += 4640 TPMS_ALG_PROPERTY_Marshal(&source->algProperties[i], buffer, size); 4641 } 4642 return total_size; 4643 } 4644 4645 TPM_RC TPML_ALG_PROPERTY_Unmarshal(TPML_ALG_PROPERTY* target, 4646 BYTE** buffer, 4647 INT32* size) { 4648 TPM_RC result; 4649 INT32 i; 4650 result = UINT32_Unmarshal(&target->count, buffer, size); 4651 if (result != TPM_RC_SUCCESS) { 4652 return result; 4653 } 4654 if (target->count > MAX_CAP_ALGS) { 4655 return TPM_RC_SIZE; 4656 } 4657 for (i = 0; i < target->count; ++i) { 4658 result = 4659 TPMS_ALG_PROPERTY_Unmarshal(&target->algProperties[i], buffer, size); 4660 if (result != TPM_RC_SUCCESS) { 4661 return result; 4662 } 4663 } 4664 return TPM_RC_SUCCESS; 4665 } 4666 4667 UINT16 TPM_CC_Marshal(TPM_CC* source, BYTE** buffer, INT32* size) { 4668 return uint32_t_Marshal(source, buffer, size); 4669 } 4670 4671 TPM_RC TPM_CC_Unmarshal(TPM_CC* target, BYTE** buffer, INT32* size) { 4672 TPM_RC result; 4673 result = uint32_t_Unmarshal(target, buffer, size); 4674 if (result != TPM_RC_SUCCESS) { 4675 return result; 4676 } 4677 #ifdef TPM_CC_FIRST 4678 if (*target == TPM_CC_FIRST) { 4679 return TPM_RC_SUCCESS; 4680 } 4681 #endif 4682 #ifdef TPM_CC_PP_FIRST 4683 if (*target == TPM_CC_PP_FIRST) { 4684 return TPM_RC_SUCCESS; 4685 } 4686 #endif 4687 #ifdef TPM_CC_NV_UndefineSpaceSpecial 4688 if (*target == TPM_CC_NV_UndefineSpaceSpecial) { 4689 return TPM_RC_SUCCESS; 4690 } 4691 #endif 4692 #ifdef TPM_CC_EvictControl 4693 if (*target == TPM_CC_EvictControl) { 4694 return TPM_RC_SUCCESS; 4695 } 4696 #endif 4697 #ifdef TPM_CC_HierarchyControl 4698 if (*target == TPM_CC_HierarchyControl) { 4699 return TPM_RC_SUCCESS; 4700 } 4701 #endif 4702 #ifdef TPM_CC_NV_UndefineSpace 4703 if (*target == TPM_CC_NV_UndefineSpace) { 4704 return TPM_RC_SUCCESS; 4705 } 4706 #endif 4707 #ifdef TPM_CC_ChangeEPS 4708 if (*target == TPM_CC_ChangeEPS) { 4709 return TPM_RC_SUCCESS; 4710 } 4711 #endif 4712 #ifdef TPM_CC_ChangePPS 4713 if (*target == TPM_CC_ChangePPS) { 4714 return TPM_RC_SUCCESS; 4715 } 4716 #endif 4717 #ifdef TPM_CC_Clear 4718 if (*target == TPM_CC_Clear) { 4719 return TPM_RC_SUCCESS; 4720 } 4721 #endif 4722 #ifdef TPM_CC_ClearControl 4723 if (*target == TPM_CC_ClearControl) { 4724 return TPM_RC_SUCCESS; 4725 } 4726 #endif 4727 #ifdef TPM_CC_ClockSet 4728 if (*target == TPM_CC_ClockSet) { 4729 return TPM_RC_SUCCESS; 4730 } 4731 #endif 4732 #ifdef TPM_CC_HierarchyChangeAuth 4733 if (*target == TPM_CC_HierarchyChangeAuth) { 4734 return TPM_RC_SUCCESS; 4735 } 4736 #endif 4737 #ifdef TPM_CC_NV_DefineSpace 4738 if (*target == TPM_CC_NV_DefineSpace) { 4739 return TPM_RC_SUCCESS; 4740 } 4741 #endif 4742 #ifdef TPM_CC_PCR_Allocate 4743 if (*target == TPM_CC_PCR_Allocate) { 4744 return TPM_RC_SUCCESS; 4745 } 4746 #endif 4747 #ifdef TPM_CC_PCR_SetAuthPolicy 4748 if (*target == TPM_CC_PCR_SetAuthPolicy) { 4749 return TPM_RC_SUCCESS; 4750 } 4751 #endif 4752 #ifdef TPM_CC_PP_Commands 4753 if (*target == TPM_CC_PP_Commands) { 4754 return TPM_RC_SUCCESS; 4755 } 4756 #endif 4757 #ifdef TPM_CC_SetPrimaryPolicy 4758 if (*target == TPM_CC_SetPrimaryPolicy) { 4759 return TPM_RC_SUCCESS; 4760 } 4761 #endif 4762 #ifdef TPM_CC_FieldUpgradeStart 4763 if (*target == TPM_CC_FieldUpgradeStart) { 4764 return TPM_RC_SUCCESS; 4765 } 4766 #endif 4767 #ifdef TPM_CC_ClockRateAdjust 4768 if (*target == TPM_CC_ClockRateAdjust) { 4769 return TPM_RC_SUCCESS; 4770 } 4771 #endif 4772 #ifdef TPM_CC_CreatePrimary 4773 if (*target == TPM_CC_CreatePrimary) { 4774 return TPM_RC_SUCCESS; 4775 } 4776 #endif 4777 #ifdef TPM_CC_NV_GlobalWriteLock 4778 if (*target == TPM_CC_NV_GlobalWriteLock) { 4779 return TPM_RC_SUCCESS; 4780 } 4781 #endif 4782 #ifdef TPM_CC_PP_LAST 4783 if (*target == TPM_CC_PP_LAST) { 4784 return TPM_RC_SUCCESS; 4785 } 4786 #endif 4787 #ifdef TPM_CC_GetCommandAuditDigest 4788 if (*target == TPM_CC_GetCommandAuditDigest) { 4789 return TPM_RC_SUCCESS; 4790 } 4791 #endif 4792 #ifdef TPM_CC_NV_Increment 4793 if (*target == TPM_CC_NV_Increment) { 4794 return TPM_RC_SUCCESS; 4795 } 4796 #endif 4797 #ifdef TPM_CC_NV_SetBits 4798 if (*target == TPM_CC_NV_SetBits) { 4799 return TPM_RC_SUCCESS; 4800 } 4801 #endif 4802 #ifdef TPM_CC_NV_Extend 4803 if (*target == TPM_CC_NV_Extend) { 4804 return TPM_RC_SUCCESS; 4805 } 4806 #endif 4807 #ifdef TPM_CC_NV_Write 4808 if (*target == TPM_CC_NV_Write) { 4809 return TPM_RC_SUCCESS; 4810 } 4811 #endif 4812 #ifdef TPM_CC_NV_WriteLock 4813 if (*target == TPM_CC_NV_WriteLock) { 4814 return TPM_RC_SUCCESS; 4815 } 4816 #endif 4817 #ifdef TPM_CC_DictionaryAttackLockReset 4818 if (*target == TPM_CC_DictionaryAttackLockReset) { 4819 return TPM_RC_SUCCESS; 4820 } 4821 #endif 4822 #ifdef TPM_CC_DictionaryAttackParameters 4823 if (*target == TPM_CC_DictionaryAttackParameters) { 4824 return TPM_RC_SUCCESS; 4825 } 4826 #endif 4827 #ifdef TPM_CC_NV_ChangeAuth 4828 if (*target == TPM_CC_NV_ChangeAuth) { 4829 return TPM_RC_SUCCESS; 4830 } 4831 #endif 4832 #ifdef TPM_CC_PCR_Event 4833 if (*target == TPM_CC_PCR_Event) { 4834 return TPM_RC_SUCCESS; 4835 } 4836 #endif 4837 #ifdef TPM_CC_PCR_Reset 4838 if (*target == TPM_CC_PCR_Reset) { 4839 return TPM_RC_SUCCESS; 4840 } 4841 #endif 4842 #ifdef TPM_CC_SequenceComplete 4843 if (*target == TPM_CC_SequenceComplete) { 4844 return TPM_RC_SUCCESS; 4845 } 4846 #endif 4847 #ifdef TPM_CC_SetAlgorithmSet 4848 if (*target == TPM_CC_SetAlgorithmSet) { 4849 return TPM_RC_SUCCESS; 4850 } 4851 #endif 4852 #ifdef TPM_CC_SetCommandCodeAuditStatus 4853 if (*target == TPM_CC_SetCommandCodeAuditStatus) { 4854 return TPM_RC_SUCCESS; 4855 } 4856 #endif 4857 #ifdef TPM_CC_FieldUpgradeData 4858 if (*target == TPM_CC_FieldUpgradeData) { 4859 return TPM_RC_SUCCESS; 4860 } 4861 #endif 4862 #ifdef TPM_CC_IncrementalSelfTest 4863 if (*target == TPM_CC_IncrementalSelfTest) { 4864 return TPM_RC_SUCCESS; 4865 } 4866 #endif 4867 #ifdef TPM_CC_SelfTest 4868 if (*target == TPM_CC_SelfTest) { 4869 return TPM_RC_SUCCESS; 4870 } 4871 #endif 4872 #ifdef TPM_CC_Startup 4873 if (*target == TPM_CC_Startup) { 4874 return TPM_RC_SUCCESS; 4875 } 4876 #endif 4877 #ifdef TPM_CC_Shutdown 4878 if (*target == TPM_CC_Shutdown) { 4879 return TPM_RC_SUCCESS; 4880 } 4881 #endif 4882 #ifdef TPM_CC_StirRandom 4883 if (*target == TPM_CC_StirRandom) { 4884 return TPM_RC_SUCCESS; 4885 } 4886 #endif 4887 #ifdef TPM_CC_ActivateCredential 4888 if (*target == TPM_CC_ActivateCredential) { 4889 return TPM_RC_SUCCESS; 4890 } 4891 #endif 4892 #ifdef TPM_CC_Certify 4893 if (*target == TPM_CC_Certify) { 4894 return TPM_RC_SUCCESS; 4895 } 4896 #endif 4897 #ifdef TPM_CC_PolicyNV 4898 if (*target == TPM_CC_PolicyNV) { 4899 return TPM_RC_SUCCESS; 4900 } 4901 #endif 4902 #ifdef TPM_CC_CertifyCreation 4903 if (*target == TPM_CC_CertifyCreation) { 4904 return TPM_RC_SUCCESS; 4905 } 4906 #endif 4907 #ifdef TPM_CC_Duplicate 4908 if (*target == TPM_CC_Duplicate) { 4909 return TPM_RC_SUCCESS; 4910 } 4911 #endif 4912 #ifdef TPM_CC_GetTime 4913 if (*target == TPM_CC_GetTime) { 4914 return TPM_RC_SUCCESS; 4915 } 4916 #endif 4917 #ifdef TPM_CC_GetSessionAuditDigest 4918 if (*target == TPM_CC_GetSessionAuditDigest) { 4919 return TPM_RC_SUCCESS; 4920 } 4921 #endif 4922 #ifdef TPM_CC_NV_Read 4923 if (*target == TPM_CC_NV_Read) { 4924 return TPM_RC_SUCCESS; 4925 } 4926 #endif 4927 #ifdef TPM_CC_NV_ReadLock 4928 if (*target == TPM_CC_NV_ReadLock) { 4929 return TPM_RC_SUCCESS; 4930 } 4931 #endif 4932 #ifdef TPM_CC_ObjectChangeAuth 4933 if (*target == TPM_CC_ObjectChangeAuth) { 4934 return TPM_RC_SUCCESS; 4935 } 4936 #endif 4937 #ifdef TPM_CC_PolicySecret 4938 if (*target == TPM_CC_PolicySecret) { 4939 return TPM_RC_SUCCESS; 4940 } 4941 #endif 4942 #ifdef TPM_CC_Rewrap 4943 if (*target == TPM_CC_Rewrap) { 4944 return TPM_RC_SUCCESS; 4945 } 4946 #endif 4947 #ifdef TPM_CC_Create 4948 if (*target == TPM_CC_Create) { 4949 return TPM_RC_SUCCESS; 4950 } 4951 #endif 4952 #ifdef TPM_CC_ECDH_ZGen 4953 if (*target == TPM_CC_ECDH_ZGen) { 4954 return TPM_RC_SUCCESS; 4955 } 4956 #endif 4957 #ifdef TPM_CC_HMAC 4958 if (*target == TPM_CC_HMAC) { 4959 return TPM_RC_SUCCESS; 4960 } 4961 #endif 4962 #ifdef TPM_CC_Import 4963 if (*target == TPM_CC_Import) { 4964 return TPM_RC_SUCCESS; 4965 } 4966 #endif 4967 #ifdef TPM_CC_Load 4968 if (*target == TPM_CC_Load) { 4969 return TPM_RC_SUCCESS; 4970 } 4971 #endif 4972 #ifdef TPM_CC_Quote 4973 if (*target == TPM_CC_Quote) { 4974 return TPM_RC_SUCCESS; 4975 } 4976 #endif 4977 #ifdef TPM_CC_RSA_Decrypt 4978 if (*target == TPM_CC_RSA_Decrypt) { 4979 return TPM_RC_SUCCESS; 4980 } 4981 #endif 4982 #ifdef TPM_CC_HMAC_Start 4983 if (*target == TPM_CC_HMAC_Start) { 4984 return TPM_RC_SUCCESS; 4985 } 4986 #endif 4987 #ifdef TPM_CC_SequenceUpdate 4988 if (*target == TPM_CC_SequenceUpdate) { 4989 return TPM_RC_SUCCESS; 4990 } 4991 #endif 4992 #ifdef TPM_CC_Sign 4993 if (*target == TPM_CC_Sign) { 4994 return TPM_RC_SUCCESS; 4995 } 4996 #endif 4997 #ifdef TPM_CC_Unseal 4998 if (*target == TPM_CC_Unseal) { 4999 return TPM_RC_SUCCESS; 5000 } 5001 #endif 5002 #ifdef TPM_CC_PolicySigned 5003 if (*target == TPM_CC_PolicySigned) { 5004 return TPM_RC_SUCCESS; 5005 } 5006 #endif 5007 #ifdef TPM_CC_ContextLoad 5008 if (*target == TPM_CC_ContextLoad) { 5009 return TPM_RC_SUCCESS; 5010 } 5011 #endif 5012 #ifdef TPM_CC_ContextSave 5013 if (*target == TPM_CC_ContextSave) { 5014 return TPM_RC_SUCCESS; 5015 } 5016 #endif 5017 #ifdef TPM_CC_ECDH_KeyGen 5018 if (*target == TPM_CC_ECDH_KeyGen) { 5019 return TPM_RC_SUCCESS; 5020 } 5021 #endif 5022 #ifdef TPM_CC_EncryptDecrypt 5023 if (*target == TPM_CC_EncryptDecrypt) { 5024 return TPM_RC_SUCCESS; 5025 } 5026 #endif 5027 #ifdef TPM_CC_FlushContext 5028 if (*target == TPM_CC_FlushContext) { 5029 return TPM_RC_SUCCESS; 5030 } 5031 #endif 5032 #ifdef TPM_CC_LoadExternal 5033 if (*target == TPM_CC_LoadExternal) { 5034 return TPM_RC_SUCCESS; 5035 } 5036 #endif 5037 #ifdef TPM_CC_MakeCredential 5038 if (*target == TPM_CC_MakeCredential) { 5039 return TPM_RC_SUCCESS; 5040 } 5041 #endif 5042 #ifdef TPM_CC_NV_ReadPublic 5043 if (*target == TPM_CC_NV_ReadPublic) { 5044 return TPM_RC_SUCCESS; 5045 } 5046 #endif 5047 #ifdef TPM_CC_PolicyAuthorize 5048 if (*target == TPM_CC_PolicyAuthorize) { 5049 return TPM_RC_SUCCESS; 5050 } 5051 #endif 5052 #ifdef TPM_CC_PolicyAuthValue 5053 if (*target == TPM_CC_PolicyAuthValue) { 5054 return TPM_RC_SUCCESS; 5055 } 5056 #endif 5057 #ifdef TPM_CC_PolicyCommandCode 5058 if (*target == TPM_CC_PolicyCommandCode) { 5059 return TPM_RC_SUCCESS; 5060 } 5061 #endif 5062 #ifdef TPM_CC_PolicyCounterTimer 5063 if (*target == TPM_CC_PolicyCounterTimer) { 5064 return TPM_RC_SUCCESS; 5065 } 5066 #endif 5067 #ifdef TPM_CC_PolicyCpHash 5068 if (*target == TPM_CC_PolicyCpHash) { 5069 return TPM_RC_SUCCESS; 5070 } 5071 #endif 5072 #ifdef TPM_CC_PolicyLocality 5073 if (*target == TPM_CC_PolicyLocality) { 5074 return TPM_RC_SUCCESS; 5075 } 5076 #endif 5077 #ifdef TPM_CC_PolicyNameHash 5078 if (*target == TPM_CC_PolicyNameHash) { 5079 return TPM_RC_SUCCESS; 5080 } 5081 #endif 5082 #ifdef TPM_CC_PolicyOR 5083 if (*target == TPM_CC_PolicyOR) { 5084 return TPM_RC_SUCCESS; 5085 } 5086 #endif 5087 #ifdef TPM_CC_PolicyTicket 5088 if (*target == TPM_CC_PolicyTicket) { 5089 return TPM_RC_SUCCESS; 5090 } 5091 #endif 5092 #ifdef TPM_CC_ReadPublic 5093 if (*target == TPM_CC_ReadPublic) { 5094 return TPM_RC_SUCCESS; 5095 } 5096 #endif 5097 #ifdef TPM_CC_RSA_Encrypt 5098 if (*target == TPM_CC_RSA_Encrypt) { 5099 return TPM_RC_SUCCESS; 5100 } 5101 #endif 5102 #ifdef TPM_CC_StartAuthSession 5103 if (*target == TPM_CC_StartAuthSession) { 5104 return TPM_RC_SUCCESS; 5105 } 5106 #endif 5107 #ifdef TPM_CC_VerifySignature 5108 if (*target == TPM_CC_VerifySignature) { 5109 return TPM_RC_SUCCESS; 5110 } 5111 #endif 5112 #ifdef TPM_CC_ECC_Parameters 5113 if (*target == TPM_CC_ECC_Parameters) { 5114 return TPM_RC_SUCCESS; 5115 } 5116 #endif 5117 #ifdef TPM_CC_FirmwareRead 5118 if (*target == TPM_CC_FirmwareRead) { 5119 return TPM_RC_SUCCESS; 5120 } 5121 #endif 5122 #ifdef TPM_CC_GetCapability 5123 if (*target == TPM_CC_GetCapability) { 5124 return TPM_RC_SUCCESS; 5125 } 5126 #endif 5127 #ifdef TPM_CC_GetRandom 5128 if (*target == TPM_CC_GetRandom) { 5129 return TPM_RC_SUCCESS; 5130 } 5131 #endif 5132 #ifdef TPM_CC_GetTestResult 5133 if (*target == TPM_CC_GetTestResult) { 5134 return TPM_RC_SUCCESS; 5135 } 5136 #endif 5137 #ifdef TPM_CC_Hash 5138 if (*target == TPM_CC_Hash) { 5139 return TPM_RC_SUCCESS; 5140 } 5141 #endif 5142 #ifdef TPM_CC_PCR_Read 5143 if (*target == TPM_CC_PCR_Read) { 5144 return TPM_RC_SUCCESS; 5145 } 5146 #endif 5147 #ifdef TPM_CC_PolicyPCR 5148 if (*target == TPM_CC_PolicyPCR) { 5149 return TPM_RC_SUCCESS; 5150 } 5151 #endif 5152 #ifdef TPM_CC_PolicyRestart 5153 if (*target == TPM_CC_PolicyRestart) { 5154 return TPM_RC_SUCCESS; 5155 } 5156 #endif 5157 #ifdef TPM_CC_ReadClock 5158 if (*target == TPM_CC_ReadClock) { 5159 return TPM_RC_SUCCESS; 5160 } 5161 #endif 5162 #ifdef TPM_CC_PCR_Extend 5163 if (*target == TPM_CC_PCR_Extend) { 5164 return TPM_RC_SUCCESS; 5165 } 5166 #endif 5167 #ifdef TPM_CC_PCR_SetAuthValue 5168 if (*target == TPM_CC_PCR_SetAuthValue) { 5169 return TPM_RC_SUCCESS; 5170 } 5171 #endif 5172 #ifdef TPM_CC_NV_Certify 5173 if (*target == TPM_CC_NV_Certify) { 5174 return TPM_RC_SUCCESS; 5175 } 5176 #endif 5177 #ifdef TPM_CC_EventSequenceComplete 5178 if (*target == TPM_CC_EventSequenceComplete) { 5179 return TPM_RC_SUCCESS; 5180 } 5181 #endif 5182 #ifdef TPM_CC_HashSequenceStart 5183 if (*target == TPM_CC_HashSequenceStart) { 5184 return TPM_RC_SUCCESS; 5185 } 5186 #endif 5187 #ifdef TPM_CC_PolicyPhysicalPresence 5188 if (*target == TPM_CC_PolicyPhysicalPresence) { 5189 return TPM_RC_SUCCESS; 5190 } 5191 #endif 5192 #ifdef TPM_CC_PolicyDuplicationSelect 5193 if (*target == TPM_CC_PolicyDuplicationSelect) { 5194 return TPM_RC_SUCCESS; 5195 } 5196 #endif 5197 #ifdef TPM_CC_PolicyGetDigest 5198 if (*target == TPM_CC_PolicyGetDigest) { 5199 return TPM_RC_SUCCESS; 5200 } 5201 #endif 5202 #ifdef TPM_CC_TestParms 5203 if (*target == TPM_CC_TestParms) { 5204 return TPM_RC_SUCCESS; 5205 } 5206 #endif 5207 #ifdef TPM_CC_Commit 5208 if (*target == TPM_CC_Commit) { 5209 return TPM_RC_SUCCESS; 5210 } 5211 #endif 5212 #ifdef TPM_CC_PolicyPassword 5213 if (*target == TPM_CC_PolicyPassword) { 5214 return TPM_RC_SUCCESS; 5215 } 5216 #endif 5217 #ifdef TPM_CC_ZGen_2Phase 5218 if (*target == TPM_CC_ZGen_2Phase) { 5219 return TPM_RC_SUCCESS; 5220 } 5221 #endif 5222 #ifdef TPM_CC_EC_Ephemeral 5223 if (*target == TPM_CC_EC_Ephemeral) { 5224 return TPM_RC_SUCCESS; 5225 } 5226 #endif 5227 #ifdef TPM_CC_PolicyNvWritten 5228 if (*target == TPM_CC_PolicyNvWritten) { 5229 return TPM_RC_SUCCESS; 5230 } 5231 #endif 5232 #ifdef TPM_CC_LAST 5233 if (*target == TPM_CC_LAST) { 5234 return TPM_RC_SUCCESS; 5235 } 5236 #endif 5237 return TPM_RC_COMMAND_CODE; 5238 } 5239 5240 UINT16 TPML_CC_Marshal(TPML_CC* source, BYTE** buffer, INT32* size) { 5241 UINT16 total_size = 0; 5242 INT32 i; 5243 total_size += UINT32_Marshal(&source->count, buffer, size); 5244 for (i = 0; i < source->count; ++i) { 5245 total_size += TPM_CC_Marshal(&source->commandCodes[i], buffer, size); 5246 } 5247 return total_size; 5248 } 5249 5250 TPM_RC TPML_CC_Unmarshal(TPML_CC* target, BYTE** buffer, INT32* size) { 5251 TPM_RC result; 5252 INT32 i; 5253 result = UINT32_Unmarshal(&target->count, buffer, size); 5254 if (result != TPM_RC_SUCCESS) { 5255 return result; 5256 } 5257 if (target->count > MAX_CAP_CC) { 5258 return TPM_RC_SIZE; 5259 } 5260 for (i = 0; i < target->count; ++i) { 5261 result = TPM_CC_Unmarshal(&target->commandCodes[i], buffer, size); 5262 if (result != TPM_RC_SUCCESS) { 5263 return result; 5264 } 5265 } 5266 return TPM_RC_SUCCESS; 5267 } 5268 5269 UINT16 TPML_CCA_Marshal(TPML_CCA* source, BYTE** buffer, INT32* size) { 5270 UINT16 total_size = 0; 5271 INT32 i; 5272 total_size += UINT32_Marshal(&source->count, buffer, size); 5273 for (i = 0; i < source->count; ++i) { 5274 total_size += TPMA_CC_Marshal(&source->commandAttributes[i], buffer, size); 5275 } 5276 return total_size; 5277 } 5278 5279 TPM_RC TPML_CCA_Unmarshal(TPML_CCA* target, BYTE** buffer, INT32* size) { 5280 TPM_RC result; 5281 INT32 i; 5282 result = UINT32_Unmarshal(&target->count, buffer, size); 5283 if (result != TPM_RC_SUCCESS) { 5284 return result; 5285 } 5286 if (target->count > MAX_CAP_CC) { 5287 return TPM_RC_SIZE; 5288 } 5289 for (i = 0; i < target->count; ++i) { 5290 result = TPMA_CC_Unmarshal(&target->commandAttributes[i], buffer, size); 5291 if (result != TPM_RC_SUCCESS) { 5292 return result; 5293 } 5294 } 5295 return TPM_RC_SUCCESS; 5296 } 5297 5298 UINT16 TPML_DIGEST_Marshal(TPML_DIGEST* source, BYTE** buffer, INT32* size) { 5299 UINT16 total_size = 0; 5300 INT32 i; 5301 total_size += UINT32_Marshal(&source->count, buffer, size); 5302 for (i = 0; i < source->count; ++i) { 5303 total_size += TPM2B_DIGEST_Marshal(&source->digests[i], buffer, size); 5304 } 5305 return total_size; 5306 } 5307 5308 TPM_RC TPML_DIGEST_Unmarshal(TPML_DIGEST* target, BYTE** buffer, INT32* size) { 5309 TPM_RC result; 5310 INT32 i; 5311 result = UINT32_Unmarshal(&target->count, buffer, size); 5312 if (result != TPM_RC_SUCCESS) { 5313 return result; 5314 } 5315 if (target->count > 8) { 5316 return TPM_RC_SIZE; 5317 } 5318 if (target->count < 2) { 5319 return TPM_RC_SIZE; 5320 } 5321 for (i = 0; i < target->count; ++i) { 5322 result = TPM2B_DIGEST_Unmarshal(&target->digests[i], buffer, size); 5323 if (result != TPM_RC_SUCCESS) { 5324 return result; 5325 } 5326 } 5327 return TPM_RC_SUCCESS; 5328 } 5329 5330 UINT16 TPMU_HA_Marshal(TPMU_HA* source, 5331 BYTE** buffer, 5332 INT32* size, 5333 UINT32 selector) { 5334 INT32 i; 5335 UINT16 total_size = 0; 5336 switch (selector) { 5337 #ifdef TPM_ALG_SHA 5338 case TPM_ALG_SHA: 5339 for (i = 0; i < SHA_DIGEST_SIZE; ++i) { 5340 total_size += BYTE_Marshal(&source->sha[i], buffer, size); 5341 } 5342 return total_size; 5343 #endif 5344 #ifdef TPM_ALG_SHA1 5345 case TPM_ALG_SHA1: 5346 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { 5347 total_size += BYTE_Marshal(&source->sha1[i], buffer, size); 5348 } 5349 return total_size; 5350 #endif 5351 #ifdef TPM_ALG_SHA256 5352 case TPM_ALG_SHA256: 5353 for (i = 0; i < SHA256_DIGEST_SIZE; ++i) { 5354 total_size += BYTE_Marshal(&source->sha256[i], buffer, size); 5355 } 5356 return total_size; 5357 #endif 5358 #ifdef TPM_ALG_SHA384 5359 case TPM_ALG_SHA384: 5360 for (i = 0; i < SHA384_DIGEST_SIZE; ++i) { 5361 total_size += BYTE_Marshal(&source->sha384[i], buffer, size); 5362 } 5363 return total_size; 5364 #endif 5365 #ifdef TPM_ALG_SHA512 5366 case TPM_ALG_SHA512: 5367 for (i = 0; i < SHA512_DIGEST_SIZE; ++i) { 5368 total_size += BYTE_Marshal(&source->sha512[i], buffer, size); 5369 } 5370 return total_size; 5371 #endif 5372 #ifdef TPM_ALG_SM3_256 5373 case TPM_ALG_SM3_256: 5374 for (i = 0; i < SM3_256_DIGEST_SIZE; ++i) { 5375 total_size += BYTE_Marshal(&source->sm3_256[i], buffer, size); 5376 } 5377 return total_size; 5378 #endif 5379 #ifdef TPM_ALG_NULL 5380 case TPM_ALG_NULL: 5381 return 0; 5382 #endif 5383 } 5384 return 0; 5385 } 5386 5387 TPM_RC TPMU_HA_Unmarshal(TPMU_HA* target, 5388 BYTE** buffer, 5389 INT32* size, 5390 UINT32 selector) { 5391 switch (selector) { 5392 INT32 i; 5393 TPM_RC result = TPM_RC_SUCCESS; 5394 #ifdef TPM_ALG_SHA 5395 case TPM_ALG_SHA: 5396 for (i = 0; i < SHA_DIGEST_SIZE; ++i) { 5397 result = BYTE_Unmarshal(&target->sha[i], buffer, size); 5398 if (result != TPM_RC_SUCCESS) { 5399 return result; 5400 } 5401 } 5402 return TPM_RC_SUCCESS; 5403 #endif 5404 #ifdef TPM_ALG_SHA1 5405 case TPM_ALG_SHA1: 5406 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { 5407 result = BYTE_Unmarshal(&target->sha1[i], buffer, size); 5408 if (result != TPM_RC_SUCCESS) { 5409 return result; 5410 } 5411 } 5412 return TPM_RC_SUCCESS; 5413 #endif 5414 #ifdef TPM_ALG_SHA256 5415 case TPM_ALG_SHA256: 5416 for (i = 0; i < SHA256_DIGEST_SIZE; ++i) { 5417 result = BYTE_Unmarshal(&target->sha256[i], buffer, size); 5418 if (result != TPM_RC_SUCCESS) { 5419 return result; 5420 } 5421 } 5422 return TPM_RC_SUCCESS; 5423 #endif 5424 #ifdef TPM_ALG_SHA384 5425 case TPM_ALG_SHA384: 5426 for (i = 0; i < SHA384_DIGEST_SIZE; ++i) { 5427 result = BYTE_Unmarshal(&target->sha384[i], buffer, size); 5428 if (result != TPM_RC_SUCCESS) { 5429 return result; 5430 } 5431 } 5432 return TPM_RC_SUCCESS; 5433 #endif 5434 #ifdef TPM_ALG_SHA512 5435 case TPM_ALG_SHA512: 5436 for (i = 0; i < SHA512_DIGEST_SIZE; ++i) { 5437 result = BYTE_Unmarshal(&target->sha512[i], buffer, size); 5438 if (result != TPM_RC_SUCCESS) { 5439 return result; 5440 } 5441 } 5442 return TPM_RC_SUCCESS; 5443 #endif 5444 #ifdef TPM_ALG_SM3_256 5445 case TPM_ALG_SM3_256: 5446 for (i = 0; i < SM3_256_DIGEST_SIZE; ++i) { 5447 result = BYTE_Unmarshal(&target->sm3_256[i], buffer, size); 5448 if (result != TPM_RC_SUCCESS) { 5449 return result; 5450 } 5451 } 5452 return TPM_RC_SUCCESS; 5453 #endif 5454 #ifdef TPM_ALG_NULL 5455 case TPM_ALG_NULL: 5456 return TPM_RC_SUCCESS; 5457 #endif 5458 } 5459 return TPM_RC_SELECTOR; 5460 } 5461 5462 UINT16 TPMT_HA_Marshal(TPMT_HA* source, BYTE** buffer, INT32* size) { 5463 UINT16 total_size = 0; 5464 total_size += TPMI_ALG_HASH_Marshal(&source->hashAlg, buffer, size); 5465 total_size += TPMU_HA_Marshal(&source->digest, buffer, size, source->hashAlg); 5466 return total_size; 5467 } 5468 5469 TPM_RC TPMT_HA_Unmarshal(TPMT_HA* target, BYTE** buffer, INT32* size) { 5470 TPM_RC result; 5471 result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, TRUE); 5472 if (result != TPM_RC_SUCCESS) { 5473 return result; 5474 } 5475 result = TPMU_HA_Unmarshal(&target->digest, buffer, size, target->hashAlg); 5476 if (result != TPM_RC_SUCCESS) { 5477 return result; 5478 } 5479 return TPM_RC_SUCCESS; 5480 } 5481 5482 UINT16 TPML_DIGEST_VALUES_Marshal(TPML_DIGEST_VALUES* source, 5483 BYTE** buffer, 5484 INT32* size) { 5485 UINT16 total_size = 0; 5486 INT32 i; 5487 total_size += UINT32_Marshal(&source->count, buffer, size); 5488 for (i = 0; i < source->count; ++i) { 5489 total_size += TPMT_HA_Marshal(&source->digests[i], buffer, size); 5490 } 5491 return total_size; 5492 } 5493 5494 TPM_RC TPML_DIGEST_VALUES_Unmarshal(TPML_DIGEST_VALUES* target, 5495 BYTE** buffer, 5496 INT32* size) { 5497 TPM_RC result; 5498 INT32 i; 5499 result = UINT32_Unmarshal(&target->count, buffer, size); 5500 if (result != TPM_RC_SUCCESS) { 5501 return result; 5502 } 5503 if (target->count > HASH_COUNT) { 5504 return TPM_RC_SIZE; 5505 } 5506 for (i = 0; i < target->count; ++i) { 5507 result = TPMT_HA_Unmarshal(&target->digests[i], buffer, size); 5508 if (result != TPM_RC_SUCCESS) { 5509 return result; 5510 } 5511 } 5512 return TPM_RC_SUCCESS; 5513 } 5514 5515 UINT16 TPM_ECC_CURVE_Marshal(TPM_ECC_CURVE* source, 5516 BYTE** buffer, 5517 INT32* size) { 5518 return uint16_t_Marshal(source, buffer, size); 5519 } 5520 5521 TPM_RC TPM_ECC_CURVE_Unmarshal(TPM_ECC_CURVE* target, 5522 BYTE** buffer, 5523 INT32* size) { 5524 TPM_RC result; 5525 result = uint16_t_Unmarshal(target, buffer, size); 5526 if (result != TPM_RC_SUCCESS) { 5527 return result; 5528 } 5529 if (*target == TPM_ECC_NONE) { 5530 return TPM_RC_SUCCESS; 5531 } 5532 if (*target == TPM_ECC_NIST_P192) { 5533 return TPM_RC_SUCCESS; 5534 } 5535 if (*target == TPM_ECC_NIST_P224) { 5536 return TPM_RC_SUCCESS; 5537 } 5538 if (*target == TPM_ECC_NIST_P256) { 5539 return TPM_RC_SUCCESS; 5540 } 5541 if (*target == TPM_ECC_NIST_P384) { 5542 return TPM_RC_SUCCESS; 5543 } 5544 if (*target == TPM_ECC_NIST_P521) { 5545 return TPM_RC_SUCCESS; 5546 } 5547 if (*target == TPM_ECC_BN_P256) { 5548 return TPM_RC_SUCCESS; 5549 } 5550 if (*target == TPM_ECC_BN_P638) { 5551 return TPM_RC_SUCCESS; 5552 } 5553 if (*target == TPM_ECC_SM2_P256) { 5554 return TPM_RC_SUCCESS; 5555 } 5556 return TPM_RC_CURVE; 5557 } 5558 5559 UINT16 TPML_ECC_CURVE_Marshal(TPML_ECC_CURVE* source, 5560 BYTE** buffer, 5561 INT32* size) { 5562 UINT16 total_size = 0; 5563 INT32 i; 5564 total_size += UINT32_Marshal(&source->count, buffer, size); 5565 for (i = 0; i < source->count; ++i) { 5566 total_size += TPM_ECC_CURVE_Marshal(&source->eccCurves[i], buffer, size); 5567 } 5568 return total_size; 5569 } 5570 5571 TPM_RC TPML_ECC_CURVE_Unmarshal(TPML_ECC_CURVE* target, 5572 BYTE** buffer, 5573 INT32* size) { 5574 TPM_RC result; 5575 INT32 i; 5576 result = UINT32_Unmarshal(&target->count, buffer, size); 5577 if (result != TPM_RC_SUCCESS) { 5578 return result; 5579 } 5580 if (target->count > MAX_ECC_CURVES) { 5581 return TPM_RC_SIZE; 5582 } 5583 for (i = 0; i < target->count; ++i) { 5584 result = TPM_ECC_CURVE_Unmarshal(&target->eccCurves[i], buffer, size); 5585 if (result != TPM_RC_SUCCESS) { 5586 return result; 5587 } 5588 } 5589 return TPM_RC_SUCCESS; 5590 } 5591 5592 UINT16 TPM_HANDLE_Marshal(TPM_HANDLE* source, BYTE** buffer, INT32* size) { 5593 return uint32_t_Marshal(source, buffer, size); 5594 } 5595 5596 TPM_RC TPM_HANDLE_Unmarshal(TPM_HANDLE* target, BYTE** buffer, INT32* size) { 5597 return uint32_t_Unmarshal(target, buffer, size); 5598 } 5599 5600 UINT16 TPML_HANDLE_Marshal(TPML_HANDLE* source, BYTE** buffer, INT32* size) { 5601 UINT16 total_size = 0; 5602 INT32 i; 5603 total_size += UINT32_Marshal(&source->count, buffer, size); 5604 for (i = 0; i < source->count; ++i) { 5605 total_size += TPM_HANDLE_Marshal(&source->handle[i], buffer, size); 5606 } 5607 return total_size; 5608 } 5609 5610 TPM_RC TPML_HANDLE_Unmarshal(TPML_HANDLE* target, BYTE** buffer, INT32* size) { 5611 TPM_RC result; 5612 INT32 i; 5613 result = UINT32_Unmarshal(&target->count, buffer, size); 5614 if (result != TPM_RC_SUCCESS) { 5615 return result; 5616 } 5617 if (target->count > MAX_CAP_HANDLES) { 5618 return TPM_RC_SIZE; 5619 } 5620 for (i = 0; i < target->count; ++i) { 5621 result = TPM_HANDLE_Unmarshal(&target->handle[i], buffer, size); 5622 if (result != TPM_RC_SUCCESS) { 5623 return result; 5624 } 5625 } 5626 return TPM_RC_SUCCESS; 5627 } 5628 5629 UINT16 TPM_PT_Marshal(TPM_PT* source, BYTE** buffer, INT32* size) { 5630 return uint32_t_Marshal(source, buffer, size); 5631 } 5632 5633 TPM_RC TPM_PT_Unmarshal(TPM_PT* target, BYTE** buffer, INT32* size) { 5634 TPM_RC result; 5635 result = uint32_t_Unmarshal(target, buffer, size); 5636 if (result != TPM_RC_SUCCESS) { 5637 return result; 5638 } 5639 if (*target == TPM_PT_NONE) { 5640 return TPM_RC_SUCCESS; 5641 } 5642 if (*target == PT_GROUP) { 5643 return TPM_RC_SUCCESS; 5644 } 5645 if (*target == PT_FIXED) { 5646 return TPM_RC_SUCCESS; 5647 } 5648 if (*target == TPM_PT_FAMILY_INDICATOR) { 5649 return TPM_RC_SUCCESS; 5650 } 5651 if (*target == TPM_PT_LEVEL) { 5652 return TPM_RC_SUCCESS; 5653 } 5654 if (*target == TPM_PT_REVISION) { 5655 return TPM_RC_SUCCESS; 5656 } 5657 if (*target == TPM_PT_DAY_OF_YEAR) { 5658 return TPM_RC_SUCCESS; 5659 } 5660 if (*target == TPM_PT_YEAR) { 5661 return TPM_RC_SUCCESS; 5662 } 5663 if (*target == TPM_PT_MANUFACTURER) { 5664 return TPM_RC_SUCCESS; 5665 } 5666 if (*target == TPM_PT_VENDOR_STRING_1) { 5667 return TPM_RC_SUCCESS; 5668 } 5669 if (*target == TPM_PT_VENDOR_STRING_2) { 5670 return TPM_RC_SUCCESS; 5671 } 5672 if (*target == TPM_PT_VENDOR_STRING_3) { 5673 return TPM_RC_SUCCESS; 5674 } 5675 if (*target == TPM_PT_VENDOR_STRING_4) { 5676 return TPM_RC_SUCCESS; 5677 } 5678 if (*target == TPM_PT_VENDOR_TPM_TYPE) { 5679 return TPM_RC_SUCCESS; 5680 } 5681 if (*target == TPM_PT_FIRMWARE_VERSION_1) { 5682 return TPM_RC_SUCCESS; 5683 } 5684 if (*target == TPM_PT_FIRMWARE_VERSION_2) { 5685 return TPM_RC_SUCCESS; 5686 } 5687 if (*target == TPM_PT_INPUT_BUFFER) { 5688 return TPM_RC_SUCCESS; 5689 } 5690 if (*target == TPM_PT_HR_TRANSIENT_MIN) { 5691 return TPM_RC_SUCCESS; 5692 } 5693 if (*target == TPM_PT_HR_PERSISTENT_MIN) { 5694 return TPM_RC_SUCCESS; 5695 } 5696 if (*target == TPM_PT_HR_LOADED_MIN) { 5697 return TPM_RC_SUCCESS; 5698 } 5699 if (*target == TPM_PT_ACTIVE_SESSIONS_MAX) { 5700 return TPM_RC_SUCCESS; 5701 } 5702 if (*target == TPM_PT_PCR_COUNT) { 5703 return TPM_RC_SUCCESS; 5704 } 5705 if (*target == TPM_PT_PCR_SELECT_MIN) { 5706 return TPM_RC_SUCCESS; 5707 } 5708 if (*target == TPM_PT_CONTEXT_GAP_MAX) { 5709 return TPM_RC_SUCCESS; 5710 } 5711 if (*target == TPM_PT_NV_COUNTERS_MAX) { 5712 return TPM_RC_SUCCESS; 5713 } 5714 if (*target == TPM_PT_NV_INDEX_MAX) { 5715 return TPM_RC_SUCCESS; 5716 } 5717 if (*target == TPM_PT_MEMORY) { 5718 return TPM_RC_SUCCESS; 5719 } 5720 if (*target == TPM_PT_CLOCK_UPDATE) { 5721 return TPM_RC_SUCCESS; 5722 } 5723 if (*target == TPM_PT_CONTEXT_HASH) { 5724 return TPM_RC_SUCCESS; 5725 } 5726 if (*target == TPM_PT_CONTEXT_SYM) { 5727 return TPM_RC_SUCCESS; 5728 } 5729 if (*target == TPM_PT_CONTEXT_SYM_SIZE) { 5730 return TPM_RC_SUCCESS; 5731 } 5732 if (*target == TPM_PT_ORDERLY_COUNT) { 5733 return TPM_RC_SUCCESS; 5734 } 5735 if (*target == TPM_PT_MAX_COMMAND_SIZE) { 5736 return TPM_RC_SUCCESS; 5737 } 5738 if (*target == TPM_PT_MAX_RESPONSE_SIZE) { 5739 return TPM_RC_SUCCESS; 5740 } 5741 if (*target == TPM_PT_MAX_DIGEST) { 5742 return TPM_RC_SUCCESS; 5743 } 5744 if (*target == TPM_PT_MAX_OBJECT_CONTEXT) { 5745 return TPM_RC_SUCCESS; 5746 } 5747 if (*target == TPM_PT_MAX_SESSION_CONTEXT) { 5748 return TPM_RC_SUCCESS; 5749 } 5750 if (*target == TPM_PT_PS_FAMILY_INDICATOR) { 5751 return TPM_RC_SUCCESS; 5752 } 5753 if (*target == TPM_PT_PS_LEVEL) { 5754 return TPM_RC_SUCCESS; 5755 } 5756 if (*target == TPM_PT_PS_REVISION) { 5757 return TPM_RC_SUCCESS; 5758 } 5759 if (*target == TPM_PT_PS_DAY_OF_YEAR) { 5760 return TPM_RC_SUCCESS; 5761 } 5762 if (*target == TPM_PT_PS_YEAR) { 5763 return TPM_RC_SUCCESS; 5764 } 5765 if (*target == TPM_PT_SPLIT_MAX) { 5766 return TPM_RC_SUCCESS; 5767 } 5768 if (*target == TPM_PT_TOTAL_COMMANDS) { 5769 return TPM_RC_SUCCESS; 5770 } 5771 if (*target == TPM_PT_LIBRARY_COMMANDS) { 5772 return TPM_RC_SUCCESS; 5773 } 5774 if (*target == TPM_PT_VENDOR_COMMANDS) { 5775 return TPM_RC_SUCCESS; 5776 } 5777 if (*target == TPM_PT_NV_BUFFER_MAX) { 5778 return TPM_RC_SUCCESS; 5779 } 5780 if (*target == PT_VAR) { 5781 return TPM_RC_SUCCESS; 5782 } 5783 if (*target == TPM_PT_PERMANENT) { 5784 return TPM_RC_SUCCESS; 5785 } 5786 if (*target == TPM_PT_STARTUP_CLEAR) { 5787 return TPM_RC_SUCCESS; 5788 } 5789 if (*target == TPM_PT_HR_NV_INDEX) { 5790 return TPM_RC_SUCCESS; 5791 } 5792 if (*target == TPM_PT_HR_LOADED) { 5793 return TPM_RC_SUCCESS; 5794 } 5795 if (*target == TPM_PT_HR_LOADED_AVAIL) { 5796 return TPM_RC_SUCCESS; 5797 } 5798 if (*target == TPM_PT_HR_ACTIVE) { 5799 return TPM_RC_SUCCESS; 5800 } 5801 if (*target == TPM_PT_HR_ACTIVE_AVAIL) { 5802 return TPM_RC_SUCCESS; 5803 } 5804 if (*target == TPM_PT_HR_TRANSIENT_AVAIL) { 5805 return TPM_RC_SUCCESS; 5806 } 5807 if (*target == TPM_PT_HR_PERSISTENT) { 5808 return TPM_RC_SUCCESS; 5809 } 5810 if (*target == TPM_PT_HR_PERSISTENT_AVAIL) { 5811 return TPM_RC_SUCCESS; 5812 } 5813 if (*target == TPM_PT_NV_COUNTERS) { 5814 return TPM_RC_SUCCESS; 5815 } 5816 if (*target == TPM_PT_NV_COUNTERS_AVAIL) { 5817 return TPM_RC_SUCCESS; 5818 } 5819 if (*target == TPM_PT_ALGORITHM_SET) { 5820 return TPM_RC_SUCCESS; 5821 } 5822 if (*target == TPM_PT_LOADED_CURVES) { 5823 return TPM_RC_SUCCESS; 5824 } 5825 if (*target == TPM_PT_LOCKOUT_COUNTER) { 5826 return TPM_RC_SUCCESS; 5827 } 5828 if (*target == TPM_PT_MAX_AUTH_FAIL) { 5829 return TPM_RC_SUCCESS; 5830 } 5831 if (*target == TPM_PT_LOCKOUT_INTERVAL) { 5832 return TPM_RC_SUCCESS; 5833 } 5834 if (*target == TPM_PT_LOCKOUT_RECOVERY) { 5835 return TPM_RC_SUCCESS; 5836 } 5837 if (*target == TPM_PT_NV_WRITE_RECOVERY) { 5838 return TPM_RC_SUCCESS; 5839 } 5840 if (*target == TPM_PT_AUDIT_COUNTER_0) { 5841 return TPM_RC_SUCCESS; 5842 } 5843 if (*target == TPM_PT_AUDIT_COUNTER_1) { 5844 return TPM_RC_SUCCESS; 5845 } 5846 return TPM_RC_VALUE; 5847 } 5848 5849 UINT16 TPMS_TAGGED_PCR_SELECT_Marshal(TPMS_TAGGED_PCR_SELECT* source, 5850 BYTE** buffer, 5851 INT32* size) { 5852 UINT16 total_size = 0; 5853 INT32 i; 5854 total_size += TPM_PT_Marshal(&source->tag, buffer, size); 5855 total_size += UINT8_Marshal(&source->sizeofSelect, buffer, size); 5856 for (i = 0; i < source->sizeofSelect; ++i) { 5857 total_size += BYTE_Marshal(&source->pcrSelect[i], buffer, size); 5858 } 5859 return total_size; 5860 } 5861 5862 TPM_RC TPMS_TAGGED_PCR_SELECT_Unmarshal(TPMS_TAGGED_PCR_SELECT* target, 5863 BYTE** buffer, 5864 INT32* size) { 5865 TPM_RC result; 5866 INT32 i; 5867 result = TPM_PT_Unmarshal(&target->tag, buffer, size); 5868 if (result != TPM_RC_SUCCESS) { 5869 return result; 5870 } 5871 result = UINT8_Unmarshal(&target->sizeofSelect, buffer, size); 5872 if (result != TPM_RC_SUCCESS) { 5873 return result; 5874 } 5875 if (target->sizeofSelect > PCR_SELECT_MAX) { 5876 return TPM_RC_VALUE; 5877 } 5878 if (target->sizeofSelect < PCR_SELECT_MIN) { 5879 return TPM_RC_VALUE; 5880 } 5881 for (i = 0; i < target->sizeofSelect; ++i) { 5882 result = BYTE_Unmarshal(&target->pcrSelect[i], buffer, size); 5883 if (result != TPM_RC_SUCCESS) { 5884 return result; 5885 } 5886 } 5887 return TPM_RC_SUCCESS; 5888 } 5889 5890 UINT16 TPML_TAGGED_PCR_PROPERTY_Marshal(TPML_TAGGED_PCR_PROPERTY* source, 5891 BYTE** buffer, 5892 INT32* size) { 5893 UINT16 total_size = 0; 5894 INT32 i; 5895 total_size += UINT32_Marshal(&source->count, buffer, size); 5896 for (i = 0; i < source->count; ++i) { 5897 total_size += 5898 TPMS_TAGGED_PCR_SELECT_Marshal(&source->pcrProperty[i], buffer, size); 5899 } 5900 return total_size; 5901 } 5902 5903 TPM_RC TPML_TAGGED_PCR_PROPERTY_Unmarshal(TPML_TAGGED_PCR_PROPERTY* target, 5904 BYTE** buffer, 5905 INT32* size) { 5906 TPM_RC result; 5907 INT32 i; 5908 result = UINT32_Unmarshal(&target->count, buffer, size); 5909 if (result != TPM_RC_SUCCESS) { 5910 return result; 5911 } 5912 if (target->count > MAX_PCR_PROPERTIES) { 5913 return TPM_RC_SIZE; 5914 } 5915 for (i = 0; i < target->count; ++i) { 5916 result = 5917 TPMS_TAGGED_PCR_SELECT_Unmarshal(&target->pcrProperty[i], buffer, size); 5918 if (result != TPM_RC_SUCCESS) { 5919 return result; 5920 } 5921 } 5922 return TPM_RC_SUCCESS; 5923 } 5924 5925 UINT16 TPMS_TAGGED_PROPERTY_Marshal(TPMS_TAGGED_PROPERTY* source, 5926 BYTE** buffer, 5927 INT32* size) { 5928 UINT16 total_size = 0; 5929 total_size += TPM_PT_Marshal(&source->property, buffer, size); 5930 total_size += UINT32_Marshal(&source->value, buffer, size); 5931 return total_size; 5932 } 5933 5934 TPM_RC TPMS_TAGGED_PROPERTY_Unmarshal(TPMS_TAGGED_PROPERTY* target, 5935 BYTE** buffer, 5936 INT32* size) { 5937 TPM_RC result; 5938 result = TPM_PT_Unmarshal(&target->property, buffer, size); 5939 if (result != TPM_RC_SUCCESS) { 5940 return result; 5941 } 5942 result = UINT32_Unmarshal(&target->value, buffer, size); 5943 if (result != TPM_RC_SUCCESS) { 5944 return result; 5945 } 5946 return TPM_RC_SUCCESS; 5947 } 5948 5949 UINT16 TPML_TAGGED_TPM_PROPERTY_Marshal(TPML_TAGGED_TPM_PROPERTY* source, 5950 BYTE** buffer, 5951 INT32* size) { 5952 UINT16 total_size = 0; 5953 INT32 i; 5954 total_size += UINT32_Marshal(&source->count, buffer, size); 5955 for (i = 0; i < source->count; ++i) { 5956 total_size += 5957 TPMS_TAGGED_PROPERTY_Marshal(&source->tpmProperty[i], buffer, size); 5958 } 5959 return total_size; 5960 } 5961 5962 TPM_RC TPML_TAGGED_TPM_PROPERTY_Unmarshal(TPML_TAGGED_TPM_PROPERTY* target, 5963 BYTE** buffer, 5964 INT32* size) { 5965 TPM_RC result; 5966 INT32 i; 5967 result = UINT32_Unmarshal(&target->count, buffer, size); 5968 if (result != TPM_RC_SUCCESS) { 5969 return result; 5970 } 5971 if (target->count > MAX_TPM_PROPERTIES) { 5972 return TPM_RC_SIZE; 5973 } 5974 for (i = 0; i < target->count; ++i) { 5975 result = 5976 TPMS_TAGGED_PROPERTY_Unmarshal(&target->tpmProperty[i], buffer, size); 5977 if (result != TPM_RC_SUCCESS) { 5978 return result; 5979 } 5980 } 5981 return TPM_RC_SUCCESS; 5982 } 5983 5984 UINT16 TPMS_ALGORITHM_DESCRIPTION_Marshal(TPMS_ALGORITHM_DESCRIPTION* source, 5985 BYTE** buffer, 5986 INT32* size) { 5987 UINT16 total_size = 0; 5988 total_size += TPM_ALG_ID_Marshal(&source->alg, buffer, size); 5989 total_size += TPMA_ALGORITHM_Marshal(&source->attributes, buffer, size); 5990 return total_size; 5991 } 5992 5993 TPM_RC TPMS_ALGORITHM_DESCRIPTION_Unmarshal(TPMS_ALGORITHM_DESCRIPTION* target, 5994 BYTE** buffer, 5995 INT32* size) { 5996 TPM_RC result; 5997 result = TPM_ALG_ID_Unmarshal(&target->alg, buffer, size); 5998 if (result != TPM_RC_SUCCESS) { 5999 return result; 6000 } 6001 result = TPMA_ALGORITHM_Unmarshal(&target->attributes, buffer, size); 6002 if (result != TPM_RC_SUCCESS) { 6003 return result; 6004 } 6005 return TPM_RC_SUCCESS; 6006 } 6007 6008 UINT16 TPMS_ALGORITHM_DETAIL_ECC_Marshal(TPMS_ALGORITHM_DETAIL_ECC* source, 6009 BYTE** buffer, 6010 INT32* size) { 6011 UINT16 total_size = 0; 6012 total_size += TPM_ECC_CURVE_Marshal(&source->curveID, buffer, size); 6013 total_size += UINT16_Marshal(&source->keySize, buffer, size); 6014 total_size += TPMT_KDF_SCHEME_Marshal(&source->kdf, buffer, size); 6015 total_size += TPMT_ECC_SCHEME_Marshal(&source->sign, buffer, size); 6016 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->p, buffer, size); 6017 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->a, buffer, size); 6018 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->b, buffer, size); 6019 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->gX, buffer, size); 6020 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->gY, buffer, size); 6021 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->n, buffer, size); 6022 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->h, buffer, size); 6023 return total_size; 6024 } 6025 6026 TPM_RC TPMS_ALGORITHM_DETAIL_ECC_Unmarshal(TPMS_ALGORITHM_DETAIL_ECC* target, 6027 BYTE** buffer, 6028 INT32* size) { 6029 TPM_RC result; 6030 result = TPM_ECC_CURVE_Unmarshal(&target->curveID, buffer, size); 6031 if (result != TPM_RC_SUCCESS) { 6032 return result; 6033 } 6034 result = UINT16_Unmarshal(&target->keySize, buffer, size); 6035 if (result != TPM_RC_SUCCESS) { 6036 return result; 6037 } 6038 result = TPMT_KDF_SCHEME_Unmarshal(&target->kdf, buffer, size); 6039 if (result != TPM_RC_SUCCESS) { 6040 return result; 6041 } 6042 result = TPMT_ECC_SCHEME_Unmarshal(&target->sign, buffer, size); 6043 if (result != TPM_RC_SUCCESS) { 6044 return result; 6045 } 6046 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->p, buffer, size); 6047 if (result != TPM_RC_SUCCESS) { 6048 return result; 6049 } 6050 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->a, buffer, size); 6051 if (result != TPM_RC_SUCCESS) { 6052 return result; 6053 } 6054 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->b, buffer, size); 6055 if (result != TPM_RC_SUCCESS) { 6056 return result; 6057 } 6058 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->gX, buffer, size); 6059 if (result != TPM_RC_SUCCESS) { 6060 return result; 6061 } 6062 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->gY, buffer, size); 6063 if (result != TPM_RC_SUCCESS) { 6064 return result; 6065 } 6066 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->n, buffer, size); 6067 if (result != TPM_RC_SUCCESS) { 6068 return result; 6069 } 6070 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->h, buffer, size); 6071 if (result != TPM_RC_SUCCESS) { 6072 return result; 6073 } 6074 return TPM_RC_SUCCESS; 6075 } 6076 6077 UINT16 UINT64_Marshal(UINT64* source, BYTE** buffer, INT32* size) { 6078 return uint64_t_Marshal(source, buffer, size); 6079 } 6080 6081 TPM_RC UINT64_Unmarshal(UINT64* target, BYTE** buffer, INT32* size) { 6082 return uint64_t_Unmarshal(target, buffer, size); 6083 } 6084 6085 UINT16 TPM_GENERATED_Marshal(TPM_GENERATED* source, 6086 BYTE** buffer, 6087 INT32* size) { 6088 return uint32_t_Marshal(source, buffer, size); 6089 } 6090 6091 TPM_RC TPM_GENERATED_Unmarshal(TPM_GENERATED* target, 6092 BYTE** buffer, 6093 INT32* size) { 6094 TPM_RC result; 6095 result = uint32_t_Unmarshal(target, buffer, size); 6096 if (result != TPM_RC_SUCCESS) { 6097 return result; 6098 } 6099 if (*target == TPM_GENERATED_VALUE) { 6100 return TPM_RC_SUCCESS; 6101 } 6102 return TPM_RC_VALUE; 6103 } 6104 6105 UINT16 TPMS_CREATION_INFO_Marshal(TPMS_CREATION_INFO* source, 6106 BYTE** buffer, 6107 INT32* size) { 6108 UINT16 total_size = 0; 6109 total_size += TPM2B_NAME_Marshal(&source->objectName, buffer, size); 6110 total_size += TPM2B_DIGEST_Marshal(&source->creationHash, buffer, size); 6111 return total_size; 6112 } 6113 6114 TPM_RC TPMS_CREATION_INFO_Unmarshal(TPMS_CREATION_INFO* target, 6115 BYTE** buffer, 6116 INT32* size) { 6117 TPM_RC result; 6118 result = TPM2B_NAME_Unmarshal(&target->objectName, buffer, size); 6119 if (result != TPM_RC_SUCCESS) { 6120 return result; 6121 } 6122 result = TPM2B_DIGEST_Unmarshal(&target->creationHash, buffer, size); 6123 if (result != TPM_RC_SUCCESS) { 6124 return result; 6125 } 6126 return TPM_RC_SUCCESS; 6127 } 6128 6129 UINT16 TPMS_COMMAND_AUDIT_INFO_Marshal(TPMS_COMMAND_AUDIT_INFO* source, 6130 BYTE** buffer, 6131 INT32* size) { 6132 UINT16 total_size = 0; 6133 total_size += UINT64_Marshal(&source->auditCounter, buffer, size); 6134 total_size += TPM_ALG_ID_Marshal(&source->digestAlg, buffer, size); 6135 total_size += TPM2B_DIGEST_Marshal(&source->auditDigest, buffer, size); 6136 total_size += TPM2B_DIGEST_Marshal(&source->commandDigest, buffer, size); 6137 return total_size; 6138 } 6139 6140 TPM_RC TPMS_COMMAND_AUDIT_INFO_Unmarshal(TPMS_COMMAND_AUDIT_INFO* target, 6141 BYTE** buffer, 6142 INT32* size) { 6143 TPM_RC result; 6144 result = UINT64_Unmarshal(&target->auditCounter, buffer, size); 6145 if (result != TPM_RC_SUCCESS) { 6146 return result; 6147 } 6148 result = TPM_ALG_ID_Unmarshal(&target->digestAlg, buffer, size); 6149 if (result != TPM_RC_SUCCESS) { 6150 return result; 6151 } 6152 result = TPM2B_DIGEST_Unmarshal(&target->auditDigest, buffer, size); 6153 if (result != TPM_RC_SUCCESS) { 6154 return result; 6155 } 6156 result = TPM2B_DIGEST_Unmarshal(&target->commandDigest, buffer, size); 6157 if (result != TPM_RC_SUCCESS) { 6158 return result; 6159 } 6160 return TPM_RC_SUCCESS; 6161 } 6162 6163 UINT16 TPMS_QUOTE_INFO_Marshal(TPMS_QUOTE_INFO* source, 6164 BYTE** buffer, 6165 INT32* size) { 6166 UINT16 total_size = 0; 6167 total_size += TPML_PCR_SELECTION_Marshal(&source->pcrSelect, buffer, size); 6168 total_size += TPM2B_DIGEST_Marshal(&source->pcrDigest, buffer, size); 6169 return total_size; 6170 } 6171 6172 TPM_RC TPMS_QUOTE_INFO_Unmarshal(TPMS_QUOTE_INFO* target, 6173 BYTE** buffer, 6174 INT32* size) { 6175 TPM_RC result; 6176 result = TPML_PCR_SELECTION_Unmarshal(&target->pcrSelect, buffer, size); 6177 if (result != TPM_RC_SUCCESS) { 6178 return result; 6179 } 6180 result = TPM2B_DIGEST_Unmarshal(&target->pcrDigest, buffer, size); 6181 if (result != TPM_RC_SUCCESS) { 6182 return result; 6183 } 6184 return TPM_RC_SUCCESS; 6185 } 6186 6187 UINT16 TPMS_CERTIFY_INFO_Marshal(TPMS_CERTIFY_INFO* source, 6188 BYTE** buffer, 6189 INT32* size) { 6190 UINT16 total_size = 0; 6191 total_size += TPM2B_NAME_Marshal(&source->name, buffer, size); 6192 total_size += TPM2B_NAME_Marshal(&source->qualifiedName, buffer, size); 6193 return total_size; 6194 } 6195 6196 TPM_RC TPMS_CERTIFY_INFO_Unmarshal(TPMS_CERTIFY_INFO* target, 6197 BYTE** buffer, 6198 INT32* size) { 6199 TPM_RC result; 6200 result = TPM2B_NAME_Unmarshal(&target->name, buffer, size); 6201 if (result != TPM_RC_SUCCESS) { 6202 return result; 6203 } 6204 result = TPM2B_NAME_Unmarshal(&target->qualifiedName, buffer, size); 6205 if (result != TPM_RC_SUCCESS) { 6206 return result; 6207 } 6208 return TPM_RC_SUCCESS; 6209 } 6210 6211 UINT16 TPMS_SESSION_AUDIT_INFO_Marshal(TPMS_SESSION_AUDIT_INFO* source, 6212 BYTE** buffer, 6213 INT32* size) { 6214 UINT16 total_size = 0; 6215 total_size += TPMI_YES_NO_Marshal(&source->exclusiveSession, buffer, size); 6216 total_size += TPM2B_DIGEST_Marshal(&source->sessionDigest, buffer, size); 6217 return total_size; 6218 } 6219 6220 TPM_RC TPMS_SESSION_AUDIT_INFO_Unmarshal(TPMS_SESSION_AUDIT_INFO* target, 6221 BYTE** buffer, 6222 INT32* size) { 6223 TPM_RC result; 6224 result = TPMI_YES_NO_Unmarshal(&target->exclusiveSession, buffer, size); 6225 if (result != TPM_RC_SUCCESS) { 6226 return result; 6227 } 6228 result = TPM2B_DIGEST_Unmarshal(&target->sessionDigest, buffer, size); 6229 if (result != TPM_RC_SUCCESS) { 6230 return result; 6231 } 6232 return TPM_RC_SUCCESS; 6233 } 6234 6235 UINT16 TPMS_CLOCK_INFO_Marshal(TPMS_CLOCK_INFO* source, 6236 BYTE** buffer, 6237 INT32* size) { 6238 UINT16 total_size = 0; 6239 total_size += UINT64_Marshal(&source->clock, buffer, size); 6240 total_size += UINT32_Marshal(&source->resetCount, buffer, size); 6241 total_size += UINT32_Marshal(&source->restartCount, buffer, size); 6242 total_size += TPMI_YES_NO_Marshal(&source->safe, buffer, size); 6243 return total_size; 6244 } 6245 6246 TPM_RC TPMS_CLOCK_INFO_Unmarshal(TPMS_CLOCK_INFO* target, 6247 BYTE** buffer, 6248 INT32* size) { 6249 TPM_RC result; 6250 result = UINT64_Unmarshal(&target->clock, buffer, size); 6251 if (result != TPM_RC_SUCCESS) { 6252 return result; 6253 } 6254 result = UINT32_Unmarshal(&target->resetCount, buffer, size); 6255 if (result != TPM_RC_SUCCESS) { 6256 return result; 6257 } 6258 result = UINT32_Unmarshal(&target->restartCount, buffer, size); 6259 if (result != TPM_RC_SUCCESS) { 6260 return result; 6261 } 6262 result = TPMI_YES_NO_Unmarshal(&target->safe, buffer, size); 6263 if (result != TPM_RC_SUCCESS) { 6264 return result; 6265 } 6266 return TPM_RC_SUCCESS; 6267 } 6268 6269 UINT16 TPMS_TIME_INFO_Marshal(TPMS_TIME_INFO* source, 6270 BYTE** buffer, 6271 INT32* size) { 6272 UINT16 total_size = 0; 6273 total_size += UINT64_Marshal(&source->time, buffer, size); 6274 total_size += TPMS_CLOCK_INFO_Marshal(&source->clockInfo, buffer, size); 6275 return total_size; 6276 } 6277 6278 TPM_RC TPMS_TIME_INFO_Unmarshal(TPMS_TIME_INFO* target, 6279 BYTE** buffer, 6280 INT32* size) { 6281 TPM_RC result; 6282 result = UINT64_Unmarshal(&target->time, buffer, size); 6283 if (result != TPM_RC_SUCCESS) { 6284 return result; 6285 } 6286 result = TPMS_CLOCK_INFO_Unmarshal(&target->clockInfo, buffer, size); 6287 if (result != TPM_RC_SUCCESS) { 6288 return result; 6289 } 6290 return TPM_RC_SUCCESS; 6291 } 6292 6293 UINT16 TPMS_TIME_ATTEST_INFO_Marshal(TPMS_TIME_ATTEST_INFO* source, 6294 BYTE** buffer, 6295 INT32* size) { 6296 UINT16 total_size = 0; 6297 total_size += TPMS_TIME_INFO_Marshal(&source->time, buffer, size); 6298 total_size += UINT64_Marshal(&source->firmwareVersion, buffer, size); 6299 return total_size; 6300 } 6301 6302 TPM_RC TPMS_TIME_ATTEST_INFO_Unmarshal(TPMS_TIME_ATTEST_INFO* target, 6303 BYTE** buffer, 6304 INT32* size) { 6305 TPM_RC result; 6306 result = TPMS_TIME_INFO_Unmarshal(&target->time, buffer, size); 6307 if (result != TPM_RC_SUCCESS) { 6308 return result; 6309 } 6310 result = UINT64_Unmarshal(&target->firmwareVersion, buffer, size); 6311 if (result != TPM_RC_SUCCESS) { 6312 return result; 6313 } 6314 return TPM_RC_SUCCESS; 6315 } 6316 6317 UINT16 TPMS_NV_CERTIFY_INFO_Marshal(TPMS_NV_CERTIFY_INFO* source, 6318 BYTE** buffer, 6319 INT32* size) { 6320 UINT16 total_size = 0; 6321 total_size += TPM2B_NAME_Marshal(&source->indexName, buffer, size); 6322 total_size += UINT16_Marshal(&source->offset, buffer, size); 6323 total_size += TPM2B_MAX_NV_BUFFER_Marshal(&source->nvContents, buffer, size); 6324 return total_size; 6325 } 6326 6327 TPM_RC TPMS_NV_CERTIFY_INFO_Unmarshal(TPMS_NV_CERTIFY_INFO* target, 6328 BYTE** buffer, 6329 INT32* size) { 6330 TPM_RC result; 6331 result = TPM2B_NAME_Unmarshal(&target->indexName, buffer, size); 6332 if (result != TPM_RC_SUCCESS) { 6333 return result; 6334 } 6335 result = UINT16_Unmarshal(&target->offset, buffer, size); 6336 if (result != TPM_RC_SUCCESS) { 6337 return result; 6338 } 6339 result = TPM2B_MAX_NV_BUFFER_Unmarshal(&target->nvContents, buffer, size); 6340 if (result != TPM_RC_SUCCESS) { 6341 return result; 6342 } 6343 return TPM_RC_SUCCESS; 6344 } 6345 6346 UINT16 TPMU_ATTEST_Marshal(TPMU_ATTEST* source, 6347 BYTE** buffer, 6348 INT32* size, 6349 UINT32 selector) { 6350 switch (selector) { 6351 case TPM_ST_ATTEST_CERTIFY: 6352 return TPMS_CERTIFY_INFO_Marshal((TPMS_CERTIFY_INFO*)&source->certify, 6353 buffer, size); 6354 case TPM_ST_ATTEST_CREATION: 6355 return TPMS_CREATION_INFO_Marshal((TPMS_CREATION_INFO*)&source->creation, 6356 buffer, size); 6357 case TPM_ST_ATTEST_QUOTE: 6358 return TPMS_QUOTE_INFO_Marshal((TPMS_QUOTE_INFO*)&source->quote, buffer, 6359 size); 6360 case TPM_ST_ATTEST_COMMAND_AUDIT: 6361 return TPMS_COMMAND_AUDIT_INFO_Marshal( 6362 (TPMS_COMMAND_AUDIT_INFO*)&source->commandAudit, buffer, size); 6363 case TPM_ST_ATTEST_SESSION_AUDIT: 6364 return TPMS_SESSION_AUDIT_INFO_Marshal( 6365 (TPMS_SESSION_AUDIT_INFO*)&source->sessionAudit, buffer, size); 6366 case TPM_ST_ATTEST_TIME: 6367 return TPMS_TIME_ATTEST_INFO_Marshal( 6368 (TPMS_TIME_ATTEST_INFO*)&source->time, buffer, size); 6369 case TPM_ST_ATTEST_NV: 6370 return TPMS_NV_CERTIFY_INFO_Marshal((TPMS_NV_CERTIFY_INFO*)&source->nv, 6371 buffer, size); 6372 } 6373 return 0; 6374 } 6375 6376 TPM_RC TPMU_ATTEST_Unmarshal(TPMU_ATTEST* target, 6377 BYTE** buffer, 6378 INT32* size, 6379 UINT32 selector) { 6380 switch (selector) { 6381 case TPM_ST_ATTEST_CERTIFY: 6382 return TPMS_CERTIFY_INFO_Unmarshal((TPMS_CERTIFY_INFO*)&target->certify, 6383 buffer, size); 6384 case TPM_ST_ATTEST_CREATION: 6385 return TPMS_CREATION_INFO_Unmarshal( 6386 (TPMS_CREATION_INFO*)&target->creation, buffer, size); 6387 case TPM_ST_ATTEST_QUOTE: 6388 return TPMS_QUOTE_INFO_Unmarshal((TPMS_QUOTE_INFO*)&target->quote, buffer, 6389 size); 6390 case TPM_ST_ATTEST_COMMAND_AUDIT: 6391 return TPMS_COMMAND_AUDIT_INFO_Unmarshal( 6392 (TPMS_COMMAND_AUDIT_INFO*)&target->commandAudit, buffer, size); 6393 case TPM_ST_ATTEST_SESSION_AUDIT: 6394 return TPMS_SESSION_AUDIT_INFO_Unmarshal( 6395 (TPMS_SESSION_AUDIT_INFO*)&target->sessionAudit, buffer, size); 6396 case TPM_ST_ATTEST_TIME: 6397 return TPMS_TIME_ATTEST_INFO_Unmarshal( 6398 (TPMS_TIME_ATTEST_INFO*)&target->time, buffer, size); 6399 case TPM_ST_ATTEST_NV: 6400 return TPMS_NV_CERTIFY_INFO_Unmarshal((TPMS_NV_CERTIFY_INFO*)&target->nv, 6401 buffer, size); 6402 } 6403 return TPM_RC_SELECTOR; 6404 } 6405 6406 UINT16 TPMS_ATTEST_Marshal(TPMS_ATTEST* source, BYTE** buffer, INT32* size) { 6407 UINT16 total_size = 0; 6408 total_size += TPM_GENERATED_Marshal(&source->magic, buffer, size); 6409 total_size += TPMI_ST_ATTEST_Marshal(&source->type, buffer, size); 6410 total_size += TPM2B_NAME_Marshal(&source->qualifiedSigner, buffer, size); 6411 total_size += TPM2B_DATA_Marshal(&source->extraData, buffer, size); 6412 total_size += TPMS_CLOCK_INFO_Marshal(&source->clockInfo, buffer, size); 6413 total_size += UINT64_Marshal(&source->firmwareVersion, buffer, size); 6414 total_size += 6415 TPMU_ATTEST_Marshal(&source->attested, buffer, size, source->type); 6416 return total_size; 6417 } 6418 6419 TPM_RC TPMS_ATTEST_Unmarshal(TPMS_ATTEST* target, BYTE** buffer, INT32* size) { 6420 TPM_RC result; 6421 result = TPM_GENERATED_Unmarshal(&target->magic, buffer, size); 6422 if (result != TPM_RC_SUCCESS) { 6423 return result; 6424 } 6425 result = TPMI_ST_ATTEST_Unmarshal(&target->type, buffer, size); 6426 if (result != TPM_RC_SUCCESS) { 6427 return result; 6428 } 6429 result = TPM2B_NAME_Unmarshal(&target->qualifiedSigner, buffer, size); 6430 if (result != TPM_RC_SUCCESS) { 6431 return result; 6432 } 6433 result = TPM2B_DATA_Unmarshal(&target->extraData, buffer, size); 6434 if (result != TPM_RC_SUCCESS) { 6435 return result; 6436 } 6437 result = TPMS_CLOCK_INFO_Unmarshal(&target->clockInfo, buffer, size); 6438 if (result != TPM_RC_SUCCESS) { 6439 return result; 6440 } 6441 result = UINT64_Unmarshal(&target->firmwareVersion, buffer, size); 6442 if (result != TPM_RC_SUCCESS) { 6443 return result; 6444 } 6445 result = TPMU_ATTEST_Unmarshal(&target->attested, buffer, size, target->type); 6446 if (result != TPM_RC_SUCCESS) { 6447 return result; 6448 } 6449 return TPM_RC_SUCCESS; 6450 } 6451 6452 UINT16 TPMS_AUTH_COMMAND_Marshal(TPMS_AUTH_COMMAND* source, 6453 BYTE** buffer, 6454 INT32* size) { 6455 UINT16 total_size = 0; 6456 total_size += 6457 TPMI_SH_AUTH_SESSION_Marshal(&source->sessionHandle, buffer, size); 6458 total_size += TPM2B_NONCE_Marshal(&source->nonce, buffer, size); 6459 total_size += TPMA_SESSION_Marshal(&source->sessionAttributes, buffer, size); 6460 total_size += TPM2B_AUTH_Marshal(&source->hmac, buffer, size); 6461 return total_size; 6462 } 6463 6464 TPM_RC TPMS_AUTH_COMMAND_Unmarshal(TPMS_AUTH_COMMAND* target, 6465 BYTE** buffer, 6466 INT32* size) { 6467 TPM_RC result; 6468 result = TPMI_SH_AUTH_SESSION_Unmarshal(&target->sessionHandle, buffer, size, 6469 TRUE); 6470 if (result != TPM_RC_SUCCESS) { 6471 return result; 6472 } 6473 result = TPM2B_NONCE_Unmarshal(&target->nonce, buffer, size); 6474 if (result != TPM_RC_SUCCESS) { 6475 return result; 6476 } 6477 result = TPMA_SESSION_Unmarshal(&target->sessionAttributes, buffer, size); 6478 if (result != TPM_RC_SUCCESS) { 6479 return result; 6480 } 6481 result = TPM2B_AUTH_Unmarshal(&target->hmac, buffer, size); 6482 if (result != TPM_RC_SUCCESS) { 6483 return result; 6484 } 6485 return TPM_RC_SUCCESS; 6486 } 6487 6488 UINT16 TPMS_AUTH_RESPONSE_Marshal(TPMS_AUTH_RESPONSE* source, 6489 BYTE** buffer, 6490 INT32* size) { 6491 UINT16 total_size = 0; 6492 total_size += TPM2B_NONCE_Marshal(&source->nonce, buffer, size); 6493 total_size += TPMA_SESSION_Marshal(&source->sessionAttributes, buffer, size); 6494 total_size += TPM2B_AUTH_Marshal(&source->hmac, buffer, size); 6495 return total_size; 6496 } 6497 6498 TPM_RC TPMS_AUTH_RESPONSE_Unmarshal(TPMS_AUTH_RESPONSE* target, 6499 BYTE** buffer, 6500 INT32* size) { 6501 TPM_RC result; 6502 result = TPM2B_NONCE_Unmarshal(&target->nonce, buffer, size); 6503 if (result != TPM_RC_SUCCESS) { 6504 return result; 6505 } 6506 result = TPMA_SESSION_Unmarshal(&target->sessionAttributes, buffer, size); 6507 if (result != TPM_RC_SUCCESS) { 6508 return result; 6509 } 6510 result = TPM2B_AUTH_Unmarshal(&target->hmac, buffer, size); 6511 if (result != TPM_RC_SUCCESS) { 6512 return result; 6513 } 6514 return TPM_RC_SUCCESS; 6515 } 6516 6517 UINT16 TPM_CAP_Marshal(TPM_CAP* source, BYTE** buffer, INT32* size) { 6518 return uint32_t_Marshal(source, buffer, size); 6519 } 6520 6521 TPM_RC TPM_CAP_Unmarshal(TPM_CAP* target, BYTE** buffer, INT32* size) { 6522 TPM_RC result; 6523 result = uint32_t_Unmarshal(target, buffer, size); 6524 if (result != TPM_RC_SUCCESS) { 6525 return result; 6526 } 6527 if (*target == TPM_CAP_FIRST) { 6528 return TPM_RC_SUCCESS; 6529 } 6530 if (*target == TPM_CAP_ALGS) { 6531 return TPM_RC_SUCCESS; 6532 } 6533 if (*target == TPM_CAP_HANDLES) { 6534 return TPM_RC_SUCCESS; 6535 } 6536 if (*target == TPM_CAP_COMMANDS) { 6537 return TPM_RC_SUCCESS; 6538 } 6539 if (*target == TPM_CAP_PP_COMMANDS) { 6540 return TPM_RC_SUCCESS; 6541 } 6542 if (*target == TPM_CAP_AUDIT_COMMANDS) { 6543 return TPM_RC_SUCCESS; 6544 } 6545 if (*target == TPM_CAP_PCRS) { 6546 return TPM_RC_SUCCESS; 6547 } 6548 if (*target == TPM_CAP_TPM_PROPERTIES) { 6549 return TPM_RC_SUCCESS; 6550 } 6551 if (*target == TPM_CAP_PCR_PROPERTIES) { 6552 return TPM_RC_SUCCESS; 6553 } 6554 if (*target == TPM_CAP_ECC_CURVES) { 6555 return TPM_RC_SUCCESS; 6556 } 6557 if (*target == TPM_CAP_LAST) { 6558 return TPM_RC_SUCCESS; 6559 } 6560 if (*target == TPM_CAP_VENDOR_PROPERTY) { 6561 return TPM_RC_SUCCESS; 6562 } 6563 return TPM_RC_VALUE; 6564 } 6565 6566 UINT16 TPMU_CAPABILITIES_Marshal(TPMU_CAPABILITIES* source, 6567 BYTE** buffer, 6568 INT32* size, 6569 UINT32 selector) { 6570 switch (selector) { 6571 case TPM_CAP_ALGS: 6572 return TPML_ALG_PROPERTY_Marshal((TPML_ALG_PROPERTY*)&source->algorithms, 6573 buffer, size); 6574 case TPM_CAP_HANDLES: 6575 return TPML_HANDLE_Marshal((TPML_HANDLE*)&source->handles, buffer, size); 6576 case TPM_CAP_COMMANDS: 6577 return TPML_CCA_Marshal((TPML_CCA*)&source->command, buffer, size); 6578 case TPM_CAP_PP_COMMANDS: 6579 return TPML_CC_Marshal((TPML_CC*)&source->ppCommands, buffer, size); 6580 case TPM_CAP_AUDIT_COMMANDS: 6581 return TPML_CC_Marshal((TPML_CC*)&source->auditCommands, buffer, size); 6582 case TPM_CAP_PCRS: 6583 return TPML_PCR_SELECTION_Marshal( 6584 (TPML_PCR_SELECTION*)&source->assignedPCR, buffer, size); 6585 case TPM_CAP_TPM_PROPERTIES: 6586 return TPML_TAGGED_TPM_PROPERTY_Marshal( 6587 (TPML_TAGGED_TPM_PROPERTY*)&source->tpmProperties, buffer, size); 6588 case TPM_CAP_PCR_PROPERTIES: 6589 return TPML_TAGGED_PCR_PROPERTY_Marshal( 6590 (TPML_TAGGED_PCR_PROPERTY*)&source->pcrProperties, buffer, size); 6591 case TPM_CAP_ECC_CURVES: 6592 return TPML_ECC_CURVE_Marshal((TPML_ECC_CURVE*)&source->eccCurves, buffer, 6593 size); 6594 } 6595 return 0; 6596 } 6597 6598 TPM_RC TPMU_CAPABILITIES_Unmarshal(TPMU_CAPABILITIES* target, 6599 BYTE** buffer, 6600 INT32* size, 6601 UINT32 selector) { 6602 switch (selector) { 6603 case TPM_CAP_ALGS: 6604 return TPML_ALG_PROPERTY_Unmarshal( 6605 (TPML_ALG_PROPERTY*)&target->algorithms, buffer, size); 6606 case TPM_CAP_HANDLES: 6607 return TPML_HANDLE_Unmarshal((TPML_HANDLE*)&target->handles, buffer, 6608 size); 6609 case TPM_CAP_COMMANDS: 6610 return TPML_CCA_Unmarshal((TPML_CCA*)&target->command, buffer, size); 6611 case TPM_CAP_PP_COMMANDS: 6612 return TPML_CC_Unmarshal((TPML_CC*)&target->ppCommands, buffer, size); 6613 case TPM_CAP_AUDIT_COMMANDS: 6614 return TPML_CC_Unmarshal((TPML_CC*)&target->auditCommands, buffer, size); 6615 case TPM_CAP_PCRS: 6616 return TPML_PCR_SELECTION_Unmarshal( 6617 (TPML_PCR_SELECTION*)&target->assignedPCR, buffer, size); 6618 case TPM_CAP_TPM_PROPERTIES: 6619 return TPML_TAGGED_TPM_PROPERTY_Unmarshal( 6620 (TPML_TAGGED_TPM_PROPERTY*)&target->tpmProperties, buffer, size); 6621 case TPM_CAP_PCR_PROPERTIES: 6622 return TPML_TAGGED_PCR_PROPERTY_Unmarshal( 6623 (TPML_TAGGED_PCR_PROPERTY*)&target->pcrProperties, buffer, size); 6624 case TPM_CAP_ECC_CURVES: 6625 return TPML_ECC_CURVE_Unmarshal((TPML_ECC_CURVE*)&target->eccCurves, 6626 buffer, size); 6627 } 6628 return TPM_RC_SELECTOR; 6629 } 6630 6631 UINT16 TPMS_CAPABILITY_DATA_Marshal(TPMS_CAPABILITY_DATA* source, 6632 BYTE** buffer, 6633 INT32* size) { 6634 UINT16 total_size = 0; 6635 total_size += TPM_CAP_Marshal(&source->capability, buffer, size); 6636 total_size += TPMU_CAPABILITIES_Marshal(&source->data, buffer, size, 6637 source->capability); 6638 return total_size; 6639 } 6640 6641 TPM_RC TPMS_CAPABILITY_DATA_Unmarshal(TPMS_CAPABILITY_DATA* target, 6642 BYTE** buffer, 6643 INT32* size) { 6644 TPM_RC result; 6645 result = TPM_CAP_Unmarshal(&target->capability, buffer, size); 6646 if (result != TPM_RC_SUCCESS) { 6647 return result; 6648 } 6649 result = TPMU_CAPABILITIES_Unmarshal(&target->data, buffer, size, 6650 target->capability); 6651 if (result != TPM_RC_SUCCESS) { 6652 return result; 6653 } 6654 return TPM_RC_SUCCESS; 6655 } 6656 6657 UINT16 TPMS_CONTEXT_Marshal(TPMS_CONTEXT* source, BYTE** buffer, INT32* size) { 6658 UINT16 total_size = 0; 6659 total_size += UINT64_Marshal(&source->sequence, buffer, size); 6660 total_size += TPMI_DH_CONTEXT_Marshal(&source->savedHandle, buffer, size); 6661 total_size += TPMI_RH_HIERARCHY_Marshal(&source->hierarchy, buffer, size); 6662 total_size += TPM2B_CONTEXT_DATA_Marshal(&source->contextBlob, buffer, size); 6663 return total_size; 6664 } 6665 6666 TPM_RC TPMS_CONTEXT_Unmarshal(TPMS_CONTEXT* target, 6667 BYTE** buffer, 6668 INT32* size) { 6669 TPM_RC result; 6670 result = UINT64_Unmarshal(&target->sequence, buffer, size); 6671 if (result != TPM_RC_SUCCESS) { 6672 return result; 6673 } 6674 result = TPMI_DH_CONTEXT_Unmarshal(&target->savedHandle, buffer, size); 6675 if (result != TPM_RC_SUCCESS) { 6676 return result; 6677 } 6678 result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); 6679 if (result != TPM_RC_SUCCESS) { 6680 return result; 6681 } 6682 result = TPM2B_CONTEXT_DATA_Unmarshal(&target->contextBlob, buffer, size); 6683 if (result != TPM_RC_SUCCESS) { 6684 return result; 6685 } 6686 return TPM_RC_SUCCESS; 6687 } 6688 6689 UINT16 TPMS_CONTEXT_DATA_Marshal(TPMS_CONTEXT_DATA* source, 6690 BYTE** buffer, 6691 INT32* size) { 6692 UINT16 total_size = 0; 6693 total_size += TPM2B_DIGEST_Marshal(&source->integrity, buffer, size); 6694 total_size += 6695 TPM2B_CONTEXT_SENSITIVE_Marshal(&source->encrypted, buffer, size); 6696 return total_size; 6697 } 6698 6699 TPM_RC TPMS_CONTEXT_DATA_Unmarshal(TPMS_CONTEXT_DATA* target, 6700 BYTE** buffer, 6701 INT32* size) { 6702 TPM_RC result; 6703 result = TPM2B_DIGEST_Unmarshal(&target->integrity, buffer, size); 6704 if (result != TPM_RC_SUCCESS) { 6705 return result; 6706 } 6707 result = TPM2B_CONTEXT_SENSITIVE_Unmarshal(&target->encrypted, buffer, size); 6708 if (result != TPM_RC_SUCCESS) { 6709 return result; 6710 } 6711 return TPM_RC_SUCCESS; 6712 } 6713 6714 UINT16 TPMS_PCR_SELECT_Marshal(TPMS_PCR_SELECT* source, 6715 BYTE** buffer, 6716 INT32* size) { 6717 UINT16 total_size = 0; 6718 INT32 i; 6719 total_size += UINT8_Marshal(&source->sizeofSelect, buffer, size); 6720 for (i = 0; i < source->sizeofSelect; ++i) { 6721 total_size += BYTE_Marshal(&source->pcrSelect[i], buffer, size); 6722 } 6723 return total_size; 6724 } 6725 6726 TPM_RC TPMS_PCR_SELECT_Unmarshal(TPMS_PCR_SELECT* target, 6727 BYTE** buffer, 6728 INT32* size) { 6729 TPM_RC result; 6730 INT32 i; 6731 result = UINT8_Unmarshal(&target->sizeofSelect, buffer, size); 6732 if (result != TPM_RC_SUCCESS) { 6733 return result; 6734 } 6735 if (target->sizeofSelect > PCR_SELECT_MAX) { 6736 return TPM_RC_VALUE; 6737 } 6738 if (target->sizeofSelect < PCR_SELECT_MIN) { 6739 return TPM_RC_VALUE; 6740 } 6741 for (i = 0; i < target->sizeofSelect; ++i) { 6742 result = BYTE_Unmarshal(&target->pcrSelect[i], buffer, size); 6743 if (result != TPM_RC_SUCCESS) { 6744 return result; 6745 } 6746 } 6747 return TPM_RC_SUCCESS; 6748 } 6749 6750 UINT16 TPMS_SIGNATURE_ECC_Marshal(TPMS_SIGNATURE_ECC* source, 6751 BYTE** buffer, 6752 INT32* size) { 6753 UINT16 total_size = 0; 6754 total_size += TPMI_ALG_HASH_Marshal(&source->hash, buffer, size); 6755 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->signatureR, buffer, size); 6756 total_size += TPM2B_ECC_PARAMETER_Marshal(&source->signatureS, buffer, size); 6757 return total_size; 6758 } 6759 6760 TPM_RC TPMS_SIGNATURE_ECC_Unmarshal(TPMS_SIGNATURE_ECC* target, 6761 BYTE** buffer, 6762 INT32* size) { 6763 TPM_RC result; 6764 result = TPMI_ALG_HASH_Unmarshal(&target->hash, buffer, size, FALSE); 6765 if (result != TPM_RC_SUCCESS) { 6766 return result; 6767 } 6768 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->signatureR, buffer, size); 6769 if (result != TPM_RC_SUCCESS) { 6770 return result; 6771 } 6772 result = TPM2B_ECC_PARAMETER_Unmarshal(&target->signatureS, buffer, size); 6773 if (result != TPM_RC_SUCCESS) { 6774 return result; 6775 } 6776 return TPM_RC_SUCCESS; 6777 } 6778 6779 UINT16 TPMS_SIGNATURE_ECDAA_Marshal(TPMS_SIGNATURE_ECDAA* source, 6780 BYTE** buffer, 6781 INT32* size) { 6782 return TPMS_SIGNATURE_ECC_Marshal(source, buffer, size); 6783 } 6784 6785 TPM_RC TPMS_SIGNATURE_ECDAA_Unmarshal(TPMS_SIGNATURE_ECDAA* target, 6786 BYTE** buffer, 6787 INT32* size) { 6788 return TPMS_SIGNATURE_ECC_Unmarshal(target, buffer, size); 6789 } 6790 6791 UINT16 TPMS_SIGNATURE_ECDSA_Marshal(TPMS_SIGNATURE_ECDSA* source, 6792 BYTE** buffer, 6793 INT32* size) { 6794 return TPMS_SIGNATURE_ECC_Marshal(source, buffer, size); 6795 } 6796 6797 TPM_RC TPMS_SIGNATURE_ECDSA_Unmarshal(TPMS_SIGNATURE_ECDSA* target, 6798 BYTE** buffer, 6799 INT32* size) { 6800 return TPMS_SIGNATURE_ECC_Unmarshal(target, buffer, size); 6801 } 6802 6803 UINT16 TPMS_SIGNATURE_ECSCHNORR_Marshal(TPMS_SIGNATURE_ECSCHNORR* source, 6804 BYTE** buffer, 6805 INT32* size) { 6806 return TPMS_SIGNATURE_ECC_Marshal(source, buffer, size); 6807 } 6808 6809 TPM_RC TPMS_SIGNATURE_ECSCHNORR_Unmarshal(TPMS_SIGNATURE_ECSCHNORR* target, 6810 BYTE** buffer, 6811 INT32* size) { 6812 return TPMS_SIGNATURE_ECC_Unmarshal(target, buffer, size); 6813 } 6814 6815 UINT16 TPMS_SIGNATURE_RSA_Marshal(TPMS_SIGNATURE_RSA* source, 6816 BYTE** buffer, 6817 INT32* size) { 6818 UINT16 total_size = 0; 6819 total_size += TPMI_ALG_HASH_Marshal(&source->hash, buffer, size); 6820 total_size += TPM2B_PUBLIC_KEY_RSA_Marshal(&source->sig, buffer, size); 6821 return total_size; 6822 } 6823 6824 TPM_RC TPMS_SIGNATURE_RSA_Unmarshal(TPMS_SIGNATURE_RSA* target, 6825 BYTE** buffer, 6826 INT32* size) { 6827 TPM_RC result; 6828 result = TPMI_ALG_HASH_Unmarshal(&target->hash, buffer, size, FALSE); 6829 if (result != TPM_RC_SUCCESS) { 6830 return result; 6831 } 6832 result = TPM2B_PUBLIC_KEY_RSA_Unmarshal(&target->sig, buffer, size); 6833 if (result != TPM_RC_SUCCESS) { 6834 return result; 6835 } 6836 return TPM_RC_SUCCESS; 6837 } 6838 6839 UINT16 TPMS_SIGNATURE_RSAPSS_Marshal(TPMS_SIGNATURE_RSAPSS* source, 6840 BYTE** buffer, 6841 INT32* size) { 6842 return TPMS_SIGNATURE_RSA_Marshal(source, buffer, size); 6843 } 6844 6845 TPM_RC TPMS_SIGNATURE_RSAPSS_Unmarshal(TPMS_SIGNATURE_RSAPSS* target, 6846 BYTE** buffer, 6847 INT32* size) { 6848 return TPMS_SIGNATURE_RSA_Unmarshal(target, buffer, size); 6849 } 6850 6851 UINT16 TPMS_SIGNATURE_RSASSA_Marshal(TPMS_SIGNATURE_RSASSA* source, 6852 BYTE** buffer, 6853 INT32* size) { 6854 return TPMS_SIGNATURE_RSA_Marshal(source, buffer, size); 6855 } 6856 6857 TPM_RC TPMS_SIGNATURE_RSASSA_Unmarshal(TPMS_SIGNATURE_RSASSA* target, 6858 BYTE** buffer, 6859 INT32* size) { 6860 return TPMS_SIGNATURE_RSA_Unmarshal(target, buffer, size); 6861 } 6862 6863 UINT16 TPMS_SIGNATURE_SM2_Marshal(TPMS_SIGNATURE_SM2* source, 6864 BYTE** buffer, 6865 INT32* size) { 6866 return TPMS_SIGNATURE_ECC_Marshal(source, buffer, size); 6867 } 6868 6869 TPM_RC TPMS_SIGNATURE_SM2_Unmarshal(TPMS_SIGNATURE_SM2* target, 6870 BYTE** buffer, 6871 INT32* size) { 6872 return TPMS_SIGNATURE_ECC_Unmarshal(target, buffer, size); 6873 } 6874 6875 UINT16 TPMT_PUBLIC_PARMS_Marshal(TPMT_PUBLIC_PARMS* source, 6876 BYTE** buffer, 6877 INT32* size) { 6878 UINT16 total_size = 0; 6879 total_size += TPMI_ALG_PUBLIC_Marshal(&source->type, buffer, size); 6880 total_size += TPMU_PUBLIC_PARMS_Marshal(&source->parameters, buffer, size, 6881 source->type); 6882 return total_size; 6883 } 6884 6885 TPM_RC TPMT_PUBLIC_PARMS_Unmarshal(TPMT_PUBLIC_PARMS* target, 6886 BYTE** buffer, 6887 INT32* size) { 6888 TPM_RC result; 6889 result = TPMI_ALG_PUBLIC_Unmarshal(&target->type, buffer, size); 6890 if (result != TPM_RC_SUCCESS) { 6891 return result; 6892 } 6893 result = TPMU_PUBLIC_PARMS_Unmarshal(&target->parameters, buffer, size, 6894 target->type); 6895 if (result != TPM_RC_SUCCESS) { 6896 return result; 6897 } 6898 return TPM_RC_SUCCESS; 6899 } 6900 6901 UINT16 TPMT_RSA_DECRYPT_Marshal(TPMT_RSA_DECRYPT* source, 6902 BYTE** buffer, 6903 INT32* size) { 6904 UINT16 total_size = 0; 6905 total_size += TPMI_ALG_RSA_DECRYPT_Marshal(&source->scheme, buffer, size); 6906 total_size += 6907 TPMU_ASYM_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 6908 return total_size; 6909 } 6910 6911 TPM_RC TPMT_RSA_DECRYPT_Unmarshal(TPMT_RSA_DECRYPT* target, 6912 BYTE** buffer, 6913 INT32* size) { 6914 TPM_RC result; 6915 result = TPMI_ALG_RSA_DECRYPT_Unmarshal(&target->scheme, buffer, size, TRUE); 6916 if (result != TPM_RC_SUCCESS) { 6917 return result; 6918 } 6919 result = TPMU_ASYM_SCHEME_Unmarshal(&target->details, buffer, size, 6920 target->scheme); 6921 if (result != TPM_RC_SUCCESS) { 6922 return result; 6923 } 6924 return TPM_RC_SUCCESS; 6925 } 6926 6927 UINT16 TPMU_SIGNATURE_Marshal(TPMU_SIGNATURE* source, 6928 BYTE** buffer, 6929 INT32* size, 6930 UINT32 selector) { 6931 switch (selector) { 6932 #ifdef TPM_ALG_RSASSA 6933 case TPM_ALG_RSASSA: 6934 return TPMS_SIGNATURE_RSASSA_Marshal( 6935 (TPMS_SIGNATURE_RSASSA*)&source->rsassa, buffer, size); 6936 #endif 6937 #ifdef TPM_ALG_RSAPSS 6938 case TPM_ALG_RSAPSS: 6939 return TPMS_SIGNATURE_RSAPSS_Marshal( 6940 (TPMS_SIGNATURE_RSAPSS*)&source->rsapss, buffer, size); 6941 #endif 6942 #ifdef TPM_ALG_ECDSA 6943 case TPM_ALG_ECDSA: 6944 return TPMS_SIGNATURE_ECDSA_Marshal((TPMS_SIGNATURE_ECDSA*)&source->ecdsa, 6945 buffer, size); 6946 #endif 6947 #ifdef TPM_ALG_ECDAA 6948 case TPM_ALG_ECDAA: 6949 return TPMS_SIGNATURE_ECDAA_Marshal((TPMS_SIGNATURE_ECDAA*)&source->ecdaa, 6950 buffer, size); 6951 #endif 6952 #ifdef TPM_ALG_SM2 6953 case TPM_ALG_SM2: 6954 return TPMS_SIGNATURE_SM2_Marshal((TPMS_SIGNATURE_SM2*)&source->sm2, 6955 buffer, size); 6956 #endif 6957 #ifdef TPM_ALG_ECSCHNORR 6958 case TPM_ALG_ECSCHNORR: 6959 return TPMS_SIGNATURE_ECSCHNORR_Marshal( 6960 (TPMS_SIGNATURE_ECSCHNORR*)&source->ecschnorr, buffer, size); 6961 #endif 6962 #ifdef TPM_ALG_HMAC 6963 case TPM_ALG_HMAC: 6964 return TPMT_HA_Marshal((TPMT_HA*)&source->hmac, buffer, size); 6965 #endif 6966 #ifdef TPM_ALG_NULL 6967 case TPM_ALG_NULL: 6968 return 0; 6969 #endif 6970 } 6971 return 0; 6972 } 6973 6974 TPM_RC TPMU_SIGNATURE_Unmarshal(TPMU_SIGNATURE* target, 6975 BYTE** buffer, 6976 INT32* size, 6977 UINT32 selector) { 6978 switch (selector) { 6979 #ifdef TPM_ALG_RSASSA 6980 case TPM_ALG_RSASSA: 6981 return TPMS_SIGNATURE_RSASSA_Unmarshal( 6982 (TPMS_SIGNATURE_RSASSA*)&target->rsassa, buffer, size); 6983 #endif 6984 #ifdef TPM_ALG_RSAPSS 6985 case TPM_ALG_RSAPSS: 6986 return TPMS_SIGNATURE_RSAPSS_Unmarshal( 6987 (TPMS_SIGNATURE_RSAPSS*)&target->rsapss, buffer, size); 6988 #endif 6989 #ifdef TPM_ALG_ECDSA 6990 case TPM_ALG_ECDSA: 6991 return TPMS_SIGNATURE_ECDSA_Unmarshal( 6992 (TPMS_SIGNATURE_ECDSA*)&target->ecdsa, buffer, size); 6993 #endif 6994 #ifdef TPM_ALG_ECDAA 6995 case TPM_ALG_ECDAA: 6996 return TPMS_SIGNATURE_ECDAA_Unmarshal( 6997 (TPMS_SIGNATURE_ECDAA*)&target->ecdaa, buffer, size); 6998 #endif 6999 #ifdef TPM_ALG_SM2 7000 case TPM_ALG_SM2: 7001 return TPMS_SIGNATURE_SM2_Unmarshal((TPMS_SIGNATURE_SM2*)&target->sm2, 7002 buffer, size); 7003 #endif 7004 #ifdef TPM_ALG_ECSCHNORR 7005 case TPM_ALG_ECSCHNORR: 7006 return TPMS_SIGNATURE_ECSCHNORR_Unmarshal( 7007 (TPMS_SIGNATURE_ECSCHNORR*)&target->ecschnorr, buffer, size); 7008 #endif 7009 #ifdef TPM_ALG_HMAC 7010 case TPM_ALG_HMAC: 7011 return TPMT_HA_Unmarshal((TPMT_HA*)&target->hmac, buffer, size); 7012 #endif 7013 #ifdef TPM_ALG_NULL 7014 case TPM_ALG_NULL: 7015 return TPM_RC_SUCCESS; 7016 #endif 7017 } 7018 return TPM_RC_SELECTOR; 7019 } 7020 7021 UINT16 TPMT_SIGNATURE_Marshal(TPMT_SIGNATURE* source, 7022 BYTE** buffer, 7023 INT32* size) { 7024 UINT16 total_size = 0; 7025 total_size += TPMI_ALG_SIG_SCHEME_Marshal(&source->sigAlg, buffer, size); 7026 total_size += 7027 TPMU_SIGNATURE_Marshal(&source->signature, buffer, size, source->sigAlg); 7028 return total_size; 7029 } 7030 7031 TPM_RC TPMT_SIGNATURE_Unmarshal(TPMT_SIGNATURE* target, 7032 BYTE** buffer, 7033 INT32* size) { 7034 TPM_RC result; 7035 result = TPMI_ALG_SIG_SCHEME_Unmarshal(&target->sigAlg, buffer, size, TRUE); 7036 if (result != TPM_RC_SUCCESS) { 7037 return result; 7038 } 7039 result = TPMU_SIGNATURE_Unmarshal(&target->signature, buffer, size, 7040 target->sigAlg); 7041 if (result != TPM_RC_SUCCESS) { 7042 return result; 7043 } 7044 return TPM_RC_SUCCESS; 7045 } 7046 7047 UINT16 TPMU_SIG_SCHEME_Marshal(TPMU_SIG_SCHEME* source, 7048 BYTE** buffer, 7049 INT32* size, 7050 UINT32 selector) { 7051 switch (selector) { 7052 #ifdef TPM_ALG_RSASSA 7053 case TPM_ALG_RSASSA: 7054 return TPMS_SIG_SCHEME_RSASSA_Marshal( 7055 (TPMS_SIG_SCHEME_RSASSA*)&source->rsassa, buffer, size); 7056 #endif 7057 #ifdef TPM_ALG_RSAPSS 7058 case TPM_ALG_RSAPSS: 7059 return TPMS_SIG_SCHEME_RSAPSS_Marshal( 7060 (TPMS_SIG_SCHEME_RSAPSS*)&source->rsapss, buffer, size); 7061 #endif 7062 #ifdef TPM_ALG_ECDSA 7063 case TPM_ALG_ECDSA: 7064 return TPMS_SIG_SCHEME_ECDSA_Marshal( 7065 (TPMS_SIG_SCHEME_ECDSA*)&source->ecdsa, buffer, size); 7066 #endif 7067 #ifdef TPM_ALG_ECDAA 7068 case TPM_ALG_ECDAA: 7069 return TPMS_SIG_SCHEME_ECDAA_Marshal( 7070 (TPMS_SIG_SCHEME_ECDAA*)&source->ecdaa, buffer, size); 7071 #endif 7072 #ifdef TPM_ALG_SM2 7073 case TPM_ALG_SM2: 7074 return TPMS_SIG_SCHEME_SM2_Marshal((TPMS_SIG_SCHEME_SM2*)&source->sm2, 7075 buffer, size); 7076 #endif 7077 #ifdef TPM_ALG_ECSCHNORR 7078 case TPM_ALG_ECSCHNORR: 7079 return TPMS_SIG_SCHEME_ECSCHNORR_Marshal( 7080 (TPMS_SIG_SCHEME_ECSCHNORR*)&source->ecschnorr, buffer, size); 7081 #endif 7082 #ifdef TPM_ALG_HMAC 7083 case TPM_ALG_HMAC: 7084 return TPMS_SCHEME_HMAC_Marshal((TPMS_SCHEME_HMAC*)&source->hmac, buffer, 7085 size); 7086 #endif 7087 #ifdef TPM_ALG_NULL 7088 case TPM_ALG_NULL: 7089 return 0; 7090 #endif 7091 } 7092 return 0; 7093 } 7094 7095 TPM_RC TPMU_SIG_SCHEME_Unmarshal(TPMU_SIG_SCHEME* target, 7096 BYTE** buffer, 7097 INT32* size, 7098 UINT32 selector) { 7099 switch (selector) { 7100 #ifdef TPM_ALG_RSASSA 7101 case TPM_ALG_RSASSA: 7102 return TPMS_SIG_SCHEME_RSASSA_Unmarshal( 7103 (TPMS_SIG_SCHEME_RSASSA*)&target->rsassa, buffer, size); 7104 #endif 7105 #ifdef TPM_ALG_RSAPSS 7106 case TPM_ALG_RSAPSS: 7107 return TPMS_SIG_SCHEME_RSAPSS_Unmarshal( 7108 (TPMS_SIG_SCHEME_RSAPSS*)&target->rsapss, buffer, size); 7109 #endif 7110 #ifdef TPM_ALG_ECDSA 7111 case TPM_ALG_ECDSA: 7112 return TPMS_SIG_SCHEME_ECDSA_Unmarshal( 7113 (TPMS_SIG_SCHEME_ECDSA*)&target->ecdsa, buffer, size); 7114 #endif 7115 #ifdef TPM_ALG_ECDAA 7116 case TPM_ALG_ECDAA: 7117 return TPMS_SIG_SCHEME_ECDAA_Unmarshal( 7118 (TPMS_SIG_SCHEME_ECDAA*)&target->ecdaa, buffer, size); 7119 #endif 7120 #ifdef TPM_ALG_SM2 7121 case TPM_ALG_SM2: 7122 return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2*)&target->sm2, 7123 buffer, size); 7124 #endif 7125 #ifdef TPM_ALG_ECSCHNORR 7126 case TPM_ALG_ECSCHNORR: 7127 return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal( 7128 (TPMS_SIG_SCHEME_ECSCHNORR*)&target->ecschnorr, buffer, size); 7129 #endif 7130 #ifdef TPM_ALG_HMAC 7131 case TPM_ALG_HMAC: 7132 return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC*)&target->hmac, 7133 buffer, size); 7134 #endif 7135 #ifdef TPM_ALG_NULL 7136 case TPM_ALG_NULL: 7137 return TPM_RC_SUCCESS; 7138 #endif 7139 } 7140 return TPM_RC_SELECTOR; 7141 } 7142 7143 UINT16 TPMT_SIG_SCHEME_Marshal(TPMT_SIG_SCHEME* source, 7144 BYTE** buffer, 7145 INT32* size) { 7146 UINT16 total_size = 0; 7147 total_size += TPMI_ALG_SIG_SCHEME_Marshal(&source->scheme, buffer, size); 7148 total_size += 7149 TPMU_SIG_SCHEME_Marshal(&source->details, buffer, size, source->scheme); 7150 return total_size; 7151 } 7152 7153 TPM_RC TPMT_SIG_SCHEME_Unmarshal(TPMT_SIG_SCHEME* target, 7154 BYTE** buffer, 7155 INT32* size) { 7156 TPM_RC result; 7157 result = TPMI_ALG_SIG_SCHEME_Unmarshal(&target->scheme, buffer, size, TRUE); 7158 if (result != TPM_RC_SUCCESS) { 7159 return result; 7160 } 7161 result = 7162 TPMU_SIG_SCHEME_Unmarshal(&target->details, buffer, size, target->scheme); 7163 if (result != TPM_RC_SUCCESS) { 7164 return result; 7165 } 7166 return TPM_RC_SUCCESS; 7167 } 7168 7169 UINT16 TPMT_SYM_DEF_Marshal(TPMT_SYM_DEF* source, BYTE** buffer, INT32* size) { 7170 UINT16 total_size = 0; 7171 total_size += TPMI_ALG_SYM_Marshal(&source->algorithm, buffer, size); 7172 total_size += TPMU_SYM_KEY_BITS_Marshal(&source->keyBits, buffer, size, 7173 source->algorithm); 7174 total_size += 7175 TPMU_SYM_MODE_Marshal(&source->mode, buffer, size, source->algorithm); 7176 return total_size; 7177 } 7178 7179 TPM_RC TPMT_SYM_DEF_Unmarshal(TPMT_SYM_DEF* target, 7180 BYTE** buffer, 7181 INT32* size) { 7182 TPM_RC result; 7183 result = TPMI_ALG_SYM_Unmarshal(&target->algorithm, buffer, size, TRUE); 7184 if (result != TPM_RC_SUCCESS) { 7185 return result; 7186 } 7187 result = TPMU_SYM_KEY_BITS_Unmarshal(&target->keyBits, buffer, size, 7188 target->algorithm); 7189 if (result != TPM_RC_SUCCESS) { 7190 return result; 7191 } 7192 result = 7193 TPMU_SYM_MODE_Unmarshal(&target->mode, buffer, size, target->algorithm); 7194 if (result != TPM_RC_SUCCESS) { 7195 return result; 7196 } 7197 return TPM_RC_SUCCESS; 7198 } 7199 7200 UINT16 TPM_ST_Marshal(TPM_ST* source, BYTE** buffer, INT32* size) { 7201 return uint16_t_Marshal(source, buffer, size); 7202 } 7203 7204 TPM_RC TPM_ST_Unmarshal(TPM_ST* target, BYTE** buffer, INT32* size) { 7205 TPM_RC result; 7206 result = uint16_t_Unmarshal(target, buffer, size); 7207 if (result != TPM_RC_SUCCESS) { 7208 return result; 7209 } 7210 if (*target == TPM_ST_RSP_COMMAND) { 7211 return TPM_RC_SUCCESS; 7212 } 7213 if (*target == TPM_ST_NULL) { 7214 return TPM_RC_SUCCESS; 7215 } 7216 if (*target == TPM_ST_NO_SESSIONS) { 7217 return TPM_RC_SUCCESS; 7218 } 7219 if (*target == TPM_ST_SESSIONS) { 7220 return TPM_RC_SUCCESS; 7221 } 7222 if (*target == TPM_ST_ATTEST_NV) { 7223 return TPM_RC_SUCCESS; 7224 } 7225 if (*target == TPM_ST_ATTEST_COMMAND_AUDIT) { 7226 return TPM_RC_SUCCESS; 7227 } 7228 if (*target == TPM_ST_ATTEST_SESSION_AUDIT) { 7229 return TPM_RC_SUCCESS; 7230 } 7231 if (*target == TPM_ST_ATTEST_CERTIFY) { 7232 return TPM_RC_SUCCESS; 7233 } 7234 if (*target == TPM_ST_ATTEST_QUOTE) { 7235 return TPM_RC_SUCCESS; 7236 } 7237 if (*target == TPM_ST_ATTEST_TIME) { 7238 return TPM_RC_SUCCESS; 7239 } 7240 if (*target == TPM_ST_ATTEST_CREATION) { 7241 return TPM_RC_SUCCESS; 7242 } 7243 if (*target == TPM_ST_CREATION) { 7244 return TPM_RC_SUCCESS; 7245 } 7246 if (*target == TPM_ST_VERIFIED) { 7247 return TPM_RC_SUCCESS; 7248 } 7249 if (*target == TPM_ST_AUTH_SECRET) { 7250 return TPM_RC_SUCCESS; 7251 } 7252 if (*target == TPM_ST_HASHCHECK) { 7253 return TPM_RC_SUCCESS; 7254 } 7255 if (*target == TPM_ST_AUTH_SIGNED) { 7256 return TPM_RC_SUCCESS; 7257 } 7258 if (*target == TPM_ST_FU_MANIFEST) { 7259 return TPM_RC_SUCCESS; 7260 } 7261 return TPM_RC_VALUE; 7262 } 7263 7264 UINT16 TPMT_TK_AUTH_Marshal(TPMT_TK_AUTH* source, BYTE** buffer, INT32* size) { 7265 UINT16 total_size = 0; 7266 total_size += TPM_ST_Marshal(&source->tag, buffer, size); 7267 total_size += TPMI_RH_HIERARCHY_Marshal(&source->hierarchy, buffer, size); 7268 total_size += TPM2B_DIGEST_Marshal(&source->digest, buffer, size); 7269 return total_size; 7270 } 7271 7272 TPM_RC TPMT_TK_AUTH_Unmarshal(TPMT_TK_AUTH* target, 7273 BYTE** buffer, 7274 INT32* size) { 7275 TPM_RC result; 7276 result = TPM_ST_Unmarshal(&target->tag, buffer, size); 7277 if (result != TPM_RC_SUCCESS) { 7278 return result; 7279 } 7280 result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); 7281 if (result != TPM_RC_SUCCESS) { 7282 return result; 7283 } 7284 result = TPM2B_DIGEST_Unmarshal(&target->digest, buffer, size); 7285 if (result != TPM_RC_SUCCESS) { 7286 return result; 7287 } 7288 return TPM_RC_SUCCESS; 7289 } 7290 7291 UINT16 TPMT_TK_CREATION_Marshal(TPMT_TK_CREATION* source, 7292 BYTE** buffer, 7293 INT32* size) { 7294 UINT16 total_size = 0; 7295 total_size += TPM_ST_Marshal(&source->tag, buffer, size); 7296 total_size += TPMI_RH_HIERARCHY_Marshal(&source->hierarchy, buffer, size); 7297 total_size += TPM2B_DIGEST_Marshal(&source->digest, buffer, size); 7298 return total_size; 7299 } 7300 7301 TPM_RC TPMT_TK_CREATION_Unmarshal(TPMT_TK_CREATION* target, 7302 BYTE** buffer, 7303 INT32* size) { 7304 TPM_RC result; 7305 result = TPM_ST_Unmarshal(&target->tag, buffer, size); 7306 if (result != TPM_RC_SUCCESS) { 7307 return result; 7308 } 7309 result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); 7310 if (result != TPM_RC_SUCCESS) { 7311 return result; 7312 } 7313 result = TPM2B_DIGEST_Unmarshal(&target->digest, buffer, size); 7314 if (result != TPM_RC_SUCCESS) { 7315 return result; 7316 } 7317 return TPM_RC_SUCCESS; 7318 } 7319 7320 UINT16 TPMT_TK_HASHCHECK_Marshal(TPMT_TK_HASHCHECK* source, 7321 BYTE** buffer, 7322 INT32* size) { 7323 UINT16 total_size = 0; 7324 total_size += TPM_ST_Marshal(&source->tag, buffer, size); 7325 total_size += TPMI_RH_HIERARCHY_Marshal(&source->hierarchy, buffer, size); 7326 total_size += TPM2B_DIGEST_Marshal(&source->digest, buffer, size); 7327 return total_size; 7328 } 7329 7330 TPM_RC TPMT_TK_HASHCHECK_Unmarshal(TPMT_TK_HASHCHECK* target, 7331 BYTE** buffer, 7332 INT32* size) { 7333 TPM_RC result; 7334 result = TPM_ST_Unmarshal(&target->tag, buffer, size); 7335 if (result != TPM_RC_SUCCESS) { 7336 return result; 7337 } 7338 result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); 7339 if (result != TPM_RC_SUCCESS) { 7340 return result; 7341 } 7342 result = TPM2B_DIGEST_Unmarshal(&target->digest, buffer, size); 7343 if (result != TPM_RC_SUCCESS) { 7344 return result; 7345 } 7346 return TPM_RC_SUCCESS; 7347 } 7348 7349 UINT16 TPMT_TK_VERIFIED_Marshal(TPMT_TK_VERIFIED* source, 7350 BYTE** buffer, 7351 INT32* size) { 7352 UINT16 total_size = 0; 7353 total_size += TPM_ST_Marshal(&source->tag, buffer, size); 7354 total_size += TPMI_RH_HIERARCHY_Marshal(&source->hierarchy, buffer, size); 7355 total_size += TPM2B_DIGEST_Marshal(&source->digest, buffer, size); 7356 return total_size; 7357 } 7358 7359 TPM_RC TPMT_TK_VERIFIED_Unmarshal(TPMT_TK_VERIFIED* target, 7360 BYTE** buffer, 7361 INT32* size) { 7362 TPM_RC result; 7363 result = TPM_ST_Unmarshal(&target->tag, buffer, size); 7364 if (result != TPM_RC_SUCCESS) { 7365 return result; 7366 } 7367 result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); 7368 if (result != TPM_RC_SUCCESS) { 7369 return result; 7370 } 7371 result = TPM2B_DIGEST_Unmarshal(&target->digest, buffer, size); 7372 if (result != TPM_RC_SUCCESS) { 7373 return result; 7374 } 7375 return TPM_RC_SUCCESS; 7376 } 7377 7378 UINT16 TPMU_SYM_DETAILS_Marshal(TPMU_SYM_DETAILS* source, 7379 BYTE** buffer, 7380 INT32* size, 7381 UINT32 selector) { 7382 switch (selector) { 7383 #ifdef TPM_ALG_AES 7384 case TPM_ALG_AES: 7385 return 0; 7386 #endif 7387 #ifdef TPM_ALG_SM4 7388 case TPM_ALG_SM4: 7389 return 0; 7390 #endif 7391 #ifdef TPM_ALG_CAMELLIA 7392 case TPM_ALG_CAMELLIA: 7393 return 0; 7394 #endif 7395 #ifdef TPM_ALG_XOR 7396 case TPM_ALG_XOR: 7397 return 0; 7398 #endif 7399 #ifdef TPM_ALG_NULL 7400 case TPM_ALG_NULL: 7401 return 0; 7402 #endif 7403 } 7404 return 0; 7405 } 7406 7407 TPM_RC TPMU_SYM_DETAILS_Unmarshal(TPMU_SYM_DETAILS* target, 7408 BYTE** buffer, 7409 INT32* size, 7410 UINT32 selector) { 7411 switch (selector) { 7412 #ifdef TPM_ALG_AES 7413 case TPM_ALG_AES: 7414 return TPM_RC_SUCCESS; 7415 #endif 7416 #ifdef TPM_ALG_SM4 7417 case TPM_ALG_SM4: 7418 return TPM_RC_SUCCESS; 7419 #endif 7420 #ifdef TPM_ALG_CAMELLIA 7421 case TPM_ALG_CAMELLIA: 7422 return TPM_RC_SUCCESS; 7423 #endif 7424 #ifdef TPM_ALG_XOR 7425 case TPM_ALG_XOR: 7426 return TPM_RC_SUCCESS; 7427 #endif 7428 #ifdef TPM_ALG_NULL 7429 case TPM_ALG_NULL: 7430 return TPM_RC_SUCCESS; 7431 #endif 7432 } 7433 return TPM_RC_SELECTOR; 7434 } 7435 7436 UINT16 TPM_ALGORITHM_ID_Marshal(TPM_ALGORITHM_ID* source, 7437 BYTE** buffer, 7438 INT32* size) { 7439 return uint32_t_Marshal(source, buffer, size); 7440 } 7441 7442 TPM_RC TPM_ALGORITHM_ID_Unmarshal(TPM_ALGORITHM_ID* target, 7443 BYTE** buffer, 7444 INT32* size) { 7445 return uint32_t_Unmarshal(target, buffer, size); 7446 } 7447 7448 UINT16 TPM_AUTHORIZATION_SIZE_Marshal(TPM_AUTHORIZATION_SIZE* source, 7449 BYTE** buffer, 7450 INT32* size) { 7451 return uint32_t_Marshal(source, buffer, size); 7452 } 7453 7454 TPM_RC TPM_AUTHORIZATION_SIZE_Unmarshal(TPM_AUTHORIZATION_SIZE* target, 7455 BYTE** buffer, 7456 INT32* size) { 7457 return uint32_t_Unmarshal(target, buffer, size); 7458 } 7459 7460 UINT16 TPM_CLOCK_ADJUST_Marshal(TPM_CLOCK_ADJUST* source, 7461 BYTE** buffer, 7462 INT32* size) { 7463 return int8_t_Marshal(source, buffer, size); 7464 } 7465 7466 TPM_RC TPM_CLOCK_ADJUST_Unmarshal(TPM_CLOCK_ADJUST* target, 7467 BYTE** buffer, 7468 INT32* size) { 7469 TPM_RC result; 7470 result = int8_t_Unmarshal(target, buffer, size); 7471 if (result != TPM_RC_SUCCESS) { 7472 return result; 7473 } 7474 if (*target == TPM_CLOCK_COARSE_SLOWER) { 7475 return TPM_RC_SUCCESS; 7476 } 7477 if (*target == TPM_CLOCK_MEDIUM_SLOWER) { 7478 return TPM_RC_SUCCESS; 7479 } 7480 if (*target == TPM_CLOCK_FINE_SLOWER) { 7481 return TPM_RC_SUCCESS; 7482 } 7483 if (*target == TPM_CLOCK_NO_CHANGE) { 7484 return TPM_RC_SUCCESS; 7485 } 7486 if (*target == TPM_CLOCK_FINE_FASTER) { 7487 return TPM_RC_SUCCESS; 7488 } 7489 if (*target == TPM_CLOCK_MEDIUM_FASTER) { 7490 return TPM_RC_SUCCESS; 7491 } 7492 if (*target == TPM_CLOCK_COARSE_FASTER) { 7493 return TPM_RC_SUCCESS; 7494 } 7495 return TPM_RC_VALUE; 7496 } 7497 7498 UINT16 TPM_EO_Marshal(TPM_EO* source, BYTE** buffer, INT32* size) { 7499 return uint16_t_Marshal(source, buffer, size); 7500 } 7501 7502 TPM_RC TPM_EO_Unmarshal(TPM_EO* target, BYTE** buffer, INT32* size) { 7503 TPM_RC result; 7504 result = uint16_t_Unmarshal(target, buffer, size); 7505 if (result != TPM_RC_SUCCESS) { 7506 return result; 7507 } 7508 if (*target == TPM_EO_EQ) { 7509 return TPM_RC_SUCCESS; 7510 } 7511 if (*target == TPM_EO_NEQ) { 7512 return TPM_RC_SUCCESS; 7513 } 7514 if (*target == TPM_EO_SIGNED_GT) { 7515 return TPM_RC_SUCCESS; 7516 } 7517 if (*target == TPM_EO_UNSIGNED_GT) { 7518 return TPM_RC_SUCCESS; 7519 } 7520 if (*target == TPM_EO_SIGNED_LT) { 7521 return TPM_RC_SUCCESS; 7522 } 7523 if (*target == TPM_EO_UNSIGNED_LT) { 7524 return TPM_RC_SUCCESS; 7525 } 7526 if (*target == TPM_EO_SIGNED_GE) { 7527 return TPM_RC_SUCCESS; 7528 } 7529 if (*target == TPM_EO_UNSIGNED_GE) { 7530 return TPM_RC_SUCCESS; 7531 } 7532 if (*target == TPM_EO_SIGNED_LE) { 7533 return TPM_RC_SUCCESS; 7534 } 7535 if (*target == TPM_EO_UNSIGNED_LE) { 7536 return TPM_RC_SUCCESS; 7537 } 7538 if (*target == TPM_EO_BITSET) { 7539 return TPM_RC_SUCCESS; 7540 } 7541 if (*target == TPM_EO_BITCLEAR) { 7542 return TPM_RC_SUCCESS; 7543 } 7544 return TPM_RC_VALUE; 7545 } 7546 7547 UINT16 TPM_HC_Marshal(TPM_HC* source, BYTE** buffer, INT32* size) { 7548 return uint32_t_Marshal(source, buffer, size); 7549 } 7550 7551 TPM_RC TPM_HC_Unmarshal(TPM_HC* target, BYTE** buffer, INT32* size) { 7552 TPM_RC result; 7553 result = uint32_t_Unmarshal(target, buffer, size); 7554 if (result != TPM_RC_SUCCESS) { 7555 return result; 7556 } 7557 if (*target == HR_HANDLE_MASK) { 7558 return TPM_RC_SUCCESS; 7559 } 7560 if (*target == HR_RANGE_MASK) { 7561 return TPM_RC_SUCCESS; 7562 } 7563 if (*target == HR_SHIFT) { 7564 return TPM_RC_SUCCESS; 7565 } 7566 if (*target == HR_PCR) { 7567 return TPM_RC_SUCCESS; 7568 } 7569 if (*target == HR_HMAC_SESSION) { 7570 return TPM_RC_SUCCESS; 7571 } 7572 if (*target == HR_POLICY_SESSION) { 7573 return TPM_RC_SUCCESS; 7574 } 7575 if (*target == HR_TRANSIENT) { 7576 return TPM_RC_SUCCESS; 7577 } 7578 if (*target == HR_PERSISTENT) { 7579 return TPM_RC_SUCCESS; 7580 } 7581 if (*target == HR_NV_INDEX) { 7582 return TPM_RC_SUCCESS; 7583 } 7584 if (*target == HR_PERMANENT) { 7585 return TPM_RC_SUCCESS; 7586 } 7587 if (*target == PCR_FIRST) { 7588 return TPM_RC_SUCCESS; 7589 } 7590 if (*target == PCR_LAST) { 7591 return TPM_RC_SUCCESS; 7592 } 7593 if (*target == HMAC_SESSION_FIRST) { 7594 return TPM_RC_SUCCESS; 7595 } 7596 if (*target == HMAC_SESSION_LAST) { 7597 return TPM_RC_SUCCESS; 7598 } 7599 if (*target == LOADED_SESSION_FIRST) { 7600 return TPM_RC_SUCCESS; 7601 } 7602 if (*target == LOADED_SESSION_LAST) { 7603 return TPM_RC_SUCCESS; 7604 } 7605 if (*target == POLICY_SESSION_FIRST) { 7606 return TPM_RC_SUCCESS; 7607 } 7608 if (*target == POLICY_SESSION_LAST) { 7609 return TPM_RC_SUCCESS; 7610 } 7611 if (*target == TRANSIENT_FIRST) { 7612 return TPM_RC_SUCCESS; 7613 } 7614 if (*target == ACTIVE_SESSION_FIRST) { 7615 return TPM_RC_SUCCESS; 7616 } 7617 if (*target == ACTIVE_SESSION_LAST) { 7618 return TPM_RC_SUCCESS; 7619 } 7620 if (*target == TRANSIENT_LAST) { 7621 return TPM_RC_SUCCESS; 7622 } 7623 if (*target == PERSISTENT_FIRST) { 7624 return TPM_RC_SUCCESS; 7625 } 7626 if (*target == PERSISTENT_LAST) { 7627 return TPM_RC_SUCCESS; 7628 } 7629 if (*target == PLATFORM_PERSISTENT) { 7630 return TPM_RC_SUCCESS; 7631 } 7632 if (*target == NV_INDEX_FIRST) { 7633 return TPM_RC_SUCCESS; 7634 } 7635 if (*target == NV_INDEX_LAST) { 7636 return TPM_RC_SUCCESS; 7637 } 7638 if (*target == PERMANENT_FIRST) { 7639 return TPM_RC_SUCCESS; 7640 } 7641 if (*target == PERMANENT_LAST) { 7642 return TPM_RC_SUCCESS; 7643 } 7644 return TPM_RC_VALUE; 7645 } 7646 7647 UINT16 TPM_HT_Marshal(TPM_HT* source, BYTE** buffer, INT32* size) { 7648 return uint8_t_Marshal(source, buffer, size); 7649 } 7650 7651 TPM_RC TPM_HT_Unmarshal(TPM_HT* target, BYTE** buffer, INT32* size) { 7652 TPM_RC result; 7653 result = uint8_t_Unmarshal(target, buffer, size); 7654 if (result != TPM_RC_SUCCESS) { 7655 return result; 7656 } 7657 if (*target == TPM_HT_PCR) { 7658 return TPM_RC_SUCCESS; 7659 } 7660 if (*target == TPM_HT_NV_INDEX) { 7661 return TPM_RC_SUCCESS; 7662 } 7663 if (*target == TPM_HT_HMAC_SESSION) { 7664 return TPM_RC_SUCCESS; 7665 } 7666 if (*target == TPM_HT_LOADED_SESSION) { 7667 return TPM_RC_SUCCESS; 7668 } 7669 if (*target == TPM_HT_POLICY_SESSION) { 7670 return TPM_RC_SUCCESS; 7671 } 7672 if (*target == TPM_HT_ACTIVE_SESSION) { 7673 return TPM_RC_SUCCESS; 7674 } 7675 if (*target == TPM_HT_PERMANENT) { 7676 return TPM_RC_SUCCESS; 7677 } 7678 if (*target == TPM_HT_TRANSIENT) { 7679 return TPM_RC_SUCCESS; 7680 } 7681 if (*target == TPM_HT_PERSISTENT) { 7682 return TPM_RC_SUCCESS; 7683 } 7684 return TPM_RC_VALUE; 7685 } 7686 7687 UINT16 TPM_KEY_SIZE_Marshal(TPM_KEY_SIZE* source, BYTE** buffer, INT32* size) { 7688 return uint16_t_Marshal(source, buffer, size); 7689 } 7690 7691 TPM_RC TPM_KEY_SIZE_Unmarshal(TPM_KEY_SIZE* target, 7692 BYTE** buffer, 7693 INT32* size) { 7694 return uint16_t_Unmarshal(target, buffer, size); 7695 } 7696 7697 UINT16 TPM_MODIFIER_INDICATOR_Marshal(TPM_MODIFIER_INDICATOR* source, 7698 BYTE** buffer, 7699 INT32* size) { 7700 return uint32_t_Marshal(source, buffer, size); 7701 } 7702 7703 TPM_RC TPM_MODIFIER_INDICATOR_Unmarshal(TPM_MODIFIER_INDICATOR* target, 7704 BYTE** buffer, 7705 INT32* size) { 7706 return uint32_t_Unmarshal(target, buffer, size); 7707 } 7708 7709 UINT16 TPM_NV_INDEX_Marshal(TPM_NV_INDEX* source, BYTE** buffer, INT32* size) { 7710 return uint32_t_Marshal((uint32_t*)source, buffer, size); 7711 } 7712 7713 TPM_RC TPM_NV_INDEX_Unmarshal(TPM_NV_INDEX* target, 7714 BYTE** buffer, 7715 INT32* size) { 7716 TPM_RC result; 7717 result = uint32_t_Unmarshal((uint32_t*)target, buffer, size); 7718 if (result != TPM_RC_SUCCESS) { 7719 return result; 7720 } 7721 return TPM_RC_SUCCESS; 7722 } 7723 7724 UINT16 TPM_PARAMETER_SIZE_Marshal(TPM_PARAMETER_SIZE* source, 7725 BYTE** buffer, 7726 INT32* size) { 7727 return uint32_t_Marshal(source, buffer, size); 7728 } 7729 7730 TPM_RC TPM_PARAMETER_SIZE_Unmarshal(TPM_PARAMETER_SIZE* target, 7731 BYTE** buffer, 7732 INT32* size) { 7733 return uint32_t_Unmarshal(target, buffer, size); 7734 } 7735 7736 UINT16 TPM_PS_Marshal(TPM_PS* source, BYTE** buffer, INT32* size) { 7737 return uint32_t_Marshal(source, buffer, size); 7738 } 7739 7740 TPM_RC TPM_PS_Unmarshal(TPM_PS* target, BYTE** buffer, INT32* size) { 7741 TPM_RC result; 7742 result = uint32_t_Unmarshal(target, buffer, size); 7743 if (result != TPM_RC_SUCCESS) { 7744 return result; 7745 } 7746 if (*target == TPM_PS_MAIN) { 7747 return TPM_RC_SUCCESS; 7748 } 7749 if (*target == TPM_PS_PC) { 7750 return TPM_RC_SUCCESS; 7751 } 7752 if (*target == TPM_PS_PDA) { 7753 return TPM_RC_SUCCESS; 7754 } 7755 if (*target == TPM_PS_CELL_PHONE) { 7756 return TPM_RC_SUCCESS; 7757 } 7758 if (*target == TPM_PS_SERVER) { 7759 return TPM_RC_SUCCESS; 7760 } 7761 if (*target == TPM_PS_PERIPHERAL) { 7762 return TPM_RC_SUCCESS; 7763 } 7764 if (*target == TPM_PS_TSS) { 7765 return TPM_RC_SUCCESS; 7766 } 7767 if (*target == TPM_PS_STORAGE) { 7768 return TPM_RC_SUCCESS; 7769 } 7770 if (*target == TPM_PS_AUTHENTICATION) { 7771 return TPM_RC_SUCCESS; 7772 } 7773 if (*target == TPM_PS_EMBEDDED) { 7774 return TPM_RC_SUCCESS; 7775 } 7776 if (*target == TPM_PS_HARDCOPY) { 7777 return TPM_RC_SUCCESS; 7778 } 7779 if (*target == TPM_PS_INFRASTRUCTURE) { 7780 return TPM_RC_SUCCESS; 7781 } 7782 if (*target == TPM_PS_VIRTUALIZATION) { 7783 return TPM_RC_SUCCESS; 7784 } 7785 if (*target == TPM_PS_TNC) { 7786 return TPM_RC_SUCCESS; 7787 } 7788 if (*target == TPM_PS_MULTI_TENANT) { 7789 return TPM_RC_SUCCESS; 7790 } 7791 if (*target == TPM_PS_TC) { 7792 return TPM_RC_SUCCESS; 7793 } 7794 return TPM_RC_VALUE; 7795 } 7796 7797 UINT16 TPM_PT_PCR_Marshal(TPM_PT_PCR* source, BYTE** buffer, INT32* size) { 7798 return uint32_t_Marshal(source, buffer, size); 7799 } 7800 7801 TPM_RC TPM_PT_PCR_Unmarshal(TPM_PT_PCR* target, BYTE** buffer, INT32* size) { 7802 TPM_RC result; 7803 result = uint32_t_Unmarshal(target, buffer, size); 7804 if (result != TPM_RC_SUCCESS) { 7805 return result; 7806 } 7807 if (*target == TPM_PT_PCR_FIRST) { 7808 return TPM_RC_SUCCESS; 7809 } 7810 if (*target == TPM_PT_PCR_SAVE) { 7811 return TPM_RC_SUCCESS; 7812 } 7813 if (*target == TPM_PT_PCR_EXTEND_L0) { 7814 return TPM_RC_SUCCESS; 7815 } 7816 if (*target == TPM_PT_PCR_RESET_L0) { 7817 return TPM_RC_SUCCESS; 7818 } 7819 if (*target == TPM_PT_PCR_EXTEND_L1) { 7820 return TPM_RC_SUCCESS; 7821 } 7822 if (*target == TPM_PT_PCR_RESET_L1) { 7823 return TPM_RC_SUCCESS; 7824 } 7825 if (*target == TPM_PT_PCR_EXTEND_L2) { 7826 return TPM_RC_SUCCESS; 7827 } 7828 if (*target == TPM_PT_PCR_RESET_L2) { 7829 return TPM_RC_SUCCESS; 7830 } 7831 if (*target == TPM_PT_PCR_EXTEND_L3) { 7832 return TPM_RC_SUCCESS; 7833 } 7834 if (*target == TPM_PT_PCR_RESET_L3) { 7835 return TPM_RC_SUCCESS; 7836 } 7837 if (*target == TPM_PT_PCR_EXTEND_L4) { 7838 return TPM_RC_SUCCESS; 7839 } 7840 if (*target == TPM_PT_PCR_RESET_L4) { 7841 return TPM_RC_SUCCESS; 7842 } 7843 if (*target == TPM_PT_PCR_NO_INCREMENT) { 7844 return TPM_RC_SUCCESS; 7845 } 7846 if (*target == TPM_PT_PCR_DRTM_RESET) { 7847 return TPM_RC_SUCCESS; 7848 } 7849 if (*target == TPM_PT_PCR_POLICY) { 7850 return TPM_RC_SUCCESS; 7851 } 7852 if (*target == TPM_PT_PCR_AUTH) { 7853 return TPM_RC_SUCCESS; 7854 } 7855 if (*target == TPM_PT_PCR_LAST) { 7856 return TPM_RC_SUCCESS; 7857 } 7858 return TPM_RC_VALUE; 7859 } 7860 7861 UINT16 TPM_RC_Marshal(TPM_RC* source, BYTE** buffer, INT32* size) { 7862 return uint32_t_Marshal(source, buffer, size); 7863 } 7864 7865 TPM_RC TPM_RC_Unmarshal(TPM_RC* target, BYTE** buffer, INT32* size) { 7866 TPM_RC result; 7867 result = uint32_t_Unmarshal(target, buffer, size); 7868 if (result != TPM_RC_SUCCESS) { 7869 return result; 7870 } 7871 if (*target == TPM_RC_SUCCESS) { 7872 return TPM_RC_SUCCESS; 7873 } 7874 if (*target == TPM_RC_BAD_TAG) { 7875 return TPM_RC_SUCCESS; 7876 } 7877 if (*target == RC_VER1) { 7878 return TPM_RC_SUCCESS; 7879 } 7880 if (*target == TPM_RC_INITIALIZE) { 7881 return TPM_RC_SUCCESS; 7882 } 7883 if (*target == TPM_RC_FAILURE) { 7884 return TPM_RC_SUCCESS; 7885 } 7886 if (*target == TPM_RC_SEQUENCE) { 7887 return TPM_RC_SUCCESS; 7888 } 7889 if (*target == TPM_RC_PRIVATE) { 7890 return TPM_RC_SUCCESS; 7891 } 7892 if (*target == TPM_RC_HMAC) { 7893 return TPM_RC_SUCCESS; 7894 } 7895 if (*target == TPM_RC_DISABLED) { 7896 return TPM_RC_SUCCESS; 7897 } 7898 if (*target == TPM_RC_EXCLUSIVE) { 7899 return TPM_RC_SUCCESS; 7900 } 7901 if (*target == TPM_RC_AUTH_TYPE) { 7902 return TPM_RC_SUCCESS; 7903 } 7904 if (*target == TPM_RC_AUTH_MISSING) { 7905 return TPM_RC_SUCCESS; 7906 } 7907 if (*target == TPM_RC_POLICY) { 7908 return TPM_RC_SUCCESS; 7909 } 7910 if (*target == TPM_RC_PCR) { 7911 return TPM_RC_SUCCESS; 7912 } 7913 if (*target == TPM_RC_PCR_CHANGED) { 7914 return TPM_RC_SUCCESS; 7915 } 7916 if (*target == TPM_RC_UPGRADE) { 7917 return TPM_RC_SUCCESS; 7918 } 7919 if (*target == TPM_RC_TOO_MANY_CONTEXTS) { 7920 return TPM_RC_SUCCESS; 7921 } 7922 if (*target == TPM_RC_AUTH_UNAVAILABLE) { 7923 return TPM_RC_SUCCESS; 7924 } 7925 if (*target == TPM_RC_REBOOT) { 7926 return TPM_RC_SUCCESS; 7927 } 7928 if (*target == TPM_RC_UNBALANCED) { 7929 return TPM_RC_SUCCESS; 7930 } 7931 if (*target == TPM_RC_COMMAND_SIZE) { 7932 return TPM_RC_SUCCESS; 7933 } 7934 if (*target == TPM_RC_COMMAND_CODE) { 7935 return TPM_RC_SUCCESS; 7936 } 7937 if (*target == TPM_RC_AUTHSIZE) { 7938 return TPM_RC_SUCCESS; 7939 } 7940 if (*target == TPM_RC_AUTH_CONTEXT) { 7941 return TPM_RC_SUCCESS; 7942 } 7943 if (*target == TPM_RC_NV_RANGE) { 7944 return TPM_RC_SUCCESS; 7945 } 7946 if (*target == TPM_RC_NV_SIZE) { 7947 return TPM_RC_SUCCESS; 7948 } 7949 if (*target == TPM_RC_NV_LOCKED) { 7950 return TPM_RC_SUCCESS; 7951 } 7952 if (*target == TPM_RC_NV_AUTHORIZATION) { 7953 return TPM_RC_SUCCESS; 7954 } 7955 if (*target == TPM_RC_NV_UNINITIALIZED) { 7956 return TPM_RC_SUCCESS; 7957 } 7958 if (*target == TPM_RC_NV_SPACE) { 7959 return TPM_RC_SUCCESS; 7960 } 7961 if (*target == TPM_RC_NV_DEFINED) { 7962 return TPM_RC_SUCCESS; 7963 } 7964 if (*target == TPM_RC_BAD_CONTEXT) { 7965 return TPM_RC_SUCCESS; 7966 } 7967 if (*target == TPM_RC_CPHASH) { 7968 return TPM_RC_SUCCESS; 7969 } 7970 if (*target == TPM_RC_PARENT) { 7971 return TPM_RC_SUCCESS; 7972 } 7973 if (*target == TPM_RC_NEEDS_TEST) { 7974 return TPM_RC_SUCCESS; 7975 } 7976 if (*target == TPM_RC_NO_RESULT) { 7977 return TPM_RC_SUCCESS; 7978 } 7979 if (*target == TPM_RC_SENSITIVE) { 7980 return TPM_RC_SUCCESS; 7981 } 7982 if (*target == RC_MAX_FM0) { 7983 return TPM_RC_SUCCESS; 7984 } 7985 if (*target == RC_FMT1) { 7986 return TPM_RC_SUCCESS; 7987 } 7988 if (*target == TPM_RC_ASYMMETRIC) { 7989 return TPM_RC_SUCCESS; 7990 } 7991 if (*target == TPM_RC_ATTRIBUTES) { 7992 return TPM_RC_SUCCESS; 7993 } 7994 if (*target == TPM_RC_HASH) { 7995 return TPM_RC_SUCCESS; 7996 } 7997 if (*target == TPM_RC_VALUE) { 7998 return TPM_RC_SUCCESS; 7999 } 8000 if (*target == TPM_RC_HIERARCHY) { 8001 return TPM_RC_SUCCESS; 8002 } 8003 if (*target == TPM_RC_KEY_SIZE) { 8004 return TPM_RC_SUCCESS; 8005 } 8006 if (*target == TPM_RC_MGF) { 8007 return TPM_RC_SUCCESS; 8008 } 8009 if (*target == TPM_RC_MODE) { 8010 return TPM_RC_SUCCESS; 8011 } 8012 if (*target == TPM_RC_TYPE) { 8013 return TPM_RC_SUCCESS; 8014 } 8015 if (*target == TPM_RC_HANDLE) { 8016 return TPM_RC_SUCCESS; 8017 } 8018 if (*target == TPM_RC_KDF) { 8019 return TPM_RC_SUCCESS; 8020 } 8021 if (*target == TPM_RC_RANGE) { 8022 return TPM_RC_SUCCESS; 8023 } 8024 if (*target == TPM_RC_AUTH_FAIL) { 8025 return TPM_RC_SUCCESS; 8026 } 8027 if (*target == TPM_RC_NONCE) { 8028 return TPM_RC_SUCCESS; 8029 } 8030 if (*target == TPM_RC_PP) { 8031 return TPM_RC_SUCCESS; 8032 } 8033 if (*target == TPM_RC_SCHEME) { 8034 return TPM_RC_SUCCESS; 8035 } 8036 if (*target == TPM_RC_SIZE) { 8037 return TPM_RC_SUCCESS; 8038 } 8039 if (*target == TPM_RC_SYMMETRIC) { 8040 return TPM_RC_SUCCESS; 8041 } 8042 if (*target == TPM_RC_TAG) { 8043 return TPM_RC_SUCCESS; 8044 } 8045 if (*target == TPM_RC_SELECTOR) { 8046 return TPM_RC_SUCCESS; 8047 } 8048 if (*target == TPM_RC_INSUFFICIENT) { 8049 return TPM_RC_SUCCESS; 8050 } 8051 if (*target == TPM_RC_SIGNATURE) { 8052 return TPM_RC_SUCCESS; 8053 } 8054 if (*target == TPM_RC_KEY) { 8055 return TPM_RC_SUCCESS; 8056 } 8057 if (*target == TPM_RC_POLICY_FAIL) { 8058 return TPM_RC_SUCCESS; 8059 } 8060 if (*target == TPM_RC_INTEGRITY) { 8061 return TPM_RC_SUCCESS; 8062 } 8063 if (*target == TPM_RC_TICKET) { 8064 return TPM_RC_SUCCESS; 8065 } 8066 if (*target == TPM_RC_RESERVED_BITS) { 8067 return TPM_RC_SUCCESS; 8068 } 8069 if (*target == TPM_RC_BAD_AUTH) { 8070 return TPM_RC_SUCCESS; 8071 } 8072 if (*target == TPM_RC_EXPIRED) { 8073 return TPM_RC_SUCCESS; 8074 } 8075 if (*target == TPM_RC_POLICY_CC) { 8076 return TPM_RC_SUCCESS; 8077 } 8078 if (*target == TPM_RC_BINDING) { 8079 return TPM_RC_SUCCESS; 8080 } 8081 if (*target == TPM_RC_CURVE) { 8082 return TPM_RC_SUCCESS; 8083 } 8084 if (*target == TPM_RC_ECC_POINT) { 8085 return TPM_RC_SUCCESS; 8086 } 8087 if (*target == RC_WARN) { 8088 return TPM_RC_SUCCESS; 8089 } 8090 if (*target == TPM_RC_CONTEXT_GAP) { 8091 return TPM_RC_SUCCESS; 8092 } 8093 if (*target == TPM_RC_OBJECT_MEMORY) { 8094 return TPM_RC_SUCCESS; 8095 } 8096 if (*target == TPM_RC_SESSION_MEMORY) { 8097 return TPM_RC_SUCCESS; 8098 } 8099 if (*target == TPM_RC_MEMORY) { 8100 return TPM_RC_SUCCESS; 8101 } 8102 if (*target == TPM_RC_SESSION_HANDLES) { 8103 return TPM_RC_SUCCESS; 8104 } 8105 if (*target == TPM_RC_OBJECT_HANDLES) { 8106 return TPM_RC_SUCCESS; 8107 } 8108 if (*target == TPM_RC_LOCALITY) { 8109 return TPM_RC_SUCCESS; 8110 } 8111 if (*target == TPM_RC_YIELDED) { 8112 return TPM_RC_SUCCESS; 8113 } 8114 if (*target == TPM_RC_CANCELED) { 8115 return TPM_RC_SUCCESS; 8116 } 8117 if (*target == TPM_RC_TESTING) { 8118 return TPM_RC_SUCCESS; 8119 } 8120 if (*target == TPM_RC_REFERENCE_H0) { 8121 return TPM_RC_SUCCESS; 8122 } 8123 if (*target == TPM_RC_REFERENCE_H1) { 8124 return TPM_RC_SUCCESS; 8125 } 8126 if (*target == TPM_RC_REFERENCE_H2) { 8127 return TPM_RC_SUCCESS; 8128 } 8129 if (*target == TPM_RC_REFERENCE_H3) { 8130 return TPM_RC_SUCCESS; 8131 } 8132 if (*target == TPM_RC_REFERENCE_H4) { 8133 return TPM_RC_SUCCESS; 8134 } 8135 if (*target == TPM_RC_REFERENCE_H5) { 8136 return TPM_RC_SUCCESS; 8137 } 8138 if (*target == TPM_RC_REFERENCE_H6) { 8139 return TPM_RC_SUCCESS; 8140 } 8141 if (*target == TPM_RC_REFERENCE_S0) { 8142 return TPM_RC_SUCCESS; 8143 } 8144 if (*target == TPM_RC_REFERENCE_S1) { 8145 return TPM_RC_SUCCESS; 8146 } 8147 if (*target == TPM_RC_REFERENCE_S2) { 8148 return TPM_RC_SUCCESS; 8149 } 8150 if (*target == TPM_RC_REFERENCE_S3) { 8151 return TPM_RC_SUCCESS; 8152 } 8153 if (*target == TPM_RC_REFERENCE_S4) { 8154 return TPM_RC_SUCCESS; 8155 } 8156 if (*target == TPM_RC_REFERENCE_S5) { 8157 return TPM_RC_SUCCESS; 8158 } 8159 if (*target == TPM_RC_REFERENCE_S6) { 8160 return TPM_RC_SUCCESS; 8161 } 8162 if (*target == TPM_RC_NV_RATE) { 8163 return TPM_RC_SUCCESS; 8164 } 8165 if (*target == TPM_RC_LOCKOUT) { 8166 return TPM_RC_SUCCESS; 8167 } 8168 if (*target == TPM_RC_RETRY) { 8169 return TPM_RC_SUCCESS; 8170 } 8171 if (*target == TPM_RC_NV_UNAVAILABLE) { 8172 return TPM_RC_SUCCESS; 8173 } 8174 if (*target == TPM_RC_NOT_USED) { 8175 return TPM_RC_SUCCESS; 8176 } 8177 if (*target == TPM_RC_H) { 8178 return TPM_RC_SUCCESS; 8179 } 8180 if (*target == TPM_RC_P) { 8181 return TPM_RC_SUCCESS; 8182 } 8183 if (*target == TPM_RC_S) { 8184 return TPM_RC_SUCCESS; 8185 } 8186 if (*target == TPM_RC_1) { 8187 return TPM_RC_SUCCESS; 8188 } 8189 if (*target == TPM_RC_2) { 8190 return TPM_RC_SUCCESS; 8191 } 8192 if (*target == TPM_RC_3) { 8193 return TPM_RC_SUCCESS; 8194 } 8195 if (*target == TPM_RC_4) { 8196 return TPM_RC_SUCCESS; 8197 } 8198 if (*target == TPM_RC_5) { 8199 return TPM_RC_SUCCESS; 8200 } 8201 if (*target == TPM_RC_6) { 8202 return TPM_RC_SUCCESS; 8203 } 8204 if (*target == TPM_RC_7) { 8205 return TPM_RC_SUCCESS; 8206 } 8207 if (*target == TPM_RC_8) { 8208 return TPM_RC_SUCCESS; 8209 } 8210 if (*target == TPM_RC_9) { 8211 return TPM_RC_SUCCESS; 8212 } 8213 if (*target == TPM_RC_A) { 8214 return TPM_RC_SUCCESS; 8215 } 8216 if (*target == TPM_RC_B) { 8217 return TPM_RC_SUCCESS; 8218 } 8219 if (*target == TPM_RC_C) { 8220 return TPM_RC_SUCCESS; 8221 } 8222 if (*target == TPM_RC_D) { 8223 return TPM_RC_SUCCESS; 8224 } 8225 if (*target == TPM_RC_E) { 8226 return TPM_RC_SUCCESS; 8227 } 8228 if (*target == TPM_RC_F) { 8229 return TPM_RC_SUCCESS; 8230 } 8231 if (*target == TPM_RC_N_MASK) { 8232 return TPM_RC_SUCCESS; 8233 } 8234 return TPM_RC_VALUE; 8235 } 8236 8237 UINT16 TPM_RH_Marshal(TPM_RH* source, BYTE** buffer, INT32* size) { 8238 return uint32_t_Marshal(source, buffer, size); 8239 } 8240 8241 TPM_RC TPM_RH_Unmarshal(TPM_RH* target, BYTE** buffer, INT32* size) { 8242 TPM_RC result; 8243 result = uint32_t_Unmarshal(target, buffer, size); 8244 if (result != TPM_RC_SUCCESS) { 8245 return result; 8246 } 8247 if (*target == TPM_RH_FIRST) { 8248 return TPM_RC_SUCCESS; 8249 } 8250 if (*target == TPM_RH_SRK) { 8251 return TPM_RC_SUCCESS; 8252 } 8253 if (*target == TPM_RH_OWNER) { 8254 return TPM_RC_SUCCESS; 8255 } 8256 if (*target == TPM_RH_REVOKE) { 8257 return TPM_RC_SUCCESS; 8258 } 8259 if (*target == TPM_RH_TRANSPORT) { 8260 return TPM_RC_SUCCESS; 8261 } 8262 if (*target == TPM_RH_OPERATOR) { 8263 return TPM_RC_SUCCESS; 8264 } 8265 if (*target == TPM_RH_ADMIN) { 8266 return TPM_RC_SUCCESS; 8267 } 8268 if (*target == TPM_RH_EK) { 8269 return TPM_RC_SUCCESS; 8270 } 8271 if (*target == TPM_RH_NULL) { 8272 return TPM_RC_SUCCESS; 8273 } 8274 if (*target == TPM_RH_UNASSIGNED) { 8275 return TPM_RC_SUCCESS; 8276 } 8277 if (*target == TPM_RS_PW) { 8278 return TPM_RC_SUCCESS; 8279 } 8280 if (*target == TPM_RH_LOCKOUT) { 8281 return TPM_RC_SUCCESS; 8282 } 8283 if (*target == TPM_RH_ENDORSEMENT) { 8284 return TPM_RC_SUCCESS; 8285 } 8286 if (*target == TPM_RH_PLATFORM) { 8287 return TPM_RC_SUCCESS; 8288 } 8289 if (*target == TPM_RH_PLATFORM_NV) { 8290 return TPM_RC_SUCCESS; 8291 } 8292 if (*target == TPM_RH_AUTH_00) { 8293 return TPM_RC_SUCCESS; 8294 } 8295 if (*target == TPM_RH_AUTH_FF) { 8296 return TPM_RC_SUCCESS; 8297 } 8298 if (*target == TPM_RH_LAST) { 8299 return TPM_RC_SUCCESS; 8300 } 8301 return TPM_RC_VALUE; 8302 } 8303 8304 UINT16 TPM_SE_Marshal(TPM_SE* source, BYTE** buffer, INT32* size) { 8305 return uint8_t_Marshal(source, buffer, size); 8306 } 8307 8308 TPM_RC TPM_SE_Unmarshal(TPM_SE* target, BYTE** buffer, INT32* size) { 8309 TPM_RC result; 8310 result = uint8_t_Unmarshal(target, buffer, size); 8311 if (result != TPM_RC_SUCCESS) { 8312 return result; 8313 } 8314 if (*target == TPM_SE_HMAC) { 8315 return TPM_RC_SUCCESS; 8316 } 8317 if (*target == TPM_SE_POLICY) { 8318 return TPM_RC_SUCCESS; 8319 } 8320 if (*target == TPM_SE_TRIAL) { 8321 return TPM_RC_SUCCESS; 8322 } 8323 return TPM_RC_VALUE; 8324 } 8325 8326 UINT16 TPM_SPEC_Marshal(TPM_SPEC* source, BYTE** buffer, INT32* size) { 8327 return uint32_t_Marshal(source, buffer, size); 8328 } 8329 8330 TPM_RC TPM_SPEC_Unmarshal(TPM_SPEC* target, BYTE** buffer, INT32* size) { 8331 TPM_RC result; 8332 result = uint32_t_Unmarshal(target, buffer, size); 8333 if (result != TPM_RC_SUCCESS) { 8334 return result; 8335 } 8336 if (*target == TPM_SPEC_FAMILY) { 8337 return TPM_RC_SUCCESS; 8338 } 8339 if (*target == TPM_SPEC_LEVEL) { 8340 return TPM_RC_SUCCESS; 8341 } 8342 if (*target == TPM_SPEC_VERSION) { 8343 return TPM_RC_SUCCESS; 8344 } 8345 if (*target == TPM_SPEC_YEAR) { 8346 return TPM_RC_SUCCESS; 8347 } 8348 if (*target == TPM_SPEC_DAY_OF_YEAR) { 8349 return TPM_RC_SUCCESS; 8350 } 8351 return TPM_RC_VALUE; 8352 } 8353 8354 UINT16 TPM_SU_Marshal(TPM_SU* source, BYTE** buffer, INT32* size) { 8355 return uint16_t_Marshal(source, buffer, size); 8356 } 8357 8358 TPM_RC TPM_SU_Unmarshal(TPM_SU* target, BYTE** buffer, INT32* size) { 8359 TPM_RC result; 8360 result = uint16_t_Unmarshal(target, buffer, size); 8361 if (result != TPM_RC_SUCCESS) { 8362 return result; 8363 } 8364 if (*target == TPM_SU_CLEAR) { 8365 return TPM_RC_SUCCESS; 8366 } 8367 if (*target == TPM_SU_STATE) { 8368 return TPM_RC_SUCCESS; 8369 } 8370 return TPM_RC_VALUE; 8371 } 8372 8373 UINT16 _ID_OBJECT_Marshal(_ID_OBJECT* source, BYTE** buffer, INT32* size) { 8374 UINT16 total_size = 0; 8375 total_size += TPM2B_DIGEST_Marshal(&source->integrityHMAC, buffer, size); 8376 total_size += TPM2B_DIGEST_Marshal(&source->encIdentity, buffer, size); 8377 return total_size; 8378 } 8379 8380 TPM_RC _ID_OBJECT_Unmarshal(_ID_OBJECT* target, BYTE** buffer, INT32* size) { 8381 TPM_RC result; 8382 result = TPM2B_DIGEST_Unmarshal(&target->integrityHMAC, buffer, size); 8383 if (result != TPM_RC_SUCCESS) { 8384 return result; 8385 } 8386 result = TPM2B_DIGEST_Unmarshal(&target->encIdentity, buffer, size); 8387 if (result != TPM_RC_SUCCESS) { 8388 return result; 8389 } 8390 return TPM_RC_SUCCESS; 8391 } 8392 8393 UINT16 _PRIVATE_Marshal(_PRIVATE* source, BYTE** buffer, INT32* size) { 8394 UINT16 total_size = 0; 8395 total_size += TPM2B_DIGEST_Marshal(&source->integrityOuter, buffer, size); 8396 total_size += TPM2B_DIGEST_Marshal(&source->integrityInner, buffer, size); 8397 total_size += TPMT_SENSITIVE_Marshal(&source->sensitive, buffer, size); 8398 return total_size; 8399 } 8400 8401 TPM_RC _PRIVATE_Unmarshal(_PRIVATE* target, BYTE** buffer, INT32* size) { 8402 TPM_RC result; 8403 result = TPM2B_DIGEST_Unmarshal(&target->integrityOuter, buffer, size); 8404 if (result != TPM_RC_SUCCESS) { 8405 return result; 8406 } 8407 result = TPM2B_DIGEST_Unmarshal(&target->integrityInner, buffer, size); 8408 if (result != TPM_RC_SUCCESS) { 8409 return result; 8410 } 8411 result = TPMT_SENSITIVE_Unmarshal(&target->sensitive, buffer, size); 8412 if (result != TPM_RC_SUCCESS) { 8413 return result; 8414 } 8415 return TPM_RC_SUCCESS; 8416 } 8417