TianoCore EDK2 master
Loading...
Searching...
No Matches
HashInstanceLibSha1.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 *Sha1Digest
29 )
30{
31 DigestList->count = 1;
32 DigestList->digests[0].hashAlg = TPM_ALG_SHA1;
33 CopyMem (
34 DigestList->digests[0].digest.sha1,
35 Sha1Digest,
37 );
38}
39
49EFIAPI
51 OUT HASH_HANDLE *HashHandle
52 )
53{
54 VOID *Sha1Ctx;
55 UINTN CtxSize;
56
57 CtxSize = Sha1GetContextSize ();
58 Sha1Ctx = AllocatePool (CtxSize);
59 ASSERT (Sha1Ctx != NULL);
60
61 Sha1Init (Sha1Ctx);
62
63 *HashHandle = (HASH_HANDLE)Sha1Ctx;
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 *Sha1Ctx;
86
87 Sha1Ctx = (VOID *)HashHandle;
88 Sha1Update (Sha1Ctx, 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[SHA1_DIGEST_SIZE];
109 VOID *Sha1Ctx;
110
111 Sha1Ctx = (VOID *)HashHandle;
112 Sha1Final (Sha1Ctx, Digest);
113
114 FreePool (Sha1Ctx);
115
116 Tpm2SetSha1ToDigestList (DigestList, Digest);
117
118 return EFI_SUCCESS;
119}
120
121HASH_INTERFACE mSha1InternalHashInstance = {
122 HASH_ALGORITHM_SHA1_GUID,
126};
127
134EFIAPI
136 VOID
137 )
138{
139 EFI_STATUS Status;
140
141 Status = RegisterHashInterfaceLib (&mSha1InternalHashInstance);
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
#define SHA1_DIGEST_SIZE
Definition: BaseCryptLib.h:39
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
Definition: CryptSha1.c:163
BOOLEAN EFIAPI Sha1Init(OUT VOID *Sha1Context)
Definition: CryptSha1.c:46
UINTN EFIAPI Sha1GetContextSize(VOID)
Definition: CryptSha1.c:22
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha1.c:115
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI HashInstanceLibSha1Constructor(VOID)
EFI_STATUS EFIAPI Sha1HashInit(OUT HASH_HANDLE *HashHandle)
EFI_STATUS EFIAPI Sha1HashFinal(IN HASH_HANDLE HashHandle, OUT TPML_DIGEST_VALUES *DigestList)
VOID Tpm2SetSha1ToDigestList(IN TPML_DIGEST_VALUES *DigestList, IN UINT8 *Sha1Digest)
EFI_STATUS EFIAPI Sha1HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
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