TianoCore EDK2 master
Loading...
Searching...
No Matches
HashInstanceLibSha512.c
Go to the documentation of this file.
1
10#include <PiPei.h>
11#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
16#include <Library/HashLib.h>
17
24VOID
26 IN TPML_DIGEST_VALUES *DigestList,
27 IN UINT8 *Sha512Digest
28 )
29{
30 DigestList->count = 1;
31 DigestList->digests[0].hashAlg = TPM_ALG_SHA512;
32 CopyMem (
33 DigestList->digests[0].digest.sha512,
34 Sha512Digest,
36 );
37}
38
48EFIAPI
50 OUT HASH_HANDLE *HashHandle
51 )
52{
53 VOID *Sha512Ctx;
54 UINTN CtxSize;
55
56 CtxSize = Sha512GetContextSize ();
57 Sha512Ctx = AllocatePool (CtxSize);
58 ASSERT (Sha512Ctx != NULL);
59
60 Sha512Init (Sha512Ctx);
61
62 *HashHandle = (HASH_HANDLE)Sha512Ctx;
63
64 return EFI_SUCCESS;
65}
66
77EFIAPI
79 IN HASH_HANDLE HashHandle,
80 IN VOID *DataToHash,
81 IN UINTN DataToHashLen
82 )
83{
84 VOID *Sha512Ctx;
85
86 Sha512Ctx = (VOID *)HashHandle;
87 Sha512Update (Sha512Ctx, DataToHash, DataToHashLen);
88
89 return EFI_SUCCESS;
90}
91
101EFIAPI
103 IN HASH_HANDLE HashHandle,
104 OUT TPML_DIGEST_VALUES *DigestList
105 )
106{
107 UINT8 Digest[SHA512_DIGEST_SIZE];
108 VOID *Sha512Ctx;
109
110 Sha512Ctx = (VOID *)HashHandle;
111 Sha512Final (Sha512Ctx, Digest);
112
113 FreePool (Sha512Ctx);
114
115 Tpm2SetSha512ToDigestList (DigestList, Digest);
116
117 return EFI_SUCCESS;
118}
119
120HASH_INTERFACE mSha512InternalHashInstance = {
121 HASH_ALGORITHM_SHA512_GUID,
125};
126
133EFIAPI
135 VOID
136 )
137{
138 EFI_STATUS Status;
139
140 Status = RegisterHashInterfaceLib (&mSha512InternalHashInstance);
141 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
142 //
143 // Unsupported means platform policy does not need this instance enabled.
144 //
145 return EFI_SUCCESS;
146 }
147
148 return Status;
149}
UINT64 UINTN
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
Definition: CryptSha512.c:389
UINTN EFIAPI Sha512GetContextSize(VOID)
Definition: CryptSha512.c:246
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
Definition: CryptSha512.c:270
#define SHA512_DIGEST_SIZE
Definition: BaseCryptLib.h:54
BOOLEAN EFIAPI Sha512Update(IN OUT VOID *Sha512Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha512.c:341
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI Sha512HashFinal(IN HASH_HANDLE HashHandle, OUT TPML_DIGEST_VALUES *DigestList)
EFI_STATUS EFIAPI HashInstanceLibSha512Constructor(VOID)
VOID Tpm2SetSha512ToDigestList(IN TPML_DIGEST_VALUES *DigestList, IN UINT8 *Sha512Digest)
EFI_STATUS EFIAPI Sha512HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
EFI_STATUS EFIAPI Sha512HashInit(OUT HASH_HANDLE *HashHandle)
EFI_STATUS EFIAPI RegisterHashInterfaceLib(IN HASH_INTERFACE *HashInterface)
Definition: HashLibTdx.c:185
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112