Arun kumar Sekar | 2ac5633 | 2018-03-30 11:20:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Intel Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | // Author: Arun Kumar Sekar |
| 17 | |
| 18 | |
| 19 | #include "marshal.h" |
| 20 | |
| 21 | TPM_RC |
| 22 | UINT8_Unmarshal( |
| 23 | UINT8 *target, BYTE **buffer, INT32 *size |
| 24 | ) |
| 25 | { |
| 26 | if((*size -= 1) < 0) |
| 27 | return TPM_RC_INSUFFICIENT; |
| 28 | *target = BYTE_ARRAY_TO_UINT8(*buffer); |
| 29 | *buffer += 1; |
| 30 | return TPM_RC_SUCCESS; |
| 31 | } |
| 32 | |
| 33 | UINT16 |
| 34 | UINT8_Marshal( |
| 35 | UINT8 *source, BYTE **buffer, INT32 *size |
| 36 | ) |
| 37 | { |
| 38 | if (buffer != 0) |
| 39 | { |
| 40 | if ((size == 0) || ((*size -= 1) >= 0)) |
| 41 | { |
| 42 | UINT8_TO_BYTE_ARRAY(*source, *buffer); |
| 43 | *buffer += 1; |
| 44 | } |
| 45 | pAssert(size == 0 || (*size >= 0)); |
| 46 | } |
| 47 | return (1); |
| 48 | } |
| 49 | |
| 50 | // BYTE definition from table 2:3 |
| 51 | // BYTE_Unmarshal changed to #define |
| 52 | // BYTE_Marshal changed to #define |
| 53 | // INT8 definition from table 2:3 |
| 54 | // INT8_Unmarshal changed to #define |
| 55 | // INT8_Marshal not referenced |
| 56 | // UINT16 definition from table 2:3 |
| 57 | TPM_RC |
| 58 | UINT16_Unmarshal( |
| 59 | UINT16 *target, BYTE **buffer, INT32 *size |
| 60 | ) |
| 61 | { |
| 62 | if((*size -= 2) < 0) |
| 63 | return TPM_RC_INSUFFICIENT; |
| 64 | *target = BYTE_ARRAY_TO_UINT16(*buffer); |
| 65 | *buffer += 2; |
| 66 | return TPM_RC_SUCCESS; |
| 67 | } |
| 68 | |
| 69 | UINT16 |
| 70 | UINT16_Marshal( |
| 71 | UINT16 *source, BYTE **buffer, INT32 *size |
| 72 | ) |
| 73 | { |
| 74 | if (buffer != 0) |
| 75 | { |
| 76 | if ((size == 0) || ((*size -= 2) >= 0)) |
| 77 | { |
| 78 | UINT16_TO_BYTE_ARRAY(*source, *buffer); |
| 79 | *buffer += 2; |
| 80 | } |
| 81 | pAssert(size == 0 || (*size >= 0)); |
| 82 | } |
| 83 | return (2); |
| 84 | } |
| 85 | |
| 86 | // INT16 definition from table 2:3 |
| 87 | // INT16_Unmarshal not referenced |
| 88 | // INT16_Marshal not referenced |
| 89 | // UINT32 definition from table 2:3 |
| 90 | TPM_RC |
| 91 | UINT32_Unmarshal( |
| 92 | UINT32 *target, BYTE **buffer, INT32 *size |
| 93 | ) |
| 94 | { |
| 95 | if((*size -= 4) < 0) |
| 96 | return TPM_RC_INSUFFICIENT; |
| 97 | *target = BYTE_ARRAY_TO_UINT32(*buffer); |
| 98 | *buffer += 4; |
| 99 | return TPM_RC_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | UINT16 |
| 103 | UINT32_Marshal( |
| 104 | UINT32 *source, BYTE **buffer, INT32 *size |
| 105 | ) |
| 106 | { |
| 107 | if (buffer != 0) |
| 108 | { |
| 109 | if ((size == 0) || ((*size -= 4) >= 0)) |
| 110 | { |
| 111 | UINT32_TO_BYTE_ARRAY(*source, *buffer); |
| 112 | *buffer += 4; |
| 113 | } |
| 114 | pAssert(size == 0 || (*size >= 0)); |
| 115 | } |
| 116 | return (4); |
| 117 | } |
| 118 | |
| 119 | // INT32 definition from table 2:3 |
| 120 | // INT32_Unmarshal changed to #define |
| 121 | // INT32_Marshal not referenced |
| 122 | // UINT64 definition from table 2:3 |
| 123 | TPM_RC |
| 124 | UINT64_Unmarshal( |
| 125 | UINT64 *target, BYTE **buffer, INT32 *size |
| 126 | ) |
| 127 | { |
| 128 | if((*size -= 8) < 0) |
| 129 | return TPM_RC_INSUFFICIENT; |
| 130 | *target = BYTE_ARRAY_TO_UINT64(*buffer); |
| 131 | *buffer += 8; |
| 132 | return TPM_RC_SUCCESS; |
| 133 | } |
| 134 | |
| 135 | UINT16 |
| 136 | UINT64_Marshal( |
| 137 | UINT64 *source, BYTE **buffer, INT32 *size |
| 138 | ) |
| 139 | { |
| 140 | if (buffer != 0) |
| 141 | { |
| 142 | if ((size == 0) || ((*size -= 8) >= 0)) |
| 143 | { |
| 144 | UINT64_TO_BYTE_ARRAY(*source, *buffer); |
| 145 | *buffer += 8; |
| 146 | } |
| 147 | pAssert(size == 0 || (*size >= 0)); |
| 148 | } |
| 149 | return (8); |
| 150 | } |
| 151 | |
| 152 | // INT64 definition from table 2:3 |
| 153 | // INT64_Unmarshal not referenced |
| 154 | // INT64_Marshal not referenced |
| 155 | |
| 156 | |
| 157 | // Table 2:4 - Defines for Logic Values (DefinesTable) |
| 158 | |
| 159 | |
| 160 | // Table 2:5 - Definition of Types for Documentation Clarity (TypesTable) |
| 161 | // UINT32 definition from table 2:5 |
| 162 | // TPM_ALGORITHM_ID_Unmarshal not referenced |
| 163 | // TPM_ALGORITHM_ID_Marshal not referenced |
| 164 | // UINT32 definition from table 2:5 |
| 165 | // TPM_MODIFIER_INDICATOR_Unmarshal not referenced |
| 166 | // TPM_MODIFIER_INDICATOR_Marshal not referenced |
| 167 | // UINT32 definition from table 2:5 |
| 168 | // TPM_AUTHORIZATION_SIZE_Unmarshal not referenced |
| 169 | // TPM_AUTHORIZATION_SIZE_Marshal not referenced |
| 170 | // UINT32 definition from table 2:5 |
| 171 | // TPM_PARAMETER_SIZE_Unmarshal not referenced |
| 172 | // TPM_PARAMETER_SIZE_Marshal not referenced |
| 173 | // UINT16 definition from table 2:5 |
| 174 | // TPM_KEY_SIZE_Unmarshal not referenced |
| 175 | // TPM_KEY_SIZE_Marshal not referenced |
| 176 | // UINT16 definition from table 2:5 |
| 177 | // TPM_KEY_BITS_Unmarshal changed to #define |
| 178 | // TPM_KEY_BITS_Marshal changed to #define |
| 179 | |
| 180 | |
| 181 | // Table 2:6 - Definition of TPM_SPEC Constants (ConstantsTable) |
| 182 | // TPM_SPEC_Unmarshal not referenced |
| 183 | // TPM_SPEC_Marshal not referenced |
| 184 | |
| 185 | |
| 186 | // Table 2:7 - Definition of TPM_GENERATED Constants (ConstantsTable) |
| 187 | // TPM_GENERATED_Unmarshal not referenced |
| 188 | // TPM_GENERATED_Marshal changed to #define |
| 189 | |
| 190 | |
| 191 | // Table 2:9 - Definition of TPM_ALG_ID Constants (ConstantsTable) |
| 192 | // TPM_ALG_ID_Unmarshal changed to #define |
| 193 | // TPM_ALG_ID_Marshal changed to #define |
| 194 | |
| 195 | |
| 196 | // Table 2:10 - Definition of TPM_ECC_CURVE Constants (ConstantsTable) |
| 197 | #ifdef TPM_ALG_ECC |
| 198 | // TPM_ECC_CURVE_Unmarshal changed to #define |
| 199 | // TPM_ECC_CURVE_Marshal changed to #define |
| 200 | #endif // TPM_ALG_ECC |
| 201 | |
| 202 | |
| 203 | // Table 2:13 - Definition of TPM_CC Constants (ConstantsTable) |
| 204 | // TPM_CC_Unmarshal changed to #define |
| 205 | // TPM_CC_Marshal changed to #define |
| 206 | |
| 207 | |
| 208 | // Table 2:17 - Definition of TPM_RC Constants (ConstantsTable) |
| 209 | // TPM_RC_Unmarshal not referenced |
| 210 | // TPM_RC_Marshal changed to #define |
| 211 | |
| 212 | |
| 213 | // Table 2:18 - Definition of TPM_CLOCK_ADJUST Constants (ConstantsTable) |
| 214 | TPM_RC |
| 215 | TPM_CLOCK_ADJUST_Unmarshal( |
| 216 | TPM_CLOCK_ADJUST *target, BYTE **buffer, INT32 *size |
| 217 | ) |
| 218 | { |
| 219 | return TPM_RC_SUCCESS; |
| 220 | } |
| 221 | |
| 222 | // TPM_CLOCK_ADJUST_Marshal not referenced |
| 223 | |
| 224 | |
| 225 | // Table 2:19 - Definition of TPM_EO Constants (ConstantsTable) |
| 226 | TPM_RC |
| 227 | TPM_EO_Unmarshal( |
| 228 | TPM_EO *target, BYTE **buffer, INT32 *size |
| 229 | ) |
| 230 | { |
| 231 | TPM_RC result; |
| 232 | result = UINT16_Unmarshal((UINT16 *)target, buffer, size); |
| 233 | if(result != TPM_RC_SUCCESS) |
| 234 | return result; |
| 235 | switch(*target) { |
| 236 | case TPM_EO_EQ : |
| 237 | case TPM_EO_NEQ : |
| 238 | case TPM_EO_SIGNED_GT : |
| 239 | case TPM_EO_UNSIGNED_GT : |
| 240 | case TPM_EO_SIGNED_LT : |
| 241 | case TPM_EO_UNSIGNED_LT : |
| 242 | case TPM_EO_SIGNED_GE : |
| 243 | case TPM_EO_UNSIGNED_GE : |
| 244 | case TPM_EO_SIGNED_LE : |
| 245 | case TPM_EO_UNSIGNED_LE : |
| 246 | case TPM_EO_BITSET : |
| 247 | case TPM_EO_BITCLEAR : |
| 248 | break; |
| 249 | default : |
| 250 | return TPM_RC_VALUE; |
| 251 | break; |
| 252 | } |
| 253 | return TPM_RC_SUCCESS; |
| 254 | } |
| 255 | |
| 256 | // TPM_EO_Marshal not referenced |
| 257 | |
| 258 | |
| 259 | // Table 2:20 - Definition of TPM_ST Constants (ConstantsTable) |
| 260 | // TPM_ST_Unmarshal changed to #define |
| 261 | // TPM_ST_Marshal changed to #define |
| 262 | |
| 263 | |
| 264 | // Table 2:21 - Definition of TPM_SU Constants (ConstantsTable) |
| 265 | TPM_RC |
| 266 | TPM_SU_Unmarshal( |
| 267 | TPM_SU *target, BYTE **buffer, INT32 *size |
| 268 | ) |
| 269 | { |
| 270 | TPM_RC result; |
| 271 | result = UINT16_Unmarshal((UINT16 *)target, buffer, size); |
| 272 | if(result != TPM_RC_SUCCESS) |
| 273 | return result; |
| 274 | switch(*target) { |
| 275 | case TPM_SU_CLEAR : |
| 276 | case TPM_SU_STATE : |
| 277 | break; |
| 278 | default : |
| 279 | return TPM_RC_VALUE; |
| 280 | break; |
| 281 | } |
| 282 | return TPM_RC_SUCCESS; |
| 283 | } |
| 284 | |
| 285 | // TPM_SU_Marshal not referenced |
| 286 | |
| 287 | |
| 288 | // Table 2:22 - Definition of TPM_SE Constants (ConstantsTable) |
| 289 | TPM_RC |
| 290 | TPM_SE_Unmarshal( |
| 291 | TPM_SE *target, BYTE **buffer, INT32 *size |
| 292 | ) |
| 293 | { |
| 294 | TPM_RC result; |
| 295 | result = UINT8_Unmarshal((UINT8 *)target, buffer, size); |
| 296 | if(result != TPM_RC_SUCCESS) |
| 297 | return result; |
| 298 | switch(*target) { |
| 299 | case TPM_SE_HMAC : |
| 300 | case TPM_SE_POLICY : |
| 301 | case TPM_SE_TRIAL : |
| 302 | break; |
| 303 | default : |
| 304 | return TPM_RC_VALUE; |
| 305 | break; |
| 306 | } |
| 307 | return TPM_RC_SUCCESS; |
| 308 | } |
| 309 | |
| 310 | // TPM_SE_Marshal not referenced |
| 311 | |
| 312 | |
| 313 | // Table 2:23 - Definition of TPM_CAP Constants (ConstantsTable) |
| 314 | TPM_RC |
| 315 | TPM_CAP_Unmarshal( |
| 316 | TPM_CAP *target, BYTE **buffer, INT32 *size |
| 317 | ) |
| 318 | { |
| 319 | TPM_RC result; |
| 320 | result = UINT32_Unmarshal((UINT32 *)target, buffer, size); |
| 321 | if(result != TPM_RC_SUCCESS) |
| 322 | return result; |
| 323 | switch(*target) { |
| 324 | case TPM_CAP_ALGS : |
| 325 | case TPM_CAP_HANDLES : |
| 326 | case TPM_CAP_COMMANDS : |
| 327 | case TPM_CAP_PP_COMMANDS : |
| 328 | case TPM_CAP_AUDIT_COMMANDS : |
| 329 | case TPM_CAP_PCRS : |
| 330 | case TPM_CAP_TPM_PROPERTIES : |
| 331 | case TPM_CAP_PCR_PROPERTIES : |
| 332 | case TPM_CAP_ECC_CURVES : |
| 333 | case TPM_CAP_VENDOR_PROPERTY : |
| 334 | break; |
| 335 | default : |
| 336 | return TPM_RC_VALUE; |
| 337 | break; |
| 338 | } |
| 339 | return TPM_RC_SUCCESS; |
| 340 | } |
| 341 | |
| 342 | // TPM_CAP_Marshal changed to #define |
| 343 | |
| 344 | |
| 345 | // Table 2:24 - Definition of TPM_PT Constants (ConstantsTable) |
| 346 | // TPM_PT_Unmarshal not referenced |
| 347 | // TPM_PT_Marshal changed to #define |
| 348 | |
| 349 | |
| 350 | // Table 2:25 - Definition of TPM_PT_PCR Constants (ConstantsTable) |
| 351 | // TPM_PT_PCR_Unmarshal not referenced |
| 352 | // TPM_PT_PCR_Marshal not referenced |
| 353 | |
| 354 | |
| 355 | // Table 2:26 - Definition of TPM_PS Constants (ConstantsTable) |
| 356 | // TPM_PS_Unmarshal not referenced |
| 357 | // TPM_PS_Marshal not referenced |
| 358 | |
| 359 | |
| 360 | // Table 2:27 - Definition of Types for Handles (TypesTable) |
| 361 | // UINT32 definition from table 2:27 |
| 362 | // TPM_HANDLE_Unmarshal changed to #define |
| 363 | // TPM_HANDLE_Marshal changed to #define |
| 364 | |
| 365 | |
| 366 | // Table 2:28 - Definition of TPM_HT Constants (ConstantsTable) |
| 367 | // TPM_HT_Unmarshal not referenced |
| 368 | // TPM_HT_Marshal not referenced |
| 369 | |
| 370 | |
| 371 | // Table 2:29 - Definition of TPM_RH Constants (ConstantsTable) |
| 372 | // TPM_RH_Unmarshal not referenced |
| 373 | // TPM_RH_Marshal not referenced |
| 374 | |
| 375 | |
| 376 | // Table 2:30 - Definition of TPM_HC Constants (ConstantsTable) |
| 377 | // TPM_HC_Unmarshal not referenced |
| 378 | // TPM_HC_Marshal not referenced |
| 379 | |
| 380 | |
| 381 | // Table 2:31 - Definition of TPMA_ALGORITHM Bits (BitsTable) |
| 382 | // TPMA_ALGORITHM_Unmarshal not referenced |
| 383 | // TPMA_ALGORITHM_Marshal changed to #define |
| 384 | |
| 385 | |
| 386 | // Table 2:32 - Definition of TPMA_OBJECT Bits (BitsTable) |
| 387 | TPM_RC |
| 388 | TPMA_OBJECT_Unmarshal( |
| 389 | TPMA_OBJECT *target, BYTE **buffer, INT32 *size |
| 390 | ) |
| 391 | { |
| 392 | TPM_RC result; |
| 393 | result = UINT32_Unmarshal((UINT32 *)target, buffer, size); |
| 394 | if(result != TPM_RC_SUCCESS) |
| 395 | return result; |
| 396 | if(*((UINT32 *)target) & (UINT32)0xfff8f309) |
| 397 | return TPM_RC_RESERVED_BITS; |
| 398 | return TPM_RC_SUCCESS; |
| 399 | } |
| 400 | |
| 401 | // TPMA_OBJECT_Marshal changed to #define |
| 402 | |
| 403 | |
| 404 | // Table 2:33 - Definition of TPMA_SESSION Bits (BitsTable) |
| 405 | TPM_RC |
| 406 | TPMA_SESSION_Unmarshal( |
| 407 | TPMA_SESSION *target, BYTE **buffer, INT32 *size |
| 408 | ) |
| 409 | { |
| 410 | TPM_RC result; |
| 411 | result = UINT8_Unmarshal((UINT8 *)target, buffer, size); |
| 412 | if(result != TPM_RC_SUCCESS) |
| 413 | return result; |
| 414 | if(*((UINT8 *)target) & (UINT8)0x18) |
| 415 | return TPM_RC_RESERVED_BITS; |
| 416 | return TPM_RC_SUCCESS; |
| 417 | } |
| 418 | |
| 419 | // TPMA_SESSION_Marshal changed to #define |
| 420 | |
| 421 | |
| 422 | // Table 2:34 - Definition of TPMA_LOCALITY Bits (BitsTable) |
| 423 | // TPMA_LOCALITY_Unmarshal changed to #define |
| 424 | // TPMA_LOCALITY_Marshal changed to #define |
| 425 | |
| 426 | |
| 427 | // Table 2:35 - Definition of TPMA_PERMANENT Bits (BitsTable) |
| 428 | // TPMA_PERMANENT_Unmarshal not referenced |
| 429 | // TPMA_PERMANENT_Marshal not referenced |
| 430 | |
| 431 | |
| 432 | // Table 2:36 - Definition of TPMA_STARTUP_CLEAR Bits (BitsTable) |
| 433 | // TPMA_STARTUP_CLEAR_Unmarshal not referenced |
| 434 | // TPMA_STARTUP_CLEAR_Marshal not referenced |
| 435 | |
| 436 | |
| 437 | // Table 2:37 - Definition of TPMA_MEMORY Bits (BitsTable) |
| 438 | // TPMA_MEMORY_Unmarshal not referenced |
| 439 | // TPMA_MEMORY_Marshal not referenced |
| 440 | |
| 441 | |
| 442 | // Table 2:38 - Definition of TPMA_CC Bits (BitsTable) |
| 443 | // TPMA_CC_Unmarshal not referenced |
| 444 | // TPMA_CC_Marshal changed to #define |
| 445 | |
| 446 | |
| 447 | // Table 2:39 - Definition of TPMI_YES_NO Type (TypeTable) |
| 448 | TPM_RC |
| 449 | TPMI_YES_NO_Unmarshal( |
| 450 | TPMI_YES_NO *target, BYTE **buffer, INT32 *size |
| 451 | ) |
| 452 | { |
| 453 | TPM_RC result; |
| 454 | result = BYTE_Unmarshal((BYTE *)target, buffer, size); |
| 455 | if(result != TPM_RC_SUCCESS) |
| 456 | return result; |
| 457 | switch (*target) { |
| 458 | case NO: |
| 459 | case YES: |
| 460 | break; |
| 461 | default: |
| 462 | return TPM_RC_VALUE; |
| 463 | } |
| 464 | return TPM_RC_SUCCESS; |
| 465 | } |
| 466 | |
| 467 | // TPMI_YES_NO_Marshal changed to #define |
| 468 | |
| 469 | |
| 470 | // Table 2:40 - Definition of TPMI_DH_OBJECT Type (TypeTable) |
| 471 | TPM_RC |
| 472 | TPMI_DH_OBJECT_Unmarshal( |
| 473 | TPMI_DH_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 474 | ) |
| 475 | { |
| 476 | TPM_RC result; |
| 477 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 478 | if(result != TPM_RC_SUCCESS) |
| 479 | return result; |
| 480 | if (*target == TPM_RH_NULL) { |
| 481 | if(flag) |
| 482 | return TPM_RC_SUCCESS; |
| 483 | else |
| 484 | return TPM_RC_VALUE; |
| 485 | } |
| 486 | |
| 487 | return TPM_RC_SUCCESS; |
| 488 | } |
| 489 | |
| 490 | // TPMI_DH_OBJECT_Marshal changed to #define |
| 491 | |
| 492 | |
| 493 | // Table 2:41 - Definition of TPMI_DH_PERSISTENT Type (TypeTable) |
| 494 | TPM_RC |
| 495 | TPMI_DH_PERSISTENT_Unmarshal( |
| 496 | TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *size |
| 497 | ) |
| 498 | { |
| 499 | TPM_RC result; |
| 500 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 501 | if(result != TPM_RC_SUCCESS) |
| 502 | return result; |
| 503 | if((*target < PERSISTENT_FIRST) || (*target > PERSISTENT_LAST)) |
| 504 | return TPM_RC_VALUE; |
| 505 | return TPM_RC_SUCCESS; |
| 506 | } |
| 507 | |
| 508 | // TPMI_DH_PERSISTENT_Marshal not referenced |
| 509 | |
| 510 | |
| 511 | // Table 2:42 - Definition of TPMI_DH_ENTITY Type (TypeTable) |
| 512 | TPM_RC |
| 513 | TPMI_DH_ENTITY_Unmarshal( |
| 514 | TPMI_DH_ENTITY *target, BYTE **buffer, INT32 *size, BOOL flag |
| 515 | ) |
| 516 | { |
| 517 | TPM_RC result; |
| 518 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 519 | if(result != TPM_RC_SUCCESS) |
| 520 | return result; |
| 521 | |
| 522 | return TPM_RC_SUCCESS; |
| 523 | } |
| 524 | |
| 525 | // TPMI_DH_ENTITY_Marshal not referenced |
| 526 | |
| 527 | |
| 528 | // Table 2:43 - Definition of TPMI_DH_PCR Type (TypeTable) |
| 529 | TPM_RC |
| 530 | TPMI_DH_PCR_Unmarshal( |
| 531 | TPMI_DH_PCR *target, BYTE **buffer, INT32 *size, BOOL flag |
| 532 | ) |
| 533 | { |
| 534 | TPM_RC result; |
| 535 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 536 | if(result != TPM_RC_SUCCESS) |
| 537 | return result; |
| 538 | if (*target == TPM_RH_NULL) { |
| 539 | if(flag) |
| 540 | return TPM_RC_SUCCESS; |
| 541 | else |
| 542 | return TPM_RC_VALUE; |
| 543 | } |
| 544 | |
| 545 | return TPM_RC_SUCCESS; |
| 546 | } |
| 547 | |
| 548 | // TPMI_DH_PCR_Marshal not referenced |
| 549 | |
| 550 | |
| 551 | // Table 2:44 - Definition of TPMI_SH_AUTH_SESSION Type (TypeTable) |
| 552 | TPM_RC |
| 553 | TPMI_SH_AUTH_SESSION_Unmarshal( |
| 554 | TPMI_SH_AUTH_SESSION *target, BYTE **buffer, INT32 *size, BOOL flag |
| 555 | ) |
| 556 | { |
| 557 | TPM_RC result; |
| 558 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 559 | if(result != TPM_RC_SUCCESS) |
| 560 | return result; |
| 561 | if (*target == TPM_RS_PW) { |
| 562 | if(flag) |
| 563 | return TPM_RC_SUCCESS; |
| 564 | else |
| 565 | return TPM_RC_VALUE; |
| 566 | } |
| 567 | |
| 568 | return TPM_RC_SUCCESS; |
| 569 | } |
| 570 | |
| 571 | // TPMI_SH_AUTH_SESSION_Marshal changed to #define |
| 572 | |
| 573 | |
| 574 | // Table 2:45 - Definition of TPMI_SH_HMAC Type (TypeTable) |
| 575 | TPM_RC |
| 576 | TPMI_SH_HMAC_Unmarshal( |
| 577 | TPMI_SH_HMAC *target, BYTE **buffer, INT32 *size |
| 578 | ) |
| 579 | { |
| 580 | TPM_RC result; |
| 581 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 582 | if(result != TPM_RC_SUCCESS) |
| 583 | return result; |
| 584 | |
| 585 | return TPM_RC_SUCCESS; |
| 586 | } |
| 587 | |
| 588 | // TPMI_SH_HMAC_Marshal not referenced |
| 589 | |
| 590 | |
| 591 | // Table 2:46 - Definition of TPMI_SH_POLICY Type (TypeTable) |
| 592 | TPM_RC |
| 593 | TPMI_SH_POLICY_Unmarshal( |
| 594 | TPMI_SH_POLICY *target, BYTE **buffer, INT32 *size |
| 595 | ) |
| 596 | { |
| 597 | TPM_RC result; |
| 598 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 599 | |
| 600 | return TPM_RC_SUCCESS; |
| 601 | } |
| 602 | |
| 603 | // TPMI_SH_POLICY_Marshal not referenced |
| 604 | |
| 605 | |
| 606 | // Table 2:47 - Definition of TPMI_DH_CONTEXT Type (TypeTable) |
| 607 | TPM_RC |
| 608 | TPMI_DH_CONTEXT_Unmarshal( |
| 609 | TPMI_DH_CONTEXT *target, BYTE **buffer, INT32 *size |
| 610 | ) |
| 611 | { |
| 612 | TPM_RC result; |
| 613 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 614 | if(result != TPM_RC_SUCCESS) |
| 615 | return result; |
| 616 | |
| 617 | return TPM_RC_SUCCESS; |
| 618 | } |
| 619 | |
| 620 | // TPMI_DH_CONTEXT_Marshal changed to #define |
| 621 | |
| 622 | |
| 623 | // Table 2:48 - Definition of TPMI_RH_HIERARCHY Type (TypeTable) |
| 624 | TPM_RC |
| 625 | TPMI_RH_HIERARCHY_Unmarshal( |
| 626 | TPMI_RH_HIERARCHY *target, BYTE **buffer, INT32 *size, BOOL flag |
| 627 | ) |
| 628 | { |
| 629 | TPM_RC result; |
| 630 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 631 | if(result != TPM_RC_SUCCESS) |
| 632 | return result; |
| 633 | switch (*target) { |
| 634 | case TPM_RH_OWNER: |
| 635 | case TPM_RH_PLATFORM: |
| 636 | case TPM_RH_ENDORSEMENT: |
| 637 | break; |
| 638 | case TPM_RH_NULL: |
| 639 | if (flag) |
| 640 | break; |
| 641 | return TPM_RC_VALUE; |
| 642 | default: |
| 643 | return TPM_RC_VALUE; |
| 644 | } |
| 645 | return TPM_RC_SUCCESS; |
| 646 | } |
| 647 | |
| 648 | // TPMI_RH_HIERARCHY_Marshal changed to #define |
| 649 | |
| 650 | |
| 651 | // Table 2:49 - Definition of TPMI_RH_ENABLES Type (TypeTable) |
| 652 | TPM_RC |
| 653 | TPMI_RH_ENABLES_Unmarshal( |
| 654 | TPMI_RH_ENABLES *target, BYTE **buffer, INT32 *size, BOOL flag |
| 655 | ) |
| 656 | { |
| 657 | TPM_RC result; |
| 658 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 659 | if(result != TPM_RC_SUCCESS) |
| 660 | return result; |
| 661 | switch (*target) { |
| 662 | case TPM_RH_OWNER: |
| 663 | case TPM_RH_PLATFORM: |
| 664 | case TPM_RH_ENDORSEMENT: |
| 665 | case TPM_RH_PLATFORM_NV: |
| 666 | break; |
| 667 | case TPM_RH_NULL: |
| 668 | if (flag) |
| 669 | break; |
| 670 | return TPM_RC_VALUE; |
| 671 | default: |
| 672 | return TPM_RC_VALUE; |
| 673 | } |
| 674 | return TPM_RC_SUCCESS; |
| 675 | } |
| 676 | |
| 677 | // TPMI_RH_ENABLES_Marshal not referenced |
| 678 | |
| 679 | |
| 680 | // Table 2:50 - Definition of TPMI_RH_HIERARCHY_AUTH Type (TypeTable) |
| 681 | TPM_RC |
| 682 | TPMI_RH_HIERARCHY_AUTH_Unmarshal( |
| 683 | TPMI_RH_HIERARCHY_AUTH *target, BYTE **buffer, INT32 *size |
| 684 | ) |
| 685 | { |
| 686 | TPM_RC result; |
| 687 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 688 | if(result != TPM_RC_SUCCESS) |
| 689 | return result; |
| 690 | switch (*target) { |
| 691 | case TPM_RH_OWNER: |
| 692 | case TPM_RH_PLATFORM: |
| 693 | case TPM_RH_ENDORSEMENT: |
| 694 | case TPM_RH_LOCKOUT: |
| 695 | break; |
| 696 | default: |
| 697 | return TPM_RC_VALUE; |
| 698 | } |
| 699 | return TPM_RC_SUCCESS; |
| 700 | } |
| 701 | |
| 702 | // TPMI_RH_HIERARCHY_AUTH_Marshal not referenced |
| 703 | |
| 704 | |
| 705 | // Table 2:51 - Definition of TPMI_RH_PLATFORM Type (TypeTable) |
| 706 | TPM_RC |
| 707 | TPMI_RH_PLATFORM_Unmarshal( |
| 708 | TPMI_RH_PLATFORM *target, BYTE **buffer, INT32 *size |
| 709 | ) |
| 710 | { |
| 711 | TPM_RC result; |
| 712 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 713 | if(result != TPM_RC_SUCCESS) |
| 714 | return result; |
| 715 | switch (*target) { |
| 716 | case TPM_RH_PLATFORM: |
| 717 | break; |
| 718 | default: |
| 719 | return TPM_RC_VALUE; |
| 720 | } |
| 721 | return TPM_RC_SUCCESS; |
| 722 | } |
| 723 | |
| 724 | // TPMI_RH_PLATFORM_Marshal not referenced |
| 725 | |
| 726 | |
| 727 | // Table 2:52 - Definition of TPMI_RH_OWNER Type (TypeTable) |
| 728 | // TPMI_RH_OWNER_Unmarshal not referenced |
| 729 | // TPMI_RH_OWNER_Marshal not referenced |
| 730 | |
| 731 | |
| 732 | // Table 2:53 - Definition of TPMI_RH_ENDORSEMENT Type (TypeTable) |
| 733 | TPM_RC |
| 734 | TPMI_RH_ENDORSEMENT_Unmarshal( |
| 735 | TPMI_RH_ENDORSEMENT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 736 | ) |
| 737 | { |
| 738 | TPM_RC result; |
| 739 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 740 | if(result != TPM_RC_SUCCESS) |
| 741 | return result; |
| 742 | switch (*target) { |
| 743 | case TPM_RH_ENDORSEMENT: |
| 744 | break; |
| 745 | case TPM_RH_NULL: |
| 746 | if (flag) |
| 747 | break; |
| 748 | return TPM_RC_VALUE; |
| 749 | default: |
| 750 | return TPM_RC_VALUE; |
| 751 | } |
| 752 | return TPM_RC_SUCCESS; |
| 753 | } |
| 754 | |
| 755 | // TPMI_RH_ENDORSEMENT_Marshal not referenced |
| 756 | |
| 757 | |
| 758 | // Table 2:54 - Definition of TPMI_RH_PROVISION Type (TypeTable) |
| 759 | TPM_RC |
| 760 | TPMI_RH_PROVISION_Unmarshal( |
| 761 | TPMI_RH_PROVISION *target, BYTE **buffer, INT32 *size |
| 762 | ) |
| 763 | { |
| 764 | TPM_RC result; |
| 765 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 766 | if(result != TPM_RC_SUCCESS) |
| 767 | return result; |
| 768 | switch (*target) { |
| 769 | case TPM_RH_OWNER: |
| 770 | case TPM_RH_PLATFORM: |
| 771 | break; |
| 772 | default: |
| 773 | return TPM_RC_VALUE; |
| 774 | } |
| 775 | return TPM_RC_SUCCESS; |
| 776 | } |
| 777 | |
| 778 | // TPMI_RH_PROVISION_Marshal not referenced |
| 779 | |
| 780 | |
| 781 | // Table 2:55 - Definition of TPMI_RH_CLEAR Type (TypeTable) |
| 782 | TPM_RC |
| 783 | TPMI_RH_CLEAR_Unmarshal( |
| 784 | TPMI_RH_CLEAR *target, BYTE **buffer, INT32 *size |
| 785 | ) |
| 786 | { |
| 787 | TPM_RC result; |
| 788 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 789 | if(result != TPM_RC_SUCCESS) |
| 790 | return result; |
| 791 | switch (*target) { |
| 792 | case TPM_RH_LOCKOUT: |
| 793 | case TPM_RH_PLATFORM: |
| 794 | break; |
| 795 | default: |
| 796 | return TPM_RC_VALUE; |
| 797 | } |
| 798 | return TPM_RC_SUCCESS; |
| 799 | } |
| 800 | |
| 801 | // TPMI_RH_CLEAR_Marshal not referenced |
| 802 | |
| 803 | |
| 804 | // Table 2:56 - Definition of TPMI_RH_NV_AUTH Type (TypeTable) |
| 805 | TPM_RC |
| 806 | TPMI_RH_NV_AUTH_Unmarshal( |
| 807 | TPMI_RH_NV_AUTH *target, BYTE **buffer, INT32 *size |
| 808 | ) |
| 809 | { |
| 810 | TPM_RC result; |
| 811 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 812 | if(result != TPM_RC_SUCCESS) |
| 813 | return result; |
| 814 | switch (*target) { |
| 815 | case TPM_RH_PLATFORM: |
| 816 | case TPM_RH_OWNER: |
| 817 | break; |
| 818 | default: |
| 819 | if((*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST)) |
| 820 | return TPM_RC_VALUE; |
| 821 | } |
| 822 | return TPM_RC_SUCCESS; |
| 823 | } |
| 824 | |
| 825 | // TPMI_RH_NV_AUTH_Marshal not referenced |
| 826 | |
| 827 | |
| 828 | // Table 2:57 - Definition of TPMI_RH_LOCKOUT Type (TypeTable) |
| 829 | TPM_RC |
| 830 | TPMI_RH_LOCKOUT_Unmarshal( |
| 831 | TPMI_RH_LOCKOUT *target, BYTE **buffer, INT32 *size |
| 832 | ) |
| 833 | { |
| 834 | TPM_RC result; |
| 835 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 836 | if(result != TPM_RC_SUCCESS) |
| 837 | return result; |
| 838 | switch (*target) { |
| 839 | case TPM_RH_LOCKOUT: |
| 840 | break; |
| 841 | default: |
| 842 | return TPM_RC_VALUE; |
| 843 | } |
| 844 | return TPM_RC_SUCCESS; |
| 845 | } |
| 846 | |
| 847 | // TPMI_RH_LOCKOUT_Marshal not referenced |
| 848 | |
| 849 | |
| 850 | // Table 2:58 - Definition of TPMI_RH_NV_INDEX Type (TypeTable) |
| 851 | TPM_RC |
| 852 | TPMI_RH_NV_INDEX_Unmarshal( |
| 853 | TPMI_RH_NV_INDEX *target, BYTE **buffer, INT32 *size |
| 854 | ) |
| 855 | { |
| 856 | TPM_RC result; |
| 857 | result = TPM_HANDLE_Unmarshal((TPM_HANDLE *)target, buffer, size); |
| 858 | if(result != TPM_RC_SUCCESS) |
| 859 | return result; |
| 860 | if((*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST)) |
| 861 | return TPM_RC_VALUE; |
| 862 | return TPM_RC_SUCCESS; |
| 863 | } |
| 864 | |
| 865 | // TPMI_RH_NV_INDEX_Marshal changed to #define |
| 866 | |
| 867 | |
| 868 | // Table 2:59 - Definition of TPMI_ALG_HASH Type (TypeTable) |
| 869 | TPM_RC |
| 870 | TPMI_ALG_HASH_Unmarshal( |
| 871 | TPMI_ALG_HASH *target, BYTE **buffer, INT32 *size, BOOL flag |
| 872 | ) |
| 873 | { |
| 874 | TPM_RC result; |
| 875 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 876 | if(result != TPM_RC_SUCCESS) |
| 877 | return result; |
| 878 | switch (*target) { |
| 879 | #ifdef TPM_ALG_SHA1 |
| 880 | case TPM_ALG_SHA1: |
| 881 | #endif // TPM_ALG_SHA1 |
| 882 | #ifdef TPM_ALG_SHA256 |
| 883 | case TPM_ALG_SHA256: |
| 884 | #endif // TPM_ALG_SHA256 |
| 885 | #ifdef TPM_ALG_SHA384 |
| 886 | case TPM_ALG_SHA384: |
| 887 | #endif // TPM_ALG_SHA384 |
| 888 | #ifdef TPM_ALG_SHA512 |
| 889 | case TPM_ALG_SHA512: |
| 890 | #endif // TPM_ALG_SHA512 |
| 891 | #ifdef TPM_ALG_SM3_256 |
| 892 | case TPM_ALG_SM3_256: |
| 893 | #endif // TPM_ALG_SM3_256 |
| 894 | break; |
| 895 | case TPM_ALG_NULL: |
| 896 | if (flag) |
| 897 | break; |
| 898 | return TPM_RC_HASH; |
| 899 | default: |
| 900 | return TPM_RC_HASH; |
| 901 | } |
| 902 | return TPM_RC_SUCCESS; |
| 903 | } |
| 904 | |
| 905 | // TPMI_ALG_HASH_Marshal changed to #define |
| 906 | |
| 907 | |
| 908 | // Table 2:60 - Definition of TPMI_ALG_ASYM Type (TypeTable) |
| 909 | // TPMI_ALG_ASYM_Unmarshal not referenced |
| 910 | // TPMI_ALG_ASYM_Marshal not referenced |
| 911 | |
| 912 | |
| 913 | // Table 2:61 - Definition of TPMI_ALG_SYM Type (TypeTable) |
| 914 | TPM_RC |
| 915 | TPMI_ALG_SYM_Unmarshal( |
| 916 | TPMI_ALG_SYM *target, BYTE **buffer, INT32 *size, BOOL flag |
| 917 | ) |
| 918 | { |
| 919 | TPM_RC result; |
| 920 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 921 | if(result != TPM_RC_SUCCESS) |
| 922 | return result; |
| 923 | switch (*target) { |
| 924 | #ifdef TPM_ALG_AES |
| 925 | case TPM_ALG_AES: |
| 926 | #endif // TPM_ALG_AES |
| 927 | #ifdef TPM_ALG_SM4 |
| 928 | case TPM_ALG_SM4: |
| 929 | #endif // TPM_ALG_SM4 |
| 930 | #ifdef TPM_ALG_CAMELLIA |
| 931 | case TPM_ALG_CAMELLIA: |
| 932 | #endif // TPM_ALG_CAMELLIA |
| 933 | #ifdef TPM_ALG_XOR |
| 934 | case TPM_ALG_XOR: |
| 935 | #endif // TPM_ALG_XOR |
| 936 | break; |
| 937 | case TPM_ALG_NULL: |
| 938 | if (flag) |
| 939 | break; |
| 940 | return TPM_RC_SYMMETRIC; |
| 941 | default: |
| 942 | return TPM_RC_SYMMETRIC; |
| 943 | } |
| 944 | return TPM_RC_SUCCESS; |
| 945 | } |
| 946 | |
| 947 | // TPMI_ALG_SYM_Marshal not referenced |
| 948 | |
| 949 | |
| 950 | // Table 2:62 - Definition of TPMI_ALG_SYM_OBJECT Type (TypeTable) |
| 951 | TPM_RC |
| 952 | TPMI_ALG_SYM_OBJECT_Unmarshal( |
| 953 | TPMI_ALG_SYM_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 954 | ) |
| 955 | { |
| 956 | TPM_RC result; |
| 957 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 958 | if(result != TPM_RC_SUCCESS) |
| 959 | return result; |
| 960 | switch (*target) { |
| 961 | #ifdef TPM_ALG_AES |
| 962 | case TPM_ALG_AES: |
| 963 | #endif // TPM_ALG_AES |
| 964 | #ifdef TPM_ALG_SM4 |
| 965 | case TPM_ALG_SM4: |
| 966 | #endif // TPM_ALG_SM4 |
| 967 | #ifdef TPM_ALG_CAMELLIA |
| 968 | case TPM_ALG_CAMELLIA: |
| 969 | #endif // TPM_ALG_CAMELLIA |
| 970 | break; |
| 971 | case TPM_ALG_NULL: |
| 972 | if (flag) |
| 973 | break; |
| 974 | return TPM_RC_SYMMETRIC; |
| 975 | default: |
| 976 | return TPM_RC_SYMMETRIC; |
| 977 | } |
| 978 | return TPM_RC_SUCCESS; |
| 979 | } |
| 980 | |
| 981 | // TPMI_ALG_SYM_OBJECT_Marshal changed to #define |
| 982 | |
| 983 | |
| 984 | // Table 2:63 - Definition of TPMI_ALG_SYM_MODE Type (TypeTable) |
| 985 | TPM_RC |
| 986 | TPMI_ALG_SYM_MODE_Unmarshal( |
| 987 | TPMI_ALG_SYM_MODE *target, BYTE **buffer, INT32 *size, BOOL flag |
| 988 | ) |
| 989 | { |
| 990 | TPM_RC result; |
| 991 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 992 | if(result != TPM_RC_SUCCESS) |
| 993 | return result; |
| 994 | switch (*target) { |
| 995 | #ifdef TPM_ALG_CTR |
| 996 | case TPM_ALG_CTR: |
| 997 | #endif // TPM_ALG_CTR |
| 998 | #ifdef TPM_ALG_OFB |
| 999 | case TPM_ALG_OFB: |
| 1000 | #endif // TPM_ALG_OFB |
| 1001 | #ifdef TPM_ALG_CBC |
| 1002 | case TPM_ALG_CBC: |
| 1003 | #endif // TPM_ALG_CBC |
| 1004 | #ifdef TPM_ALG_CFB |
| 1005 | case TPM_ALG_CFB: |
| 1006 | #endif // TPM_ALG_CFB |
| 1007 | #ifdef TPM_ALG_ECB |
| 1008 | case TPM_ALG_ECB: |
| 1009 | #endif // TPM_ALG_ECB |
| 1010 | break; |
| 1011 | case TPM_ALG_NULL: |
| 1012 | if (flag) |
| 1013 | break; |
| 1014 | return TPM_RC_MODE; |
| 1015 | default: |
| 1016 | return TPM_RC_MODE; |
| 1017 | } |
| 1018 | return TPM_RC_SUCCESS; |
| 1019 | } |
| 1020 | |
| 1021 | // TPMI_ALG_SYM_MODE_Marshal changed to #define |
| 1022 | |
| 1023 | |
| 1024 | // Table 2:64 - Definition of TPMI_ALG_KDF Type (TypeTable) |
| 1025 | TPM_RC |
| 1026 | TPMI_ALG_KDF_Unmarshal( |
| 1027 | TPMI_ALG_KDF *target, BYTE **buffer, INT32 *size, BOOL flag |
| 1028 | ) |
| 1029 | { |
| 1030 | TPM_RC result; |
| 1031 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 1032 | if(result != TPM_RC_SUCCESS) |
| 1033 | return result; |
| 1034 | switch (*target) { |
| 1035 | #ifdef TPM_ALG_MGF1 |
| 1036 | case TPM_ALG_MGF1: |
| 1037 | #endif // TPM_ALG_MGF1 |
| 1038 | #ifdef TPM_ALG_KDF1_SP800_56A |
| 1039 | case TPM_ALG_KDF1_SP800_56A: |
| 1040 | #endif // TPM_ALG_KDF1_SP800_56A |
| 1041 | #ifdef TPM_ALG_KDF2 |
| 1042 | case TPM_ALG_KDF2: |
| 1043 | #endif // TPM_ALG_KDF2 |
| 1044 | #ifdef TPM_ALG_KDF1_SP800_108 |
| 1045 | case TPM_ALG_KDF1_SP800_108: |
| 1046 | #endif // TPM_ALG_KDF1_SP800_108 |
| 1047 | break; |
| 1048 | case TPM_ALG_NULL: |
| 1049 | if (flag) |
| 1050 | break; |
| 1051 | return TPM_RC_KDF; |
| 1052 | default: |
| 1053 | return TPM_RC_KDF; |
| 1054 | } |
| 1055 | return TPM_RC_SUCCESS; |
| 1056 | } |
| 1057 | |
| 1058 | // TPMI_ALG_KDF_Marshal changed to #define |
| 1059 | |
| 1060 | |
| 1061 | // Table 2:65 - Definition of TPMI_ALG_SIG_SCHEME Type (TypeTable) |
| 1062 | TPM_RC |
| 1063 | TPMI_ALG_SIG_SCHEME_Unmarshal( |
| 1064 | TPMI_ALG_SIG_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 1065 | ) |
| 1066 | { |
| 1067 | TPM_RC result; |
| 1068 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 1069 | if(result != TPM_RC_SUCCESS) |
| 1070 | return result; |
| 1071 | switch (*target) { |
| 1072 | #ifdef TPM_ALG_RSASSA |
| 1073 | case TPM_ALG_RSASSA: |
| 1074 | #endif // TPM_ALG_RSASSA |
| 1075 | #ifdef TPM_ALG_RSAPSS |
| 1076 | case TPM_ALG_RSAPSS: |
| 1077 | #endif // TPM_ALG_RSAPSS |
| 1078 | #ifdef TPM_ALG_ECDSA |
| 1079 | case TPM_ALG_ECDSA: |
| 1080 | #endif // TPM_ALG_ECDSA |
| 1081 | #ifdef TPM_ALG_SM2 |
| 1082 | case TPM_ALG_SM2: |
| 1083 | #endif // TPM_ALG_SM2 |
| 1084 | #ifdef TPM_ALG_ECSCHNORR |
| 1085 | case TPM_ALG_ECSCHNORR: |
| 1086 | #endif // TPM_ALG_ECSCHNORR |
| 1087 | #ifdef TPM_ALG_ECDAA |
| 1088 | case TPM_ALG_ECDAA: |
| 1089 | #endif // TPM_ALG_ECDAA |
| 1090 | #ifdef TPM_ALG_HMAC |
| 1091 | case TPM_ALG_HMAC: |
| 1092 | #endif // TPM_ALG_HMAC |
| 1093 | break; |
| 1094 | case TPM_ALG_NULL: |
| 1095 | if (flag) |
| 1096 | break; |
| 1097 | return TPM_RC_SCHEME; |
| 1098 | default: |
| 1099 | return TPM_RC_SCHEME; |
| 1100 | } |
| 1101 | return TPM_RC_SUCCESS; |
| 1102 | } |
| 1103 | |
| 1104 | // TPMI_ALG_SIG_SCHEME_Marshal changed to #define |
| 1105 | |
| 1106 | |
| 1107 | // Table 2:66 - Definition of TPMI_ECC_KEY_EXCHANGE Type (TypeTable) |
| 1108 | #ifdef TPM_ALG_ECC |
| 1109 | TPM_RC |
| 1110 | TPMI_ECC_KEY_EXCHANGE_Unmarshal( |
| 1111 | TPMI_ECC_KEY_EXCHANGE *target, BYTE **buffer, INT32 *size, BOOL flag |
| 1112 | ) |
| 1113 | { |
| 1114 | TPM_RC result; |
| 1115 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 1116 | if(result != TPM_RC_SUCCESS) |
| 1117 | return result; |
| 1118 | switch (*target) { |
| 1119 | #ifdef TPM_ALG_ECDH |
| 1120 | case TPM_ALG_ECDH: |
| 1121 | #endif // TPM_ALG_ECDH |
| 1122 | #ifdef TPM_ALG_ECMQV |
| 1123 | case TPM_ALG_ECMQV: |
| 1124 | #endif // TPM_ALG_ECMQV |
| 1125 | #ifdef TPM_ALG_SM2 |
| 1126 | case TPM_ALG_SM2: |
| 1127 | #endif // TPM_ALG_SM2 |
| 1128 | break; |
| 1129 | case TPM_ALG_NULL: |
| 1130 | if (flag) |
| 1131 | break; |
| 1132 | return TPM_RC_SCHEME; |
| 1133 | default: |
| 1134 | return TPM_RC_SCHEME; |
| 1135 | } |
| 1136 | return TPM_RC_SUCCESS; |
| 1137 | } |
| 1138 | |
| 1139 | // TPMI_ECC_KEY_EXCHANGE_Marshal not referenced |
| 1140 | #endif // TPM_ALG_ECC |
| 1141 | |
| 1142 | |
| 1143 | // Table 2:67 - Definition of TPMI_ST_COMMAND_TAG Type (TypeTable) |
| 1144 | TPM_RC |
| 1145 | TPMI_ST_COMMAND_TAG_Unmarshal( |
| 1146 | TPMI_ST_COMMAND_TAG *target, BYTE **buffer, INT32 *size |
| 1147 | ) |
| 1148 | { |
| 1149 | TPM_RC result; |
| 1150 | result = TPM_ST_Unmarshal((TPM_ST *)target, buffer, size); |
| 1151 | if(result != TPM_RC_SUCCESS) |
| 1152 | return result; |
| 1153 | switch (*target) { |
| 1154 | case TPM_ST_NO_SESSIONS: |
| 1155 | case TPM_ST_SESSIONS: |
| 1156 | break; |
| 1157 | default: |
| 1158 | return TPM_RC_BAD_TAG; |
| 1159 | } |
| 1160 | return TPM_RC_SUCCESS; |
| 1161 | } |
| 1162 | |
| 1163 | // TPMI_ST_COMMAND_TAG_Marshal not referenced |
| 1164 | TPM_RC |
| 1165 | TPMS_EMPTY_Unmarshal( |
| 1166 | TPMS_EMPTY *target, BYTE **buffer, INT32 *size |
| 1167 | ) |
| 1168 | { |
| 1169 | // to prevent the compiler from complaining |
| 1170 | UNREFERENCED(target); |
| 1171 | UNREFERENCED(buffer); |
| 1172 | UNREFERENCED(size); |
| 1173 | return TPM_RC_SUCCESS; |
| 1174 | } |
| 1175 | |
| 1176 | UINT16 |
| 1177 | TPMS_EMPTY_Marshal( |
| 1178 | TPMS_EMPTY *source, BYTE **buffer, INT32 *size |
| 1179 | ) |
| 1180 | { |
| 1181 | // to prevent the compiler from complaining |
| 1182 | UNREFERENCED(source); |
| 1183 | UNREFERENCED(buffer); |
| 1184 | UNREFERENCED(size); |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
| 1188 | |
| 1189 | // Table 2:69 - Definition of TPMS_ALGORITHM_DESCRIPTION Structure (StructureTable) |
| 1190 | // TPMS_ALGORITHM_DESCRIPTION_Unmarshal not referenced |
| 1191 | // TPMS_ALGORITHM_DESCRIPTION_Marshal not referenced |
| 1192 | |
| 1193 | |
| 1194 | // Table 2:70 - Definition of TPMU_HA Union (UnionTable) |
| 1195 | TPM_RC |
| 1196 | TPMU_HA_Unmarshal( |
| 1197 | TPMU_HA *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 1198 | ) |
| 1199 | { |
| 1200 | switch(selector) { |
| 1201 | #ifdef TPM_ALG_SHA1 |
| 1202 | case TPM_ALG_SHA1: |
| 1203 | return BYTE_Array_Unmarshal((BYTE *)(target->sha1), buffer, size, (INT32)SHA1_DIGEST_SIZE); |
| 1204 | #endif // TPM_ALG_SHA1 |
| 1205 | #ifdef TPM_ALG_SHA256 |
| 1206 | case TPM_ALG_SHA256: |
| 1207 | return BYTE_Array_Unmarshal((BYTE *)(target->sha256), buffer, size, (INT32)SHA256_DIGEST_SIZE); |
| 1208 | #endif // TPM_ALG_SHA256 |
| 1209 | #ifdef TPM_ALG_SHA384 |
| 1210 | case TPM_ALG_SHA384: |
| 1211 | return BYTE_Array_Unmarshal((BYTE *)(target->sha384), buffer, size, (INT32)SHA384_DIGEST_SIZE); |
| 1212 | #endif // TPM_ALG_SHA384 |
| 1213 | #ifdef TPM_ALG_SHA512 |
| 1214 | case TPM_ALG_SHA512: |
| 1215 | return BYTE_Array_Unmarshal((BYTE *)(target->sha512), buffer, size, (INT32)SHA512_DIGEST_SIZE); |
| 1216 | #endif // TPM_ALG_SHA512 |
| 1217 | #ifdef TPM_ALG_SM3_256 |
| 1218 | case TPM_ALG_SM3_256: |
| 1219 | return BYTE_Array_Unmarshal((BYTE *)(target->sm3_256), buffer, size, (INT32)SM3_256_DIGEST_SIZE); |
| 1220 | #endif // TPM_ALG_SM3_256 |
| 1221 | case TPM_ALG_NULL: |
| 1222 | return TPM_RC_SUCCESS; |
| 1223 | } |
| 1224 | return TPM_RC_SELECTOR; |
| 1225 | } |
| 1226 | |
| 1227 | UINT16 |
| 1228 | TPMU_HA_Marshal( |
| 1229 | TPMU_HA *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 1230 | ) |
| 1231 | { |
| 1232 | switch(selector) { |
| 1233 | #ifdef TPM_ALG_SHA1 |
| 1234 | case TPM_ALG_SHA1: |
| 1235 | return BYTE_Array_Marshal((BYTE *)(source->sha1), buffer, size, (INT32)SHA1_DIGEST_SIZE); |
| 1236 | #endif // TPM_ALG_SHA1 |
| 1237 | #ifdef TPM_ALG_SHA256 |
| 1238 | case TPM_ALG_SHA256: |
| 1239 | return BYTE_Array_Marshal((BYTE *)(source->sha256), buffer, size, (INT32)SHA256_DIGEST_SIZE); |
| 1240 | #endif // TPM_ALG_SHA256 |
| 1241 | #ifdef TPM_ALG_SHA384 |
| 1242 | case TPM_ALG_SHA384: |
| 1243 | return BYTE_Array_Marshal((BYTE *)(source->sha384), buffer, size, (INT32)SHA384_DIGEST_SIZE); |
| 1244 | #endif // TPM_ALG_SHA384 |
| 1245 | #ifdef TPM_ALG_SHA512 |
| 1246 | case TPM_ALG_SHA512: |
| 1247 | return BYTE_Array_Marshal((BYTE *)(source->sha512), buffer, size, (INT32)SHA512_DIGEST_SIZE); |
| 1248 | #endif // TPM_ALG_SHA512 |
| 1249 | #ifdef TPM_ALG_SM3_256 |
| 1250 | case TPM_ALG_SM3_256: |
| 1251 | return BYTE_Array_Marshal((BYTE *)(source->sm3_256), buffer, size, (INT32)SM3_256_DIGEST_SIZE); |
| 1252 | #endif // TPM_ALG_SM3_256 |
| 1253 | case TPM_ALG_NULL: |
| 1254 | return 0; |
| 1255 | } |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | // Table 2:71 - Definition of TPMT_HA Structure (StructureTable) |
| 1261 | TPM_RC |
| 1262 | TPMT_HA_Unmarshal( |
| 1263 | TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag |
| 1264 | ) |
| 1265 | { |
| 1266 | TPM_RC result; |
| 1267 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, flag); |
| 1268 | if(result != TPM_RC_SUCCESS) |
| 1269 | return result; |
| 1270 | result = TPMU_HA_Unmarshal((TPMU_HA *)&(target->digest), buffer, size, (UINT32)target->hashAlg); |
| 1271 | return result; |
| 1272 | } |
| 1273 | |
| 1274 | UINT16 |
| 1275 | TPMT_HA_Marshal( |
| 1276 | TPMT_HA *source, BYTE **buffer, INT32 *size |
| 1277 | ) |
| 1278 | { |
| 1279 | UINT16 result = 0; |
| 1280 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size)); |
| 1281 | result = (UINT16)(result + TPMU_HA_Marshal((TPMU_HA *)&(source->digest), buffer, size, (UINT32)source->hashAlg)); |
| 1282 | return result; |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | // Table 2:72 - Definition of TPM2B_DIGEST Structure (StructureTable) |
| 1287 | TPM_RC |
| 1288 | TPM2B_DIGEST_Unmarshal( |
| 1289 | TPM2B_DIGEST *target, BYTE **buffer, INT32 *size |
| 1290 | ) |
| 1291 | { |
| 1292 | TPM_RC result; |
| 1293 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1294 | if(result != TPM_RC_SUCCESS) |
| 1295 | return result; |
| 1296 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1297 | if(target->t.size == 0) |
| 1298 | return TPM_RC_SUCCESS; |
| 1299 | if((target->t.size) > sizeof(TPMU_HA)) |
| 1300 | return TPM_RC_SIZE; |
| 1301 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1302 | return result; |
| 1303 | } |
| 1304 | |
| 1305 | UINT16 |
| 1306 | TPM2B_DIGEST_Marshal( |
| 1307 | TPM2B_DIGEST *source, BYTE **buffer, INT32 *size |
| 1308 | ) |
| 1309 | { |
| 1310 | UINT16 result = 0; |
| 1311 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1312 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1313 | if(source->t.size == 0) |
| 1314 | return result; |
| 1315 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1316 | return result; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | // Table 2:73 - Definition of TPM2B_DATA Structure (StructureTable) |
| 1321 | TPM_RC |
| 1322 | TPM2B_DATA_Unmarshal( |
| 1323 | TPM2B_DATA *target, BYTE **buffer, INT32 *size |
| 1324 | ) |
| 1325 | { |
| 1326 | TPM_RC result; |
| 1327 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1328 | if(result != TPM_RC_SUCCESS) |
| 1329 | return result; |
| 1330 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1331 | if(target->t.size == 0) |
| 1332 | return TPM_RC_SUCCESS; |
| 1333 | if((target->t.size) > sizeof(TPMT_HA)) |
| 1334 | return TPM_RC_SIZE; |
| 1335 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1336 | return result; |
| 1337 | } |
| 1338 | |
| 1339 | UINT16 |
| 1340 | TPM2B_DATA_Marshal( |
| 1341 | TPM2B_DATA *source, BYTE **buffer, INT32 *size |
| 1342 | ) |
| 1343 | { |
| 1344 | UINT16 result = 0; |
| 1345 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1346 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1347 | if(source->t.size == 0) |
| 1348 | return result; |
| 1349 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1350 | return result; |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | // Table 2:74 - Definition of Types for TPM2B_NONCE (TypesTable) |
| 1355 | // TPM2B_DIGEST definition from table 2:74 |
| 1356 | // TPM2B_NONCE_Unmarshal changed to #define |
| 1357 | // TPM2B_NONCE_Marshal changed to #define |
| 1358 | |
| 1359 | |
| 1360 | // Table 2:75 - Definition of Types for TPM2B_AUTH (TypesTable) |
| 1361 | // TPM2B_DIGEST definition from table 2:75 |
| 1362 | // TPM2B_AUTH_Unmarshal changed to #define |
| 1363 | // TPM2B_AUTH_Marshal changed to #define |
| 1364 | |
| 1365 | |
| 1366 | // Table 2:76 - Definition of Types for TPM2B_OPERAND (TypesTable) |
| 1367 | // TPM2B_DIGEST definition from table 2:76 |
| 1368 | // TPM2B_OPERAND_Unmarshal changed to #define |
| 1369 | // TPM2B_OPERAND_Marshal not referenced |
| 1370 | |
| 1371 | |
| 1372 | // Table 2:77 - Definition of TPM2B_EVENT Structure (StructureTable) |
| 1373 | TPM_RC |
| 1374 | TPM2B_EVENT_Unmarshal( |
| 1375 | TPM2B_EVENT *target, BYTE **buffer, INT32 *size |
| 1376 | ) |
| 1377 | { |
| 1378 | TPM_RC result; |
| 1379 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1380 | if(result != TPM_RC_SUCCESS) |
| 1381 | return result; |
| 1382 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1383 | if(target->t.size == 0) |
| 1384 | return TPM_RC_SUCCESS; |
| 1385 | if((target->t.size) > 1024) |
| 1386 | return TPM_RC_SIZE; |
| 1387 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1388 | return result; |
| 1389 | } |
| 1390 | |
| 1391 | // TPM2B_EVENT_Marshal not referenced |
| 1392 | |
| 1393 | |
| 1394 | // Table 2:78 - Definition of TPM2B_MAX_BUFFER Structure (StructureTable) |
| 1395 | TPM_RC |
| 1396 | TPM2B_MAX_BUFFER_Unmarshal( |
| 1397 | TPM2B_MAX_BUFFER *target, BYTE **buffer, INT32 *size |
| 1398 | ) |
| 1399 | { |
| 1400 | TPM_RC result; |
| 1401 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1402 | if(result != TPM_RC_SUCCESS) |
| 1403 | return result; |
| 1404 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1405 | if(target->t.size == 0) |
| 1406 | return TPM_RC_SUCCESS; |
| 1407 | if((target->t.size) > MAX_DIGEST_BUFFER) |
| 1408 | return TPM_RC_SIZE; |
| 1409 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1410 | return result; |
| 1411 | } |
| 1412 | |
| 1413 | UINT16 |
| 1414 | TPM2B_MAX_BUFFER_Marshal( |
| 1415 | TPM2B_MAX_BUFFER *source, BYTE **buffer, INT32 *size |
| 1416 | ) |
| 1417 | { |
| 1418 | UINT16 result = 0; |
| 1419 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1420 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1421 | if(source->t.size == 0) |
| 1422 | return result; |
| 1423 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1424 | return result; |
| 1425 | } |
| 1426 | |
| 1427 | |
| 1428 | // Table 2:79 - Definition of TPM2B_MAX_NV_BUFFER Structure (StructureTable) |
| 1429 | TPM_RC |
| 1430 | TPM2B_MAX_NV_BUFFER_Unmarshal( |
| 1431 | TPM2B_MAX_NV_BUFFER *target, BYTE **buffer, INT32 *size |
| 1432 | ) |
| 1433 | { |
| 1434 | TPM_RC result; |
| 1435 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1436 | if(result != TPM_RC_SUCCESS) |
| 1437 | return result; |
| 1438 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1439 | if(target->t.size == 0) |
| 1440 | return TPM_RC_SUCCESS; |
| 1441 | if((target->t.size) > MAX_NV_BUFFER_SIZE) |
| 1442 | return TPM_RC_SIZE; |
| 1443 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1444 | return result; |
| 1445 | } |
| 1446 | |
| 1447 | UINT16 |
| 1448 | TPM2B_MAX_NV_BUFFER_Marshal( |
| 1449 | TPM2B_MAX_NV_BUFFER *source, BYTE **buffer, INT32 *size |
| 1450 | ) |
| 1451 | { |
| 1452 | UINT16 result = 0; |
| 1453 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1454 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1455 | if(source->t.size == 0) |
| 1456 | return result; |
| 1457 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1458 | return result; |
| 1459 | } |
| 1460 | |
| 1461 | |
| 1462 | // Table 2:80 - Definition of TPM2B_TIMEOUT Structure (StructureTable) |
| 1463 | TPM_RC |
| 1464 | TPM2B_TIMEOUT_Unmarshal( |
| 1465 | TPM2B_TIMEOUT *target, BYTE **buffer, INT32 *size |
| 1466 | ) |
| 1467 | { |
| 1468 | TPM_RC result; |
| 1469 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1470 | if(result != TPM_RC_SUCCESS) |
| 1471 | return result; |
| 1472 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1473 | if(target->t.size == 0) |
| 1474 | return TPM_RC_SUCCESS; |
| 1475 | if((target->t.size) > sizeof(UINT64)) |
| 1476 | return TPM_RC_SIZE; |
| 1477 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1478 | return result; |
| 1479 | } |
| 1480 | |
| 1481 | UINT16 |
| 1482 | TPM2B_TIMEOUT_Marshal( |
| 1483 | TPM2B_TIMEOUT *source, BYTE **buffer, INT32 *size |
| 1484 | ) |
| 1485 | { |
| 1486 | UINT16 result = 0; |
| 1487 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1488 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1489 | if(source->t.size == 0) |
| 1490 | return result; |
| 1491 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1492 | return result; |
| 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | // Table 2:81 - Definition of TPM2B_IV Structure (StructureTable) |
| 1497 | TPM_RC |
| 1498 | TPM2B_IV_Unmarshal( |
| 1499 | TPM2B_IV *target, BYTE **buffer, INT32 *size |
| 1500 | ) |
| 1501 | { |
| 1502 | TPM_RC result; |
| 1503 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1504 | if(result != TPM_RC_SUCCESS) |
| 1505 | return result; |
| 1506 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1507 | if(target->t.size == 0) |
| 1508 | return TPM_RC_SUCCESS; |
| 1509 | if((target->t.size) > MAX_SYM_BLOCK_SIZE) |
| 1510 | return TPM_RC_SIZE; |
| 1511 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 1512 | return result; |
| 1513 | } |
| 1514 | |
| 1515 | UINT16 |
| 1516 | TPM2B_IV_Marshal( |
| 1517 | TPM2B_IV *source, BYTE **buffer, INT32 *size |
| 1518 | ) |
| 1519 | { |
| 1520 | UINT16 result = 0; |
| 1521 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1522 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1523 | if(source->t.size == 0) |
| 1524 | return result; |
| 1525 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 1526 | return result; |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | // Table 2:82 - Definition of TPMU_NAME Union (UnionTable) |
| 1531 | |
| 1532 | |
| 1533 | // Table 2:83 - Definition of TPM2B_NAME Structure (StructureTable) |
| 1534 | TPM_RC |
| 1535 | TPM2B_NAME_Unmarshal( |
| 1536 | TPM2B_NAME *target, BYTE **buffer, INT32 *size |
| 1537 | ) |
| 1538 | { |
| 1539 | TPM_RC result; |
| 1540 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 1541 | if(result != TPM_RC_SUCCESS) |
| 1542 | return result; |
| 1543 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1544 | if(target->t.size == 0) |
| 1545 | return TPM_RC_SUCCESS; |
| 1546 | if((target->t.size) > sizeof(TPMU_NAME)) |
| 1547 | return TPM_RC_SIZE; |
| 1548 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.name), buffer, size, (INT32)(target->t.size)); |
| 1549 | return result; |
| 1550 | } |
| 1551 | |
| 1552 | UINT16 |
| 1553 | TPM2B_NAME_Marshal( |
| 1554 | TPM2B_NAME *source, BYTE **buffer, INT32 *size |
| 1555 | ) |
| 1556 | { |
| 1557 | UINT16 result = 0; |
| 1558 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 1559 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 1560 | if(source->t.size == 0) |
| 1561 | return result; |
| 1562 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.name), buffer, size, (INT32)(source->t.size))); |
| 1563 | return result; |
| 1564 | } |
| 1565 | |
| 1566 | |
| 1567 | // Table 2:84 - Definition of TPMS_PCR_SELECT Structure (StructureTable) |
| 1568 | // TPMS_PCR_SELECT_Unmarshal not referenced |
| 1569 | // TPMS_PCR_SELECT_Marshal not referenced |
| 1570 | |
| 1571 | |
| 1572 | // Table 2:85 - Definition of TPMS_PCR_SELECTION Structure (StructureTable) |
| 1573 | TPM_RC |
| 1574 | TPMS_PCR_SELECTION_Unmarshal( |
| 1575 | TPMS_PCR_SELECTION *target, BYTE **buffer, INT32 *size |
| 1576 | ) |
| 1577 | { |
| 1578 | TPM_RC result; |
| 1579 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0); |
| 1580 | if(result != TPM_RC_SUCCESS) |
| 1581 | return result; |
| 1582 | result = UINT8_Unmarshal((UINT8 *)&(target->sizeofSelect), buffer, size); |
| 1583 | if(result != TPM_RC_SUCCESS) |
| 1584 | return result; |
| 1585 | if( (target->sizeofSelect < PCR_SELECT_MIN)) |
| 1586 | return TPM_RC_VALUE; |
| 1587 | if((target->sizeofSelect) > PCR_SELECT_MAX) |
| 1588 | return TPM_RC_VALUE; |
| 1589 | result = BYTE_Array_Unmarshal((BYTE *)(target->pcrSelect), buffer, size, (INT32)(target->sizeofSelect)); |
| 1590 | return result; |
| 1591 | } |
| 1592 | |
| 1593 | UINT16 |
| 1594 | TPMS_PCR_SELECTION_Marshal( |
| 1595 | TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size |
| 1596 | ) |
| 1597 | { |
| 1598 | UINT16 result = 0; |
| 1599 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size)); |
| 1600 | result = (UINT16)(result + UINT8_Marshal((UINT8 *)&(source->sizeofSelect), buffer, size)); |
| 1601 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->pcrSelect), buffer, size, (INT32)(source->sizeofSelect))); |
| 1602 | return result; |
| 1603 | } |
| 1604 | |
| 1605 | |
| 1606 | // Table 2:88 - Definition of TPMT_TK_CREATION Structure (StructureTable) |
| 1607 | TPM_RC |
| 1608 | TPMT_TK_CREATION_Unmarshal( |
| 1609 | TPMT_TK_CREATION *target, BYTE **buffer, INT32 *size |
| 1610 | ) |
| 1611 | { |
| 1612 | TPM_RC result; |
| 1613 | result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size); |
| 1614 | if(result != TPM_RC_SUCCESS) |
| 1615 | return result; |
| 1616 | if( ((target->tag) != TPM_ST_CREATION)) |
| 1617 | return TPM_RC_TAG; |
| 1618 | result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1); |
| 1619 | if(result != TPM_RC_SUCCESS) |
| 1620 | return result; |
| 1621 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size); |
| 1622 | return result; |
| 1623 | } |
| 1624 | |
| 1625 | UINT16 |
| 1626 | TPMT_TK_CREATION_Marshal( |
| 1627 | TPMT_TK_CREATION *source, BYTE **buffer, INT32 *size |
| 1628 | ) |
| 1629 | { |
| 1630 | UINT16 result = 0; |
| 1631 | result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size)); |
| 1632 | result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size)); |
| 1633 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size)); |
| 1634 | return result; |
| 1635 | } |
| 1636 | |
| 1637 | |
| 1638 | // Table 2:89 - Definition of TPMT_TK_VERIFIED Structure (StructureTable) |
| 1639 | TPM_RC |
| 1640 | TPMT_TK_VERIFIED_Unmarshal( |
| 1641 | TPMT_TK_VERIFIED *target, BYTE **buffer, INT32 *size |
| 1642 | ) |
| 1643 | { |
| 1644 | TPM_RC result; |
| 1645 | result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size); |
| 1646 | if(result != TPM_RC_SUCCESS) |
| 1647 | return result; |
| 1648 | if( ((target->tag) != TPM_ST_VERIFIED)) |
| 1649 | return TPM_RC_TAG; |
| 1650 | result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1); |
| 1651 | if(result != TPM_RC_SUCCESS) |
| 1652 | return result; |
| 1653 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size); |
| 1654 | return result; |
| 1655 | } |
| 1656 | |
| 1657 | UINT16 |
| 1658 | TPMT_TK_VERIFIED_Marshal( |
| 1659 | TPMT_TK_VERIFIED *source, BYTE **buffer, INT32 *size |
| 1660 | ) |
| 1661 | { |
| 1662 | UINT16 result = 0; |
| 1663 | result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size)); |
| 1664 | result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size)); |
| 1665 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size)); |
| 1666 | return result; |
| 1667 | } |
| 1668 | |
| 1669 | |
| 1670 | // Table 2:90 - Definition of TPMT_TK_AUTH Structure (StructureTable) |
| 1671 | TPM_RC |
| 1672 | TPMT_TK_AUTH_Unmarshal( |
| 1673 | TPMT_TK_AUTH *target, BYTE **buffer, INT32 *size |
| 1674 | ) |
| 1675 | { |
| 1676 | TPM_RC result; |
| 1677 | result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size); |
| 1678 | if(result != TPM_RC_SUCCESS) |
| 1679 | return result; |
| 1680 | if( ((target->tag) != TPM_ST_AUTH_SIGNED) |
| 1681 | && ((target->tag) != TPM_ST_AUTH_SECRET)) |
| 1682 | return TPM_RC_TAG; |
| 1683 | result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1); |
| 1684 | if(result != TPM_RC_SUCCESS) |
| 1685 | return result; |
| 1686 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size); |
| 1687 | return result; |
| 1688 | } |
| 1689 | |
| 1690 | UINT16 |
| 1691 | TPMT_TK_AUTH_Marshal( |
| 1692 | TPMT_TK_AUTH *source, BYTE **buffer, INT32 *size |
| 1693 | ) |
| 1694 | { |
| 1695 | UINT16 result = 0; |
| 1696 | result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size)); |
| 1697 | result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size)); |
| 1698 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size)); |
| 1699 | return result; |
| 1700 | } |
| 1701 | |
| 1702 | |
| 1703 | // Table 2:91 - Definition of TPMT_TK_HASHCHECK Structure (StructureTable) |
| 1704 | TPM_RC |
| 1705 | TPMT_TK_HASHCHECK_Unmarshal( |
| 1706 | TPMT_TK_HASHCHECK *target, BYTE **buffer, INT32 *size |
| 1707 | ) |
| 1708 | { |
| 1709 | TPM_RC result; |
| 1710 | result = TPM_ST_Unmarshal((TPM_ST *)&(target->tag), buffer, size); |
| 1711 | if(result != TPM_RC_SUCCESS) |
| 1712 | return result; |
| 1713 | if( ((target->tag) != TPM_ST_HASHCHECK)) |
| 1714 | return TPM_RC_TAG; |
| 1715 | result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1); |
| 1716 | if(result != TPM_RC_SUCCESS) |
| 1717 | return result; |
| 1718 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->digest), buffer, size); |
| 1719 | return result; |
| 1720 | } |
| 1721 | |
| 1722 | UINT16 |
| 1723 | TPMT_TK_HASHCHECK_Marshal( |
| 1724 | TPMT_TK_HASHCHECK *source, BYTE **buffer, INT32 *size |
| 1725 | ) |
| 1726 | { |
| 1727 | UINT16 result = 0; |
| 1728 | result = (UINT16)(result + TPM_ST_Marshal((TPM_ST *)&(source->tag), buffer, size)); |
| 1729 | result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size)); |
| 1730 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->digest), buffer, size)); |
| 1731 | return result; |
| 1732 | } |
| 1733 | |
| 1734 | |
| 1735 | // Table 2:92 - Definition of TPMS_ALG_PROPERTY Structure (StructureTable) |
| 1736 | // TPMS_ALG_PROPERTY_Unmarshal not referenced |
| 1737 | UINT16 |
| 1738 | TPMS_ALG_PROPERTY_Marshal( |
| 1739 | TPMS_ALG_PROPERTY *source, BYTE **buffer, INT32 *size |
| 1740 | ) |
| 1741 | { |
| 1742 | UINT16 result = 0; |
| 1743 | result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->alg), buffer, size)); |
| 1744 | result = (UINT16)(result + TPMA_ALGORITHM_Marshal((TPMA_ALGORITHM *)&(source->algProperties), buffer, size)); |
| 1745 | return result; |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | // Table 2:93 - Definition of TPMS_TAGGED_PROPERTY Structure (StructureTable) |
| 1750 | // TPMS_TAGGED_PROPERTY_Unmarshal not referenced |
| 1751 | UINT16 |
| 1752 | TPMS_TAGGED_PROPERTY_Marshal( |
| 1753 | TPMS_TAGGED_PROPERTY *source, BYTE **buffer, INT32 *size |
| 1754 | ) |
| 1755 | { |
| 1756 | UINT16 result = 0; |
| 1757 | result = (UINT16)(result + TPM_PT_Marshal((TPM_PT *)&(source->property), buffer, size)); |
| 1758 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->value), buffer, size)); |
| 1759 | return result; |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | // Table 2:94 - Definition of TPMS_TAGGED_PCR_SELECT Structure (StructureTable) |
| 1764 | // TPMS_TAGGED_PCR_SELECT_Unmarshal not referenced |
| 1765 | UINT16 |
| 1766 | TPMS_TAGGED_PCR_SELECT_Marshal( |
| 1767 | TPMS_TAGGED_PCR_SELECT *source, BYTE **buffer, INT32 *size |
| 1768 | ) |
| 1769 | { |
| 1770 | UINT16 result = 0; |
| 1771 | result = (UINT16)(result + TPM_PT_Marshal((TPM_PT *)&(source->tag), buffer, size)); |
| 1772 | result = (UINT16)(result + UINT8_Marshal((UINT8 *)&(source->sizeofSelect), buffer, size)); |
| 1773 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->pcrSelect), buffer, size, (INT32)(source->sizeofSelect))); |
| 1774 | return result; |
| 1775 | } |
| 1776 | |
| 1777 | |
| 1778 | // Table 2:95 - Definition of TPML_CC Structure (StructureTable) |
| 1779 | TPM_RC |
| 1780 | TPML_CC_Unmarshal( |
| 1781 | TPML_CC *target, BYTE **buffer, INT32 *size |
| 1782 | ) |
| 1783 | { |
| 1784 | TPM_RC result; |
| 1785 | result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size); |
| 1786 | if(result != TPM_RC_SUCCESS) |
| 1787 | return result; |
| 1788 | if((target->count) > MAX_CAP_CC) |
| 1789 | return TPM_RC_SIZE; |
| 1790 | result = TPM_CC_Array_Unmarshal((TPM_CC *)(target->commandCodes), buffer, size, (INT32)(target->count)); |
| 1791 | return result; |
| 1792 | } |
| 1793 | |
| 1794 | UINT16 |
| 1795 | TPML_CC_Marshal( |
| 1796 | TPML_CC *source, BYTE **buffer, INT32 *size |
| 1797 | ) |
| 1798 | { |
| 1799 | UINT16 result = 0; |
| 1800 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1801 | result = (UINT16)(result + TPM_CC_Array_Marshal((TPM_CC *)(source->commandCodes), buffer, size, (INT32)(source->count))); |
| 1802 | return result; |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | // Table 2:96 - Definition of TPML_CCA Structure (StructureTable) |
| 1807 | // TPML_CCA_Unmarshal not referenced |
| 1808 | UINT16 |
| 1809 | TPML_CCA_Marshal( |
| 1810 | TPML_CCA *source, BYTE **buffer, INT32 *size |
| 1811 | ) |
| 1812 | { |
| 1813 | UINT16 result = 0; |
| 1814 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1815 | result = (UINT16)(result + TPMA_CC_Array_Marshal((TPMA_CC *)(source->commandAttributes), buffer, size, (INT32)(source->count))); |
| 1816 | return result; |
| 1817 | } |
| 1818 | |
| 1819 | |
| 1820 | // Table 2:97 - Definition of TPML_ALG Structure (StructureTable) |
| 1821 | TPM_RC |
| 1822 | TPML_ALG_Unmarshal( |
| 1823 | TPML_ALG *target, BYTE **buffer, INT32 *size |
| 1824 | ) |
| 1825 | { |
| 1826 | TPM_RC result; |
| 1827 | result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size); |
| 1828 | if(result != TPM_RC_SUCCESS) |
| 1829 | return result; |
| 1830 | if((target->count) > MAX_ALG_LIST_SIZE) |
| 1831 | return TPM_RC_SIZE; |
| 1832 | result = TPM_ALG_ID_Array_Unmarshal((TPM_ALG_ID *)(target->algorithms), buffer, size, (INT32)(target->count)); |
| 1833 | return result; |
| 1834 | } |
| 1835 | |
| 1836 | UINT16 |
| 1837 | TPML_ALG_Marshal( |
| 1838 | TPML_ALG *source, BYTE **buffer, INT32 *size |
| 1839 | ) |
| 1840 | { |
| 1841 | UINT16 result = 0; |
| 1842 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1843 | result = (UINT16)(result + TPM_ALG_ID_Array_Marshal((TPM_ALG_ID *)(source->algorithms), buffer, size, (INT32)(source->count))); |
| 1844 | return result; |
| 1845 | } |
| 1846 | |
| 1847 | |
| 1848 | // Table 2:98 - Definition of TPML_HANDLE Structure (StructureTable) |
| 1849 | // TPML_HANDLE_Unmarshal not referenced |
| 1850 | UINT16 |
| 1851 | TPML_HANDLE_Marshal( |
| 1852 | TPML_HANDLE *source, BYTE **buffer, INT32 *size |
| 1853 | ) |
| 1854 | { |
| 1855 | UINT16 result = 0; |
| 1856 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1857 | result = (UINT16)(result + TPM_HANDLE_Array_Marshal((TPM_HANDLE *)(source->handle), buffer, size, (INT32)(source->count))); |
| 1858 | return result; |
| 1859 | } |
| 1860 | |
| 1861 | |
| 1862 | // Table 2:99 - Definition of TPML_DIGEST Structure (StructureTable) |
| 1863 | TPM_RC |
| 1864 | TPML_DIGEST_Unmarshal( |
| 1865 | TPML_DIGEST *target, BYTE **buffer, INT32 *size |
| 1866 | ) |
| 1867 | { |
| 1868 | TPM_RC result; |
| 1869 | result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size); |
| 1870 | if(result != TPM_RC_SUCCESS) |
| 1871 | return result; |
| 1872 | if( (target->count < 2)) |
| 1873 | return TPM_RC_SIZE; |
| 1874 | if((target->count) > 8) |
| 1875 | return TPM_RC_SIZE; |
| 1876 | result = TPM2B_DIGEST_Array_Unmarshal((TPM2B_DIGEST *)(target->digests), buffer, size, (INT32)(target->count)); |
| 1877 | return result; |
| 1878 | } |
| 1879 | |
| 1880 | UINT16 |
| 1881 | TPML_DIGEST_Marshal( |
| 1882 | TPML_DIGEST *source, BYTE **buffer, INT32 *size |
| 1883 | ) |
| 1884 | { |
| 1885 | UINT16 result = 0; |
| 1886 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1887 | result = (UINT16)(result + TPM2B_DIGEST_Array_Marshal((TPM2B_DIGEST *)(source->digests), buffer, size, (INT32)(source->count))); |
| 1888 | return result; |
| 1889 | } |
| 1890 | |
| 1891 | |
| 1892 | // Table 2:100 - Definition of TPML_DIGEST_VALUES Structure (StructureTable) |
| 1893 | TPM_RC |
| 1894 | TPML_DIGEST_VALUES_Unmarshal( |
| 1895 | TPML_DIGEST_VALUES *target, BYTE **buffer, INT32 *size |
| 1896 | ) |
| 1897 | { |
| 1898 | TPM_RC result; |
| 1899 | result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size); |
| 1900 | if(result != TPM_RC_SUCCESS) |
| 1901 | return result; |
| 1902 | if((target->count) > HASH_COUNT) |
| 1903 | return TPM_RC_SIZE; |
| 1904 | result = TPMT_HA_Array_Unmarshal((TPMT_HA *)(target->digests), buffer, size, 0, (INT32)(target->count)); |
| 1905 | return result; |
| 1906 | } |
| 1907 | |
| 1908 | UINT16 |
| 1909 | TPML_DIGEST_VALUES_Marshal( |
| 1910 | TPML_DIGEST_VALUES *source, BYTE **buffer, INT32 *size |
| 1911 | ) |
| 1912 | { |
| 1913 | UINT16 result = 0; |
| 1914 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1915 | result = (UINT16)(result + TPMT_HA_Array_Marshal((TPMT_HA *)(source->digests), buffer, size, (INT32)(source->count))); |
| 1916 | return result; |
| 1917 | } |
| 1918 | |
| 1919 | |
| 1920 | // Table 2:101 - Definition of TPM2B_DIGEST_VALUES Structure (StructureTable) |
| 1921 | // TPM2B_DIGEST_VALUES_Unmarshal not referenced |
| 1922 | // TPM2B_DIGEST_VALUES_Marshal not referenced |
| 1923 | |
| 1924 | |
| 1925 | // Table 2:102 - Definition of TPML_PCR_SELECTION Structure (StructureTable) |
| 1926 | TPM_RC |
| 1927 | TPML_PCR_SELECTION_Unmarshal( |
| 1928 | TPML_PCR_SELECTION *target, BYTE **buffer, INT32 *size |
| 1929 | ) |
| 1930 | { |
| 1931 | TPM_RC result; |
| 1932 | result = UINT32_Unmarshal((UINT32 *)&(target->count), buffer, size); |
| 1933 | if(result != TPM_RC_SUCCESS) |
| 1934 | return result; |
| 1935 | if((target->count) > HASH_COUNT) |
| 1936 | return TPM_RC_SIZE; |
| 1937 | result = TPMS_PCR_SELECTION_Array_Unmarshal((TPMS_PCR_SELECTION *)(target->pcrSelections), buffer, size, (INT32)(target->count)); |
| 1938 | return result; |
| 1939 | } |
| 1940 | |
| 1941 | UINT16 |
| 1942 | TPML_PCR_SELECTION_Marshal( |
| 1943 | TPML_PCR_SELECTION *source, BYTE **buffer, INT32 *size |
| 1944 | ) |
| 1945 | { |
| 1946 | UINT16 result = 0; |
| 1947 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1948 | result = (UINT16)(result + TPMS_PCR_SELECTION_Array_Marshal((TPMS_PCR_SELECTION *)(source->pcrSelections), buffer, size, (INT32)(source->count))); |
| 1949 | return result; |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | // Table 2:103 - Definition of TPML_ALG_PROPERTY Structure (StructureTable) |
| 1954 | // TPML_ALG_PROPERTY_Unmarshal not referenced |
| 1955 | UINT16 |
| 1956 | TPML_ALG_PROPERTY_Marshal( |
| 1957 | TPML_ALG_PROPERTY *source, BYTE **buffer, INT32 *size |
| 1958 | ) |
| 1959 | { |
| 1960 | UINT16 result = 0; |
| 1961 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1962 | result = (UINT16)(result + TPMS_ALG_PROPERTY_Array_Marshal((TPMS_ALG_PROPERTY *)(source->algProperties), buffer, size, (INT32)(source->count))); |
| 1963 | return result; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | // Table 2:104 - Definition of TPML_TAGGED_TPM_PROPERTY Structure (StructureTable) |
| 1968 | // TPML_TAGGED_TPM_PROPERTY_Unmarshal not referenced |
| 1969 | UINT16 |
| 1970 | TPML_TAGGED_TPM_PROPERTY_Marshal( |
| 1971 | TPML_TAGGED_TPM_PROPERTY *source, BYTE **buffer, INT32 *size |
| 1972 | ) |
| 1973 | { |
| 1974 | UINT16 result = 0; |
| 1975 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1976 | result = (UINT16)(result + TPMS_TAGGED_PROPERTY_Array_Marshal((TPMS_TAGGED_PROPERTY *)(source->tpmProperty), buffer, size, (INT32)(source->count))); |
| 1977 | return result; |
| 1978 | } |
| 1979 | |
| 1980 | |
| 1981 | // Table 2:105 - Definition of TPML_TAGGED_PCR_PROPERTY Structure (StructureTable) |
| 1982 | // TPML_TAGGED_PCR_PROPERTY_Unmarshal not referenced |
| 1983 | UINT16 |
| 1984 | TPML_TAGGED_PCR_PROPERTY_Marshal( |
| 1985 | TPML_TAGGED_PCR_PROPERTY *source, BYTE **buffer, INT32 *size |
| 1986 | ) |
| 1987 | { |
| 1988 | UINT16 result = 0; |
| 1989 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 1990 | result = (UINT16)(result + TPMS_TAGGED_PCR_SELECT_Array_Marshal((TPMS_TAGGED_PCR_SELECT *)(source->pcrProperty), buffer, size, (INT32)(source->count))); |
| 1991 | return result; |
| 1992 | } |
| 1993 | |
| 1994 | |
| 1995 | // Table 2:106 - Definition of TPML_ECC_CURVE Structure (StructureTable) |
| 1996 | #ifdef TPM_ALG_ECC |
| 1997 | // TPML_ECC_CURVE_Unmarshal not referenced |
| 1998 | UINT16 |
| 1999 | TPML_ECC_CURVE_Marshal( |
| 2000 | TPML_ECC_CURVE *source, BYTE **buffer, INT32 *size |
| 2001 | ) |
| 2002 | { |
| 2003 | UINT16 result = 0; |
| 2004 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 2005 | result = (UINT16)(result + TPM_ECC_CURVE_Array_Marshal((TPM_ECC_CURVE *)(source->eccCurves), buffer, size, (INT32)(source->count))); |
| 2006 | return result; |
| 2007 | } |
| 2008 | |
| 2009 | #endif // TPM_ALG_ECC |
| 2010 | |
| 2011 | #ifdef ME11_SIM |
| 2012 | UINT16 |
| 2013 | INTEL_PROP_VALUE_Marshal(INTEL_PROP_VALUE *source, BYTE **buffer, INT32 *size) |
| 2014 | { |
| 2015 | UINT16 result = 0; |
| 2016 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)source, buffer, size)); |
| 2017 | return result; |
| 2018 | } |
| 2019 | |
| 2020 | UINT16 |
| 2021 | INTEL_PROPERTY_Marshal(INTEL_PROPERTY *source, BYTE **buffer, INT32 *size) |
| 2022 | { |
| 2023 | UINT16 result = 0; |
| 2024 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->count), buffer, size)); |
| 2025 | result = (UINT16)(result + INTEL_PROP_VALUE_Marshal(&(source->property), buffer, size)); |
| 2026 | |
| 2027 | return result; |
| 2028 | } |
| 2029 | #endif |
| 2030 | |
| 2031 | // Table 2:107 - Definition of TPMU_CAPABILITIES Union (UnionTable) |
| 2032 | // TPMU_CAPABILITIES_Unmarshal not referenced |
| 2033 | UINT16 |
| 2034 | TPMU_CAPABILITIES_Marshal( |
| 2035 | TPMU_CAPABILITIES *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2036 | ) |
| 2037 | { |
| 2038 | switch(selector) { |
| 2039 | case TPM_CAP_ALGS: |
| 2040 | return TPML_ALG_PROPERTY_Marshal((TPML_ALG_PROPERTY *)&(source->algorithms), buffer, size); |
| 2041 | case TPM_CAP_HANDLES: |
| 2042 | return TPML_HANDLE_Marshal((TPML_HANDLE *)&(source->handles), buffer, size); |
| 2043 | case TPM_CAP_COMMANDS: |
| 2044 | return TPML_CCA_Marshal((TPML_CCA *)&(source->command), buffer, size); |
| 2045 | case TPM_CAP_PP_COMMANDS: |
| 2046 | return TPML_CC_Marshal((TPML_CC *)&(source->ppCommands), buffer, size); |
| 2047 | case TPM_CAP_AUDIT_COMMANDS: |
| 2048 | return TPML_CC_Marshal((TPML_CC *)&(source->auditCommands), buffer, size); |
| 2049 | case TPM_CAP_PCRS: |
| 2050 | return TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->assignedPCR), buffer, size); |
| 2051 | case TPM_CAP_TPM_PROPERTIES: |
| 2052 | return TPML_TAGGED_TPM_PROPERTY_Marshal((TPML_TAGGED_TPM_PROPERTY *)&(source->tpmProperties), buffer, size); |
| 2053 | case TPM_CAP_PCR_PROPERTIES: |
| 2054 | return TPML_TAGGED_PCR_PROPERTY_Marshal((TPML_TAGGED_PCR_PROPERTY *)&(source->pcrProperties), buffer, size); |
| 2055 | #ifdef TPM_ALG_ECC |
| 2056 | case TPM_CAP_ECC_CURVES: |
| 2057 | return TPML_ECC_CURVE_Marshal((TPML_ECC_CURVE *)&(source->eccCurves), buffer, size); |
| 2058 | #endif // TPM_ALG_ECC |
| 2059 | #ifdef ME11_SIM |
| 2060 | case TPM_CAP_VENDOR_PROPERTY: |
| 2061 | return INTEL_PROPERTY_Marshal((INTEL_PROPERTY *)&(source->intelProperty), buffer, size); |
| 2062 | #endif |
| 2063 | } |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | // Table 2:108 - Definition of TPMS_CAPABILITY_DATA Structure (StructureTable) |
| 2069 | // TPMS_CAPABILITY_DATA_Unmarshal not referenced |
| 2070 | UINT16 |
| 2071 | TPMS_CAPABILITY_DATA_Marshal( |
| 2072 | TPMS_CAPABILITY_DATA *source, BYTE **buffer, INT32 *size |
| 2073 | ) |
| 2074 | { |
| 2075 | UINT16 result = 0; |
| 2076 | result = (UINT16)(result + TPM_CAP_Marshal((TPM_CAP *)&(source->capability), buffer, size)); |
| 2077 | result = (UINT16)(result + TPMU_CAPABILITIES_Marshal((TPMU_CAPABILITIES *)&(source->data), buffer, size, (UINT32)source->capability)); |
| 2078 | return result; |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | // Table 2:109 - Definition of TPMS_CLOCK_INFO Structure (StructureTable) |
| 2083 | // TPMS_CLOCK_INFO_Unmarshal not referenced |
| 2084 | UINT16 |
| 2085 | TPMS_CLOCK_INFO_Marshal( |
| 2086 | TPMS_CLOCK_INFO *source, BYTE **buffer, INT32 *size |
| 2087 | ) |
| 2088 | { |
| 2089 | UINT16 result = 0; |
| 2090 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->clock), buffer, size)); |
| 2091 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->resetCount), buffer, size)); |
| 2092 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->restartCount), buffer, size)); |
| 2093 | result = (UINT16)(result + TPMI_YES_NO_Marshal((TPMI_YES_NO *)&(source->safe), buffer, size)); |
| 2094 | return result; |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | // Table 2:110 - Definition of TPMS_TIME_INFO Structure (StructureTable) |
| 2099 | // TPMS_TIME_INFO_Unmarshal not referenced |
| 2100 | UINT16 |
| 2101 | TPMS_TIME_INFO_Marshal( |
| 2102 | TPMS_TIME_INFO *source, BYTE **buffer, INT32 *size |
| 2103 | ) |
| 2104 | { |
| 2105 | UINT16 result = 0; |
| 2106 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->time), buffer, size)); |
| 2107 | result = (UINT16)(result + TPMS_CLOCK_INFO_Marshal((TPMS_CLOCK_INFO *)&(source->clockInfo), buffer, size)); |
| 2108 | return result; |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | // Table 2:111 - Definition of TPMS_TIME_ATTEST_INFO Structure (StructureTable) |
| 2113 | // TPMS_TIME_ATTEST_INFO_Unmarshal not referenced |
| 2114 | UINT16 |
| 2115 | TPMS_TIME_ATTEST_INFO_Marshal( |
| 2116 | TPMS_TIME_ATTEST_INFO *source, BYTE **buffer, INT32 *size |
| 2117 | ) |
| 2118 | { |
| 2119 | UINT16 result = 0; |
| 2120 | result = (UINT16)(result + TPMS_TIME_INFO_Marshal((TPMS_TIME_INFO *)&(source->time), buffer, size)); |
| 2121 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->firmwareVersion), buffer, size)); |
| 2122 | return result; |
| 2123 | } |
| 2124 | |
| 2125 | |
| 2126 | // Table 2:112 - Definition of TPMS_CERTIFY_INFO Structure (StructureTable) |
| 2127 | // TPMS_CERTIFY_INFO_Unmarshal not referenced |
| 2128 | UINT16 |
| 2129 | TPMS_CERTIFY_INFO_Marshal( |
| 2130 | TPMS_CERTIFY_INFO *source, BYTE **buffer, INT32 *size |
| 2131 | ) |
| 2132 | { |
| 2133 | UINT16 result = 0; |
| 2134 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->name), buffer, size)); |
| 2135 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->qualifiedName), buffer, size)); |
| 2136 | return result; |
| 2137 | } |
| 2138 | |
| 2139 | |
| 2140 | // Table 2:113 - Definition of TPMS_QUOTE_INFO Structure (StructureTable) |
| 2141 | // TPMS_QUOTE_INFO_Unmarshal not referenced |
| 2142 | UINT16 |
| 2143 | TPMS_QUOTE_INFO_Marshal( |
| 2144 | TPMS_QUOTE_INFO *source, BYTE **buffer, INT32 *size |
| 2145 | ) |
| 2146 | { |
| 2147 | UINT16 result = 0; |
| 2148 | result = (UINT16)(result + TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->pcrSelect), buffer, size)); |
| 2149 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->pcrDigest), buffer, size)); |
| 2150 | return result; |
| 2151 | } |
| 2152 | |
| 2153 | |
| 2154 | // Table 2:114 - Definition of TPMS_COMMAND_AUDIT_INFO Structure (StructureTable) |
| 2155 | // TPMS_COMMAND_AUDIT_INFO_Unmarshal not referenced |
| 2156 | UINT16 |
| 2157 | TPMS_COMMAND_AUDIT_INFO_Marshal( |
| 2158 | TPMS_COMMAND_AUDIT_INFO *source, BYTE **buffer, INT32 *size |
| 2159 | ) |
| 2160 | { |
| 2161 | UINT16 result = 0; |
| 2162 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->auditCounter), buffer, size)); |
| 2163 | result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->digestAlg), buffer, size)); |
| 2164 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->auditDigest), buffer, size)); |
| 2165 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->commandDigest), buffer, size)); |
| 2166 | return result; |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | // Table 2:115 - Definition of TPMS_SESSION_AUDIT_INFO Structure (StructureTable) |
| 2171 | // TPMS_SESSION_AUDIT_INFO_Unmarshal not referenced |
| 2172 | UINT16 |
| 2173 | TPMS_SESSION_AUDIT_INFO_Marshal( |
| 2174 | TPMS_SESSION_AUDIT_INFO *source, BYTE **buffer, INT32 *size |
| 2175 | ) |
| 2176 | { |
| 2177 | UINT16 result = 0; |
| 2178 | result = (UINT16)(result + TPMI_YES_NO_Marshal((TPMI_YES_NO *)&(source->exclusiveSession), buffer, size)); |
| 2179 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->sessionDigest), buffer, size)); |
| 2180 | return result; |
| 2181 | } |
| 2182 | |
| 2183 | |
| 2184 | // Table 2:116 - Definition of TPMS_CREATION_INFO Structure (StructureTable) |
| 2185 | // TPMS_CREATION_INFO_Unmarshal not referenced |
| 2186 | UINT16 |
| 2187 | TPMS_CREATION_INFO_Marshal( |
| 2188 | TPMS_CREATION_INFO *source, BYTE **buffer, INT32 *size |
| 2189 | ) |
| 2190 | { |
| 2191 | UINT16 result = 0; |
| 2192 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->objectName), buffer, size)); |
| 2193 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->creationHash), buffer, size)); |
| 2194 | return result; |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | // Table 2:117 - Definition of TPMS_NV_CERTIFY_INFO Structure (StructureTable) |
| 2199 | // TPMS_NV_CERTIFY_INFO_Unmarshal not referenced |
| 2200 | UINT16 |
| 2201 | TPMS_NV_CERTIFY_INFO_Marshal( |
| 2202 | TPMS_NV_CERTIFY_INFO *source, BYTE **buffer, INT32 *size |
| 2203 | ) |
| 2204 | { |
| 2205 | UINT16 result = 0; |
| 2206 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->indexName), buffer, size)); |
| 2207 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->offset), buffer, size)); |
| 2208 | result = (UINT16)(result + TPM2B_MAX_NV_BUFFER_Marshal((TPM2B_MAX_NV_BUFFER *)&(source->nvContents), buffer, size)); |
| 2209 | return result; |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | // Table 2:118 - Definition of TPMI_ST_ATTEST Type (TypeTable) |
| 2214 | // TPMI_ST_ATTEST_Unmarshal not referenced |
| 2215 | // TPMI_ST_ATTEST_Marshal changed to #define |
| 2216 | |
| 2217 | |
| 2218 | // Table 2:119 - Definition of TPMU_ATTEST Union (UnionTable) |
| 2219 | // TPMU_ATTEST_Unmarshal not referenced |
| 2220 | UINT16 |
| 2221 | TPMU_ATTEST_Marshal( |
| 2222 | TPMU_ATTEST *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2223 | ) |
| 2224 | { |
| 2225 | switch(selector) { |
| 2226 | case TPM_ST_ATTEST_CERTIFY: |
| 2227 | return TPMS_CERTIFY_INFO_Marshal((TPMS_CERTIFY_INFO *)&(source->certify), buffer, size); |
| 2228 | case TPM_ST_ATTEST_CREATION: |
| 2229 | return TPMS_CREATION_INFO_Marshal((TPMS_CREATION_INFO *)&(source->creation), buffer, size); |
| 2230 | case TPM_ST_ATTEST_QUOTE: |
| 2231 | return TPMS_QUOTE_INFO_Marshal((TPMS_QUOTE_INFO *)&(source->quote), buffer, size); |
| 2232 | case TPM_ST_ATTEST_COMMAND_AUDIT: |
| 2233 | return TPMS_COMMAND_AUDIT_INFO_Marshal((TPMS_COMMAND_AUDIT_INFO *)&(source->commandAudit), buffer, size); |
| 2234 | case TPM_ST_ATTEST_SESSION_AUDIT: |
| 2235 | return TPMS_SESSION_AUDIT_INFO_Marshal((TPMS_SESSION_AUDIT_INFO *)&(source->sessionAudit), buffer, size); |
| 2236 | case TPM_ST_ATTEST_TIME: |
| 2237 | return TPMS_TIME_ATTEST_INFO_Marshal((TPMS_TIME_ATTEST_INFO *)&(source->time), buffer, size); |
| 2238 | case TPM_ST_ATTEST_NV: |
| 2239 | return TPMS_NV_CERTIFY_INFO_Marshal((TPMS_NV_CERTIFY_INFO *)&(source->nv), buffer, size); |
| 2240 | } |
| 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | |
| 2245 | // Table 2:120 - Definition of TPMS_ATTEST Structure (StructureTable) |
| 2246 | // TPMS_ATTEST_Unmarshal not referenced |
| 2247 | UINT16 |
| 2248 | TPMS_ATTEST_Marshal( |
| 2249 | TPMS_ATTEST *source, BYTE **buffer, INT32 *size |
| 2250 | ) |
| 2251 | { |
| 2252 | UINT16 result = 0; |
| 2253 | result = (UINT16)(result + TPM_GENERATED_Marshal((TPM_GENERATED *)&(source->magic), buffer, size)); |
| 2254 | result = (UINT16)(result + TPMI_ST_ATTEST_Marshal((TPMI_ST_ATTEST *)&(source->type), buffer, size)); |
| 2255 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->qualifiedSigner), buffer, size)); |
| 2256 | result = (UINT16)(result + TPM2B_DATA_Marshal((TPM2B_DATA *)&(source->extraData), buffer, size)); |
| 2257 | result = (UINT16)(result + TPMS_CLOCK_INFO_Marshal((TPMS_CLOCK_INFO *)&(source->clockInfo), buffer, size)); |
| 2258 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->firmwareVersion), buffer, size)); |
| 2259 | result = (UINT16)(result + TPMU_ATTEST_Marshal((TPMU_ATTEST *)&(source->attested), buffer, size, (UINT32)source->type)); |
| 2260 | return result; |
| 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | // Table 2:121 - Definition of TPM2B_ATTEST Structure (StructureTable) |
| 2265 | // TPM2B_ATTEST_Unmarshal not referenced |
| 2266 | UINT16 |
| 2267 | TPM2B_ATTEST_Marshal( |
| 2268 | TPM2B_ATTEST *source, BYTE **buffer, INT32 *size |
| 2269 | ) |
| 2270 | { |
| 2271 | UINT16 result = 0; |
| 2272 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 2273 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 2274 | if(source->t.size == 0) |
| 2275 | return result; |
| 2276 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.attestationData), buffer, size, (INT32)(source->t.size))); |
| 2277 | return result; |
| 2278 | } |
| 2279 | |
| 2280 | |
| 2281 | // Table 2:122 - Definition of TPMS_AUTH_COMMAND Structure (StructureTable) |
| 2282 | // TPMS_AUTH_COMMAND_Unmarshal not referenced |
| 2283 | // TPMS_AUTH_COMMAND_Marshal not referenced |
| 2284 | |
| 2285 | |
| 2286 | // Table 2:123 - Definition of TPMS_AUTH_RESPONSE Structure (StructureTable) |
| 2287 | // TPMS_AUTH_RESPONSE_Unmarshal not referenced |
| 2288 | // TPMS_AUTH_RESPONSE_Marshal not referenced |
| 2289 | |
| 2290 | |
| 2291 | // Table 2:124 - Definition of TPMI_AES_KEY_BITS Type (TypeTable) |
| 2292 | #ifdef TPM_ALG_AES |
| 2293 | TPM_RC |
| 2294 | TPMI_AES_KEY_BITS_Unmarshal( |
| 2295 | TPMI_AES_KEY_BITS *target, BYTE **buffer, INT32 *size |
| 2296 | ) |
| 2297 | { |
| 2298 | TPM_RC result; |
| 2299 | result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size); |
| 2300 | if(result != TPM_RC_SUCCESS) |
| 2301 | return result; |
| 2302 | switch (*target) { |
| 2303 | case 128: |
| 2304 | case 256: |
| 2305 | break; |
| 2306 | default: |
| 2307 | return TPM_RC_VALUE; |
| 2308 | } |
| 2309 | return TPM_RC_SUCCESS; |
| 2310 | } |
| 2311 | |
| 2312 | // TPMI_AES_KEY_BITS_Marshal changed to #define |
| 2313 | #endif // TPM_ALG_AES |
| 2314 | |
| 2315 | |
| 2316 | // Table 2:124 - Definition of TPMI_SM4_KEY_BITS Type (TypeTable) |
| 2317 | #ifdef TPM_ALG_SM4 |
| 2318 | TPM_RC |
| 2319 | TPMI_SM4_KEY_BITS_Unmarshal( |
| 2320 | TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *size |
| 2321 | ) |
| 2322 | { |
| 2323 | TPM_RC result; |
| 2324 | result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size); |
| 2325 | if(result != TPM_RC_SUCCESS) |
| 2326 | return result; |
| 2327 | switch (*target) { |
| 2328 | case 128: |
| 2329 | break; |
| 2330 | default: |
| 2331 | return TPM_RC_VALUE; |
| 2332 | } |
| 2333 | return TPM_RC_SUCCESS; |
| 2334 | } |
| 2335 | |
| 2336 | // TPMI_SM4_KEY_BITS_Marshal changed to #define |
| 2337 | #endif // TPM_ALG_SM4 |
| 2338 | |
| 2339 | |
| 2340 | // Table 2:124 - Definition of TPMI_CAMELLIA_KEY_BITS Type (TypeTable) |
| 2341 | #ifdef TPM_ALG_CAMELLIA |
| 2342 | TPM_RC |
| 2343 | TPMI_CAMELLIA_KEY_BITS_Unmarshal( |
| 2344 | TPMI_CAMELLIA_KEY_BITS *target, BYTE **buffer, INT32 *size |
| 2345 | ) |
| 2346 | { |
| 2347 | TPM_RC result; |
| 2348 | result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size); |
| 2349 | if(result != TPM_RC_SUCCESS) |
| 2350 | return result; |
| 2351 | switch (*target) { |
| 2352 | case 128: |
| 2353 | break; |
| 2354 | default: |
| 2355 | return TPM_RC_VALUE; |
| 2356 | } |
| 2357 | return TPM_RC_SUCCESS; |
| 2358 | } |
| 2359 | |
| 2360 | // TPMI_CAMELLIA_KEY_BITS_Marshal changed to #define |
| 2361 | #endif // TPM_ALG_CAMELLIA |
| 2362 | |
| 2363 | |
| 2364 | // Table 2:125 - Definition of TPMU_SYM_KEY_BITS Union (UnionTable) |
| 2365 | TPM_RC |
| 2366 | TPMU_SYM_KEY_BITS_Unmarshal( |
| 2367 | TPMU_SYM_KEY_BITS *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 2368 | ) |
| 2369 | { |
| 2370 | switch(selector) { |
| 2371 | #ifdef TPM_ALG_AES |
| 2372 | case TPM_ALG_AES: |
| 2373 | return TPMI_AES_KEY_BITS_Unmarshal((TPMI_AES_KEY_BITS *)&(target->aes), buffer, size); |
| 2374 | #endif // TPM_ALG_AES |
| 2375 | #ifdef TPM_ALG_SM4 |
| 2376 | case TPM_ALG_SM4: |
| 2377 | return TPMI_SM4_KEY_BITS_Unmarshal((TPMI_SM4_KEY_BITS *)&(target->sm4), buffer, size); |
| 2378 | #endif // TPM_ALG_SM4 |
| 2379 | #ifdef TPM_ALG_CAMELLIA |
| 2380 | case TPM_ALG_CAMELLIA: |
| 2381 | return TPMI_CAMELLIA_KEY_BITS_Unmarshal((TPMI_CAMELLIA_KEY_BITS *)&(target->camellia), buffer, size); |
| 2382 | #endif // TPM_ALG_CAMELLIA |
| 2383 | #ifdef TPM_ALG_XOR |
| 2384 | case TPM_ALG_XOR: |
| 2385 | return TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->exclusiveOr |
| 2386 | ), buffer, size, 0); |
| 2387 | #endif // TPM_ALG_XOR |
| 2388 | case TPM_ALG_NULL: |
| 2389 | return TPM_RC_SUCCESS; |
| 2390 | } |
| 2391 | return TPM_RC_SELECTOR; |
| 2392 | } |
| 2393 | |
| 2394 | UINT16 |
| 2395 | TPMU_SYM_KEY_BITS_Marshal( |
| 2396 | TPMU_SYM_KEY_BITS *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2397 | ) |
| 2398 | { |
| 2399 | switch(selector) { |
| 2400 | #ifdef TPM_ALG_AES |
| 2401 | case TPM_ALG_AES: |
| 2402 | return TPMI_AES_KEY_BITS_Marshal((TPMI_AES_KEY_BITS *)&(source->aes), buffer, size); |
| 2403 | #endif // TPM_ALG_AES |
| 2404 | #ifdef TPM_ALG_SM4 |
| 2405 | case TPM_ALG_SM4: |
| 2406 | return TPMI_SM4_KEY_BITS_Marshal((TPMI_SM4_KEY_BITS *)&(source->sm4), buffer, size); |
| 2407 | #endif // TPM_ALG_SM4 |
| 2408 | #ifdef TPM_ALG_CAMELLIA |
| 2409 | case TPM_ALG_CAMELLIA: |
| 2410 | return TPMI_CAMELLIA_KEY_BITS_Marshal((TPMI_CAMELLIA_KEY_BITS *)&(source->camellia), buffer, size); |
| 2411 | #endif // TPM_ALG_CAMELLIA |
| 2412 | #ifdef TPM_ALG_XOR |
| 2413 | case TPM_ALG_XOR: |
| 2414 | return TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->exclusiveOr |
| 2415 | ), buffer, size); |
| 2416 | #endif // TPM_ALG_XOR |
| 2417 | case TPM_ALG_NULL: |
| 2418 | return 0; |
| 2419 | } |
| 2420 | return 0; |
| 2421 | } |
| 2422 | |
| 2423 | |
| 2424 | // Table 2:126 - Definition of TPMU_SYM_MODE Union (UnionTable) |
| 2425 | TPM_RC |
| 2426 | TPMU_SYM_MODE_Unmarshal( |
| 2427 | TPMU_SYM_MODE *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 2428 | ) |
| 2429 | { |
| 2430 | switch(selector) { |
| 2431 | #ifdef TPM_ALG_AES |
| 2432 | case TPM_ALG_AES: |
| 2433 | return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->aes), buffer, size, 1); |
| 2434 | #endif // TPM_ALG_AES |
| 2435 | #ifdef TPM_ALG_SM4 |
| 2436 | case TPM_ALG_SM4: |
| 2437 | return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->sm4), buffer, size, 1); |
| 2438 | #endif // TPM_ALG_SM4 |
| 2439 | #ifdef TPM_ALG_CAMELLIA |
| 2440 | case TPM_ALG_CAMELLIA: |
| 2441 | return TPMI_ALG_SYM_MODE_Unmarshal((TPMI_ALG_SYM_MODE *)&(target->camellia), buffer, size, 1); |
| 2442 | #endif // TPM_ALG_CAMELLIA |
| 2443 | #ifdef TPM_ALG_XOR |
| 2444 | case TPM_ALG_XOR: |
| 2445 | return TPM_RC_SUCCESS; |
| 2446 | #endif // TPM_ALG_XOR |
| 2447 | case TPM_ALG_NULL: |
| 2448 | return TPM_RC_SUCCESS; |
| 2449 | } |
| 2450 | return TPM_RC_SELECTOR; |
| 2451 | } |
| 2452 | |
| 2453 | UINT16 |
| 2454 | TPMU_SYM_MODE_Marshal( |
| 2455 | TPMU_SYM_MODE *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2456 | ) |
| 2457 | { |
| 2458 | switch(selector) { |
| 2459 | #ifdef TPM_ALG_AES |
| 2460 | case TPM_ALG_AES: |
| 2461 | return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->aes), buffer, size); |
| 2462 | #endif // TPM_ALG_AES |
| 2463 | #ifdef TPM_ALG_SM4 |
| 2464 | case TPM_ALG_SM4: |
| 2465 | return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->sm4), buffer, size); |
| 2466 | #endif // TPM_ALG_SM4 |
| 2467 | #ifdef TPM_ALG_CAMELLIA |
| 2468 | case TPM_ALG_CAMELLIA: |
| 2469 | return TPMI_ALG_SYM_MODE_Marshal((TPMI_ALG_SYM_MODE *)&(source->camellia), buffer, size); |
| 2470 | #endif // TPM_ALG_CAMELLIA |
| 2471 | #ifdef TPM_ALG_XOR |
| 2472 | case TPM_ALG_XOR: |
| 2473 | return 0; |
| 2474 | #endif // TPM_ALG_XOR |
| 2475 | case TPM_ALG_NULL: |
| 2476 | return 0; |
| 2477 | } |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | // Table 2:128 - Definition of TPMT_SYM_DEF Structure (StructureTable) |
| 2483 | TPM_RC |
| 2484 | TPMT_SYM_DEF_Unmarshal( |
| 2485 | TPMT_SYM_DEF *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2486 | ) |
| 2487 | { |
| 2488 | TPM_RC result; |
| 2489 | result = TPMI_ALG_SYM_Unmarshal((TPMI_ALG_SYM *)&(target->algorithm), buffer, size, flag); |
| 2490 | if(result != TPM_RC_SUCCESS) |
| 2491 | return result; |
| 2492 | result = TPMU_SYM_KEY_BITS_Unmarshal((TPMU_SYM_KEY_BITS *)&(target->keyBits), buffer, size, (UINT32)target->algorithm); |
| 2493 | if(result != TPM_RC_SUCCESS) |
| 2494 | return result; |
| 2495 | result = TPMU_SYM_MODE_Unmarshal((TPMU_SYM_MODE *)&(target->mode), buffer, size, (UINT32)target->algorithm); |
| 2496 | return result; |
| 2497 | } |
| 2498 | |
| 2499 | // TPMT_SYM_DEF_Marshal not referenced |
| 2500 | |
| 2501 | |
| 2502 | // Table 2:129 - Definition of TPMT_SYM_DEF_OBJECT Structure (StructureTable) |
| 2503 | TPM_RC |
| 2504 | TPMT_SYM_DEF_OBJECT_Unmarshal( |
| 2505 | TPMT_SYM_DEF_OBJECT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2506 | ) |
| 2507 | { |
| 2508 | TPM_RC result; |
| 2509 | result = TPMI_ALG_SYM_OBJECT_Unmarshal((TPMI_ALG_SYM_OBJECT *)&(target->algorithm), buffer, size, flag); |
| 2510 | if(result != TPM_RC_SUCCESS) |
| 2511 | return result; |
| 2512 | result = TPMU_SYM_KEY_BITS_Unmarshal((TPMU_SYM_KEY_BITS *)&(target->keyBits), buffer, size, (UINT32)target->algorithm); |
| 2513 | if(result != TPM_RC_SUCCESS) |
| 2514 | return result; |
| 2515 | result = TPMU_SYM_MODE_Unmarshal((TPMU_SYM_MODE *)&(target->mode), buffer, size, (UINT32)target->algorithm); |
| 2516 | return result; |
| 2517 | } |
| 2518 | |
| 2519 | UINT16 |
| 2520 | TPMT_SYM_DEF_OBJECT_Marshal( |
| 2521 | TPMT_SYM_DEF_OBJECT *source, BYTE **buffer, INT32 *size |
| 2522 | ) |
| 2523 | { |
| 2524 | UINT16 result = 0; |
| 2525 | result = (UINT16)(result + TPMI_ALG_SYM_OBJECT_Marshal((TPMI_ALG_SYM_OBJECT *)&(source->algorithm), buffer, size)); |
| 2526 | result = (UINT16)(result + TPMU_SYM_KEY_BITS_Marshal((TPMU_SYM_KEY_BITS *)&(source->keyBits), buffer, size, (UINT32)source->algorithm)); |
| 2527 | result = (UINT16)(result + TPMU_SYM_MODE_Marshal((TPMU_SYM_MODE *)&(source->mode), buffer, size, (UINT32)source->algorithm)); |
| 2528 | return result; |
| 2529 | } |
| 2530 | |
| 2531 | |
| 2532 | // Table 2:130 - Definition of TPM2B_SYM_KEY Structure (StructureTable) |
| 2533 | TPM_RC |
| 2534 | TPM2B_SYM_KEY_Unmarshal( |
| 2535 | TPM2B_SYM_KEY *target, BYTE **buffer, INT32 *size |
| 2536 | ) |
| 2537 | { |
| 2538 | TPM_RC result; |
| 2539 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 2540 | if(result != TPM_RC_SUCCESS) |
| 2541 | return result; |
| 2542 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 2543 | if(target->t.size == 0) |
| 2544 | return TPM_RC_SUCCESS; |
| 2545 | if((target->t.size) > MAX_SYM_KEY_BYTES) |
| 2546 | return TPM_RC_SIZE; |
| 2547 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 2548 | return result; |
| 2549 | } |
| 2550 | |
| 2551 | UINT16 |
| 2552 | TPM2B_SYM_KEY_Marshal( |
| 2553 | TPM2B_SYM_KEY *source, BYTE **buffer, INT32 *size |
| 2554 | ) |
| 2555 | { |
| 2556 | UINT16 result = 0; |
| 2557 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 2558 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 2559 | if(source->t.size == 0) |
| 2560 | return result; |
| 2561 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 2562 | return result; |
| 2563 | } |
| 2564 | |
| 2565 | |
| 2566 | // Table 2:131 - Definition of TPMS_SYMCIPHER_PARMS Structure (StructureTable) |
| 2567 | // TPMS_SYMCIPHER_PARMS_Unmarshal changed to #define |
| 2568 | // TPMS_SYMCIPHER_PARMS_Marshal changed to #define |
| 2569 | |
| 2570 | |
| 2571 | // Table 2:132 - Definition of TPM2B_SENSITIVE_DATA Structure (StructureTable) |
| 2572 | TPM_RC |
| 2573 | TPM2B_SENSITIVE_DATA_Unmarshal( |
| 2574 | TPM2B_SENSITIVE_DATA *target, BYTE **buffer, INT32 *size |
| 2575 | ) |
| 2576 | { |
| 2577 | TPM_RC result; |
| 2578 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 2579 | if(result != TPM_RC_SUCCESS) |
| 2580 | return result; |
| 2581 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 2582 | if(target->t.size == 0) |
| 2583 | return TPM_RC_SUCCESS; |
| 2584 | if((target->t.size) > MAX_SYM_DATA) |
| 2585 | return TPM_RC_SIZE; |
| 2586 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 2587 | return result; |
| 2588 | } |
| 2589 | |
| 2590 | UINT16 |
| 2591 | TPM2B_SENSITIVE_DATA_Marshal( |
| 2592 | TPM2B_SENSITIVE_DATA *source, BYTE **buffer, INT32 *size |
| 2593 | ) |
| 2594 | { |
| 2595 | UINT16 result = 0; |
| 2596 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 2597 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 2598 | if(source->t.size == 0) |
| 2599 | return result; |
| 2600 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 2601 | return result; |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | // Table 2:133 - Definition of TPMS_SENSITIVE_CREATE Structure (StructureTable) |
| 2606 | TPM_RC |
| 2607 | TPMS_SENSITIVE_CREATE_Unmarshal( |
| 2608 | TPMS_SENSITIVE_CREATE *target, BYTE **buffer, INT32 *size |
| 2609 | ) |
| 2610 | { |
| 2611 | TPM_RC result; |
| 2612 | result = TPM2B_AUTH_Unmarshal((TPM2B_AUTH *)&(target->userAuth), buffer, size); |
| 2613 | if(result != TPM_RC_SUCCESS) |
| 2614 | return result; |
| 2615 | result = TPM2B_SENSITIVE_DATA_Unmarshal((TPM2B_SENSITIVE_DATA *)&(target->data), buffer, size); |
| 2616 | return result; |
| 2617 | } |
| 2618 | |
| 2619 | // TPMS_SENSITIVE_CREATE_Marshal not referenced |
| 2620 | |
| 2621 | |
| 2622 | // Table 2:134 - Definition of TPM2B_SENSITIVE_CREATE Structure (StructureTable) |
| 2623 | TPM_RC |
| 2624 | TPM2B_SENSITIVE_CREATE_Unmarshal( |
| 2625 | TPM2B_SENSITIVE_CREATE *target, BYTE **buffer, INT32 *size |
| 2626 | ) |
| 2627 | { |
| 2628 | TPM_RC result; |
| 2629 | INT32 startSize; |
| 2630 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 2631 | if(result != TPM_RC_SUCCESS) |
| 2632 | return result; |
| 2633 | // if size is zero, then the required structure is missing |
| 2634 | if(target->t.size == 0) |
| 2635 | return TPM_RC_SIZE; |
| 2636 | startSize = *size; |
| 2637 | result = TPMS_SENSITIVE_CREATE_Unmarshal((TPMS_SENSITIVE_CREATE *)&(target->t.sensitive), buffer, size); |
| 2638 | if(result != TPM_RC_SUCCESS) |
| 2639 | return result; |
| 2640 | if(target->t.size != (startSize - *size)) return TPM_RC_SIZE; |
| 2641 | return TPM_RC_SUCCESS; |
| 2642 | } |
| 2643 | |
| 2644 | // TPM2B_SENSITIVE_CREATE_Marshal not referenced |
| 2645 | |
| 2646 | |
| 2647 | // Table 2:135 - Definition of TPMS_SCHEME_HASH Structure (StructureTable) |
| 2648 | // TPMS_SCHEME_HASH_Unmarshal changed to #define |
| 2649 | // TPMS_SCHEME_HASH_Marshal changed to #define |
| 2650 | |
| 2651 | |
| 2652 | // Table 2:136 - Definition of TPMS_SCHEME_ECDAA Structure (StructureTable) |
| 2653 | #ifdef TPM_ALG_ECC |
| 2654 | TPM_RC |
| 2655 | TPMS_SCHEME_ECDAA_Unmarshal( |
| 2656 | TPMS_SCHEME_ECDAA *target, BYTE **buffer, INT32 *size |
| 2657 | ) |
| 2658 | { |
| 2659 | TPM_RC result; |
| 2660 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, 0); |
| 2661 | if(result != TPM_RC_SUCCESS) |
| 2662 | return result; |
| 2663 | result = UINT16_Unmarshal((UINT16 *)&(target->count), buffer, size); |
| 2664 | return result; |
| 2665 | } |
| 2666 | |
| 2667 | UINT16 |
| 2668 | TPMS_SCHEME_ECDAA_Marshal( |
| 2669 | TPMS_SCHEME_ECDAA *source, BYTE **buffer, INT32 *size |
| 2670 | ) |
| 2671 | { |
| 2672 | UINT16 result = 0; |
| 2673 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size)); |
| 2674 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->count), buffer, size)); |
| 2675 | return result; |
| 2676 | } |
| 2677 | |
| 2678 | #endif // TPM_ALG_ECC |
| 2679 | |
| 2680 | |
| 2681 | // Table 2:137 - Definition of TPMI_ALG_KEYEDHASH_SCHEME Type (TypeTable) |
| 2682 | TPM_RC |
| 2683 | TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal( |
| 2684 | TPMI_ALG_KEYEDHASH_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2685 | ) |
| 2686 | { |
| 2687 | TPM_RC result; |
| 2688 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 2689 | if(result != TPM_RC_SUCCESS) |
| 2690 | return result; |
| 2691 | switch (*target) { |
| 2692 | #ifdef TPM_ALG_HMAC |
| 2693 | case TPM_ALG_HMAC: |
| 2694 | #endif // TPM_ALG_HMAC |
| 2695 | #ifdef TPM_ALG_XOR |
| 2696 | case TPM_ALG_XOR: |
| 2697 | #endif // TPM_ALG_XOR |
| 2698 | break; |
| 2699 | case TPM_ALG_NULL: |
| 2700 | if (flag) |
| 2701 | break; |
| 2702 | return TPM_RC_VALUE; |
| 2703 | default: |
| 2704 | return TPM_RC_VALUE; |
| 2705 | } |
| 2706 | return TPM_RC_SUCCESS; |
| 2707 | } |
| 2708 | |
| 2709 | // TPMI_ALG_KEYEDHASH_SCHEME_Marshal changed to #define |
| 2710 | |
| 2711 | |
| 2712 | // Table 2:138 - Definition of Types for HMAC_SIG_SCHEME (TypesTable) |
| 2713 | // TPMS_SCHEME_HASH definition from table 2:138 |
| 2714 | // TPMS_SCHEME_HMAC_Unmarshal changed to #define |
| 2715 | // TPMS_SCHEME_HMAC_Marshal changed to #define |
| 2716 | |
| 2717 | |
| 2718 | // Table 2:139 - Definition of TPMS_SCHEME_XOR Structure (StructureTable) |
| 2719 | TPM_RC |
| 2720 | TPMS_SCHEME_XOR_Unmarshal( |
| 2721 | TPMS_SCHEME_XOR *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2722 | ) |
| 2723 | { |
| 2724 | TPM_RC result; |
| 2725 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hashAlg), buffer, size, flag); |
| 2726 | if(result != TPM_RC_SUCCESS) |
| 2727 | return result; |
| 2728 | result = TPMI_ALG_KDF_Unmarshal((TPMI_ALG_KDF *)&(target->kdf), buffer, size, 1); |
| 2729 | return result; |
| 2730 | } |
| 2731 | |
| 2732 | UINT16 |
| 2733 | TPMS_SCHEME_XOR_Marshal( |
| 2734 | TPMS_SCHEME_XOR *source, BYTE **buffer, INT32 *size |
| 2735 | ) |
| 2736 | { |
| 2737 | UINT16 result = 0; |
| 2738 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hashAlg), buffer, size)); |
| 2739 | result = (UINT16)(result + TPMI_ALG_KDF_Marshal((TPMI_ALG_KDF *)&(source->kdf), buffer, size)); |
| 2740 | return result; |
| 2741 | } |
| 2742 | |
| 2743 | |
| 2744 | // Table 2:140 - Definition of TPMU_SCHEME_KEYEDHASH Union (UnionTable) |
| 2745 | TPM_RC |
| 2746 | TPMU_SCHEME_KEYEDHASH_Unmarshal( |
| 2747 | TPMU_SCHEME_KEYEDHASH *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 2748 | ) |
| 2749 | { |
| 2750 | switch(selector) { |
| 2751 | #ifdef TPM_ALG_HMAC |
| 2752 | case TPM_ALG_HMAC: |
| 2753 | return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC *)&(target->hmac), buffer, size); |
| 2754 | #endif // TPM_ALG_HMAC |
| 2755 | #ifdef TPM_ALG_XOR |
| 2756 | case TPM_ALG_XOR: |
| 2757 | return TPMS_SCHEME_XOR_Unmarshal((TPMS_SCHEME_XOR *)&(target->exclusiveOr |
| 2758 | ), buffer, size, 1); |
| 2759 | #endif // TPM_ALG_XOR |
| 2760 | case TPM_ALG_NULL: |
| 2761 | return TPM_RC_SUCCESS; |
| 2762 | } |
| 2763 | return TPM_RC_SELECTOR; |
| 2764 | } |
| 2765 | |
| 2766 | UINT16 |
| 2767 | TPMU_SCHEME_KEYEDHASH_Marshal( |
| 2768 | TPMU_SCHEME_KEYEDHASH *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2769 | ) |
| 2770 | { |
| 2771 | switch(selector) { |
| 2772 | #ifdef TPM_ALG_HMAC |
| 2773 | case TPM_ALG_HMAC: |
| 2774 | return TPMS_SCHEME_HMAC_Marshal((TPMS_SCHEME_HMAC *)&(source->hmac), buffer, size); |
| 2775 | #endif // TPM_ALG_HMAC |
| 2776 | #ifdef TPM_ALG_XOR |
| 2777 | case TPM_ALG_XOR: |
| 2778 | return TPMS_SCHEME_XOR_Marshal((TPMS_SCHEME_XOR *)&(source->exclusiveOr |
| 2779 | ), buffer, size); |
| 2780 | #endif // TPM_ALG_XOR |
| 2781 | case TPM_ALG_NULL: |
| 2782 | return 0; |
| 2783 | } |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
| 2787 | |
| 2788 | // Table 2:141 - Definition of TPMT_KEYEDHASH_SCHEME Structure (StructureTable) |
| 2789 | TPM_RC |
| 2790 | TPMT_KEYEDHASH_SCHEME_Unmarshal( |
| 2791 | TPMT_KEYEDHASH_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2792 | ) |
| 2793 | { |
| 2794 | TPM_RC result; |
| 2795 | result = TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal((TPMI_ALG_KEYEDHASH_SCHEME *)&(target->scheme), buffer, size, flag); |
| 2796 | if(result != TPM_RC_SUCCESS) |
| 2797 | return result; |
| 2798 | result = TPMU_SCHEME_KEYEDHASH_Unmarshal((TPMU_SCHEME_KEYEDHASH *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 2799 | return result; |
| 2800 | } |
| 2801 | |
| 2802 | UINT16 |
| 2803 | TPMT_KEYEDHASH_SCHEME_Marshal( |
| 2804 | TPMT_KEYEDHASH_SCHEME *source, BYTE **buffer, INT32 *size |
| 2805 | ) |
| 2806 | { |
| 2807 | UINT16 result = 0; |
| 2808 | result = (UINT16)(result + TPMI_ALG_KEYEDHASH_SCHEME_Marshal((TPMI_ALG_KEYEDHASH_SCHEME *)&(source->scheme), buffer, size)); |
| 2809 | result = (UINT16)(result + TPMU_SCHEME_KEYEDHASH_Marshal((TPMU_SCHEME_KEYEDHASH *)&(source->details), buffer, size, (UINT32)source->scheme)); |
| 2810 | return result; |
| 2811 | } |
| 2812 | |
| 2813 | |
| 2814 | // Table 2:142 - Definition of Types for RSA Signature Schemes (TypesTable) |
| 2815 | #ifdef TPM_ALG_RSA |
| 2816 | // TPMS_SCHEME_HASH definition from table 2:142 |
| 2817 | #ifdef TPM_ALG_RSA |
| 2818 | // TPMS_SIG_SCHEME_RSASSA_Unmarshal changed to #define |
| 2819 | // TPMS_SIG_SCHEME_RSASSA_Marshal changed to #define |
| 2820 | #endif // TPM_ALG_RSA |
| 2821 | // TPMS_SCHEME_HASH definition from table 2:142 |
| 2822 | #ifdef TPM_ALG_RSA |
| 2823 | // TPMS_SIG_SCHEME_RSAPSS_Unmarshal changed to #define |
| 2824 | // TPMS_SIG_SCHEME_RSAPSS_Marshal changed to #define |
| 2825 | #endif // TPM_ALG_RSA |
| 2826 | #endif // TPM_ALG_RSA |
| 2827 | |
| 2828 | |
| 2829 | // Table 2:143 - Definition of Types for ECC Signature Schemes (TypesTable) |
| 2830 | #ifdef TPM_ALG_ECC |
| 2831 | // TPMS_SCHEME_HASH definition from table 2:143 |
| 2832 | #ifdef TPM_ALG_ECC |
| 2833 | // TPMS_SIG_SCHEME_ECDSA_Unmarshal changed to #define |
| 2834 | // TPMS_SIG_SCHEME_ECDSA_Marshal changed to #define |
| 2835 | #endif // TPM_ALG_ECC |
| 2836 | // TPMS_SCHEME_HASH definition from table 2:143 |
| 2837 | #ifdef TPM_ALG_ECC |
| 2838 | // TPMS_SIG_SCHEME_SM2_Unmarshal changed to #define |
| 2839 | // TPMS_SIG_SCHEME_SM2_Marshal changed to #define |
| 2840 | #endif // TPM_ALG_ECC |
| 2841 | // TPMS_SCHEME_HASH definition from table 2:143 |
| 2842 | #ifdef TPM_ALG_ECC |
| 2843 | // TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal changed to #define |
| 2844 | // TPMS_SIG_SCHEME_ECSCHNORR_Marshal changed to #define |
| 2845 | #endif // TPM_ALG_ECC |
| 2846 | // TPMS_SCHEME_ECDAA definition from table 2:143 |
| 2847 | #ifdef TPM_ALG_ECC |
| 2848 | // TPMS_SIG_SCHEME_ECDAA_Unmarshal changed to #define |
| 2849 | // TPMS_SIG_SCHEME_ECDAA_Marshal changed to #define |
| 2850 | #endif // TPM_ALG_ECC |
| 2851 | #endif // TPM_ALG_ECC |
| 2852 | |
| 2853 | |
| 2854 | // Table 2:144 - Definition of TPMU_SIG_SCHEME Union (UnionTable) |
| 2855 | TPM_RC |
| 2856 | TPMU_SIG_SCHEME_Unmarshal( |
| 2857 | TPMU_SIG_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 2858 | ) |
| 2859 | { |
| 2860 | switch(selector) { |
| 2861 | #ifdef TPM_ALG_RSASSA |
| 2862 | case TPM_ALG_RSASSA: |
| 2863 | return TPMS_SIG_SCHEME_RSASSA_Unmarshal((TPMS_SIG_SCHEME_RSASSA *)&(target->rsassa), buffer, size); |
| 2864 | #endif // TPM_ALG_RSASSA |
| 2865 | #ifdef TPM_ALG_RSAPSS |
| 2866 | case TPM_ALG_RSAPSS: |
| 2867 | return TPMS_SIG_SCHEME_RSAPSS_Unmarshal((TPMS_SIG_SCHEME_RSAPSS *)&(target->rsapss), buffer, size); |
| 2868 | #endif // TPM_ALG_RSAPSS |
| 2869 | #ifdef TPM_ALG_ECDSA |
| 2870 | case TPM_ALG_ECDSA: |
| 2871 | return TPMS_SIG_SCHEME_ECDSA_Unmarshal((TPMS_SIG_SCHEME_ECDSA *)&(target->ecdsa), buffer, size); |
| 2872 | #endif // TPM_ALG_ECDSA |
| 2873 | #ifdef TPM_ALG_SM2 |
| 2874 | case TPM_ALG_SM2: |
| 2875 | return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2 *)&(target->sm2), buffer, size); |
| 2876 | #endif // TPM_ALG_SM2 |
| 2877 | #ifdef TPM_ALG_ECSCHNORR |
| 2878 | case TPM_ALG_ECSCHNORR: |
| 2879 | return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(target->ecschnorr), buffer, size); |
| 2880 | #endif // TPM_ALG_ECSCHNORR |
| 2881 | #ifdef TPM_ALG_ECDAA |
| 2882 | case TPM_ALG_ECDAA: |
| 2883 | return TPMS_SIG_SCHEME_ECDAA_Unmarshal((TPMS_SIG_SCHEME_ECDAA *)&(target->ecdaa), buffer, size); |
| 2884 | #endif // TPM_ALG_ECDAA |
| 2885 | #ifdef TPM_ALG_HMAC |
| 2886 | case TPM_ALG_HMAC: |
| 2887 | return TPMS_SCHEME_HMAC_Unmarshal((TPMS_SCHEME_HMAC *)&(target->hmac), buffer, size); |
| 2888 | #endif // TPM_ALG_HMAC |
| 2889 | case TPM_ALG_NULL: |
| 2890 | return TPM_RC_SUCCESS; |
| 2891 | } |
| 2892 | return TPM_RC_SELECTOR; |
| 2893 | } |
| 2894 | |
| 2895 | // TPMU_SIG_SCHEME_Marshal not referenced |
| 2896 | |
| 2897 | |
| 2898 | // Table 2:145 - Definition of TPMT_SIG_SCHEME Structure (StructureTable) |
| 2899 | TPM_RC |
| 2900 | TPMT_SIG_SCHEME_Unmarshal( |
| 2901 | TPMT_SIG_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 2902 | ) |
| 2903 | { |
| 2904 | TPM_RC result; |
| 2905 | result = TPMI_ALG_SIG_SCHEME_Unmarshal((TPMI_ALG_SIG_SCHEME *)&(target->scheme), buffer, size, flag); |
| 2906 | if(result != TPM_RC_SUCCESS) |
| 2907 | return result; |
| 2908 | result = TPMU_SIG_SCHEME_Unmarshal((TPMU_SIG_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 2909 | return result; |
| 2910 | } |
| 2911 | |
| 2912 | // TPMT_SIG_SCHEME_Marshal not referenced |
| 2913 | |
| 2914 | |
| 2915 | // Table 2:146 - Definition of Types for Encryption Schemes (TypesTable) |
| 2916 | #ifdef TPM_ALG_RSA |
| 2917 | // TPMS_SCHEME_HASH definition from table 2:146 |
| 2918 | #ifdef TPM_ALG_RSA |
| 2919 | // TPMS_ENC_SCHEME_OAEP_Unmarshal changed to #define |
| 2920 | // TPMS_ENC_SCHEME_OAEP_Marshal changed to #define |
| 2921 | #endif // TPM_ALG_RSA |
| 2922 | // TPMS_EMPTY definition from table 2:146 |
| 2923 | #ifdef TPM_ALG_RSA |
| 2924 | // TPMS_ENC_SCHEME_RSAES_Unmarshal changed to #define |
| 2925 | // TPMS_ENC_SCHEME_RSAES_Marshal changed to #define |
| 2926 | #endif // TPM_ALG_RSA |
| 2927 | #endif // TPM_ALG_RSA |
| 2928 | |
| 2929 | |
| 2930 | // Table 2:147 - Definition of Types for ECC Key Exchange (TypesTable) |
| 2931 | #ifdef TPM_ALG_ECC |
| 2932 | // TPMS_SCHEME_HASH definition from table 2:147 |
| 2933 | #ifdef TPM_ALG_ECC |
| 2934 | // TPMS_KEY_SCHEME_ECDH_Unmarshal changed to #define |
| 2935 | // TPMS_KEY_SCHEME_ECDH_Marshal changed to #define |
| 2936 | #endif // TPM_ALG_ECC |
| 2937 | // TPMS_SCHEME_HASH definition from table 2:147 |
| 2938 | #ifdef TPM_ALG_ECC |
| 2939 | // TPMS_KEY_SCHEME_ECMQV_Unmarshal changed to #define |
| 2940 | // TPMS_KEY_SCHEME_ECMQV_Marshal changed to #define |
| 2941 | #endif // TPM_ALG_ECC |
| 2942 | #endif // TPM_ALG_ECC |
| 2943 | |
| 2944 | |
| 2945 | // Table 2:148 - Definition of Types for KDF Schemes (TypesTable) |
| 2946 | // TPMS_SCHEME_HASH definition from table 2:148 |
| 2947 | // TPMS_SCHEME_MGF1_Unmarshal changed to #define |
| 2948 | // TPMS_SCHEME_MGF1_Marshal changed to #define |
| 2949 | // TPMS_SCHEME_HASH definition from table 2:148 |
| 2950 | // TPMS_SCHEME_KDF1_SP800_56A_Unmarshal changed to #define |
| 2951 | // TPMS_SCHEME_KDF1_SP800_56A_Marshal changed to #define |
| 2952 | // TPMS_SCHEME_HASH definition from table 2:148 |
| 2953 | // TPMS_SCHEME_KDF2_Unmarshal changed to #define |
| 2954 | // TPMS_SCHEME_KDF2_Marshal changed to #define |
| 2955 | // TPMS_SCHEME_HASH definition from table 2:148 |
| 2956 | // TPMS_SCHEME_KDF1_SP800_108_Unmarshal changed to #define |
| 2957 | // TPMS_SCHEME_KDF1_SP800_108_Marshal changed to #define |
| 2958 | |
| 2959 | |
| 2960 | // Table 2:149 - Definition of TPMU_KDF_SCHEME Union (UnionTable) |
| 2961 | TPM_RC |
| 2962 | TPMU_KDF_SCHEME_Unmarshal( |
| 2963 | TPMU_KDF_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 2964 | ) |
| 2965 | { |
| 2966 | switch(selector) { |
| 2967 | #ifdef TPM_ALG_MGF1 |
| 2968 | case TPM_ALG_MGF1: |
| 2969 | return TPMS_SCHEME_MGF1_Unmarshal((TPMS_SCHEME_MGF1 *)&(target->mgf1), buffer, size); |
| 2970 | #endif // TPM_ALG_MGF1 |
| 2971 | #ifdef TPM_ALG_KDF1_SP800_56A |
| 2972 | case TPM_ALG_KDF1_SP800_56A: |
| 2973 | return TPMS_SCHEME_KDF1_SP800_56A_Unmarshal((TPMS_SCHEME_KDF1_SP800_56A *)&(target->kdf1_sp800_56a), buffer, size); |
| 2974 | #endif // TPM_ALG_KDF1_SP800_56A |
| 2975 | #ifdef TPM_ALG_KDF2 |
| 2976 | case TPM_ALG_KDF2: |
| 2977 | return TPMS_SCHEME_KDF2_Unmarshal((TPMS_SCHEME_KDF2 *)&(target->kdf2), buffer, size); |
| 2978 | #endif // TPM_ALG_KDF2 |
| 2979 | #ifdef TPM_ALG_KDF1_SP800_108 |
| 2980 | case TPM_ALG_KDF1_SP800_108: |
| 2981 | return TPMS_SCHEME_KDF1_SP800_108_Unmarshal((TPMS_SCHEME_KDF1_SP800_108 *)&(target->kdf1_sp800_108), buffer, size); |
| 2982 | #endif // TPM_ALG_KDF1_SP800_108 |
| 2983 | case TPM_ALG_NULL: |
| 2984 | return TPM_RC_SUCCESS; |
| 2985 | } |
| 2986 | return TPM_RC_SELECTOR; |
| 2987 | } |
| 2988 | |
| 2989 | UINT16 |
| 2990 | TPMU_KDF_SCHEME_Marshal( |
| 2991 | TPMU_KDF_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 2992 | ) |
| 2993 | { |
| 2994 | switch(selector) { |
| 2995 | #ifdef TPM_ALG_MGF1 |
| 2996 | case TPM_ALG_MGF1: |
| 2997 | return TPMS_SCHEME_MGF1_Marshal((TPMS_SCHEME_MGF1 *)&(source->mgf1), buffer, size); |
| 2998 | #endif // TPM_ALG_MGF1 |
| 2999 | #ifdef TPM_ALG_KDF1_SP800_56A |
| 3000 | case TPM_ALG_KDF1_SP800_56A: |
| 3001 | return TPMS_SCHEME_KDF1_SP800_56A_Marshal((TPMS_SCHEME_KDF1_SP800_56A *)&(source->kdf1_sp800_56a), buffer, size); |
| 3002 | #endif // TPM_ALG_KDF1_SP800_56A |
| 3003 | #ifdef TPM_ALG_KDF2 |
| 3004 | case TPM_ALG_KDF2: |
| 3005 | return TPMS_SCHEME_KDF2_Marshal((TPMS_SCHEME_KDF2 *)&(source->kdf2), buffer, size); |
| 3006 | #endif // TPM_ALG_KDF2 |
| 3007 | #ifdef TPM_ALG_KDF1_SP800_108 |
| 3008 | case TPM_ALG_KDF1_SP800_108: |
| 3009 | return TPMS_SCHEME_KDF1_SP800_108_Marshal((TPMS_SCHEME_KDF1_SP800_108 *)&(source->kdf1_sp800_108), buffer, size); |
| 3010 | #endif // TPM_ALG_KDF1_SP800_108 |
| 3011 | case TPM_ALG_NULL: |
| 3012 | return 0; |
| 3013 | } |
| 3014 | return 0; |
| 3015 | } |
| 3016 | |
| 3017 | |
| 3018 | // Table 2:150 - Definition of TPMT_KDF_SCHEME Structure (StructureTable) |
| 3019 | TPM_RC |
| 3020 | TPMT_KDF_SCHEME_Unmarshal( |
| 3021 | TPMT_KDF_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3022 | ) |
| 3023 | { |
| 3024 | TPM_RC result; |
| 3025 | result = TPMI_ALG_KDF_Unmarshal((TPMI_ALG_KDF *)&(target->scheme), buffer, size, flag); |
| 3026 | if(result != TPM_RC_SUCCESS) |
| 3027 | return result; |
| 3028 | result = TPMU_KDF_SCHEME_Unmarshal((TPMU_KDF_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 3029 | return result; |
| 3030 | } |
| 3031 | |
| 3032 | UINT16 |
| 3033 | TPMT_KDF_SCHEME_Marshal( |
| 3034 | TPMT_KDF_SCHEME *source, BYTE **buffer, INT32 *size |
| 3035 | ) |
| 3036 | { |
| 3037 | UINT16 result = 0; |
| 3038 | result = (UINT16)(result + TPMI_ALG_KDF_Marshal((TPMI_ALG_KDF *)&(source->scheme), buffer, size)); |
| 3039 | result = (UINT16)(result + TPMU_KDF_SCHEME_Marshal((TPMU_KDF_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme)); |
| 3040 | return result; |
| 3041 | } |
| 3042 | |
| 3043 | |
| 3044 | // Table 2:151 - Definition of TPMI_ALG_ASYM_SCHEME Type (TypeTable) |
| 3045 | // TPMI_ALG_ASYM_SCHEME_Unmarshal not referenced |
| 3046 | // TPMI_ALG_ASYM_SCHEME_Marshal not referenced |
| 3047 | |
| 3048 | |
| 3049 | // Table 2:152 - Definition of TPMU_ASYM_SCHEME Union (UnionTable) |
| 3050 | TPM_RC |
| 3051 | TPMU_ASYM_SCHEME_Unmarshal( |
| 3052 | TPMU_ASYM_SCHEME *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 3053 | ) |
| 3054 | { |
| 3055 | switch(selector) { |
| 3056 | #ifdef TPM_ALG_ECDH |
| 3057 | case TPM_ALG_ECDH: |
| 3058 | return TPMS_KEY_SCHEME_ECDH_Unmarshal((TPMS_KEY_SCHEME_ECDH *)&(target->ecdh), buffer, size); |
| 3059 | #endif // TPM_ALG_ECDH |
| 3060 | #ifdef TPM_ALG_ECMQV |
| 3061 | case TPM_ALG_ECMQV: |
| 3062 | return TPMS_KEY_SCHEME_ECMQV_Unmarshal((TPMS_KEY_SCHEME_ECMQV *)&(target->ecmqv), buffer, size); |
| 3063 | #endif // TPM_ALG_ECMQV |
| 3064 | #ifdef TPM_ALG_RSASSA |
| 3065 | case TPM_ALG_RSASSA: |
| 3066 | return TPMS_SIG_SCHEME_RSASSA_Unmarshal((TPMS_SIG_SCHEME_RSASSA *)&(target->rsassa), buffer, size); |
| 3067 | #endif // TPM_ALG_RSASSA |
| 3068 | #ifdef TPM_ALG_RSAPSS |
| 3069 | case TPM_ALG_RSAPSS: |
| 3070 | return TPMS_SIG_SCHEME_RSAPSS_Unmarshal((TPMS_SIG_SCHEME_RSAPSS *)&(target->rsapss), buffer, size); |
| 3071 | #endif // TPM_ALG_RSAPSS |
| 3072 | #ifdef TPM_ALG_ECDSA |
| 3073 | case TPM_ALG_ECDSA: |
| 3074 | return TPMS_SIG_SCHEME_ECDSA_Unmarshal((TPMS_SIG_SCHEME_ECDSA *)&(target->ecdsa), buffer, size); |
| 3075 | #endif // TPM_ALG_ECDSA |
| 3076 | #ifdef TPM_ALG_SM2 |
| 3077 | case TPM_ALG_SM2: |
| 3078 | return TPMS_SIG_SCHEME_SM2_Unmarshal((TPMS_SIG_SCHEME_SM2 *)&(target->sm2), buffer, size); |
| 3079 | #endif // TPM_ALG_SM2 |
| 3080 | #ifdef TPM_ALG_ECSCHNORR |
| 3081 | case TPM_ALG_ECSCHNORR: |
| 3082 | return TPMS_SIG_SCHEME_ECSCHNORR_Unmarshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(target->ecschnorr), buffer, size); |
| 3083 | #endif // TPM_ALG_ECSCHNORR |
| 3084 | #ifdef TPM_ALG_ECDAA |
| 3085 | case TPM_ALG_ECDAA: |
| 3086 | return TPMS_SIG_SCHEME_ECDAA_Unmarshal((TPMS_SIG_SCHEME_ECDAA *)&(target->ecdaa), buffer, size); |
| 3087 | #endif // TPM_ALG_ECDAA |
| 3088 | #ifdef TPM_ALG_OAEP |
| 3089 | case TPM_ALG_OAEP: |
| 3090 | return TPMS_ENC_SCHEME_OAEP_Unmarshal((TPMS_ENC_SCHEME_OAEP *)&(target->oaep), buffer, size); |
| 3091 | #endif // TPM_ALG_OAEP |
| 3092 | #ifdef TPM_ALG_RSAES |
| 3093 | case TPM_ALG_RSAES: |
| 3094 | return TPMS_ENC_SCHEME_RSAES_Unmarshal((TPMS_ENC_SCHEME_RSAES *)&(target->rsaes), buffer, size); |
| 3095 | #endif // TPM_ALG_RSAES |
| 3096 | case TPM_ALG_NULL: |
| 3097 | return TPM_RC_SUCCESS; |
| 3098 | } |
| 3099 | return TPM_RC_SELECTOR; |
| 3100 | } |
| 3101 | |
| 3102 | UINT16 |
| 3103 | TPMU_ASYM_SCHEME_Marshal( |
| 3104 | TPMU_ASYM_SCHEME *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 3105 | ) |
| 3106 | { |
| 3107 | switch(selector) { |
| 3108 | #ifdef TPM_ALG_ECDH |
| 3109 | case TPM_ALG_ECDH: |
| 3110 | return TPMS_KEY_SCHEME_ECDH_Marshal((TPMS_KEY_SCHEME_ECDH *)&(source->ecdh), buffer, size); |
| 3111 | #endif // TPM_ALG_ECDH |
| 3112 | #ifdef TPM_ALG_ECMQV |
| 3113 | case TPM_ALG_ECMQV: |
| 3114 | return TPMS_KEY_SCHEME_ECMQV_Marshal((TPMS_KEY_SCHEME_ECMQV *)&(source->ecmqv), buffer, size); |
| 3115 | #endif // TPM_ALG_ECMQV |
| 3116 | #ifdef TPM_ALG_RSASSA |
| 3117 | case TPM_ALG_RSASSA: |
| 3118 | return TPMS_SIG_SCHEME_RSASSA_Marshal((TPMS_SIG_SCHEME_RSASSA *)&(source->rsassa), buffer, size); |
| 3119 | #endif // TPM_ALG_RSASSA |
| 3120 | #ifdef TPM_ALG_RSAPSS |
| 3121 | case TPM_ALG_RSAPSS: |
| 3122 | return TPMS_SIG_SCHEME_RSAPSS_Marshal((TPMS_SIG_SCHEME_RSAPSS *)&(source->rsapss), buffer, size); |
| 3123 | #endif // TPM_ALG_RSAPSS |
| 3124 | #ifdef TPM_ALG_ECDSA |
| 3125 | case TPM_ALG_ECDSA: |
| 3126 | return TPMS_SIG_SCHEME_ECDSA_Marshal((TPMS_SIG_SCHEME_ECDSA *)&(source->ecdsa), buffer, size); |
| 3127 | #endif // TPM_ALG_ECDSA |
| 3128 | #ifdef TPM_ALG_SM2 |
| 3129 | case TPM_ALG_SM2: |
| 3130 | return TPMS_SIG_SCHEME_SM2_Marshal((TPMS_SIG_SCHEME_SM2 *)&(source->sm2), buffer, size); |
| 3131 | #endif // TPM_ALG_SM2 |
| 3132 | #ifdef TPM_ALG_ECSCHNORR |
| 3133 | case TPM_ALG_ECSCHNORR: |
| 3134 | return TPMS_SIG_SCHEME_ECSCHNORR_Marshal((TPMS_SIG_SCHEME_ECSCHNORR *)&(source->ecschnorr), buffer, size); |
| 3135 | #endif // TPM_ALG_ECSCHNORR |
| 3136 | #ifdef TPM_ALG_ECDAA |
| 3137 | case TPM_ALG_ECDAA: |
| 3138 | return TPMS_SIG_SCHEME_ECDAA_Marshal((TPMS_SIG_SCHEME_ECDAA *)&(source->ecdaa), buffer, size); |
| 3139 | #endif // TPM_ALG_ECDAA |
| 3140 | #ifdef TPM_ALG_OAEP |
| 3141 | case TPM_ALG_OAEP: |
| 3142 | return TPMS_ENC_SCHEME_OAEP_Marshal((TPMS_ENC_SCHEME_OAEP *)&(source->oaep), buffer, size); |
| 3143 | #endif // TPM_ALG_OAEP |
| 3144 | #ifdef TPM_ALG_RSAES |
| 3145 | case TPM_ALG_RSAES: |
| 3146 | return TPMS_ENC_SCHEME_RSAES_Marshal((TPMS_ENC_SCHEME_RSAES *)&(source->rsaes), buffer, size); |
| 3147 | #endif // TPM_ALG_RSAES |
| 3148 | case TPM_ALG_NULL: |
| 3149 | return 0; |
| 3150 | } |
| 3151 | return 0; |
| 3152 | } |
| 3153 | |
| 3154 | |
| 3155 | // Table 2:153 - Definition of TPMT_ASYM_SCHEME Structure (StructureTable) |
| 3156 | // TPMT_ASYM_SCHEME_Unmarshal not referenced |
| 3157 | // TPMT_ASYM_SCHEME_Marshal not referenced |
| 3158 | |
| 3159 | |
| 3160 | // Table 2:154 - Definition of TPMI_ALG_RSA_SCHEME Type (TypeTable) |
| 3161 | #ifdef TPM_ALG_RSA |
| 3162 | TPM_RC |
| 3163 | TPMI_ALG_RSA_SCHEME_Unmarshal( |
| 3164 | TPMI_ALG_RSA_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3165 | ) |
| 3166 | { |
| 3167 | TPM_RC result; |
| 3168 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 3169 | if(result != TPM_RC_SUCCESS) |
| 3170 | return result; |
| 3171 | switch (*target) { |
| 3172 | #ifdef TPM_ALG_OAEP |
| 3173 | case TPM_ALG_OAEP: |
| 3174 | #endif // TPM_ALG_OAEP |
| 3175 | #ifdef TPM_ALG_RSASSA |
| 3176 | case TPM_ALG_RSASSA: |
| 3177 | #endif // TPM_ALG_RSASSA |
| 3178 | #ifdef TPM_ALG_RSAPSS |
| 3179 | case TPM_ALG_RSAPSS: |
| 3180 | #endif // TPM_ALG_RSAPSS |
| 3181 | #ifdef TPM_ALG_RSAES |
| 3182 | case TPM_ALG_RSAES: |
| 3183 | #endif // TPM_ALG_RSAES |
| 3184 | break; |
| 3185 | case TPM_ALG_NULL: |
| 3186 | if (flag) |
| 3187 | break; |
| 3188 | return TPM_RC_VALUE; |
| 3189 | default: |
| 3190 | return TPM_RC_VALUE; |
| 3191 | } |
| 3192 | return TPM_RC_SUCCESS; |
| 3193 | } |
| 3194 | |
| 3195 | // TPMI_ALG_RSA_SCHEME_Marshal changed to #define |
| 3196 | #endif // TPM_ALG_RSA |
| 3197 | |
| 3198 | |
| 3199 | // Table 2:155 - Definition of TPMT_RSA_SCHEME Structure (StructureTable) |
| 3200 | #ifdef TPM_ALG_RSA |
| 3201 | TPM_RC |
| 3202 | TPMT_RSA_SCHEME_Unmarshal( |
| 3203 | TPMT_RSA_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3204 | ) |
| 3205 | { |
| 3206 | TPM_RC result; |
| 3207 | result = TPMI_ALG_RSA_SCHEME_Unmarshal((TPMI_ALG_RSA_SCHEME *)&(target->scheme), buffer, size, flag); |
| 3208 | if(result != TPM_RC_SUCCESS) |
| 3209 | return result; |
| 3210 | result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 3211 | return result; |
| 3212 | } |
| 3213 | |
| 3214 | UINT16 |
| 3215 | TPMT_RSA_SCHEME_Marshal( |
| 3216 | TPMT_RSA_SCHEME *source, BYTE **buffer, INT32 *size |
| 3217 | ) |
| 3218 | { |
| 3219 | UINT16 result = 0; |
| 3220 | result = (UINT16)(result + TPMI_ALG_RSA_SCHEME_Marshal((TPMI_ALG_RSA_SCHEME *)&(source->scheme), buffer, size)); |
| 3221 | result = (UINT16)(result + TPMU_ASYM_SCHEME_Marshal((TPMU_ASYM_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme)); |
| 3222 | return result; |
| 3223 | } |
| 3224 | |
| 3225 | #endif // TPM_ALG_RSA |
| 3226 | |
| 3227 | |
| 3228 | // Table 2:156 - Definition of TPMI_ALG_RSA_DECRYPT Type (TypeTable) |
| 3229 | #ifdef TPM_ALG_RSA |
| 3230 | TPM_RC |
| 3231 | TPMI_ALG_RSA_DECRYPT_Unmarshal( |
| 3232 | TPMI_ALG_RSA_DECRYPT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3233 | ) |
| 3234 | { |
| 3235 | TPM_RC result; |
| 3236 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 3237 | if(result != TPM_RC_SUCCESS) |
| 3238 | return result; |
| 3239 | switch (*target) { |
| 3240 | #ifdef TPM_ALG_OAEP |
| 3241 | case TPM_ALG_OAEP: |
| 3242 | #endif // TPM_ALG_OAEP |
| 3243 | #ifdef TPM_ALG_RSAES |
| 3244 | case TPM_ALG_RSAES: |
| 3245 | #endif // TPM_ALG_RSAES |
| 3246 | break; |
| 3247 | case TPM_ALG_NULL: |
| 3248 | if (flag) |
| 3249 | break; |
| 3250 | return TPM_RC_VALUE; |
| 3251 | default: |
| 3252 | return TPM_RC_VALUE; |
| 3253 | } |
| 3254 | return TPM_RC_SUCCESS; |
| 3255 | } |
| 3256 | |
| 3257 | // TPMI_ALG_RSA_DECRYPT_Marshal not referenced |
| 3258 | #endif // TPM_ALG_RSA |
| 3259 | |
| 3260 | |
| 3261 | // Table 2:157 - Definition of TPMT_RSA_DECRYPT Structure (StructureTable) |
| 3262 | #ifdef TPM_ALG_RSA |
| 3263 | TPM_RC |
| 3264 | TPMT_RSA_DECRYPT_Unmarshal( |
| 3265 | TPMT_RSA_DECRYPT *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3266 | ) |
| 3267 | { |
| 3268 | TPM_RC result; |
| 3269 | result = TPMI_ALG_RSA_DECRYPT_Unmarshal((TPMI_ALG_RSA_DECRYPT *)&(target->scheme), buffer, size, flag); |
| 3270 | if(result != TPM_RC_SUCCESS) |
| 3271 | return result; |
| 3272 | result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 3273 | return result; |
| 3274 | } |
| 3275 | |
| 3276 | // TPMT_RSA_DECRYPT_Marshal not referenced |
| 3277 | #endif // TPM_ALG_RSA |
| 3278 | |
| 3279 | |
| 3280 | // Table 2:158 - Definition of TPM2B_PUBLIC_KEY_RSA Structure (StructureTable) |
| 3281 | #ifdef TPM_ALG_RSA |
| 3282 | TPM_RC |
| 3283 | TPM2B_PUBLIC_KEY_RSA_Unmarshal( |
| 3284 | TPM2B_PUBLIC_KEY_RSA *target, BYTE **buffer, INT32 *size |
| 3285 | ) |
| 3286 | { |
| 3287 | TPM_RC result; |
| 3288 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 3289 | if(result != TPM_RC_SUCCESS) |
| 3290 | return result; |
| 3291 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3292 | if(target->t.size == 0) |
| 3293 | return TPM_RC_SUCCESS; |
| 3294 | if((target->t.size) > MAX_RSA_KEY_BYTES) |
| 3295 | return TPM_RC_SIZE; |
| 3296 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 3297 | return result; |
| 3298 | } |
| 3299 | |
| 3300 | UINT16 |
| 3301 | TPM2B_PUBLIC_KEY_RSA_Marshal( |
| 3302 | TPM2B_PUBLIC_KEY_RSA *source, BYTE **buffer, INT32 *size |
| 3303 | ) |
| 3304 | { |
| 3305 | UINT16 result = 0; |
| 3306 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 3307 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3308 | if(source->t.size == 0) |
| 3309 | return result; |
| 3310 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 3311 | return result; |
| 3312 | } |
| 3313 | |
| 3314 | #endif // TPM_ALG_RSA |
| 3315 | |
| 3316 | |
| 3317 | // Table 2:159 - Definition of TPMI_RSA_KEY_BITS Type (TypeTable) |
| 3318 | #ifdef TPM_ALG_RSA |
| 3319 | TPM_RC |
| 3320 | TPMI_RSA_KEY_BITS_Unmarshal( |
| 3321 | TPMI_RSA_KEY_BITS *target, BYTE **buffer, INT32 *size |
| 3322 | ) |
| 3323 | { |
| 3324 | TPM_RC result; |
| 3325 | result = TPM_KEY_BITS_Unmarshal((TPM_KEY_BITS *)target, buffer, size); |
| 3326 | if(result != TPM_RC_SUCCESS) |
| 3327 | return result; |
| 3328 | switch (*target) { |
| 3329 | case 1024: |
| 3330 | case 2048: |
| 3331 | break; |
| 3332 | default: |
| 3333 | return TPM_RC_VALUE; |
| 3334 | } |
| 3335 | return TPM_RC_SUCCESS; |
| 3336 | } |
| 3337 | |
| 3338 | // TPMI_RSA_KEY_BITS_Marshal changed to #define |
| 3339 | #endif // TPM_ALG_RSA |
| 3340 | |
| 3341 | |
| 3342 | // Table 2:160 - Definition of TPM2B_PRIVATE_KEY_RSA Structure (StructureTable) |
| 3343 | #ifdef TPM_ALG_RSA |
| 3344 | TPM_RC |
| 3345 | TPM2B_PRIVATE_KEY_RSA_Unmarshal( |
| 3346 | TPM2B_PRIVATE_KEY_RSA *target, BYTE **buffer, INT32 *size |
| 3347 | ) |
| 3348 | { |
| 3349 | TPM_RC result; |
| 3350 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 3351 | if(result != TPM_RC_SUCCESS) |
| 3352 | return result; |
| 3353 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3354 | if(target->t.size == 0) |
| 3355 | return TPM_RC_SUCCESS; |
| 3356 | if((target->t.size) > MAX_RSA_KEY_BYTES/2) |
| 3357 | return TPM_RC_SIZE; |
| 3358 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 3359 | return result; |
| 3360 | } |
| 3361 | |
| 3362 | UINT16 |
| 3363 | TPM2B_PRIVATE_KEY_RSA_Marshal( |
| 3364 | TPM2B_PRIVATE_KEY_RSA *source, BYTE **buffer, INT32 *size |
| 3365 | ) |
| 3366 | { |
| 3367 | UINT16 result = 0; |
| 3368 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 3369 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3370 | if(source->t.size == 0) |
| 3371 | return result; |
| 3372 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 3373 | return result; |
| 3374 | } |
| 3375 | |
| 3376 | #endif // TPM_ALG_RSA |
| 3377 | |
| 3378 | |
| 3379 | // Table 2:161 - Definition of TPM2B_ECC_PARAMETER Structure (StructureTable) |
| 3380 | #ifdef TPM_ALG_ECC |
| 3381 | TPM_RC |
| 3382 | TPM2B_ECC_PARAMETER_Unmarshal( |
| 3383 | TPM2B_ECC_PARAMETER *target, BYTE **buffer, INT32 *size |
| 3384 | ) |
| 3385 | { |
| 3386 | TPM_RC result; |
| 3387 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 3388 | if(result != TPM_RC_SUCCESS) |
| 3389 | return result; |
| 3390 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3391 | if(target->t.size == 0) |
| 3392 | return TPM_RC_SUCCESS; |
| 3393 | if((target->t.size) > MAX_ECC_KEY_BYTES) |
| 3394 | return TPM_RC_SIZE; |
| 3395 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 3396 | return result; |
| 3397 | } |
| 3398 | |
| 3399 | UINT16 |
| 3400 | TPM2B_ECC_PARAMETER_Marshal( |
| 3401 | TPM2B_ECC_PARAMETER *source, BYTE **buffer, INT32 *size |
| 3402 | ) |
| 3403 | { |
| 3404 | UINT16 result = 0; |
| 3405 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 3406 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3407 | if(source->t.size == 0) |
| 3408 | return result; |
| 3409 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 3410 | return result; |
| 3411 | } |
| 3412 | |
| 3413 | #endif // TPM_ALG_ECC |
| 3414 | |
| 3415 | |
| 3416 | // Table 2:162 - Definition of TPMS_ECC_POINT Structure (StructureTable) |
| 3417 | #ifdef TPM_ALG_ECC |
| 3418 | TPM_RC |
| 3419 | TPMS_ECC_POINT_Unmarshal( |
| 3420 | TPMS_ECC_POINT *target, BYTE **buffer, INT32 *size |
| 3421 | ) |
| 3422 | { |
| 3423 | TPM_RC result; |
| 3424 | result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->x), buffer, size); |
| 3425 | if(result != TPM_RC_SUCCESS) |
| 3426 | return result; |
| 3427 | result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->y), buffer, size); |
| 3428 | return result; |
| 3429 | } |
| 3430 | |
| 3431 | UINT16 |
| 3432 | TPMS_ECC_POINT_Marshal( |
| 3433 | TPMS_ECC_POINT *source, BYTE **buffer, INT32 *size |
| 3434 | ) |
| 3435 | { |
| 3436 | UINT16 result = 0; |
| 3437 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->x), buffer, size)); |
| 3438 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->y), buffer, size)); |
| 3439 | return result; |
| 3440 | } |
| 3441 | |
| 3442 | #endif // TPM_ALG_ECC |
| 3443 | |
| 3444 | |
| 3445 | // Table 2:163 - Definition of TPM2B_ECC_POINT Structure (StructureTable) |
| 3446 | #ifdef TPM_ALG_ECC |
| 3447 | TPM_RC |
| 3448 | TPM2B_ECC_POINT_Unmarshal( |
| 3449 | TPM2B_ECC_POINT *target, BYTE **buffer, INT32 *size |
| 3450 | ) |
| 3451 | { |
| 3452 | TPM_RC result; |
| 3453 | INT32 startSize; |
| 3454 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 3455 | if(result != TPM_RC_SUCCESS) |
| 3456 | return result; |
| 3457 | // if size is zero, then the required structure is missing |
| 3458 | if(target->t.size == 0) |
| 3459 | return TPM_RC_SIZE; |
| 3460 | startSize = *size; |
| 3461 | result = TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT *)&(target->t.point), buffer, size); |
| 3462 | if(result != TPM_RC_SUCCESS) |
| 3463 | return result; |
| 3464 | if(target->t.size != (startSize - *size)) return TPM_RC_SIZE; |
| 3465 | return TPM_RC_SUCCESS; |
| 3466 | } |
| 3467 | |
| 3468 | UINT16 |
| 3469 | TPM2B_ECC_POINT_Marshal( |
| 3470 | TPM2B_ECC_POINT *source, BYTE **buffer, INT32 *size |
| 3471 | ) |
| 3472 | { |
| 3473 | UINT16 result = 0; |
| 3474 | BYTE *sizeField = *buffer; |
| 3475 | // Advance buffer pointer by cononical size of a UINT16 |
| 3476 | *buffer += 2; |
| 3477 | // Marshal the structure |
| 3478 | result = (UINT16)(result + TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT *)&(source->t.point), buffer, size)); |
| 3479 | // Marshal the size |
| 3480 | result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size)); |
| 3481 | return result; |
| 3482 | } |
| 3483 | |
| 3484 | #endif // TPM_ALG_ECC |
| 3485 | |
| 3486 | |
| 3487 | // Table 2:164 - Definition of TPMI_ALG_ECC_SCHEME Type (TypeTable) |
| 3488 | #ifdef TPM_ALG_ECC |
| 3489 | TPM_RC |
| 3490 | TPMI_ALG_ECC_SCHEME_Unmarshal( |
| 3491 | TPMI_ALG_ECC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3492 | ) |
| 3493 | { |
| 3494 | TPM_RC result; |
| 3495 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 3496 | if(result != TPM_RC_SUCCESS) |
| 3497 | return result; |
| 3498 | switch (*target) { |
| 3499 | #ifdef TPM_ALG_ECDSA |
| 3500 | case TPM_ALG_ECDSA: |
| 3501 | #endif // TPM_ALG_ECDSA |
| 3502 | #ifdef TPM_ALG_SM2 |
| 3503 | case TPM_ALG_SM2: |
| 3504 | #endif // TPM_ALG_SM2 |
| 3505 | #ifdef TPM_ALG_ECSCHNORR |
| 3506 | case TPM_ALG_ECSCHNORR: |
| 3507 | #endif // TPM_ALG_ECSCHNORR |
| 3508 | #ifdef TPM_ALG_ECDAA |
| 3509 | case TPM_ALG_ECDAA: |
| 3510 | #endif // TPM_ALG_ECDAA |
| 3511 | #ifdef TPM_ALG_ECDH |
| 3512 | case TPM_ALG_ECDH: |
| 3513 | #endif // TPM_ALG_ECDH |
| 3514 | #ifdef TPM_ALG_ECMQV |
| 3515 | case TPM_ALG_ECMQV: |
| 3516 | #endif // TPM_ALG_ECMQV |
| 3517 | break; |
| 3518 | case TPM_ALG_NULL: |
| 3519 | if (flag) |
| 3520 | break; |
| 3521 | return TPM_RC_SCHEME; |
| 3522 | default: |
| 3523 | return TPM_RC_SCHEME; |
| 3524 | } |
| 3525 | return TPM_RC_SUCCESS; |
| 3526 | } |
| 3527 | |
| 3528 | // TPMI_ALG_ECC_SCHEME_Marshal changed to #define |
| 3529 | #endif // TPM_ALG_ECC |
| 3530 | |
| 3531 | |
| 3532 | // Table 2:165 - Definition of TPMI_ECC_CURVE Type (TypeTable) |
| 3533 | #ifdef TPM_ALG_ECC |
| 3534 | TPM_RC |
| 3535 | TPMI_ECC_CURVE_Unmarshal( |
| 3536 | TPMI_ECC_CURVE *target, BYTE **buffer, INT32 *size |
| 3537 | ) |
| 3538 | { |
| 3539 | TPM_RC result; |
| 3540 | result = TPM_ECC_CURVE_Unmarshal((TPM_ECC_CURVE *)target, buffer, size); |
| 3541 | if(result != TPM_RC_SUCCESS) |
| 3542 | return result; |
| 3543 | switch (*target) { |
| 3544 | case TPM_ECC_BN_P256: |
| 3545 | case TPM_ECC_NIST_P256: |
| 3546 | #if defined ME11_SIM |
| 3547 | #elif defined INTEL_SMX |
| 3548 | case TPM_ECC_SM2_P256: |
| 3549 | #else |
| 3550 | case TPM_ECC_NIST_P384: |
| 3551 | #endif |
| 3552 | break; |
| 3553 | default: |
| 3554 | return TPM_RC_CURVE; |
| 3555 | } |
| 3556 | return TPM_RC_SUCCESS; |
| 3557 | } |
| 3558 | |
| 3559 | // TPMI_ECC_CURVE_Marshal changed to #define |
| 3560 | #endif // TPM_ALG_ECC |
| 3561 | |
| 3562 | |
| 3563 | // Table 2:166 - Definition of TPMT_ECC_SCHEME Structure (StructureTable) |
| 3564 | #ifdef TPM_ALG_ECC |
| 3565 | TPM_RC |
| 3566 | TPMT_ECC_SCHEME_Unmarshal( |
| 3567 | TPMT_ECC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3568 | ) |
| 3569 | { |
| 3570 | TPM_RC result; |
| 3571 | result = TPMI_ALG_ECC_SCHEME_Unmarshal((TPMI_ALG_ECC_SCHEME *)&(target->scheme), buffer, size, flag); |
| 3572 | if(result != TPM_RC_SUCCESS) |
| 3573 | return result; |
| 3574 | result = TPMU_ASYM_SCHEME_Unmarshal((TPMU_ASYM_SCHEME *)&(target->details), buffer, size, (UINT32)target->scheme); |
| 3575 | return result; |
| 3576 | } |
| 3577 | |
| 3578 | UINT16 |
| 3579 | TPMT_ECC_SCHEME_Marshal( |
| 3580 | TPMT_ECC_SCHEME *source, BYTE **buffer, INT32 *size |
| 3581 | ) |
| 3582 | { |
| 3583 | UINT16 result = 0; |
| 3584 | result = (UINT16)(result + TPMI_ALG_ECC_SCHEME_Marshal((TPMI_ALG_ECC_SCHEME *)&(source->scheme), buffer, size)); |
| 3585 | result = (UINT16)(result + TPMU_ASYM_SCHEME_Marshal((TPMU_ASYM_SCHEME *)&(source->details), buffer, size, (UINT32)source->scheme)); |
| 3586 | return result; |
| 3587 | } |
| 3588 | |
| 3589 | #endif // TPM_ALG_ECC |
| 3590 | |
| 3591 | |
| 3592 | // Table 2:167 - Definition of TPMS_ALGORITHM_DETAIL_ECC Structure (StructureTable) |
| 3593 | #ifdef TPM_ALG_ECC |
| 3594 | // TPMS_ALGORITHM_DETAIL_ECC_Unmarshal not referenced |
| 3595 | UINT16 |
| 3596 | TPMS_ALGORITHM_DETAIL_ECC_Marshal( |
| 3597 | TPMS_ALGORITHM_DETAIL_ECC *source, BYTE **buffer, INT32 *size |
| 3598 | ) |
| 3599 | { |
| 3600 | UINT16 result = 0; |
| 3601 | result = (UINT16)(result + TPM_ECC_CURVE_Marshal((TPM_ECC_CURVE *)&(source->curveID), buffer, size)); |
| 3602 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->keySize), buffer, size)); |
| 3603 | result = (UINT16)(result + TPMT_KDF_SCHEME_Marshal((TPMT_KDF_SCHEME *)&(source->kdf), buffer, size)); |
| 3604 | result = (UINT16)(result + TPMT_ECC_SCHEME_Marshal((TPMT_ECC_SCHEME *)&(source->sign), buffer, size)); |
| 3605 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->p), buffer, size)); |
| 3606 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->a), buffer, size)); |
| 3607 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->b), buffer, size)); |
| 3608 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->gX), buffer, size)); |
| 3609 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->gY), buffer, size)); |
| 3610 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->n), buffer, size)); |
| 3611 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->h), buffer, size)); |
| 3612 | return result; |
| 3613 | } |
| 3614 | |
| 3615 | #endif // TPM_ALG_ECC |
| 3616 | |
| 3617 | |
| 3618 | // Table 2:168 - Definition of TPMS_SIGNATURE_RSA Structure (StructureTable) |
| 3619 | #ifdef TPM_ALG_RSA |
| 3620 | TPM_RC |
| 3621 | TPMS_SIGNATURE_RSA_Unmarshal( |
| 3622 | TPMS_SIGNATURE_RSA *target, BYTE **buffer, INT32 *size |
| 3623 | ) |
| 3624 | { |
| 3625 | TPM_RC result; |
| 3626 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0); |
| 3627 | if(result != TPM_RC_SUCCESS) |
| 3628 | return result; |
| 3629 | result = TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA *)&(target->sig), buffer, size); |
| 3630 | return result; |
| 3631 | } |
| 3632 | |
| 3633 | UINT16 |
| 3634 | TPMS_SIGNATURE_RSA_Marshal( |
| 3635 | TPMS_SIGNATURE_RSA *source, BYTE **buffer, INT32 *size |
| 3636 | ) |
| 3637 | { |
| 3638 | UINT16 result = 0; |
| 3639 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size)); |
| 3640 | result = (UINT16)(result + TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA *)&(source->sig), buffer, size)); |
| 3641 | return result; |
| 3642 | } |
| 3643 | |
| 3644 | #endif // TPM_ALG_RSA |
| 3645 | |
| 3646 | |
| 3647 | // Table 2:169 - Definition of Types for Signature (TypesTable) |
| 3648 | #ifdef TPM_ALG_RSA |
| 3649 | // TPMS_SIGNATURE_RSA definition from table 2:169 |
| 3650 | #ifdef TPM_ALG_RSA |
| 3651 | // TPMS_SIGNATURE_RSASSA_Unmarshal changed to #define |
| 3652 | // TPMS_SIGNATURE_RSASSA_Marshal changed to #define |
| 3653 | #endif // TPM_ALG_RSA |
| 3654 | // TPMS_SIGNATURE_RSA definition from table 2:169 |
| 3655 | #ifdef TPM_ALG_RSA |
| 3656 | // TPMS_SIGNATURE_RSAPSS_Unmarshal changed to #define |
| 3657 | // TPMS_SIGNATURE_RSAPSS_Marshal changed to #define |
| 3658 | #endif // TPM_ALG_RSA |
| 3659 | #endif // TPM_ALG_RSA |
| 3660 | |
| 3661 | |
| 3662 | // Table 2:170 - Definition of TPMS_SIGNATURE_ECC Structure (StructureTable) |
| 3663 | #ifdef TPM_ALG_ECC |
| 3664 | TPM_RC |
| 3665 | TPMS_SIGNATURE_ECC_Unmarshal( |
| 3666 | TPMS_SIGNATURE_ECC *target, BYTE **buffer, INT32 *size |
| 3667 | ) |
| 3668 | { |
| 3669 | TPM_RC result; |
| 3670 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->hash), buffer, size, 0); |
| 3671 | if(result != TPM_RC_SUCCESS) |
| 3672 | return result; |
| 3673 | result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->signatureR), buffer, size); |
| 3674 | if(result != TPM_RC_SUCCESS) |
| 3675 | return result; |
| 3676 | result = TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->signatureS), buffer, size); |
| 3677 | return result; |
| 3678 | } |
| 3679 | |
| 3680 | UINT16 |
| 3681 | TPMS_SIGNATURE_ECC_Marshal( |
| 3682 | TPMS_SIGNATURE_ECC *source, BYTE **buffer, INT32 *size |
| 3683 | ) |
| 3684 | { |
| 3685 | UINT16 result = 0; |
| 3686 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->hash), buffer, size)); |
| 3687 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->signatureR), buffer, size)); |
| 3688 | result = (UINT16)(result + TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->signatureS), buffer, size)); |
| 3689 | return result; |
| 3690 | } |
| 3691 | |
| 3692 | #endif // TPM_ALG_ECC |
| 3693 | |
| 3694 | |
| 3695 | // Table 2:171 - Definition of Types for TPMS_SIGNATUE_ECC (TypesTable) |
| 3696 | #ifdef TPM_ALG_ECC |
| 3697 | // TPMS_SIGNATURE_ECC definition from table 2:171 |
| 3698 | #ifdef TPM_ALG_ECC |
| 3699 | // TPMS_SIGNATURE_ECDSA_Unmarshal changed to #define |
| 3700 | // TPMS_SIGNATURE_ECDSA_Marshal changed to #define |
| 3701 | #endif // TPM_ALG_ECC |
| 3702 | // TPMS_SIGNATURE_ECC definition from table 2:171 |
| 3703 | #ifdef TPM_ALG_ECC |
| 3704 | // TPMS_SIGNATURE_SM2_Unmarshal changed to #define |
| 3705 | // TPMS_SIGNATURE_SM2_Marshal changed to #define |
| 3706 | #endif // TPM_ALG_ECC |
| 3707 | // TPMS_SIGNATURE_ECC definition from table 2:171 |
| 3708 | #ifdef TPM_ALG_ECC |
| 3709 | // TPMS_SIGNATURE_ECSCHNORR_Unmarshal changed to #define |
| 3710 | // TPMS_SIGNATURE_ECSCHNORR_Marshal changed to #define |
| 3711 | #endif // TPM_ALG_ECC |
| 3712 | // TPMS_SIGNATURE_ECC definition from table 2:171 |
| 3713 | #ifdef TPM_ALG_ECC |
| 3714 | // TPMS_SIGNATURE_ECDAA_Unmarshal changed to #define |
| 3715 | // TPMS_SIGNATURE_ECDAA_Marshal changed to #define |
| 3716 | #endif // TPM_ALG_ECC |
| 3717 | #endif // TPM_ALG_ECC |
| 3718 | |
| 3719 | |
| 3720 | // Table 2:172 - Definition of TPMU_SIGNATURE Union (UnionTable) |
| 3721 | TPM_RC |
| 3722 | TPMU_SIGNATURE_Unmarshal( |
| 3723 | TPMU_SIGNATURE *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 3724 | ) |
| 3725 | { |
| 3726 | switch(selector) { |
| 3727 | #ifdef TPM_ALG_RSASSA |
| 3728 | case TPM_ALG_RSASSA: |
| 3729 | return TPMS_SIGNATURE_RSASSA_Unmarshal((TPMS_SIGNATURE_RSASSA *)&(target->rsassa), buffer, size); |
| 3730 | #endif // TPM_ALG_RSASSA |
| 3731 | #ifdef TPM_ALG_RSAPSS |
| 3732 | case TPM_ALG_RSAPSS: |
| 3733 | return TPMS_SIGNATURE_RSAPSS_Unmarshal((TPMS_SIGNATURE_RSAPSS *)&(target->rsapss), buffer, size); |
| 3734 | #endif // TPM_ALG_RSAPSS |
| 3735 | #ifdef TPM_ALG_ECDSA |
| 3736 | case TPM_ALG_ECDSA: |
| 3737 | return TPMS_SIGNATURE_ECDSA_Unmarshal((TPMS_SIGNATURE_ECDSA *)&(target->ecdsa), buffer, size); |
| 3738 | #endif // TPM_ALG_ECDSA |
| 3739 | #ifdef TPM_ALG_SM2 |
| 3740 | case TPM_ALG_SM2: |
| 3741 | return TPMS_SIGNATURE_SM2_Unmarshal((TPMS_SIGNATURE_SM2 *)&(target->sm2), buffer, size); |
| 3742 | #endif // TPM_ALG_SM2 |
| 3743 | #ifdef TPM_ALG_ECSCHNORR |
| 3744 | case TPM_ALG_ECSCHNORR: |
| 3745 | return TPMS_SIGNATURE_ECSCHNORR_Unmarshal((TPMS_SIGNATURE_ECSCHNORR *)&(target->ecschnorr), buffer, size); |
| 3746 | #endif // TPM_ALG_ECSCHNORR |
| 3747 | #ifdef TPM_ALG_ECDAA |
| 3748 | case TPM_ALG_ECDAA: |
| 3749 | return TPMS_SIGNATURE_ECDAA_Unmarshal((TPMS_SIGNATURE_ECDAA *)&(target->ecdaa), buffer, size); |
| 3750 | #endif // TPM_ALG_ECDAA |
| 3751 | #ifdef TPM_ALG_HMAC |
| 3752 | case TPM_ALG_HMAC: |
| 3753 | return TPMT_HA_Unmarshal((TPMT_HA *)&(target->hmac), buffer, size, 0); |
| 3754 | #endif // TPM_ALG_HMAC |
| 3755 | case TPM_ALG_NULL: |
| 3756 | return TPM_RC_SUCCESS; |
| 3757 | } |
| 3758 | return TPM_RC_SELECTOR; |
| 3759 | } |
| 3760 | |
| 3761 | UINT16 |
| 3762 | TPMU_SIGNATURE_Marshal( |
| 3763 | TPMU_SIGNATURE *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 3764 | ) |
| 3765 | { |
| 3766 | switch(selector) { |
| 3767 | #ifdef TPM_ALG_RSASSA |
| 3768 | case TPM_ALG_RSASSA: |
| 3769 | return TPMS_SIGNATURE_RSASSA_Marshal((TPMS_SIGNATURE_RSASSA *)&(source->rsassa), buffer, size); |
| 3770 | #endif // TPM_ALG_RSASSA |
| 3771 | #ifdef TPM_ALG_RSAPSS |
| 3772 | case TPM_ALG_RSAPSS: |
| 3773 | return TPMS_SIGNATURE_RSAPSS_Marshal((TPMS_SIGNATURE_RSAPSS *)&(source->rsapss), buffer, size); |
| 3774 | #endif // TPM_ALG_RSAPSS |
| 3775 | #ifdef TPM_ALG_ECDSA |
| 3776 | case TPM_ALG_ECDSA: |
| 3777 | return TPMS_SIGNATURE_ECDSA_Marshal((TPMS_SIGNATURE_ECDSA *)&(source->ecdsa), buffer, size); |
| 3778 | #endif // TPM_ALG_ECDSA |
| 3779 | #ifdef TPM_ALG_SM2 |
| 3780 | case TPM_ALG_SM2: |
| 3781 | return TPMS_SIGNATURE_SM2_Marshal((TPMS_SIGNATURE_SM2 *)&(source->sm2), buffer, size); |
| 3782 | #endif // TPM_ALG_SM2 |
| 3783 | #ifdef TPM_ALG_ECSCHNORR |
| 3784 | case TPM_ALG_ECSCHNORR: |
| 3785 | return TPMS_SIGNATURE_ECSCHNORR_Marshal((TPMS_SIGNATURE_ECSCHNORR *)&(source->ecschnorr), buffer, size); |
| 3786 | #endif // TPM_ALG_ECSCHNORR |
| 3787 | #ifdef TPM_ALG_ECDAA |
| 3788 | case TPM_ALG_ECDAA: |
| 3789 | return TPMS_SIGNATURE_ECDAA_Marshal((TPMS_SIGNATURE_ECDAA *)&(source->ecdaa), buffer, size); |
| 3790 | #endif // TPM_ALG_ECDAA |
| 3791 | #ifdef TPM_ALG_HMAC |
| 3792 | case TPM_ALG_HMAC: |
| 3793 | return TPMT_HA_Marshal((TPMT_HA *)&(source->hmac), buffer, size); |
| 3794 | #endif // TPM_ALG_HMAC |
| 3795 | case TPM_ALG_NULL: |
| 3796 | return 0; |
| 3797 | } |
| 3798 | return 0; |
| 3799 | } |
| 3800 | |
| 3801 | |
| 3802 | // Table 2:173 - Definition of TPMT_SIGNATURE Structure (StructureTable) |
| 3803 | TPM_RC |
| 3804 | TPMT_SIGNATURE_Unmarshal( |
| 3805 | TPMT_SIGNATURE *target, BYTE **buffer, INT32 *size, BOOL flag |
| 3806 | ) |
| 3807 | { |
| 3808 | TPM_RC result; |
| 3809 | result = TPMI_ALG_SIG_SCHEME_Unmarshal((TPMI_ALG_SIG_SCHEME *)&(target->sigAlg), buffer, size, flag); |
| 3810 | if(result != TPM_RC_SUCCESS) |
| 3811 | return result; |
| 3812 | result = TPMU_SIGNATURE_Unmarshal((TPMU_SIGNATURE *)&(target->signature), buffer, size, (UINT32)target->sigAlg); |
| 3813 | return result; |
| 3814 | } |
| 3815 | |
| 3816 | UINT16 |
| 3817 | TPMT_SIGNATURE_Marshal( |
| 3818 | TPMT_SIGNATURE *source, BYTE **buffer, INT32 *size |
| 3819 | ) |
| 3820 | { |
| 3821 | UINT16 result = 0; |
| 3822 | result = (UINT16)(result + TPMI_ALG_SIG_SCHEME_Marshal((TPMI_ALG_SIG_SCHEME *)&(source->sigAlg), buffer, size)); |
| 3823 | result = (UINT16)(result + TPMU_SIGNATURE_Marshal((TPMU_SIGNATURE *)&(source->signature), buffer, size, (UINT32)source->sigAlg)); |
| 3824 | return result; |
| 3825 | } |
| 3826 | |
| 3827 | |
| 3828 | // Table 2:174 - Definition of TPMU_ENCRYPTED_SECRET Union (UnionTable) |
| 3829 | // TPMU_ENCRYPTED_SECRET_Unmarshal not referenced |
| 3830 | // TPMU_ENCRYPTED_SECRET_Marshal not referenced |
| 3831 | |
| 3832 | |
| 3833 | // Table 2:175 - Definition of TPM2B_ENCRYPTED_SECRET Structure (StructureTable) |
| 3834 | TPM_RC |
| 3835 | TPM2B_ENCRYPTED_SECRET_Unmarshal( |
| 3836 | TPM2B_ENCRYPTED_SECRET *target, BYTE **buffer, INT32 *size |
| 3837 | ) |
| 3838 | { |
| 3839 | TPM_RC result; |
| 3840 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 3841 | if(result != TPM_RC_SUCCESS) |
| 3842 | return result; |
| 3843 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3844 | if(target->t.size == 0) |
| 3845 | return TPM_RC_SUCCESS; |
| 3846 | if((target->t.size) > sizeof(TPMU_ENCRYPTED_SECRET)) |
| 3847 | return TPM_RC_SIZE; |
| 3848 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.secret), buffer, size, (INT32)(target->t.size)); |
| 3849 | return result; |
| 3850 | } |
| 3851 | |
| 3852 | UINT16 |
| 3853 | TPM2B_ENCRYPTED_SECRET_Marshal( |
| 3854 | TPM2B_ENCRYPTED_SECRET *source, BYTE **buffer, INT32 *size |
| 3855 | ) |
| 3856 | { |
| 3857 | UINT16 result = 0; |
| 3858 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 3859 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 3860 | if(source->t.size == 0) |
| 3861 | return result; |
| 3862 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.secret), buffer, size, (INT32)(source->t.size))); |
| 3863 | return result; |
| 3864 | } |
| 3865 | |
| 3866 | |
| 3867 | // Table 2:176 - Definition of TPMI_ALG_PUBLIC Type (TypeTable) |
| 3868 | TPM_RC |
| 3869 | TPMI_ALG_PUBLIC_Unmarshal( |
| 3870 | TPMI_ALG_PUBLIC *target, BYTE **buffer, INT32 *size |
| 3871 | ) |
| 3872 | { |
| 3873 | TPM_RC result; |
| 3874 | result = TPM_ALG_ID_Unmarshal((TPM_ALG_ID *)target, buffer, size); |
| 3875 | if(result != TPM_RC_SUCCESS) |
| 3876 | return result; |
| 3877 | switch (*target) { |
| 3878 | #ifdef TPM_ALG_SYMCIPHER |
| 3879 | case TPM_ALG_SYMCIPHER: |
| 3880 | #endif // TPM_ALG_SYMCIPHER |
| 3881 | #ifdef TPM_ALG_RSA |
| 3882 | case TPM_ALG_RSA: |
| 3883 | #endif // TPM_ALG_RSA |
| 3884 | #ifdef TPM_ALG_ECC |
| 3885 | case TPM_ALG_ECC: |
| 3886 | #endif // TPM_ALG_ECC |
| 3887 | #ifdef TPM_ALG_KEYEDHASH |
| 3888 | case TPM_ALG_KEYEDHASH: |
| 3889 | #endif // TPM_ALG_KEYEDHASH |
| 3890 | break; |
| 3891 | default: |
| 3892 | return TPM_RC_TYPE; |
| 3893 | } |
| 3894 | return TPM_RC_SUCCESS; |
| 3895 | } |
| 3896 | |
| 3897 | // TPMI_ALG_PUBLIC_Marshal changed to #define |
| 3898 | |
| 3899 | |
| 3900 | // Table 2:177 - Definition of TPMU_PUBLIC_ID Union (UnionTable) |
| 3901 | TPM_RC |
| 3902 | TPMU_PUBLIC_ID_Unmarshal( |
| 3903 | TPMU_PUBLIC_ID *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 3904 | ) |
| 3905 | { |
| 3906 | switch(selector) { |
| 3907 | #ifdef TPM_ALG_KEYEDHASH |
| 3908 | case TPM_ALG_KEYEDHASH: |
| 3909 | return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->keyedHash), buffer, size); |
| 3910 | #endif // TPM_ALG_KEYEDHASH |
| 3911 | #ifdef TPM_ALG_SYMCIPHER |
| 3912 | case TPM_ALG_SYMCIPHER: |
| 3913 | return TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->sym), buffer, size); |
| 3914 | #endif // TPM_ALG_SYMCIPHER |
| 3915 | #ifdef TPM_ALG_RSA |
| 3916 | case TPM_ALG_RSA: |
| 3917 | return TPM2B_PUBLIC_KEY_RSA_Unmarshal((TPM2B_PUBLIC_KEY_RSA *)&(target->rsa), buffer, size); |
| 3918 | #endif // TPM_ALG_RSA |
| 3919 | #ifdef TPM_ALG_ECC |
| 3920 | case TPM_ALG_ECC: |
| 3921 | return TPMS_ECC_POINT_Unmarshal((TPMS_ECC_POINT *)&(target->ecc), buffer, size); |
| 3922 | #endif // TPM_ALG_ECC |
| 3923 | } |
| 3924 | return TPM_RC_SELECTOR; |
| 3925 | } |
| 3926 | |
| 3927 | UINT16 |
| 3928 | TPMU_PUBLIC_ID_Marshal( |
| 3929 | TPMU_PUBLIC_ID *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 3930 | ) |
| 3931 | { |
| 3932 | switch(selector) { |
| 3933 | #ifdef TPM_ALG_KEYEDHASH |
| 3934 | case TPM_ALG_KEYEDHASH: |
| 3935 | return TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->keyedHash), buffer, size); |
| 3936 | #endif // TPM_ALG_KEYEDHASH |
| 3937 | #ifdef TPM_ALG_SYMCIPHER |
| 3938 | case TPM_ALG_SYMCIPHER: |
| 3939 | return TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->sym), buffer, size); |
| 3940 | #endif // TPM_ALG_SYMCIPHER |
| 3941 | #ifdef TPM_ALG_RSA |
| 3942 | case TPM_ALG_RSA: |
| 3943 | return TPM2B_PUBLIC_KEY_RSA_Marshal((TPM2B_PUBLIC_KEY_RSA *)&(source->rsa), buffer, size); |
| 3944 | #endif // TPM_ALG_RSA |
| 3945 | #ifdef TPM_ALG_ECC |
| 3946 | case TPM_ALG_ECC: |
| 3947 | return TPMS_ECC_POINT_Marshal((TPMS_ECC_POINT *)&(source->ecc), buffer, size); |
| 3948 | #endif // TPM_ALG_ECC |
| 3949 | } |
| 3950 | return 0; |
| 3951 | } |
| 3952 | |
| 3953 | |
| 3954 | // Table 2:178 - Definition of TPMS_KEYEDHASH_PARMS Structure (StructureTable) |
| 3955 | // TPMS_KEYEDHASH_PARMS_Unmarshal changed to #define |
| 3956 | // TPMS_KEYEDHASH_PARMS_Marshal changed to #define |
| 3957 | |
| 3958 | |
| 3959 | // Table 2:179 - Definition of TPMS_ASYM_PARMS Structure (StructureTable) |
| 3960 | // TPMS_ASYM_PARMS_Unmarshal not referenced |
| 3961 | // TPMS_ASYM_PARMS_Marshal not referenced |
| 3962 | |
| 3963 | |
| 3964 | // Table 2:180 - Definition of TPMS_RSA_PARMS Structure (StructureTable) |
| 3965 | #ifdef TPM_ALG_RSA |
| 3966 | TPM_RC |
| 3967 | TPMS_RSA_PARMS_Unmarshal( |
| 3968 | TPMS_RSA_PARMS *target, BYTE **buffer, INT32 *size |
| 3969 | ) |
| 3970 | { |
| 3971 | TPM_RC result; |
| 3972 | result = TPMT_SYM_DEF_OBJECT_Unmarshal((TPMT_SYM_DEF_OBJECT *)&(target->symmetric), buffer, size, 1); |
| 3973 | if(result != TPM_RC_SUCCESS) |
| 3974 | return result; |
| 3975 | result = TPMT_RSA_SCHEME_Unmarshal((TPMT_RSA_SCHEME *)&(target->scheme), buffer, size, 1); |
| 3976 | if(result != TPM_RC_SUCCESS) |
| 3977 | return result; |
| 3978 | result = TPMI_RSA_KEY_BITS_Unmarshal((TPMI_RSA_KEY_BITS *)&(target->keyBits), buffer, size); |
| 3979 | if(result != TPM_RC_SUCCESS) |
| 3980 | return result; |
| 3981 | result = UINT32_Unmarshal((UINT32 *)&(target->exponent), buffer, size); |
| 3982 | return result; |
| 3983 | } |
| 3984 | |
| 3985 | UINT16 |
| 3986 | TPMS_RSA_PARMS_Marshal( |
| 3987 | TPMS_RSA_PARMS *source, BYTE **buffer, INT32 *size |
| 3988 | ) |
| 3989 | { |
| 3990 | UINT16 result = 0; |
| 3991 | result = (UINT16)(result + TPMT_SYM_DEF_OBJECT_Marshal((TPMT_SYM_DEF_OBJECT *)&(source->symmetric), buffer, size)); |
| 3992 | result = (UINT16)(result + TPMT_RSA_SCHEME_Marshal((TPMT_RSA_SCHEME *)&(source->scheme), buffer, size)); |
| 3993 | result = (UINT16)(result + TPMI_RSA_KEY_BITS_Marshal((TPMI_RSA_KEY_BITS *)&(source->keyBits), buffer, size)); |
| 3994 | result = (UINT16)(result + UINT32_Marshal((UINT32 *)&(source->exponent), buffer, size)); |
| 3995 | return result; |
| 3996 | } |
| 3997 | |
| 3998 | #endif // TPM_ALG_RSA |
| 3999 | |
| 4000 | |
| 4001 | // Table 2:181 - Definition of TPMS_ECC_PARMS Structure (StructureTable) |
| 4002 | #ifdef TPM_ALG_ECC |
| 4003 | TPM_RC |
| 4004 | TPMS_ECC_PARMS_Unmarshal( |
| 4005 | TPMS_ECC_PARMS *target, BYTE **buffer, INT32 *size |
| 4006 | ) |
| 4007 | { |
| 4008 | TPM_RC result; |
| 4009 | result = TPMT_SYM_DEF_OBJECT_Unmarshal((TPMT_SYM_DEF_OBJECT *)&(target->symmetric), buffer, size, 1); |
| 4010 | if(result != TPM_RC_SUCCESS) |
| 4011 | return result; |
| 4012 | result = TPMT_ECC_SCHEME_Unmarshal((TPMT_ECC_SCHEME *)&(target->scheme), buffer, size, 1); |
| 4013 | if(result != TPM_RC_SUCCESS) |
| 4014 | return result; |
| 4015 | result = TPMI_ECC_CURVE_Unmarshal((TPMI_ECC_CURVE *)&(target->curveID), buffer, size); |
| 4016 | if(result != TPM_RC_SUCCESS) |
| 4017 | return result; |
| 4018 | result = TPMT_KDF_SCHEME_Unmarshal((TPMT_KDF_SCHEME *)&(target->kdf), buffer, size, 1); |
| 4019 | return result; |
| 4020 | } |
| 4021 | |
| 4022 | UINT16 |
| 4023 | TPMS_ECC_PARMS_Marshal( |
| 4024 | TPMS_ECC_PARMS *source, BYTE **buffer, INT32 *size |
| 4025 | ) |
| 4026 | { |
| 4027 | UINT16 result = 0; |
| 4028 | result = (UINT16)(result + TPMT_SYM_DEF_OBJECT_Marshal((TPMT_SYM_DEF_OBJECT *)&(source->symmetric), buffer, size)); |
| 4029 | result = (UINT16)(result + TPMT_ECC_SCHEME_Marshal((TPMT_ECC_SCHEME *)&(source->scheme), buffer, size)); |
| 4030 | result = (UINT16)(result + TPMI_ECC_CURVE_Marshal((TPMI_ECC_CURVE *)&(source->curveID), buffer, size)); |
| 4031 | result = (UINT16)(result + TPMT_KDF_SCHEME_Marshal((TPMT_KDF_SCHEME *)&(source->kdf), buffer, size)); |
| 4032 | return result; |
| 4033 | } |
| 4034 | |
| 4035 | #endif // TPM_ALG_ECC |
| 4036 | |
| 4037 | |
| 4038 | // Table 2:182 - Definition of TPMU_PUBLIC_PARMS Union (UnionTable) |
| 4039 | TPM_RC |
| 4040 | TPMU_PUBLIC_PARMS_Unmarshal( |
| 4041 | TPMU_PUBLIC_PARMS *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 4042 | ) |
| 4043 | { |
| 4044 | switch(selector) { |
| 4045 | #ifdef TPM_ALG_KEYEDHASH |
| 4046 | case TPM_ALG_KEYEDHASH: |
| 4047 | return TPMS_KEYEDHASH_PARMS_Unmarshal((TPMS_KEYEDHASH_PARMS *)&(target->keyedHashDetail), buffer, size); |
| 4048 | #endif // TPM_ALG_KEYEDHASH |
| 4049 | #ifdef TPM_ALG_SYMCIPHER |
| 4050 | case TPM_ALG_SYMCIPHER: |
| 4051 | return TPMS_SYMCIPHER_PARMS_Unmarshal((TPMS_SYMCIPHER_PARMS *)&(target->symDetail), buffer, size); |
| 4052 | #endif // TPM_ALG_SYMCIPHER |
| 4053 | #ifdef TPM_ALG_RSA |
| 4054 | case TPM_ALG_RSA: |
| 4055 | return TPMS_RSA_PARMS_Unmarshal((TPMS_RSA_PARMS *)&(target->rsaDetail), buffer, size); |
| 4056 | #endif // TPM_ALG_RSA |
| 4057 | #ifdef TPM_ALG_ECC |
| 4058 | case TPM_ALG_ECC: |
| 4059 | return TPMS_ECC_PARMS_Unmarshal((TPMS_ECC_PARMS *)&(target->eccDetail), buffer, size); |
| 4060 | #endif // TPM_ALG_ECC |
| 4061 | } |
| 4062 | return TPM_RC_SELECTOR; |
| 4063 | } |
| 4064 | |
| 4065 | UINT16 |
| 4066 | TPMU_PUBLIC_PARMS_Marshal( |
| 4067 | TPMU_PUBLIC_PARMS *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 4068 | ) |
| 4069 | { |
| 4070 | switch(selector) { |
| 4071 | #ifdef TPM_ALG_KEYEDHASH |
| 4072 | case TPM_ALG_KEYEDHASH: |
| 4073 | return TPMS_KEYEDHASH_PARMS_Marshal((TPMS_KEYEDHASH_PARMS *)&(source->keyedHashDetail), buffer, size); |
| 4074 | #endif // TPM_ALG_KEYEDHASH |
| 4075 | #ifdef TPM_ALG_SYMCIPHER |
| 4076 | case TPM_ALG_SYMCIPHER: |
| 4077 | return TPMS_SYMCIPHER_PARMS_Marshal((TPMS_SYMCIPHER_PARMS *)&(source->symDetail), buffer, size); |
| 4078 | #endif // TPM_ALG_SYMCIPHER |
| 4079 | #ifdef TPM_ALG_RSA |
| 4080 | case TPM_ALG_RSA: |
| 4081 | return TPMS_RSA_PARMS_Marshal((TPMS_RSA_PARMS *)&(source->rsaDetail), buffer, size); |
| 4082 | #endif // TPM_ALG_RSA |
| 4083 | #ifdef TPM_ALG_ECC |
| 4084 | case TPM_ALG_ECC: |
| 4085 | return TPMS_ECC_PARMS_Marshal((TPMS_ECC_PARMS *)&(source->eccDetail), buffer, size); |
| 4086 | #endif // TPM_ALG_ECC |
| 4087 | } |
| 4088 | return 0; |
| 4089 | } |
| 4090 | |
| 4091 | |
| 4092 | // Table 2:183 - Definition of TPMT_PUBLIC_PARMS Structure (StructureTable) |
| 4093 | TPM_RC |
| 4094 | TPMT_PUBLIC_PARMS_Unmarshal( |
| 4095 | TPMT_PUBLIC_PARMS *target, BYTE **buffer, INT32 *size |
| 4096 | ) |
| 4097 | { |
| 4098 | TPM_RC result; |
| 4099 | result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->type), buffer, size); |
| 4100 | if(result != TPM_RC_SUCCESS) |
| 4101 | return result; |
| 4102 | result = TPMU_PUBLIC_PARMS_Unmarshal((TPMU_PUBLIC_PARMS *)&(target->parameters), buffer, size, (UINT32)target->type); |
| 4103 | return result; |
| 4104 | } |
| 4105 | |
| 4106 | // TPMT_PUBLIC_PARMS_Marshal not referenced |
| 4107 | |
| 4108 | |
| 4109 | // Table 2:184 - Definition of TPMT_PUBLIC Structure (StructureTable) |
| 4110 | TPM_RC |
| 4111 | TPMT_PUBLIC_Unmarshal( |
| 4112 | TPMT_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL flag |
| 4113 | ) |
| 4114 | { |
| 4115 | TPM_RC result; |
| 4116 | result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->type), buffer, size); |
| 4117 | if(result != TPM_RC_SUCCESS) |
| 4118 | return result; |
| 4119 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->nameAlg), buffer, size, flag); |
| 4120 | if(result != TPM_RC_SUCCESS) |
| 4121 | return result; |
| 4122 | result = TPMA_OBJECT_Unmarshal((TPMA_OBJECT *)&(target->objectAttributes), buffer, size); |
| 4123 | if(result != TPM_RC_SUCCESS) |
| 4124 | return result; |
| 4125 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->authPolicy), buffer, size); |
| 4126 | if(result != TPM_RC_SUCCESS) |
| 4127 | return result; |
| 4128 | result = TPMU_PUBLIC_PARMS_Unmarshal((TPMU_PUBLIC_PARMS *)&(target->parameters), buffer, size, (UINT32)target->type); |
| 4129 | if(result != TPM_RC_SUCCESS) |
| 4130 | return result; |
| 4131 | result = TPMU_PUBLIC_ID_Unmarshal((TPMU_PUBLIC_ID *)&(target->unique), buffer, size, (UINT32)target->type); |
| 4132 | return result; |
| 4133 | } |
| 4134 | |
| 4135 | UINT16 |
| 4136 | TPMT_PUBLIC_Marshal( |
| 4137 | TPMT_PUBLIC *source, BYTE **buffer, INT32 *size |
| 4138 | ) |
| 4139 | { |
| 4140 | UINT16 result = 0; |
| 4141 | result = (UINT16)(result + TPMI_ALG_PUBLIC_Marshal((TPMI_ALG_PUBLIC *)&(source->type), buffer, size)); |
| 4142 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->nameAlg), buffer, size)); |
| 4143 | result = (UINT16)(result + TPMA_OBJECT_Marshal((TPMA_OBJECT *)&(source->objectAttributes), buffer, size)); |
| 4144 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->authPolicy), buffer, size)); |
| 4145 | result = (UINT16)(result + TPMU_PUBLIC_PARMS_Marshal((TPMU_PUBLIC_PARMS *)&(source->parameters), buffer, size, (UINT32)source->type)); |
| 4146 | result = (UINT16)(result + TPMU_PUBLIC_ID_Marshal((TPMU_PUBLIC_ID *)&(source->unique), buffer, size, (UINT32)source->type)); |
| 4147 | return result; |
| 4148 | } |
| 4149 | |
| 4150 | |
| 4151 | // Table 2:185 - Definition of TPM2B_PUBLIC Structure (StructureTable) |
| 4152 | TPM_RC |
| 4153 | TPM2B_PUBLIC_Unmarshal( |
| 4154 | TPM2B_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL flag |
| 4155 | ) |
| 4156 | { |
| 4157 | TPM_RC result; |
| 4158 | INT32 startSize; |
| 4159 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4160 | if(result != TPM_RC_SUCCESS) |
| 4161 | return result; |
| 4162 | // if size is zero, then the required structure is missing |
| 4163 | if(target->t.size == 0) |
| 4164 | return TPM_RC_SIZE; |
| 4165 | startSize = *size; |
| 4166 | result = TPMT_PUBLIC_Unmarshal((TPMT_PUBLIC *)&(target->t.publicArea), buffer, size, flag); |
| 4167 | if(result != TPM_RC_SUCCESS) |
| 4168 | return result; |
| 4169 | if(target->t.size != (startSize - *size)) return TPM_RC_SIZE; |
| 4170 | return TPM_RC_SUCCESS; |
| 4171 | } |
| 4172 | |
| 4173 | UINT16 |
| 4174 | TPM2B_PUBLIC_Marshal( |
| 4175 | TPM2B_PUBLIC *source, BYTE **buffer, INT32 *size |
| 4176 | ) |
| 4177 | { |
| 4178 | UINT16 result = 0; |
| 4179 | BYTE *sizeField = *buffer; |
| 4180 | // Advance buffer pointer by cononical size of a UINT16 |
| 4181 | *buffer += 2; |
| 4182 | // Marshal the structure |
| 4183 | result = (UINT16)(result + TPMT_PUBLIC_Marshal((TPMT_PUBLIC *)&(source->t.publicArea), buffer, size)); |
| 4184 | // Marshal the size |
| 4185 | result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size)); |
| 4186 | return result; |
| 4187 | } |
| 4188 | |
| 4189 | |
| 4190 | // Table 2:186 - Definition of TPM2B_PRIVATE_VENDOR_SPECIFIC Structure (StructureTable) |
| 4191 | // TPM2B_PRIVATE_VENDOR_SPECIFIC_Unmarshal not referenced |
| 4192 | // TPM2B_PRIVATE_VENDOR_SPECIFIC_Marshal not referenced |
| 4193 | |
| 4194 | |
| 4195 | // Table 2:187 - Definition of TPMU_SENSITIVE_COMPOSITE Union (UnionTable) |
| 4196 | TPM_RC |
| 4197 | TPMU_SENSITIVE_COMPOSITE_Unmarshal( |
| 4198 | TPMU_SENSITIVE_COMPOSITE *target, BYTE **buffer, INT32 *size, UINT32 selector |
| 4199 | ) |
| 4200 | { |
| 4201 | switch(selector) { |
| 4202 | #ifdef TPM_ALG_RSA |
| 4203 | case TPM_ALG_RSA: |
| 4204 | return TPM2B_PRIVATE_KEY_RSA_Unmarshal((TPM2B_PRIVATE_KEY_RSA *)&(target->rsa), buffer, size); |
| 4205 | #endif // TPM_ALG_RSA |
| 4206 | #ifdef TPM_ALG_ECC |
| 4207 | case TPM_ALG_ECC: |
| 4208 | return TPM2B_ECC_PARAMETER_Unmarshal((TPM2B_ECC_PARAMETER *)&(target->ecc), buffer, size); |
| 4209 | #endif // TPM_ALG_ECC |
| 4210 | #ifdef TPM_ALG_KEYEDHASH |
| 4211 | case TPM_ALG_KEYEDHASH: |
| 4212 | return TPM2B_SENSITIVE_DATA_Unmarshal((TPM2B_SENSITIVE_DATA *)&(target->bits), buffer, size); |
| 4213 | #endif // TPM_ALG_KEYEDHASH |
| 4214 | #ifdef TPM_ALG_SYMCIPHER |
| 4215 | case TPM_ALG_SYMCIPHER: |
| 4216 | return TPM2B_SYM_KEY_Unmarshal((TPM2B_SYM_KEY *)&(target->sym), buffer, size); |
| 4217 | #endif // TPM_ALG_SYMCIPHER |
| 4218 | } |
| 4219 | return TPM_RC_SELECTOR; |
| 4220 | } |
| 4221 | |
| 4222 | UINT16 |
| 4223 | TPMU_SENSITIVE_COMPOSITE_Marshal( |
| 4224 | TPMU_SENSITIVE_COMPOSITE *source, BYTE **buffer, INT32 *size, UINT32 selector |
| 4225 | ) |
| 4226 | { |
| 4227 | switch(selector) { |
| 4228 | #ifdef TPM_ALG_RSA |
| 4229 | case TPM_ALG_RSA: |
| 4230 | return TPM2B_PRIVATE_KEY_RSA_Marshal((TPM2B_PRIVATE_KEY_RSA *)&(source->rsa), buffer, size); |
| 4231 | #endif // TPM_ALG_RSA |
| 4232 | #ifdef TPM_ALG_ECC |
| 4233 | case TPM_ALG_ECC: |
| 4234 | return TPM2B_ECC_PARAMETER_Marshal((TPM2B_ECC_PARAMETER *)&(source->ecc), buffer, size); |
| 4235 | #endif // TPM_ALG_ECC |
| 4236 | #ifdef TPM_ALG_KEYEDHASH |
| 4237 | case TPM_ALG_KEYEDHASH: |
| 4238 | return TPM2B_SENSITIVE_DATA_Marshal((TPM2B_SENSITIVE_DATA *)&(source->bits), buffer, size); |
| 4239 | #endif // TPM_ALG_KEYEDHASH |
| 4240 | #ifdef TPM_ALG_SYMCIPHER |
| 4241 | case TPM_ALG_SYMCIPHER: |
| 4242 | return TPM2B_SYM_KEY_Marshal((TPM2B_SYM_KEY *)&(source->sym), buffer, size); |
| 4243 | #endif // TPM_ALG_SYMCIPHER |
| 4244 | } |
| 4245 | return 0; |
| 4246 | } |
| 4247 | |
| 4248 | |
| 4249 | // Table 2:188 - Definition of TPMT_SENSITIVE Structure (StructureTable) |
| 4250 | TPM_RC |
| 4251 | TPMT_SENSITIVE_Unmarshal( |
| 4252 | TPMT_SENSITIVE *target, BYTE **buffer, INT32 *size |
| 4253 | ) |
| 4254 | { |
| 4255 | TPM_RC result; |
| 4256 | result = TPMI_ALG_PUBLIC_Unmarshal((TPMI_ALG_PUBLIC *)&(target->sensitiveType), buffer, size); |
| 4257 | if(result != TPM_RC_SUCCESS) |
| 4258 | return result; |
| 4259 | result = TPM2B_AUTH_Unmarshal((TPM2B_AUTH *)&(target->authValue), buffer, size); |
| 4260 | if(result != TPM_RC_SUCCESS) |
| 4261 | return result; |
| 4262 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->seedValue), buffer, size); |
| 4263 | if(result != TPM_RC_SUCCESS) |
| 4264 | return result; |
| 4265 | result = TPMU_SENSITIVE_COMPOSITE_Unmarshal((TPMU_SENSITIVE_COMPOSITE *)&(target->sensitive), buffer, size, (UINT32)target->sensitiveType); |
| 4266 | return result; |
| 4267 | } |
| 4268 | |
| 4269 | UINT16 |
| 4270 | TPMT_SENSITIVE_Marshal( |
| 4271 | TPMT_SENSITIVE *source, BYTE **buffer, INT32 *size |
| 4272 | ) |
| 4273 | { |
| 4274 | UINT16 result = 0; |
| 4275 | result = (UINT16)(result + TPMI_ALG_PUBLIC_Marshal((TPMI_ALG_PUBLIC *)&(source->sensitiveType), buffer, size)); |
| 4276 | result = (UINT16)(result + TPM2B_AUTH_Marshal((TPM2B_AUTH *)&(source->authValue), buffer, size)); |
| 4277 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->seedValue), buffer, size)); |
| 4278 | result = (UINT16)(result + TPMU_SENSITIVE_COMPOSITE_Marshal((TPMU_SENSITIVE_COMPOSITE *)&(source->sensitive), buffer, size, (UINT32)source->sensitiveType)); |
| 4279 | return result; |
| 4280 | } |
| 4281 | |
| 4282 | |
| 4283 | // Table 2:189 - Definition of TPM2B_SENSITIVE Structure (StructureTable) |
| 4284 | TPM_RC |
| 4285 | TPM2B_SENSITIVE_Unmarshal( |
| 4286 | TPM2B_SENSITIVE *target, BYTE **buffer, INT32 *size |
| 4287 | ) |
| 4288 | { |
| 4289 | TPM_RC result; |
| 4290 | INT32 startSize; |
| 4291 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4292 | if(result != TPM_RC_SUCCESS) |
| 4293 | return result; |
| 4294 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4295 | if(target->t.size == 0) |
| 4296 | return TPM_RC_SUCCESS; |
| 4297 | startSize = *size; |
| 4298 | result = TPMT_SENSITIVE_Unmarshal((TPMT_SENSITIVE *)&(target->t.sensitiveArea), buffer, size); |
| 4299 | if(result != TPM_RC_SUCCESS) |
| 4300 | return result; |
| 4301 | if(target->t.size != (startSize - *size)) return TPM_RC_SIZE; |
| 4302 | return TPM_RC_SUCCESS; |
| 4303 | } |
| 4304 | |
| 4305 | // TPM2B_SENSITIVE_Marshal not referenced |
| 4306 | |
| 4307 | |
| 4308 | // Table 2:190 - Definition of _PRIVATE Structure (StructureTable) |
| 4309 | // _PRIVATE_Unmarshal not referenced |
| 4310 | // _PRIVATE_Marshal not referenced |
| 4311 | |
| 4312 | |
| 4313 | // Table 2:191 - Definition of TPM2B_PRIVATE Structure (StructureTable) |
| 4314 | TPM_RC |
| 4315 | TPM2B_PRIVATE_Unmarshal( |
| 4316 | TPM2B_PRIVATE *target, BYTE **buffer, INT32 *size |
| 4317 | ) |
| 4318 | { |
| 4319 | TPM_RC result; |
| 4320 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4321 | if(result != TPM_RC_SUCCESS) |
| 4322 | return result; |
| 4323 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4324 | if(target->t.size == 0) |
| 4325 | return TPM_RC_SUCCESS; |
| 4326 | if((target->t.size) > sizeof(_PRIVATE)) |
| 4327 | return TPM_RC_SIZE; |
| 4328 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 4329 | return result; |
| 4330 | } |
| 4331 | |
| 4332 | UINT16 |
| 4333 | TPM2B_PRIVATE_Marshal( |
| 4334 | TPM2B_PRIVATE *source, BYTE **buffer, INT32 *size |
| 4335 | ) |
| 4336 | { |
| 4337 | UINT16 result = 0; |
| 4338 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 4339 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4340 | if(source->t.size == 0) |
| 4341 | return result; |
| 4342 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 4343 | return result; |
| 4344 | } |
| 4345 | |
| 4346 | |
| 4347 | // Table 2:192 - Definition of _ID_OBJECT Structure (StructureTable) |
| 4348 | // _ID_OBJECT_Unmarshal not referenced |
| 4349 | // _ID_OBJECT_Marshal not referenced |
| 4350 | |
| 4351 | |
| 4352 | // Table 2:193 - Definition of TPM2B_ID_OBJECT Structure (StructureTable) |
| 4353 | TPM_RC |
| 4354 | TPM2B_ID_OBJECT_Unmarshal( |
| 4355 | TPM2B_ID_OBJECT *target, BYTE **buffer, INT32 *size |
| 4356 | ) |
| 4357 | { |
| 4358 | TPM_RC result; |
| 4359 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4360 | if(result != TPM_RC_SUCCESS) |
| 4361 | return result; |
| 4362 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4363 | if(target->t.size == 0) |
| 4364 | return TPM_RC_SUCCESS; |
| 4365 | if((target->t.size) > sizeof(_ID_OBJECT)) |
| 4366 | return TPM_RC_SIZE; |
| 4367 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.credential), buffer, size, (INT32)(target->t.size)); |
| 4368 | return result; |
| 4369 | } |
| 4370 | |
| 4371 | UINT16 |
| 4372 | TPM2B_ID_OBJECT_Marshal( |
| 4373 | TPM2B_ID_OBJECT *source, BYTE **buffer, INT32 *size |
| 4374 | ) |
| 4375 | { |
| 4376 | UINT16 result = 0; |
| 4377 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 4378 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4379 | if(source->t.size == 0) |
| 4380 | return result; |
| 4381 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.credential), buffer, size, (INT32)(source->t.size))); |
| 4382 | return result; |
| 4383 | } |
| 4384 | |
| 4385 | |
| 4386 | // Table 2:194 - Definition of TPM_NV_INDEX Bits (BitsTable) |
| 4387 | // TPM_NV_INDEX_Unmarshal not referenced |
| 4388 | // TPM_NV_INDEX_Marshal not referenced |
| 4389 | |
| 4390 | |
| 4391 | // Table 2:195 - Definition of TPMA_NV Bits (BitsTable) |
| 4392 | TPM_RC |
| 4393 | TPMA_NV_Unmarshal( |
| 4394 | TPMA_NV *target, BYTE **buffer, INT32 *size |
| 4395 | ) |
| 4396 | { |
| 4397 | TPM_RC result; |
| 4398 | result = UINT32_Unmarshal((UINT32 *)target, buffer, size); |
| 4399 | if(result != TPM_RC_SUCCESS) |
| 4400 | return result; |
| 4401 | if(*((UINT32 *)target) & (UINT32)0x01f00380) |
| 4402 | return TPM_RC_RESERVED_BITS; |
| 4403 | return TPM_RC_SUCCESS; |
| 4404 | } |
| 4405 | |
| 4406 | // TPMA_NV_Marshal changed to #define |
| 4407 | |
| 4408 | |
| 4409 | // Table 2:196 - Definition of TPMS_NV_PUBLIC Structure (StructureTable) |
| 4410 | TPM_RC |
| 4411 | TPMS_NV_PUBLIC_Unmarshal( |
| 4412 | TPMS_NV_PUBLIC *target, BYTE **buffer, INT32 *size |
| 4413 | ) |
| 4414 | { |
| 4415 | TPM_RC result; |
| 4416 | result = TPMI_RH_NV_INDEX_Unmarshal((TPMI_RH_NV_INDEX *)&(target->nvIndex), buffer, size); |
| 4417 | if(result != TPM_RC_SUCCESS) |
| 4418 | return result; |
| 4419 | result = TPMI_ALG_HASH_Unmarshal((TPMI_ALG_HASH *)&(target->nameAlg), buffer, size, 0); |
| 4420 | if(result != TPM_RC_SUCCESS) |
| 4421 | return result; |
| 4422 | result = TPMA_NV_Unmarshal((TPMA_NV *)&(target->attributes), buffer, size); |
| 4423 | if(result != TPM_RC_SUCCESS) |
| 4424 | return result; |
| 4425 | result = TPM2B_DIGEST_Unmarshal((TPM2B_DIGEST *)&(target->authPolicy), buffer, size); |
| 4426 | if(result != TPM_RC_SUCCESS) |
| 4427 | return result; |
| 4428 | result = UINT16_Unmarshal((UINT16 *)&(target->dataSize), buffer, size); |
| 4429 | if(result != TPM_RC_SUCCESS) |
| 4430 | return result; |
| 4431 | if( (target->dataSize> MAX_NV_INDEX_SIZE)) |
| 4432 | return TPM_RC_SIZE; |
| 4433 | return TPM_RC_SUCCESS; |
| 4434 | } |
| 4435 | |
| 4436 | UINT16 |
| 4437 | TPMS_NV_PUBLIC_Marshal( |
| 4438 | TPMS_NV_PUBLIC *source, BYTE **buffer, INT32 *size |
| 4439 | ) |
| 4440 | { |
| 4441 | UINT16 result = 0; |
| 4442 | result = (UINT16)(result + TPMI_RH_NV_INDEX_Marshal((TPMI_RH_NV_INDEX *)&(source->nvIndex), buffer, size)); |
| 4443 | result = (UINT16)(result + TPMI_ALG_HASH_Marshal((TPMI_ALG_HASH *)&(source->nameAlg), buffer, size)); |
| 4444 | result = (UINT16)(result + TPMA_NV_Marshal((TPMA_NV *)&(source->attributes), buffer, size)); |
| 4445 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->authPolicy), buffer, size)); |
| 4446 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->dataSize), buffer, size)); |
| 4447 | return result; |
| 4448 | } |
| 4449 | |
| 4450 | |
| 4451 | // Table 2:197 - Definition of TPM2B_NV_PUBLIC Structure (StructureTable) |
| 4452 | TPM_RC |
| 4453 | TPM2B_NV_PUBLIC_Unmarshal( |
| 4454 | TPM2B_NV_PUBLIC *target, BYTE **buffer, INT32 *size |
| 4455 | ) |
| 4456 | { |
| 4457 | TPM_RC result; |
| 4458 | INT32 startSize; |
| 4459 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4460 | if(result != TPM_RC_SUCCESS) |
| 4461 | return result; |
| 4462 | // if size is zero, then the required structure is missing |
| 4463 | if(target->t.size == 0) |
| 4464 | return TPM_RC_SIZE; |
| 4465 | startSize = *size; |
| 4466 | result = TPMS_NV_PUBLIC_Unmarshal((TPMS_NV_PUBLIC *)&(target->t.nvPublic), buffer, size); |
| 4467 | if(result != TPM_RC_SUCCESS) |
| 4468 | return result; |
| 4469 | if(target->t.size != (startSize - *size)) return TPM_RC_SIZE; |
| 4470 | return TPM_RC_SUCCESS; |
| 4471 | } |
| 4472 | |
| 4473 | UINT16 |
| 4474 | TPM2B_NV_PUBLIC_Marshal( |
| 4475 | TPM2B_NV_PUBLIC *source, BYTE **buffer, INT32 *size |
| 4476 | ) |
| 4477 | { |
| 4478 | UINT16 result = 0; |
| 4479 | BYTE *sizeField = *buffer; |
| 4480 | // Advance buffer pointer by cononical size of a UINT16 |
| 4481 | *buffer += 2; |
| 4482 | // Marshal the structure |
| 4483 | result = (UINT16)(result + TPMS_NV_PUBLIC_Marshal((TPMS_NV_PUBLIC *)&(source->t.nvPublic), buffer, size)); |
| 4484 | // Marshal the size |
| 4485 | result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size)); |
| 4486 | return result; |
| 4487 | } |
| 4488 | |
| 4489 | |
| 4490 | // Table 2:198 - Definition of TPM2B_CONTEXT_SENSITIVE Structure (StructureTable) |
| 4491 | // TPM2B_CONTEXT_SENSITIVE_Unmarshal not referenced |
| 4492 | // TPM2B_CONTEXT_SENSITIVE_Marshal not referenced |
| 4493 | |
| 4494 | |
| 4495 | // Table 2:199 - Definition of TPMS_CONTEXT_DATA Structure (StructureTable) |
| 4496 | // TPMS_CONTEXT_DATA_Unmarshal not referenced |
| 4497 | // TPMS_CONTEXT_DATA_Marshal not referenced |
| 4498 | |
| 4499 | |
| 4500 | // Table 2:200 - Definition of TPM2B_CONTEXT_DATA Structure (StructureTable) |
| 4501 | TPM_RC |
| 4502 | TPM2B_CONTEXT_DATA_Unmarshal( |
| 4503 | TPM2B_CONTEXT_DATA *target, BYTE **buffer, INT32 *size |
| 4504 | ) |
| 4505 | { |
| 4506 | TPM_RC result; |
| 4507 | result = UINT16_Unmarshal((UINT16 *)&(target->t.size), buffer, size); |
| 4508 | if(result != TPM_RC_SUCCESS) |
| 4509 | return result; |
| 4510 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4511 | if(target->t.size == 0) |
| 4512 | return TPM_RC_SUCCESS; |
| 4513 | if((target->t.size) > sizeof(TPMS_CONTEXT_DATA)) |
| 4514 | return TPM_RC_SIZE; |
| 4515 | result = BYTE_Array_Unmarshal((BYTE *)(target->t.buffer), buffer, size, (INT32)(target->t.size)); |
| 4516 | return result; |
| 4517 | } |
| 4518 | |
| 4519 | UINT16 |
| 4520 | TPM2B_CONTEXT_DATA_Marshal( |
| 4521 | TPM2B_CONTEXT_DATA *source, BYTE **buffer, INT32 *size |
| 4522 | ) |
| 4523 | { |
| 4524 | UINT16 result = 0; |
| 4525 | result = (UINT16)(result + UINT16_Marshal((UINT16 *)&(source->t.size), buffer, size)); |
| 4526 | // if size equal to 0, the rest of the structure is a zero buffer. Stop processing |
| 4527 | if(source->t.size == 0) |
| 4528 | return result; |
| 4529 | result = (UINT16)(result + BYTE_Array_Marshal((BYTE *)(source->t.buffer), buffer, size, (INT32)(source->t.size))); |
| 4530 | return result; |
| 4531 | } |
| 4532 | |
| 4533 | |
| 4534 | // Table 2:201 - Definition of TPMS_CONTEXT Structure (StructureTable) |
| 4535 | TPM_RC |
| 4536 | TPMS_CONTEXT_Unmarshal( |
| 4537 | TPMS_CONTEXT *target, BYTE **buffer, INT32 *size |
| 4538 | ) |
| 4539 | { |
| 4540 | TPM_RC result; |
| 4541 | result = UINT64_Unmarshal((UINT64 *)&(target->sequence), buffer, size); |
| 4542 | if(result != TPM_RC_SUCCESS) |
| 4543 | return result; |
| 4544 | result = TPMI_DH_CONTEXT_Unmarshal((TPMI_DH_CONTEXT *)&(target->savedHandle), buffer, size); |
| 4545 | if(result != TPM_RC_SUCCESS) |
| 4546 | return result; |
| 4547 | result = TPMI_RH_HIERARCHY_Unmarshal((TPMI_RH_HIERARCHY *)&(target->hierarchy), buffer, size, 1); |
| 4548 | if(result != TPM_RC_SUCCESS) |
| 4549 | return result; |
| 4550 | result = TPM2B_CONTEXT_DATA_Unmarshal((TPM2B_CONTEXT_DATA *)&(target->contextBlob), buffer, size); |
| 4551 | return result; |
| 4552 | } |
| 4553 | |
| 4554 | UINT16 |
| 4555 | TPMS_CONTEXT_Marshal( |
| 4556 | TPMS_CONTEXT *source, BYTE **buffer, INT32 *size |
| 4557 | ) |
| 4558 | { |
| 4559 | UINT16 result = 0; |
| 4560 | result = (UINT16)(result + UINT64_Marshal((UINT64 *)&(source->sequence), buffer, size)); |
| 4561 | result = (UINT16)(result + TPMI_DH_CONTEXT_Marshal((TPMI_DH_CONTEXT *)&(source->savedHandle), buffer, size)); |
| 4562 | result = (UINT16)(result + TPMI_RH_HIERARCHY_Marshal((TPMI_RH_HIERARCHY *)&(source->hierarchy), buffer, size)); |
| 4563 | result = (UINT16)(result + TPM2B_CONTEXT_DATA_Marshal((TPM2B_CONTEXT_DATA *)&(source->contextBlob), buffer, size)); |
| 4564 | return result; |
| 4565 | } |
| 4566 | |
| 4567 | |
| 4568 | // Table 2:203 - Definition of TPMS_CREATION_DATA Structure (StructureTable) |
| 4569 | // TPMS_CREATION_DATA_Unmarshal not referenced |
| 4570 | UINT16 |
| 4571 | TPMS_CREATION_DATA_Marshal( |
| 4572 | TPMS_CREATION_DATA *source, BYTE **buffer, INT32 *size |
| 4573 | ) |
| 4574 | { |
| 4575 | UINT16 result = 0; |
| 4576 | result = (UINT16)(result + TPML_PCR_SELECTION_Marshal((TPML_PCR_SELECTION *)&(source->pcrSelect), buffer, size)); |
| 4577 | result = (UINT16)(result + TPM2B_DIGEST_Marshal((TPM2B_DIGEST *)&(source->pcrDigest), buffer, size)); |
| 4578 | result = (UINT16)(result + TPMA_LOCALITY_Marshal((TPMA_LOCALITY *)&(source->locality), buffer, size)); |
| 4579 | result = (UINT16)(result + TPM_ALG_ID_Marshal((TPM_ALG_ID *)&(source->parentNameAlg), buffer, size)); |
| 4580 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->parentName), buffer, size)); |
| 4581 | result = (UINT16)(result + TPM2B_NAME_Marshal((TPM2B_NAME *)&(source->parentQualifiedName), buffer, size)); |
| 4582 | result = (UINT16)(result + TPM2B_DATA_Marshal((TPM2B_DATA *)&(source->outsideInfo), buffer, size)); |
| 4583 | return result; |
| 4584 | } |
| 4585 | |
| 4586 | |
| 4587 | // Table 2:204 - Definition of TPM2B_CREATION_DATA Structure (StructureTable) |
| 4588 | // TPM2B_CREATION_DATA_Unmarshal not referenced |
| 4589 | UINT16 |
| 4590 | TPM2B_CREATION_DATA_Marshal( |
| 4591 | TPM2B_CREATION_DATA *source, BYTE **buffer, INT32 *size |
| 4592 | ) |
| 4593 | { |
| 4594 | UINT16 result = 0; |
| 4595 | BYTE *sizeField = *buffer; |
| 4596 | // Advance buffer pointer by cononical size of a UINT16 |
| 4597 | *buffer += 2; |
| 4598 | // Marshal the structure |
| 4599 | result = (UINT16)(result + TPMS_CREATION_DATA_Marshal((TPMS_CREATION_DATA *)&(source->t.creationData), buffer, size)); |
| 4600 | // Marshal the size |
| 4601 | result = (UINT16)(result + UINT16_Marshal(&result, &sizeField, size)); |
| 4602 | return result; |
| 4603 | } |
| 4604 | |
| 4605 | // Array Marshal/Unmarshal for TPMS_TAGGED_PROPERTY |
| 4606 | // TPMS_TAGGED_PROPERTY_Array_Unmarshal not referenced |
| 4607 | UINT16 |
| 4608 | TPMS_TAGGED_PROPERTY_Array_Marshal( |
| 4609 | TPMS_TAGGED_PROPERTY *source, BYTE **buffer, INT32 *size, INT32 count |
| 4610 | ) |
| 4611 | { |
| 4612 | UINT16 result = 0; |
| 4613 | INT32 i; |
| 4614 | for(i = 0; i < count; i++) { |
| 4615 | result = (UINT16)(result + TPMS_TAGGED_PROPERTY_Marshal(&source[i], buffer, size)); |
| 4616 | } |
| 4617 | return result; |
| 4618 | } |
| 4619 | |
| 4620 | // Array Marshal/Unmarshal for TPMS_ALG_PROPERTY |
| 4621 | // TPMS_ALG_PROPERTY_Array_Unmarshal not referenced |
| 4622 | UINT16 |
| 4623 | TPMS_ALG_PROPERTY_Array_Marshal( |
| 4624 | TPMS_ALG_PROPERTY *source, BYTE **buffer, INT32 *size, INT32 count |
| 4625 | ) |
| 4626 | { |
| 4627 | UINT16 result = 0; |
| 4628 | INT32 i; |
| 4629 | for(i = 0; i < count; i++) { |
| 4630 | result = (UINT16)(result + TPMS_ALG_PROPERTY_Marshal(&source[i], buffer, size)); |
| 4631 | } |
| 4632 | return result; |
| 4633 | } |
| 4634 | |
| 4635 | // Array Marshal/Unmarshal for TPMS_PCR_SELECTION |
| 4636 | TPM_RC |
| 4637 | TPMS_PCR_SELECTION_Array_Unmarshal( |
| 4638 | TPMS_PCR_SELECTION *target, BYTE **buffer, INT32 *size, INT32 count |
| 4639 | ) |
| 4640 | { |
| 4641 | TPM_RC result; |
| 4642 | INT32 i; |
| 4643 | for(i = 0; i < count; i++) { |
| 4644 | result = TPMS_PCR_SELECTION_Unmarshal(&target[i], buffer, size); |
| 4645 | if(result != TPM_RC_SUCCESS) |
| 4646 | return result; |
| 4647 | } |
| 4648 | return TPM_RC_SUCCESS; |
| 4649 | } |
| 4650 | |
| 4651 | UINT16 |
| 4652 | TPMS_PCR_SELECTION_Array_Marshal( |
| 4653 | TPMS_PCR_SELECTION *source, BYTE **buffer, INT32 *size, INT32 count |
| 4654 | ) |
| 4655 | { |
| 4656 | UINT16 result = 0; |
| 4657 | INT32 i; |
| 4658 | for(i = 0; i < count; i++) { |
| 4659 | result = (UINT16)(result + TPMS_PCR_SELECTION_Marshal(&source[i], buffer, size)); |
| 4660 | } |
| 4661 | return result; |
| 4662 | } |
| 4663 | |
| 4664 | // Array Marshal/Unmarshal for TPMT_HA |
| 4665 | TPM_RC |
| 4666 | TPMT_HA_Array_Unmarshal( |
| 4667 | TPMT_HA *target, BYTE **buffer, INT32 *size, BOOL flag, INT32 count |
| 4668 | ) |
| 4669 | { |
| 4670 | TPM_RC result; |
| 4671 | INT32 i; |
| 4672 | for(i = 0; i < count; i++) { |
| 4673 | result = TPMT_HA_Unmarshal(&target[i], buffer, size, flag); |
| 4674 | if(result != TPM_RC_SUCCESS) |
| 4675 | return result; |
| 4676 | } |
| 4677 | return TPM_RC_SUCCESS; |
| 4678 | } |
| 4679 | |
| 4680 | UINT16 |
| 4681 | TPMT_HA_Array_Marshal( |
| 4682 | TPMT_HA *source, BYTE **buffer, INT32 *size, INT32 count |
| 4683 | ) |
| 4684 | { |
| 4685 | UINT16 result = 0; |
| 4686 | INT32 i; |
| 4687 | for(i = 0; i < count; i++) { |
| 4688 | result = (UINT16)(result + TPMT_HA_Marshal(&source[i], buffer, size)); |
| 4689 | } |
| 4690 | return result; |
| 4691 | } |
| 4692 | |
| 4693 | // Array Marshal/Unmarshal for BYTE |
| 4694 | TPM_RC |
| 4695 | BYTE_Array_Unmarshal( |
| 4696 | BYTE *target, BYTE **buffer, INT32 *size, INT32 count |
| 4697 | ) |
| 4698 | { |
| 4699 | TPM_RC result; |
| 4700 | INT32 i; |
| 4701 | for(i = 0; i < count; i++) { |
| 4702 | result = BYTE_Unmarshal(&target[i], buffer, size); |
| 4703 | if(result != TPM_RC_SUCCESS) |
| 4704 | return result; |
| 4705 | } |
| 4706 | return TPM_RC_SUCCESS; |
| 4707 | } |
| 4708 | |
| 4709 | UINT16 |
| 4710 | BYTE_Array_Marshal( |
| 4711 | BYTE *source, BYTE **buffer, INT32 *size, INT32 count |
| 4712 | ) |
| 4713 | { |
| 4714 | UINT16 result = 0; |
| 4715 | INT32 i; |
| 4716 | for(i = 0; i < count; i++) { |
| 4717 | result = (UINT16)(result + BYTE_Marshal(&source[i], buffer, size)); |
| 4718 | } |
| 4719 | return result; |
| 4720 | } |
| 4721 | |
| 4722 | // Array Marshal/Unmarshal for TPM_HANDLE |
| 4723 | // TPM_HANDLE_Array_Unmarshal not referenced |
| 4724 | UINT16 |
| 4725 | TPM_HANDLE_Array_Marshal( |
| 4726 | TPM_HANDLE *source, BYTE **buffer, INT32 *size, INT32 count |
| 4727 | ) |
| 4728 | { |
| 4729 | UINT16 result = 0; |
| 4730 | INT32 i; |
| 4731 | for(i = 0; i < count; i++) { |
| 4732 | result = (UINT16)(result + TPM_HANDLE_Marshal(&source[i], buffer, size)); |
| 4733 | } |
| 4734 | return result; |
| 4735 | } |
| 4736 | |
| 4737 | // Array Marshal/Unmarshal for TPMA_CC |
| 4738 | // TPMA_CC_Array_Unmarshal not referenced |
| 4739 | UINT16 |
| 4740 | TPMA_CC_Array_Marshal( |
| 4741 | TPMA_CC *source, BYTE **buffer, INT32 *size, INT32 count |
| 4742 | ) |
| 4743 | { |
| 4744 | UINT16 result = 0; |
| 4745 | INT32 i; |
| 4746 | for(i = 0; i < count; i++) { |
| 4747 | result = (UINT16)(result + TPMA_CC_Marshal(&source[i], buffer, size)); |
| 4748 | } |
| 4749 | return result; |
| 4750 | } |
| 4751 | |
| 4752 | // Array Marshal/Unmarshal for TPMS_TAGGED_PCR_SELECT |
| 4753 | // TPMS_TAGGED_PCR_SELECT_Array_Unmarshal not referenced |
| 4754 | UINT16 |
| 4755 | TPMS_TAGGED_PCR_SELECT_Array_Marshal( |
| 4756 | TPMS_TAGGED_PCR_SELECT *source, BYTE **buffer, INT32 *size, INT32 count |
| 4757 | ) |
| 4758 | { |
| 4759 | UINT16 result = 0; |
| 4760 | INT32 i; |
| 4761 | for(i = 0; i < count; i++) { |
| 4762 | result = (UINT16)(result + TPMS_TAGGED_PCR_SELECT_Marshal(&source[i], buffer, size)); |
| 4763 | } |
| 4764 | return result; |
| 4765 | } |
| 4766 | |
| 4767 | // Array Marshal/Unmarshal for TPM_ECC_CURVE |
| 4768 | #ifdef TPM_ALG_ECC |
| 4769 | // TPM_ECC_CURVE_Array_Unmarshal not referenced |
| 4770 | UINT16 |
| 4771 | TPM_ECC_CURVE_Array_Marshal( |
| 4772 | TPM_ECC_CURVE *source, BYTE **buffer, INT32 *size, INT32 count |
| 4773 | ) |
| 4774 | { |
| 4775 | UINT16 result = 0; |
| 4776 | INT32 i; |
| 4777 | for(i = 0; i < count; i++) { |
| 4778 | result = (UINT16)(result + TPM_ECC_CURVE_Marshal(&source[i], buffer, size)); |
| 4779 | } |
| 4780 | return result; |
| 4781 | } |
| 4782 | |
| 4783 | #endif // TPM_ALG_ECC |
| 4784 | // Array Marshal/Unmarshal for TPM2B_DIGEST |
| 4785 | TPM_RC |
| 4786 | TPM2B_DIGEST_Array_Unmarshal( |
| 4787 | TPM2B_DIGEST *target, BYTE **buffer, INT32 *size, INT32 count |
| 4788 | ) |
| 4789 | { |
| 4790 | TPM_RC result; |
| 4791 | INT32 i; |
| 4792 | for(i = 0; i < count; i++) { |
| 4793 | result = TPM2B_DIGEST_Unmarshal(&target[i], buffer, size); |
| 4794 | if(result != TPM_RC_SUCCESS) |
| 4795 | return result; |
| 4796 | } |
| 4797 | return TPM_RC_SUCCESS; |
| 4798 | } |
| 4799 | |
| 4800 | UINT16 |
| 4801 | TPM2B_DIGEST_Array_Marshal( |
| 4802 | TPM2B_DIGEST *source, BYTE **buffer, INT32 *size, INT32 count |
| 4803 | ) |
| 4804 | { |
| 4805 | UINT16 result = 0; |
| 4806 | INT32 i; |
| 4807 | for(i = 0; i < count; i++) { |
| 4808 | result = (UINT16)(result + TPM2B_DIGEST_Marshal(&source[i], buffer, size)); |
| 4809 | } |
| 4810 | return result; |
| 4811 | } |
| 4812 | |
| 4813 | // Array Marshal/Unmarshal for TPM_CC |
| 4814 | TPM_RC |
| 4815 | TPM_CC_Array_Unmarshal( |
| 4816 | TPM_CC *target, BYTE **buffer, INT32 *size, INT32 count |
| 4817 | ) |
| 4818 | { |
| 4819 | TPM_RC result; |
| 4820 | INT32 i; |
| 4821 | for(i = 0; i < count; i++) { |
| 4822 | result = TPM_CC_Unmarshal(&target[i], buffer, size); |
| 4823 | if(result != TPM_RC_SUCCESS) |
| 4824 | return result; |
| 4825 | } |
| 4826 | return TPM_RC_SUCCESS; |
| 4827 | } |
| 4828 | |
| 4829 | UINT16 |
| 4830 | TPM_CC_Array_Marshal( |
| 4831 | TPM_CC *source, BYTE **buffer, INT32 *size, INT32 count |
| 4832 | ) |
| 4833 | { |
| 4834 | UINT16 result = 0; |
| 4835 | INT32 i; |
| 4836 | for(i = 0; i < count; i++) { |
| 4837 | result = (UINT16)(result + TPM_CC_Marshal(&source[i], buffer, size)); |
| 4838 | } |
| 4839 | return result; |
| 4840 | } |
| 4841 | |
| 4842 | // Array Marshal/Unmarshal for TPM_ALG_ID |
| 4843 | TPM_RC |
| 4844 | TPM_ALG_ID_Array_Unmarshal( |
| 4845 | TPM_ALG_ID *target, BYTE **buffer, INT32 *size, INT32 count |
| 4846 | ) |
| 4847 | { |
| 4848 | TPM_RC result; |
| 4849 | INT32 i; |
| 4850 | for(i = 0; i < count; i++) { |
| 4851 | result = TPM_ALG_ID_Unmarshal(&target[i], buffer, size); |
| 4852 | if(result != TPM_RC_SUCCESS) |
| 4853 | return result; |
| 4854 | } |
| 4855 | return TPM_RC_SUCCESS; |
| 4856 | } |
| 4857 | |
| 4858 | UINT16 |
| 4859 | TPM_ALG_ID_Array_Marshal( |
| 4860 | TPM_ALG_ID *source, BYTE **buffer, INT32 *size, INT32 count |
| 4861 | ) |
| 4862 | { |
| 4863 | UINT16 result = 0; |
| 4864 | INT32 i; |
| 4865 | for(i = 0; i < count; i++) { |
| 4866 | result = (UINT16)(result + TPM_ALG_ID_Marshal(&source[i], buffer, size)); |
| 4867 | } |
| 4868 | return result; |
| 4869 | } |
| 4870 | |