VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c

Last change on this file was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/** @file
2 Implement TPM2 Miscellaneous related command.
3
4Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <IndustryStandard/UefiTcgPlatform.h>
10#include <Library/Tpm2CommandLib.h>
11#include <Library/Tpm2DeviceLib.h>
12#include <Library/BaseMemoryLib.h>
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
19 TPM2_COMMAND_HEADER Header;
20 TPMI_RH_HIERARCHY_AUTH AuthHandle;
21 UINT32 AuthSessionSize;
22 TPMS_AUTH_COMMAND AuthSession;
23 UINT32 AlgorithmSet;
24} TPM2_SET_ALGORITHM_SET_COMMAND;
25
26typedef struct {
27 TPM2_RESPONSE_HEADER Header;
28 UINT32 AuthSessionSize;
29 TPMS_AUTH_RESPONSE AuthSession;
30} TPM2_SET_ALGORITHM_SET_RESPONSE;
31
32#pragma pack()
33
34/**
35 This command allows the platform to change the set of algorithms that are used by the TPM.
36 The algorithmSet setting is a vendor-dependent value.
37
38 @param[in] AuthHandle TPM_RH_PLATFORM
39 @param[in] AuthSession Auth Session context
40 @param[in] AlgorithmSet A TPM vendor-dependent value indicating the
41 algorithm set selection
42
43 @retval EFI_SUCCESS Operation completed successfully.
44 @retval EFI_DEVICE_ERROR Unexpected device behavior.
45**/
46EFI_STATUS
47EFIAPI
48Tpm2SetAlgorithmSet (
49 IN TPMI_RH_PLATFORM AuthHandle,
50 IN TPMS_AUTH_COMMAND *AuthSession,
51 IN UINT32 AlgorithmSet
52 )
53{
54 EFI_STATUS Status;
55 TPM2_SET_ALGORITHM_SET_COMMAND SendBuffer;
56 TPM2_SET_ALGORITHM_SET_RESPONSE RecvBuffer;
57 UINT32 SendBufferSize;
58 UINT32 RecvBufferSize;
59 UINT8 *Buffer;
60 UINT32 SessionInfoSize;
61
62 //
63 // Construct command
64 //
65 SendBuffer.Header.tag = SwapBytes16 (TPM_ST_SESSIONS);
66 SendBuffer.Header.commandCode = SwapBytes32 (TPM_CC_SetAlgorithmSet);
67
68 SendBuffer.AuthHandle = SwapBytes32 (AuthHandle);
69
70 //
71 // Add in Auth session
72 //
73 Buffer = (UINT8 *)&SendBuffer.AuthSession;
74
75 // sessionInfoSize
76 SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer);
77 Buffer += SessionInfoSize;
78 SendBuffer.AuthSessionSize = SwapBytes32 (SessionInfoSize);
79
80 //
81 // Real data
82 //
83 WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (AlgorithmSet));
84 Buffer += sizeof (UINT32);
85
86 SendBufferSize = (UINT32)((UINTN)Buffer - (UINTN)&SendBuffer);
87 SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);
88
89 //
90 // send Tpm command
91 //
92 RecvBufferSize = sizeof (RecvBuffer);
93 Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
94 if (EFI_ERROR (Status)) {
95 goto Done;
96 }
97
98 if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
99 DEBUG ((DEBUG_ERROR, "Tpm2SetAlgorithmSet - RecvBufferSize Error - %x\n", RecvBufferSize));
100 Status = EFI_DEVICE_ERROR;
101 goto Done;
102 }
103
104 if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
105 DEBUG ((DEBUG_ERROR, "Tpm2SetAlgorithmSet - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));
106 Status = EFI_DEVICE_ERROR;
107 goto Done;
108 }
109
110Done:
111 //
112 // Clear AuthSession Content
113 //
114 ZeroMem (&SendBuffer, sizeof (SendBuffer));
115 ZeroMem (&RecvBuffer, sizeof (RecvBuffer));
116 return Status;
117}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette