Coverage Report

Created: 2025-07-09 06:07

/src/tpm2/Marshal_Commit.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 "Commit_fp.h"
9
10
#if IS_CC_ENABLED(Commit)
11
static UINT16 Commit_Out_Marshal(Commit_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(&parameter_size, buffer, size);
26
0
  }
27
  // Marshal response parameters.
28
0
  total_size += TPM2B_ECC_POINT_Marshal(&source->K, buffer, size);
29
0
  total_size += TPM2B_ECC_POINT_Marshal(&source->L, buffer, size);
30
0
  total_size += TPM2B_ECC_POINT_Marshal(&source->E, buffer, size);
31
0
  total_size += UINT16_Marshal(&source->counter, 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(&parameter_size, &parameter_size_location,
36
0
                   &parameter_size_size);
37
0
  }
38
0
  return total_size;
39
0
}
40
#endif
41
42
static TPM_RC Commit_In_Unmarshal(Commit_In* target,
43
                                  TPM_HANDLE request_handles[],
44
                                  BYTE** buffer,
45
0
                                  INT32* size) {
46
0
  TPM_RC result = TPM_RC_SUCCESS;
47
  // Get request handles from request_handles array.
48
0
  target->signHandle = request_handles[0];
49
  // Unmarshal request parameters.
50
0
  result = TPM2B_ECC_POINT_Unmarshal(&target->P1, buffer, size);
51
0
  if (result != TPM_RC_SUCCESS) {
52
0
    return result;
53
0
  }
54
0
  result = TPM2B_SENSITIVE_DATA_Unmarshal(&target->s2, buffer, size);
55
0
  if (result != TPM_RC_SUCCESS) {
56
0
    return result;
57
0
  }
58
0
  result = TPM2B_ECC_PARAMETER_Unmarshal(&target->y2, buffer, size);
59
0
  if (result != TPM_RC_SUCCESS) {
60
0
    return result;
61
0
  }
62
0
  if ((result == TPM_RC_SUCCESS) && *size) {
63
0
    result = TPM_RC_SIZE;
64
0
  }
65
0
  return result;
66
0
}
67
68
TPM_RC Exec_Commit(TPMI_ST_COMMAND_TAG tag,
69
                   BYTE** request_parameter_buffer,
70
                   INT32* request_parameter_buffer_size,
71
                   TPM_HANDLE request_handles[],
72
                   UINT32* response_handle_buffer_size,
73
0
                   UINT32* response_parameter_buffer_size) {
74
0
  TPM_RC result = TPM_RC_SUCCESS;
75
0
  Commit_In in;
76
0
  Commit_Out out;
77
0
#if IS_CC_ENABLED(Commit)
78
0
  BYTE* response_buffer;
79
0
  INT32 response_buffer_size;
80
0
  UINT16 bytes_marshalled;
81
0
  UINT16 num_response_handles = 0;
82
0
#endif
83
0
  *response_handle_buffer_size = 0;
84
0
  *response_parameter_buffer_size = 0;
85
  // Unmarshal request parameters to input structure.
86
0
  result = Commit_In_Unmarshal(&in, request_handles, request_parameter_buffer,
87
0
                               request_parameter_buffer_size);
88
0
  if (result != TPM_RC_SUCCESS) {
89
0
    return result;
90
0
  }
91
  // Execute command.
92
0
  result = TPM2_Commit(&in, &out);
93
0
  if (result != TPM_RC_SUCCESS) {
94
0
    return result;
95
0
  }
96
// Marshal output structure to global response buffer.
97
0
#if IS_CC_ENABLED(Commit)
98
0
  response_buffer = MemoryGetResponseBuffer(TPM_CC_Commit) + 10;
99
0
  response_buffer_size = MAX_RESPONSE_SIZE - 10;
100
0
  bytes_marshalled =
101
0
      Commit_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size);
102
0
  *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
103
0
  *response_parameter_buffer_size =
104
0
      bytes_marshalled - *response_handle_buffer_size;
105
0
  return TPM_RC_SUCCESS;
106
0
#endif
107
0
  return TPM_RC_COMMAND_CODE;
108
0
}