/src/tpm2/Marshal_CreatePrimary.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 "CreatePrimary_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(CreatePrimary) |
11 | | static UINT16 CreatePrimary_Out_Marshal(CreatePrimary_Out* source, |
12 | | TPMI_ST_COMMAND_TAG tag, |
13 | | BYTE** buffer, |
14 | 77 | INT32* size) { |
15 | 77 | UINT16 total_size = 0; |
16 | 77 | UINT32 parameter_size = 0; |
17 | 77 | BYTE* parameter_size_location; |
18 | 77 | INT32 parameter_size_size = sizeof(UINT32); |
19 | 77 | UINT32 num_response_handles = 1; |
20 | | // Marshal response handles. |
21 | 77 | total_size += TPM_HANDLE_Marshal(&source->objectHandle, buffer, size); |
22 | | // Add parameter_size=0 to indicate size of the parameter area. Will be |
23 | | // replaced later by computed parameter_size. |
24 | 77 | if (tag == TPM_ST_SESSIONS) { |
25 | 77 | parameter_size_location = *buffer; |
26 | | // Don't add to total_size, but increment *buffer and decrement *size. |
27 | 77 | UINT32_Marshal(¶meter_size, buffer, size); |
28 | 77 | } |
29 | | // Marshal response parameters. |
30 | 77 | total_size += TPM2B_PUBLIC_Marshal(&source->outPublic, buffer, size); |
31 | 77 | total_size += |
32 | 77 | TPM2B_CREATION_DATA_Marshal(&source->creationData, buffer, size); |
33 | 77 | total_size += TPM2B_DIGEST_Marshal(&source->creationHash, buffer, size); |
34 | 77 | total_size += TPMT_TK_CREATION_Marshal(&source->creationTicket, buffer, size); |
35 | 77 | total_size += TPM2B_NAME_Marshal(&source->name, buffer, size); |
36 | | // Compute actual parameter_size. Don't add result to total_size. |
37 | 77 | if (tag == TPM_ST_SESSIONS) { |
38 | 77 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
39 | 77 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
40 | 77 | ¶meter_size_size); |
41 | 77 | } |
42 | 77 | return total_size; |
43 | 77 | } |
44 | | #endif |
45 | | |
46 | | static TPM_RC CreatePrimary_In_Unmarshal(CreatePrimary_In* target, |
47 | | TPM_HANDLE request_handles[], |
48 | | BYTE** buffer, |
49 | 113 | INT32* size) { |
50 | 113 | TPM_RC result = TPM_RC_SUCCESS; |
51 | | // Get request handles from request_handles array. |
52 | 113 | target->primaryHandle = request_handles[0]; |
53 | | // Unmarshal request parameters. |
54 | 113 | result = TPM2B_SENSITIVE_CREATE_Unmarshal(&target->inSensitive, buffer, size); |
55 | 113 | if (result != TPM_RC_SUCCESS) { |
56 | 12 | return result; |
57 | 12 | } |
58 | 101 | result = TPM2B_PUBLIC_Unmarshal(&target->inPublic, buffer, size); |
59 | 101 | if (result != TPM_RC_SUCCESS) { |
60 | 8 | return result; |
61 | 8 | } |
62 | 93 | result = TPM2B_DATA_Unmarshal(&target->outsideInfo, buffer, size); |
63 | 93 | if (result != TPM_RC_SUCCESS) { |
64 | 1 | return result; |
65 | 1 | } |
66 | 92 | result = TPML_PCR_SELECTION_Unmarshal(&target->creationPCR, buffer, size); |
67 | 92 | if (result != TPM_RC_SUCCESS) { |
68 | 1 | return result; |
69 | 1 | } |
70 | 91 | if ((result == TPM_RC_SUCCESS) && *size) { |
71 | 0 | result = TPM_RC_SIZE; |
72 | 0 | } |
73 | 91 | return result; |
74 | 92 | } |
75 | | |
76 | | TPM_RC Exec_CreatePrimary(TPMI_ST_COMMAND_TAG tag, |
77 | | BYTE** request_parameter_buffer, |
78 | | INT32* request_parameter_buffer_size, |
79 | | TPM_HANDLE request_handles[], |
80 | | UINT32* response_handle_buffer_size, |
81 | 113 | UINT32* response_parameter_buffer_size) { |
82 | 113 | TPM_RC result = TPM_RC_SUCCESS; |
83 | 113 | CreatePrimary_In in; |
84 | 113 | CreatePrimary_Out out; |
85 | 113 | #if IS_CC_ENABLED(CreatePrimary) |
86 | 113 | BYTE* response_buffer; |
87 | 113 | INT32 response_buffer_size; |
88 | 113 | UINT16 bytes_marshalled; |
89 | 113 | UINT16 num_response_handles = 1; |
90 | 113 | #endif |
91 | 113 | *response_handle_buffer_size = 0; |
92 | 113 | *response_parameter_buffer_size = 0; |
93 | | // Unmarshal request parameters to input structure. |
94 | 113 | result = |
95 | 113 | CreatePrimary_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
96 | 113 | request_parameter_buffer_size); |
97 | 113 | if (result != TPM_RC_SUCCESS) { |
98 | 22 | return result; |
99 | 22 | } |
100 | | // Execute command. |
101 | 91 | result = TPM2_CreatePrimary(&in, &out); |
102 | 91 | if (result != TPM_RC_SUCCESS) { |
103 | 14 | return result; |
104 | 14 | } |
105 | | // Marshal output structure to global response buffer. |
106 | 77 | #if IS_CC_ENABLED(CreatePrimary) |
107 | 77 | response_buffer = MemoryGetResponseBuffer(TPM_CC_CreatePrimary) + 10; |
108 | 77 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
109 | 77 | bytes_marshalled = CreatePrimary_Out_Marshal(&out, tag, &response_buffer, |
110 | 77 | &response_buffer_size); |
111 | 77 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
112 | 77 | *response_parameter_buffer_size = |
113 | 77 | bytes_marshalled - *response_handle_buffer_size; |
114 | 77 | return TPM_RC_SUCCESS; |
115 | 0 | #endif |
116 | 0 | return TPM_RC_COMMAND_CODE; |
117 | 91 | } |