/src/tpm2/Marshal_Create.c
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2015 The Chromium OS Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. |
4 | | |
5 | | // THIS CODE IS GENERATED - DO NOT MODIFY! |
6 | | |
7 | | #include "MemoryLib_fp.h" |
8 | | #include "Create_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(Create) |
11 | | static UINT16 Create_Out_Marshal(Create_Out* source, |
12 | | TPMI_ST_COMMAND_TAG tag, |
13 | | BYTE** buffer, |
14 | 0 | INT32* size) { |
15 | 0 | UINT16 total_size = 0; |
16 | 0 | UINT32 parameter_size = 0; |
17 | 0 | BYTE* parameter_size_location; |
18 | 0 | INT32 parameter_size_size = sizeof(UINT32); |
19 | 0 | UINT32 num_response_handles = 0; |
20 | | // Add parameter_size=0 to indicate size of the parameter area. Will be |
21 | | // replaced later by computed parameter_size. |
22 | 0 | if (tag == TPM_ST_SESSIONS) { |
23 | 0 | parameter_size_location = *buffer; |
24 | | // Don't add to total_size, but increment *buffer and decrement *size. |
25 | 0 | UINT32_Marshal(¶meter_size, buffer, size); |
26 | 0 | } |
27 | | // Marshal response parameters. |
28 | 0 | total_size += TPM2B_PRIVATE_Marshal(&source->outPrivate, buffer, size); |
29 | 0 | total_size += TPM2B_PUBLIC_Marshal(&source->outPublic, buffer, size); |
30 | 0 | total_size += |
31 | 0 | TPM2B_CREATION_DATA_Marshal(&source->creationData, buffer, size); |
32 | 0 | total_size += TPM2B_DIGEST_Marshal(&source->creationHash, buffer, size); |
33 | 0 | total_size += TPMT_TK_CREATION_Marshal(&source->creationTicket, buffer, size); |
34 | | // Compute actual parameter_size. Don't add result to total_size. |
35 | 0 | if (tag == TPM_ST_SESSIONS) { |
36 | 0 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
37 | 0 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
38 | 0 | ¶meter_size_size); |
39 | 0 | } |
40 | 0 | return total_size; |
41 | 0 | } |
42 | | #endif |
43 | | |
44 | | static TPM_RC Create_In_Unmarshal(Create_In* target, |
45 | | TPM_HANDLE request_handles[], |
46 | | BYTE** buffer, |
47 | 0 | INT32* size) { |
48 | 0 | TPM_RC result = TPM_RC_SUCCESS; |
49 | | // Get request handles from request_handles array. |
50 | 0 | target->parentHandle = request_handles[0]; |
51 | | // Unmarshal request parameters. |
52 | 0 | result = TPM2B_SENSITIVE_CREATE_Unmarshal(&target->inSensitive, buffer, size); |
53 | 0 | if (result != TPM_RC_SUCCESS) { |
54 | 0 | return result; |
55 | 0 | } |
56 | 0 | result = TPM2B_PUBLIC_Unmarshal(&target->inPublic, buffer, size); |
57 | 0 | if (result != TPM_RC_SUCCESS) { |
58 | 0 | return result; |
59 | 0 | } |
60 | 0 | result = TPM2B_DATA_Unmarshal(&target->outsideInfo, buffer, size); |
61 | 0 | if (result != TPM_RC_SUCCESS) { |
62 | 0 | return result; |
63 | 0 | } |
64 | 0 | result = TPML_PCR_SELECTION_Unmarshal(&target->creationPCR, buffer, size); |
65 | 0 | if (result != TPM_RC_SUCCESS) { |
66 | 0 | return result; |
67 | 0 | } |
68 | 0 | if ((result == TPM_RC_SUCCESS) && *size) { |
69 | 0 | result = TPM_RC_SIZE; |
70 | 0 | } |
71 | 0 | return result; |
72 | 0 | } |
73 | | |
74 | | TPM_RC Exec_Create(TPMI_ST_COMMAND_TAG tag, |
75 | | BYTE** request_parameter_buffer, |
76 | | INT32* request_parameter_buffer_size, |
77 | | TPM_HANDLE request_handles[], |
78 | | UINT32* response_handle_buffer_size, |
79 | 0 | UINT32* response_parameter_buffer_size) { |
80 | 0 | TPM_RC result = TPM_RC_SUCCESS; |
81 | 0 | Create_In in; |
82 | 0 | Create_Out out; |
83 | 0 | #if IS_CC_ENABLED(Create) |
84 | 0 | BYTE* response_buffer; |
85 | 0 | INT32 response_buffer_size; |
86 | 0 | UINT16 bytes_marshalled; |
87 | 0 | UINT16 num_response_handles = 0; |
88 | 0 | #endif |
89 | 0 | *response_handle_buffer_size = 0; |
90 | 0 | *response_parameter_buffer_size = 0; |
91 | | // Unmarshal request parameters to input structure. |
92 | 0 | result = Create_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
93 | 0 | request_parameter_buffer_size); |
94 | 0 | if (result != TPM_RC_SUCCESS) { |
95 | 0 | return result; |
96 | 0 | } |
97 | | // Execute command. |
98 | 0 | result = TPM2_Create(&in, &out); |
99 | 0 | if (result != TPM_RC_SUCCESS) { |
100 | 0 | return result; |
101 | 0 | } |
102 | | // Marshal output structure to global response buffer. |
103 | 0 | #if IS_CC_ENABLED(Create) |
104 | 0 | response_buffer = MemoryGetResponseBuffer(TPM_CC_Create) + 10; |
105 | 0 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
106 | 0 | bytes_marshalled = |
107 | 0 | Create_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size); |
108 | 0 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
109 | 0 | *response_parameter_buffer_size = |
110 | 0 | bytes_marshalled - *response_handle_buffer_size; |
111 | 0 | return TPM_RC_SUCCESS; |
112 | 0 | #endif |
113 | 0 | return TPM_RC_COMMAND_CODE; |
114 | 0 | } |