Coverage Report

Created: 2026-02-26 06:47

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