Coverage Report

Created: 2023-06-07 06:46

/src/tpm2/Marshal_PCR_Allocate.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 "PCR_Allocate_fp.h"
9
10
#if IS_CC_ENABLED(PCR_Allocate)
11
static UINT16 PCR_Allocate_Out_Marshal(PCR_Allocate_Out* source,
12
                                       TPMI_ST_COMMAND_TAG tag,
13
                                       BYTE** buffer,
14
21
                                       INT32* size) {
15
21
  UINT16 total_size = 0;
16
21
  UINT32 parameter_size = 0;
17
21
  BYTE* parameter_size_location;
18
21
  INT32 parameter_size_size = sizeof(UINT32);
19
21
  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
21
  if (tag == TPM_ST_SESSIONS) {
23
21
    parameter_size_location = *buffer;
24
    // Don't add to total_size, but increment *buffer and decrement *size.
25
21
    UINT32_Marshal(&parameter_size, buffer, size);
26
21
  }
27
  // Marshal response parameters.
28
21
  total_size += TPMI_YES_NO_Marshal(&source->allocationSuccess, buffer, size);
29
21
  total_size += UINT32_Marshal(&source->maxPCR, buffer, size);
30
21
  total_size += UINT32_Marshal(&source->sizeNeeded, buffer, size);
31
21
  total_size += UINT32_Marshal(&source->sizeAvailable, buffer, size);
32
  // Compute actual parameter_size. Don't add result to total_size.
33
21
  if (tag == TPM_ST_SESSIONS) {
34
21
    parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
35
21
    UINT32_Marshal(&parameter_size, &parameter_size_location,
36
21
                   &parameter_size_size);
37
21
  }
38
21
  return total_size;
39
21
}
40
#endif
41
42
static TPM_RC PCR_Allocate_In_Unmarshal(PCR_Allocate_In* target,
43
                                        TPM_HANDLE request_handles[],
44
                                        BYTE** buffer,
45
25
                                        INT32* size) {
46
25
  TPM_RC result = TPM_RC_SUCCESS;
47
  // Get request handles from request_handles array.
48
25
  target->authHandle = request_handles[0];
49
  // Unmarshal request parameters.
50
25
  result = TPML_PCR_SELECTION_Unmarshal(&target->pcrAllocation, buffer, size);
51
25
  if (result != TPM_RC_SUCCESS) {
52
3
    return result;
53
3
  }
54
22
  if ((result == TPM_RC_SUCCESS) && *size) {
55
1
    result = TPM_RC_SIZE;
56
1
  }
57
22
  return result;
58
25
}
59
60
TPM_RC Exec_PCR_Allocate(TPMI_ST_COMMAND_TAG tag,
61
                         BYTE** request_parameter_buffer,
62
                         INT32* request_parameter_buffer_size,
63
                         TPM_HANDLE request_handles[],
64
                         UINT32* response_handle_buffer_size,
65
25
                         UINT32* response_parameter_buffer_size) {
66
25
  TPM_RC result = TPM_RC_SUCCESS;
67
25
  PCR_Allocate_In in;
68
25
  PCR_Allocate_Out out;
69
25
#if IS_CC_ENABLED(PCR_Allocate)
70
25
  BYTE* response_buffer;
71
25
  INT32 response_buffer_size;
72
25
  UINT16 bytes_marshalled;
73
25
  UINT16 num_response_handles = 0;
74
25
#endif
75
25
  *response_handle_buffer_size = 0;
76
25
  *response_parameter_buffer_size = 0;
77
  // Unmarshal request parameters to input structure.
78
25
  result =
79
25
      PCR_Allocate_In_Unmarshal(&in, request_handles, request_parameter_buffer,
80
25
                                request_parameter_buffer_size);
81
25
  if (result != TPM_RC_SUCCESS) {
82
4
    return result;
83
4
  }
84
  // Execute command.
85
21
  result = TPM2_PCR_Allocate(&in, &out);
86
21
  if (result != TPM_RC_SUCCESS) {
87
0
    return result;
88
0
  }
89
// Marshal output structure to global response buffer.
90
21
#if IS_CC_ENABLED(PCR_Allocate)
91
21
  response_buffer = MemoryGetResponseBuffer(TPM_CC_PCR_Allocate) + 10;
92
21
  response_buffer_size = MAX_RESPONSE_SIZE - 10;
93
21
  bytes_marshalled = PCR_Allocate_Out_Marshal(&out, tag, &response_buffer,
94
21
                                              &response_buffer_size);
95
21
  *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
96
21
  *response_parameter_buffer_size =
97
21
      bytes_marshalled - *response_handle_buffer_size;
98
21
  return TPM_RC_SUCCESS;
99
0
#endif
100
0
  return TPM_RC_COMMAND_CODE;
101
21
}