TianoCore EDK2 master
Loading...
Searching...
No Matches
HashInstanceLibSm3.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10#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 *Sm3Digest
28 )
29{
30 DigestList->count = 1;
31 DigestList->digests[0].hashAlg = TPM_ALG_SM3_256;
32 CopyMem (
33 DigestList->digests[0].digest.sm3_256,
34 Sm3Digest,
36 );
37}
38
48EFIAPI
50 OUT HASH_HANDLE *HashHandle
51 )
52{
53 VOID *Sm3Ctx;
54 UINTN CtxSize;
55
56 CtxSize = Sm3GetContextSize ();
57 Sm3Ctx = AllocatePool (CtxSize);
58 if (Sm3Ctx == NULL) {
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 Sm3Init (Sm3Ctx);
63
64 *HashHandle = (HASH_HANDLE)Sm3Ctx;
65
66 return EFI_SUCCESS;
67}
68
79EFIAPI
81 IN HASH_HANDLE HashHandle,
82 IN VOID *DataToHash,
83 IN UINTN DataToHashLen
84 )
85{
86 VOID *Sm3Ctx;
87
88 Sm3Ctx = (VOID *)HashHandle;
89 Sm3Update (Sm3Ctx, DataToHash, DataToHashLen);
90
91 return EFI_SUCCESS;
92}
93
103EFIAPI
105 IN HASH_HANDLE HashHandle,
106 OUT TPML_DIGEST_VALUES *DigestList
107 )
108{
109 UINT8 Digest[SM3_256_DIGEST_SIZE];
110 VOID *Sm3Ctx;
111
112 Sm3Ctx = (VOID *)HashHandle;
113 Sm3Final (Sm3Ctx, Digest);
114
115 FreePool (Sm3Ctx);
116
117 Tpm2SetSm3ToDigestList (DigestList, Digest);
118
119 return EFI_SUCCESS;
120}
121
122HASH_INTERFACE mSm3InternalHashInstance = {
123 HASH_ALGORITHM_SM3_256_GUID,
127};
128
135EFIAPI
137 VOID
138 )
139{
140 EFI_STATUS Status;
141
142 Status = RegisterHashInterfaceLib (&mSm3InternalHashInstance);
143 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
144 //
145 // Unsupported means platform policy does not need this instance enabled.
146 //
147 return EFI_SUCCESS;
148 }
149
150 return Status;
151}
UINT64 UINTN
UINTN EFIAPI Sm3GetContextSize(VOID)
Definition: CryptSm3.c:20
BOOLEAN EFIAPI Sm3Update(IN OUT VOID *Sm3Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSm3.c:116
#define SM3_256_DIGEST_SIZE
Definition: BaseCryptLib.h:59
BOOLEAN EFIAPI Sm3Final(IN OUT VOID *Sm3Context, OUT UINT8 *HashValue)
Definition: CryptSm3.c:166
BOOLEAN EFIAPI Sm3Init(OUT VOID *Sm3Context)
Definition: CryptSm3.c:44
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI Sm3HashFinal(IN HASH_HANDLE HashHandle, OUT TPML_DIGEST_VALUES *DigestList)
EFI_STATUS EFIAPI Sm3HashInit(OUT HASH_HANDLE *HashHandle)
EFI_STATUS EFIAPI HashInstanceLibSm3Constructor(VOID)
EFI_STATUS EFIAPI Sm3HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
VOID Tpm2SetSm3ToDigestList(IN TPML_DIGEST_VALUES *DigestList, IN UINT8 *Sm3Digest)
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