Coverage Report

Created: 2023-06-07 06:46

/src/tpm2/Marshal_Hash.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 "Hash_fp.h"
9
10
#if IS_CC_ENABLED(Hash)
11
static UINT16 Hash_Out_Marshal(Hash_Out* source,
12
                               TPMI_ST_COMMAND_TAG tag,
13
                               BYTE** buffer,
14
15
                               INT32* size) {
15
15
  UINT16 total_size = 0;
16
15
  UINT32 parameter_size = 0;
17
15
  BYTE* parameter_size_location;
18
15
  INT32 parameter_size_size = sizeof(UINT32);
19
15
  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
15
  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
15
  total_size += TPM2B_DIGEST_Marshal(&source->outHash, buffer, size);
29
15
  total_size += TPMT_TK_HASHCHECK_Marshal(&source->validation, buffer, size);
30
  // Compute actual parameter_size. Don't add result to total_size.
31
15
  if (tag == TPM_ST_SESSIONS) {
32
0
    parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
33
0
    UINT32_Marshal(&parameter_size, &parameter_size_location,
34
0
                   &parameter_size_size);
35
0
  }
36
15
  return total_size;
37
15
}
38
#endif
39
40
static TPM_RC Hash_In_Unmarshal(Hash_In* target,
41
                                TPM_HANDLE request_handles[],
42
                                BYTE** buffer,
43
55
                                INT32* size) {
44
55
  TPM_RC result = TPM_RC_SUCCESS;
45
  // Unmarshal request parameters.
46
55
  result = TPM2B_MAX_BUFFER_Unmarshal(&target->data, buffer, size);
47
55
  if (result != TPM_RC_SUCCESS) {
48
28
    return result;
49
28
  }
50
27
  result = TPMI_ALG_HASH_Unmarshal(&target->hashAlg, buffer, size, FALSE);
51
27
  if (result != TPM_RC_SUCCESS) {
52
6
    return result;
53
6
  }
54
21
  result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE);
55
21
  if (result != TPM_RC_SUCCESS) {
56
4
    return result;
57
4
  }
58
17
  if ((result == TPM_RC_SUCCESS) && *size) {
59
2
    result = TPM_RC_SIZE;
60
2
  }
61
17
  return result;
62
21
}
63
64
TPM_RC Exec_Hash(TPMI_ST_COMMAND_TAG tag,
65
                 BYTE** request_parameter_buffer,
66
                 INT32* request_parameter_buffer_size,
67
                 TPM_HANDLE request_handles[],
68
                 UINT32* response_handle_buffer_size,
69
55
                 UINT32* response_parameter_buffer_size) {
70
55
  TPM_RC result = TPM_RC_SUCCESS;
71
55
  Hash_In in;
72
55
  Hash_Out out;
73
55
#if IS_CC_ENABLED(Hash)
74
55
  BYTE* response_buffer;
75
55
  INT32 response_buffer_size;
76
55
  UINT16 bytes_marshalled;
77
55
  UINT16 num_response_handles = 0;
78
55
#endif
79
55
  *response_handle_buffer_size = 0;
80
55
  *response_parameter_buffer_size = 0;
81
  // Unmarshal request parameters to input structure.
82
55
  result = Hash_In_Unmarshal(&in, request_handles, request_parameter_buffer,
83
55
                             request_parameter_buffer_size);
84
55
  if (result != TPM_RC_SUCCESS) {
85
40
    return result;
86
40
  }
87
  // Execute command.
88
15
  result = TPM2_Hash(&in, &out);
89
15
  if (result != TPM_RC_SUCCESS) {
90
0
    return result;
91
0
  }
92
// Marshal output structure to global response buffer.
93
15
#if IS_CC_ENABLED(Hash)
94
15
  response_buffer = MemoryGetResponseBuffer(TPM_CC_Hash) + 10;
95
15
  response_buffer_size = MAX_RESPONSE_SIZE - 10;
96
15
  bytes_marshalled =
97
15
      Hash_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size);
98
15
  *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
99
15
  *response_parameter_buffer_size =
100
15
      bytes_marshalled - *response_handle_buffer_size;
101
15
  return TPM_RC_SUCCESS;
102
0
#endif
103
0
  return TPM_RC_COMMAND_CODE;
104
15
}