/src/tpm2/Marshal_StartAuthSession.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 "StartAuthSession_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(StartAuthSession) |
11 | | static UINT16 StartAuthSession_Out_Marshal(StartAuthSession_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 = 1; |
20 | | // Marshal response handles. |
21 | 0 | total_size += |
22 | 0 | TPMI_SH_AUTH_SESSION_Marshal(&source->sessionHandle, buffer, size); |
23 | | // Add parameter_size=0 to indicate size of the parameter area. Will be |
24 | | // replaced later by computed parameter_size. |
25 | 0 | if (tag == TPM_ST_SESSIONS) { |
26 | 0 | parameter_size_location = *buffer; |
27 | | // Don't add to total_size, but increment *buffer and decrement *size. |
28 | 0 | UINT32_Marshal(¶meter_size, buffer, size); |
29 | 0 | } |
30 | | // Marshal response parameters. |
31 | 0 | total_size += TPM2B_NONCE_Marshal(&source->nonceTPM, buffer, size); |
32 | | // Compute actual parameter_size. Don't add result to total_size. |
33 | 0 | if (tag == TPM_ST_SESSIONS) { |
34 | 0 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
35 | 0 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
36 | 0 | ¶meter_size_size); |
37 | 0 | } |
38 | 0 | return total_size; |
39 | 0 | } |
40 | | #endif |
41 | | |
42 | | static TPM_RC StartAuthSession_In_Unmarshal(StartAuthSession_In* target, |
43 | | TPM_HANDLE request_handles[], |
44 | | BYTE** buffer, |
45 | 2 | INT32* size) { |
46 | 2 | TPM_RC result = TPM_RC_SUCCESS; |
47 | | // Get request handles from request_handles array. |
48 | 2 | target->tpmKey = request_handles[0]; |
49 | 2 | target->bind = request_handles[1]; |
50 | | // Unmarshal request parameters. |
51 | 2 | result = TPM2B_NONCE_Unmarshal(&target->nonceCaller, buffer, size); |
52 | 2 | if (result != TPM_RC_SUCCESS) { |
53 | 0 | return result; |
54 | 0 | } |
55 | 2 | result = |
56 | 2 | TPM2B_ENCRYPTED_SECRET_Unmarshal(&target->encryptedSalt, buffer, size); |
57 | 2 | if (result != TPM_RC_SUCCESS) { |
58 | 1 | return result; |
59 | 1 | } |
60 | 1 | result = TPM_SE_Unmarshal(&target->sessionType, buffer, size); |
61 | 1 | if (result != TPM_RC_SUCCESS) { |
62 | 1 | return result; |
63 | 1 | } |
64 | 0 | result = TPMT_SYM_DEF_Unmarshal(&target->symmetric, buffer, size); |
65 | 0 | if (result != TPM_RC_SUCCESS) { |
66 | 0 | return result; |
67 | 0 | } |
68 | 0 | result = TPMI_ALG_HASH_Unmarshal(&target->authHash, buffer, size, FALSE); |
69 | 0 | if (result != TPM_RC_SUCCESS) { |
70 | 0 | return result; |
71 | 0 | } |
72 | 0 | if ((result == TPM_RC_SUCCESS) && *size) { |
73 | 0 | result = TPM_RC_SIZE; |
74 | 0 | } |
75 | 0 | return result; |
76 | 0 | } |
77 | | |
78 | | TPM_RC Exec_StartAuthSession(TPMI_ST_COMMAND_TAG tag, |
79 | | BYTE** request_parameter_buffer, |
80 | | INT32* request_parameter_buffer_size, |
81 | | TPM_HANDLE request_handles[], |
82 | | UINT32* response_handle_buffer_size, |
83 | 2 | UINT32* response_parameter_buffer_size) { |
84 | 2 | TPM_RC result = TPM_RC_SUCCESS; |
85 | 2 | StartAuthSession_In in; |
86 | 2 | StartAuthSession_Out out; |
87 | 2 | #if IS_CC_ENABLED(StartAuthSession) |
88 | 2 | BYTE* response_buffer; |
89 | 2 | INT32 response_buffer_size; |
90 | 2 | UINT16 bytes_marshalled; |
91 | 2 | UINT16 num_response_handles = 1; |
92 | 2 | #endif |
93 | 2 | *response_handle_buffer_size = 0; |
94 | 2 | *response_parameter_buffer_size = 0; |
95 | | // Unmarshal request parameters to input structure. |
96 | 2 | result = StartAuthSession_In_Unmarshal(&in, request_handles, |
97 | 2 | request_parameter_buffer, |
98 | 2 | request_parameter_buffer_size); |
99 | 2 | if (result != TPM_RC_SUCCESS) { |
100 | 2 | return result; |
101 | 2 | } |
102 | | // Execute command. |
103 | 0 | result = TPM2_StartAuthSession(&in, &out); |
104 | 0 | if (result != TPM_RC_SUCCESS) { |
105 | 0 | return result; |
106 | 0 | } |
107 | | // Marshal output structure to global response buffer. |
108 | 0 | #if IS_CC_ENABLED(StartAuthSession) |
109 | 0 | response_buffer = MemoryGetResponseBuffer(TPM_CC_StartAuthSession) + 10; |
110 | 0 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
111 | 0 | bytes_marshalled = StartAuthSession_Out_Marshal(&out, tag, &response_buffer, |
112 | 0 | &response_buffer_size); |
113 | 0 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
114 | 0 | *response_parameter_buffer_size = |
115 | 0 | bytes_marshalled - *response_handle_buffer_size; |
116 | 0 | return TPM_RC_SUCCESS; |
117 | 0 | #endif |
118 | 0 | return TPM_RC_COMMAND_CODE; |
119 | 0 | } |