TianoCore EDK2 master
Loading...
Searching...
No Matches
HashInstanceLibSha256.c
Go to the documentation of this file.
1
10#include <PiPei.h>
11#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
17#include <Library/HashLib.h>
18
25VOID
27 IN TPML_DIGEST_VALUES *DigestList,
28 IN UINT8 *Sha256Digest
29 )
30{
31 DigestList->count = 1;
32 DigestList->digests[0].hashAlg = TPM_ALG_SHA256;
33 CopyMem (
34 DigestList->digests[0].digest.sha256,
35 Sha256Digest,
37 );
38}
39
49EFIAPI
51 OUT HASH_HANDLE *HashHandle
52 )
53{
54 VOID *Sha256Ctx;
55 UINTN CtxSize;
56
57 CtxSize = Sha256GetContextSize ();
58 Sha256Ctx = AllocatePool (CtxSize);
59 ASSERT (Sha256Ctx != NULL);
60
61 Sha256Init (Sha256Ctx);
62
63 *HashHandle = (HASH_HANDLE)Sha256Ctx;
64
65 return EFI_SUCCESS;
66}
67
78EFIAPI
80 IN HASH_HANDLE HashHandle,
81 IN VOID *DataToHash,
82 IN UINTN DataToHashLen
83 )
84{
85 VOID *Sha256Ctx;
86
87 Sha256Ctx = (VOID *)HashHandle;
88 Sha256Update (Sha256Ctx, DataToHash, DataToHashLen);
89
90 return EFI_SUCCESS;
91}
92
102EFIAPI
104 IN HASH_HANDLE HashHandle,
105 OUT TPML_DIGEST_VALUES *DigestList
106 )
107{
108 UINT8 Digest[SHA256_DIGEST_SIZE];
109 VOID *Sha256Ctx;
110
111 Sha256Ctx = (VOID *)HashHandle;
112 Sha256Final (Sha256Ctx, Digest);
113
114 FreePool (Sha256Ctx);
115
116 Tpm2SetSha256ToDigestList (DigestList, Digest);
117
118 return EFI_SUCCESS;
119}
120
121HASH_INTERFACE mSha256InternalHashInstance = {
122 HASH_ALGORITHM_SHA256_GUID,
126};
127
134EFIAPI
136 VOID
137 )
138{
139 EFI_STATUS Status;
140
141 Status = RegisterHashInterfaceLib (&mSha256InternalHashInstance);
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}
UINT64 UINTN
UINTN EFIAPI Sha256GetContextSize(VOID)
Definition: CryptSha256.c:20
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
Definition: CryptSha256.c:44
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
Definition: CryptSha256.c:161
#define SHA256_DIGEST_SIZE
Definition: BaseCryptLib.h:44
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha256.c:113
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID Tpm2SetSha256ToDigestList(IN TPML_DIGEST_VALUES *DigestList, IN UINT8 *Sha256Digest)
EFI_STATUS EFIAPI Sha256HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
EFI_STATUS EFIAPI HashInstanceLibSha256Constructor(VOID)
EFI_STATUS EFIAPI Sha256HashInit(OUT HASH_HANDLE *HashHandle)
EFI_STATUS EFIAPI Sha256HashFinal(IN HASH_HANDLE HashHandle, OUT TPML_DIGEST_VALUES *DigestList)
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