Coverage Report

Created: 2026-04-29 06:37

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