Coverage Report

Created: 2026-01-09 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tpm2/Marshal_GetRandom.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 "GetRandom_fp.h"
9
10
#if IS_CC_ENABLED(GetRandom)
11
static UINT16 GetRandom_Out_Marshal(GetRandom_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_DIGEST_Marshal(&source->randomBytes, buffer, size);
29
  // Compute actual parameter_size. Don't add result to total_size.
30
0
  if (tag == TPM_ST_SESSIONS) {
31
0
    parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
32
0
    UINT32_Marshal(&parameter_size, &parameter_size_location,
33
0
                   &parameter_size_size);
34
0
  }
35
0
  return total_size;
36
0
}
37
#endif
38
39
static TPM_RC GetRandom_In_Unmarshal(GetRandom_In* target,
40
                                     TPM_HANDLE request_handles[],
41
                                     BYTE** buffer,
42
3
                                     INT32* size) {
43
3
  TPM_RC result = TPM_RC_SUCCESS;
44
  // Unmarshal request parameters.
45
3
  result = UINT16_Unmarshal(&target->bytesRequested, buffer, size);
46
3
  if (result != TPM_RC_SUCCESS) {
47
0
    return result;
48
0
  }
49
3
  if ((result == TPM_RC_SUCCESS) && *size) {
50
3
    result = TPM_RC_SIZE;
51
3
  }
52
3
  return result;
53
3
}
54
55
TPM_RC Exec_GetRandom(TPMI_ST_COMMAND_TAG tag,
56
                      BYTE** request_parameter_buffer,
57
                      INT32* request_parameter_buffer_size,
58
                      TPM_HANDLE request_handles[],
59
                      UINT32* response_handle_buffer_size,
60
3
                      UINT32* response_parameter_buffer_size) {
61
3
  TPM_RC result = TPM_RC_SUCCESS;
62
3
  GetRandom_In in;
63
3
  GetRandom_Out out;
64
3
#if IS_CC_ENABLED(GetRandom)
65
3
  BYTE* response_buffer;
66
3
  INT32 response_buffer_size;
67
3
  UINT16 bytes_marshalled;
68
3
  UINT16 num_response_handles = 0;
69
3
#endif
70
3
  *response_handle_buffer_size = 0;
71
3
  *response_parameter_buffer_size = 0;
72
  // Unmarshal request parameters to input structure.
73
3
  result =
74
3
      GetRandom_In_Unmarshal(&in, request_handles, request_parameter_buffer,
75
3
                             request_parameter_buffer_size);
76
3
  if (result != TPM_RC_SUCCESS) {
77
3
    return result;
78
3
  }
79
  // Execute command.
80
0
  result = TPM2_GetRandom(&in, &out);
81
0
  if (result != TPM_RC_SUCCESS) {
82
0
    return result;
83
0
  }
84
// Marshal output structure to global response buffer.
85
0
#if IS_CC_ENABLED(GetRandom)
86
0
  response_buffer = MemoryGetResponseBuffer(TPM_CC_GetRandom) + 10;
87
0
  response_buffer_size = MAX_RESPONSE_SIZE - 10;
88
0
  bytes_marshalled =
89
0
      GetRandom_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size);
90
0
  *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
91
0
  *response_parameter_buffer_size =
92
0
      bytes_marshalled - *response_handle_buffer_size;
93
0
  return TPM_RC_SUCCESS;
94
0
#endif
95
0
  return TPM_RC_COMMAND_CODE;
96
0
}