1a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr// Copyright 2015 The Chromium OS Authors. All rights reserved.
2a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr// Use of this source code is governed by a BSD-style license that can be
3a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr// found in the LICENSE file.
4a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr
5a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr// THIS CODE IS GENERATED - DO NOT MODIFY!
6a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr
7a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#include "MemoryLib_fp.h"
8a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#include "ECC_Parameters_fp.h"
9a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr
10a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn BohrUINT16 ECC_Parameters_Out_Marshal(ECC_Parameters_Out* source,
11a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                  TPMI_ST_COMMAND_TAG tag,
12a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                  BYTE** buffer,
13a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                  INT32* size) {
14a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  UINT16 total_size = 0;
15a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  UINT32 parameter_size = 0;
16a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  BYTE* parameter_size_location;
17a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  INT32 parameter_size_size = sizeof(UINT32);
18a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  UINT32 num_response_handles = 0;
19a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Add parameter_size=0 to indicate size of the parameter area. Will be
20a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // replaced later by computed parameter_size.
21a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  if (tag == TPM_ST_SESSIONS) {
22a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    parameter_size_location = *buffer;
23a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    // Don't add to total_size, but increment *buffer and decrement *size.
24a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    UINT32_Marshal(&parameter_size, buffer, size);
25a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  }
26a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Marshal response parameters.
27a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  total_size +=
28a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr      TPMS_ALGORITHM_DETAIL_ECC_Marshal(&source->parameters, buffer, size);
29a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Compute actual parameter_size. Don't add result to total_size.
30a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  if (tag == TPM_ST_SESSIONS) {
31a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
32a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    UINT32_Marshal(&parameter_size, &parameter_size_location,
33a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                   &parameter_size_size);
34a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  }
35a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  return total_size;
36a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr}
37a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr
38a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn BohrTPM_RC ECC_Parameters_In_Unmarshal(ECC_Parameters_In* target,
39a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                   TPM_HANDLE request_handles[],
40a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                   BYTE** buffer,
41a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                   INT32* size) {
42a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  TPM_RC result = TPM_RC_SUCCESS;
43a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Unmarshal request parameters.
44a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  result = TPMI_ECC_CURVE_Unmarshal(&target->curveID, buffer, size);
45a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  if (result != TPM_RC_SUCCESS) {
46a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    return result;
47a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  }
483dfffca12cb483bee81b6f65b6aeed027204b8f1Vadim Bendebury  if ((result == TPM_RC_SUCCESS) && *size) {
493dfffca12cb483bee81b6f65b6aeed027204b8f1Vadim Bendebury    result = TPM_RC_SIZE;
503dfffca12cb483bee81b6f65b6aeed027204b8f1Vadim Bendebury  }
51a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  return result;
52a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr}
53a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr
54a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn BohrTPM_RC Exec_ECC_Parameters(TPMI_ST_COMMAND_TAG tag,
55a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                           BYTE** request_parameter_buffer,
56a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                           INT32* request_parameter_buffer_size,
57a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                           TPM_HANDLE request_handles[],
58a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                           UINT32* response_handle_buffer_size,
59a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                           UINT32* response_parameter_buffer_size) {
60a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  TPM_RC result = TPM_RC_SUCCESS;
61a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  ECC_Parameters_In in;
62a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  ECC_Parameters_Out out;
63a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#ifdef TPM_CC_ECC_Parameters
64a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  BYTE* response_buffer;
65a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  INT32 response_buffer_size;
66a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  UINT16 bytes_marshalled;
67a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  UINT16 num_response_handles = 0;
68a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#endif
69a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  *response_handle_buffer_size = 0;
70a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  *response_parameter_buffer_size = 0;
71a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Unmarshal request parameters to input structure.
72a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  result = ECC_Parameters_In_Unmarshal(&in, request_handles,
73a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                       request_parameter_buffer,
74a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                       request_parameter_buffer_size);
75a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  if (result != TPM_RC_SUCCESS) {
76a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    return result;
77a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  }
78a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  // Execute command.
79a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  result = TPM2_ECC_Parameters(&in, &out);
80a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  if (result != TPM_RC_SUCCESS) {
81a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr    return result;
82a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  }
83a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr// Marshal output structure to global response buffer.
84a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#ifdef TPM_CC_ECC_Parameters
85a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  response_buffer = MemoryGetResponseBuffer(TPM_CC_ECC_Parameters) + 10;
86a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  response_buffer_size = MAX_RESPONSE_SIZE - 10;
87a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  bytes_marshalled = ECC_Parameters_Out_Marshal(&out, tag, &response_buffer,
88a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr                                                &response_buffer_size);
89a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
90a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  *response_parameter_buffer_size =
91a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr      bytes_marshalled - *response_handle_buffer_size;
92a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  return TPM_RC_SUCCESS;
93a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr#endif
94a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr  return TPM_RC_COMMAND_CODE;
95a4ed3aa64664a1241ea982d685db744caaae3ffaJocelyn Bohr}
96