VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.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.0 KB
Line 
1/** @file
2 This library is BaseCrypto SHA384 hash instance.
3 It can be registered to BaseCrypto router, to serve as hash engine.
4
5Copyright (c) 2018, Intel Corporation. All rights reserved. <BR>
6SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <PiPei.h>
11
12#include <Library/BaseLib.h>
13#include <Library/BaseMemoryLib.h>
14#include <Library/DebugLib.h>
15#include <Library/BaseCryptLib.h>
16#include <Library/MemoryAllocationLib.h>
17#include <Library/HashLib.h>
18
19/**
20 The function set SHA384 to digest list.
21
22 @param DigestList digest list
23 @param Sha384Digest SHA384 digest
24**/
25VOID
26Tpm2SetSha384ToDigestList (
27 IN TPML_DIGEST_VALUES *DigestList,
28 IN UINT8 *Sha384Digest
29 )
30{
31 DigestList->count = 1;
32 DigestList->digests[0].hashAlg = TPM_ALG_SHA384;
33 CopyMem (
34 DigestList->digests[0].digest.sha384,
35 Sha384Digest,
36 SHA384_DIGEST_SIZE
37 );
38}
39
40/**
41 Start hash sequence.
42
43 @param HashHandle Hash handle.
44
45 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
46 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
47**/
48EFI_STATUS
49EFIAPI
50Sha384HashInit (
51 OUT HASH_HANDLE *HashHandle
52 )
53{
54 VOID *Sha384Ctx;
55 UINTN CtxSize;
56
57 CtxSize = Sha384GetContextSize ();
58 Sha384Ctx = AllocatePool (CtxSize);
59 ASSERT (Sha384Ctx != NULL);
60
61 Sha384Init (Sha384Ctx);
62
63 *HashHandle = (HASH_HANDLE)Sha384Ctx;
64
65 return EFI_SUCCESS;
66}
67
68/**
69 Update hash sequence data.
70
71 @param HashHandle Hash handle.
72 @param DataToHash Data to be hashed.
73 @param DataToHashLen Data size.
74
75 @retval EFI_SUCCESS Hash sequence updated.
76**/
77EFI_STATUS
78EFIAPI
79Sha384HashUpdate (
80 IN HASH_HANDLE HashHandle,
81 IN VOID *DataToHash,
82 IN UINTN DataToHashLen
83 )
84{
85 VOID *Sha384Ctx;
86
87 Sha384Ctx = (VOID *)HashHandle;
88 Sha384Update (Sha384Ctx, DataToHash, DataToHashLen);
89
90 return EFI_SUCCESS;
91}
92
93/**
94 Complete hash sequence complete.
95
96 @param HashHandle Hash handle.
97 @param DigestList Digest list.
98
99 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
100**/
101EFI_STATUS
102EFIAPI
103Sha384HashFinal (
104 IN HASH_HANDLE HashHandle,
105 OUT TPML_DIGEST_VALUES *DigestList
106 )
107{
108 UINT8 Digest[SHA384_DIGEST_SIZE];
109 VOID *Sha384Ctx;
110
111 Sha384Ctx = (VOID *)HashHandle;
112 Sha384Final (Sha384Ctx, Digest);
113
114 FreePool (Sha384Ctx);
115
116 Tpm2SetSha384ToDigestList (DigestList, Digest);
117
118 return EFI_SUCCESS;
119}
120
121HASH_INTERFACE mSha384InternalHashInstance = {
122 HASH_ALGORITHM_SHA384_GUID,
123 Sha384HashInit,
124 Sha384HashUpdate,
125 Sha384HashFinal,
126};
127
128/**
129 The function register SHA384 instance.
130
131 @retval EFI_SUCCESS SHA384 instance is registered, or system does not support register SHA384 instance
132**/
133EFI_STATUS
134EFIAPI
135HashInstanceLibSha384Constructor (
136 VOID
137 )
138{
139 EFI_STATUS Status;
140
141 Status = RegisterHashInterfaceLib (&mSha384InternalHashInstance);
142 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
143 //
144 // Unsupported means platform policy does not need this instance enabled.
145 //
146 return EFI_SUCCESS;
147 }
148
149 return Status;
150}
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