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