25 { TPM_ALG_SHA1, HASH_ALG_SHA1 },
26 { TPM_ALG_SHA256, HASH_ALG_SHA256 },
27 { TPM_ALG_SHA384, HASH_ALG_SHA384 },
28 { TPM_ALG_SHA512, HASH_ALG_SHA512 },
44 HashMask =
PcdGet32 (PcdTpm2HashMask);
45 for (Index = 0; Index <
sizeof (mTpm2HashMask)/
sizeof (mTpm2HashMask[0]); Index++) {
46 if (mTpm2HashMask[Index].Mask == HashMask) {
47 return mTpm2HashMask[Index].AlgoId;
65 OUT HASH_HANDLE *HashHandle
68 TPMI_DH_OBJECT SequenceHandle;
75 if (!EFI_ERROR (Status)) {
76 *HashHandle = (HASH_HANDLE)SequenceHandle;
94 IN HASH_HANDLE HashHandle,
104 Buffer = (UINT8 *)(
UINTN)DataToHash;
105 for (HashLen = DataToHashLen; HashLen >
sizeof (HashBuffer.buffer); HashLen -=
sizeof (HashBuffer.buffer)) {
106 HashBuffer.size =
sizeof (HashBuffer.buffer);
107 CopyMem (HashBuffer.buffer, Buffer, sizeof (HashBuffer.buffer));
108 Buffer +=
sizeof (HashBuffer.buffer);
111 if (EFI_ERROR (Status)) {
112 return EFI_DEVICE_ERROR;
119 HashBuffer.size = (UINT16)HashLen;
122 if (EFI_ERROR (Status)) {
123 return EFI_DEVICE_ERROR;
143 IN HASH_HANDLE HashHandle,
144 IN TPMI_DH_PCR PcrIndex,
159 Buffer = (UINT8 *)(
UINTN)DataToHash;
160 for (HashLen = DataToHashLen; HashLen >
sizeof (HashBuffer.buffer); HashLen -=
sizeof (HashBuffer.buffer)) {
161 HashBuffer.size =
sizeof (HashBuffer.buffer);
162 CopyMem (HashBuffer.buffer, Buffer, sizeof (HashBuffer.buffer));
163 Buffer +=
sizeof (HashBuffer.buffer);
166 if (EFI_ERROR (Status)) {
167 return EFI_DEVICE_ERROR;
174 HashBuffer.size = (UINT16)HashLen;
177 ZeroMem (DigestList,
sizeof (*DigestList));
178 DigestList->count = HASH_COUNT;
180 if (AlgoId == TPM_ALG_NULL) {
183 (TPMI_DH_OBJECT)HashHandle,
189 (TPMI_DH_OBJECT)HashHandle,
193 if (EFI_ERROR (Status)) {
194 return EFI_DEVICE_ERROR;
197 DigestList->count = 1;
198 DigestList->digests[0].hashAlg = AlgoId;
199 CopyMem (&DigestList->digests[0].digest, Result.buffer, Result.size);
206 if (EFI_ERROR (Status)) {
207 return EFI_DEVICE_ERROR;
226 IN TPMI_DH_PCR PcrIndex,
235 TPMI_DH_OBJECT SequenceHandle;
241 DEBUG ((DEBUG_VERBOSE,
"\n HashAndExtend Entry \n"));
243 SequenceHandle = 0xFFFFFFFF;
247 if ((AlgoId == TPM_ALG_NULL) && (DataToHashLen <=
sizeof (EventData.buffer))) {
248 EventData.size = (UINT16)DataToHashLen;
249 CopyMem (EventData.buffer, DataToHash, DataToHashLen);
250 Status =
Tpm2PcrEvent (PcrIndex, &EventData, DigestList);
251 if (EFI_ERROR (Status)) {
252 return EFI_DEVICE_ERROR;
259 if (EFI_ERROR (Status)) {
260 return EFI_DEVICE_ERROR;
263 DEBUG ((DEBUG_VERBOSE,
"\n Tpm2HashSequenceStart Success \n"));
265 Buffer = (UINT8 *)(
UINTN)DataToHash;
266 for (HashLen = DataToHashLen; HashLen >
sizeof (HashBuffer.buffer); HashLen -=
sizeof (HashBuffer.buffer)) {
267 HashBuffer.size =
sizeof (HashBuffer.buffer);
268 CopyMem (HashBuffer.buffer, Buffer, sizeof (HashBuffer.buffer));
269 Buffer +=
sizeof (HashBuffer.buffer);
272 if (EFI_ERROR (Status)) {
273 return EFI_DEVICE_ERROR;
277 DEBUG ((DEBUG_VERBOSE,
"\n Tpm2SequenceUpdate Success \n"));
279 HashBuffer.size = (UINT16)HashLen;
282 ZeroMem (DigestList,
sizeof (*DigestList));
283 DigestList->count = HASH_COUNT;
285 if (AlgoId == TPM_ALG_NULL) {
292 if (EFI_ERROR (Status)) {
293 return EFI_DEVICE_ERROR;
296 DEBUG ((DEBUG_VERBOSE,
"\n Tpm2EventSequenceComplete Success \n"));
303 if (EFI_ERROR (Status)) {
304 return EFI_DEVICE_ERROR;
307 DEBUG ((DEBUG_VERBOSE,
"\n Tpm2SequenceComplete Success \n"));
309 DigestList->count = 1;
310 DigestList->digests[0].hashAlg = AlgoId;
311 CopyMem (&DigestList->digests[0].digest, Result.buffer, Result.size);
316 if (EFI_ERROR (Status)) {
317 return EFI_DEVICE_ERROR;
320 DEBUG ((DEBUG_VERBOSE,
"\n Tpm2PcrExtend Success \n"));
341 return EFI_UNSUPPORTED;
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI HashStart(OUT HASH_HANDLE *HashHandle)
TPM_ALG_ID Tpm2GetAlgoFromHashMask(VOID)
EFI_STATUS EFIAPI RegisterHashInterfaceLib(IN HASH_INTERFACE *HashInterface)
EFI_STATUS EFIAPI HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
EFI_STATUS EFIAPI HashAndExtend(IN TPMI_DH_PCR PcrIndex, IN VOID *DataToHash, IN UINTN DataToHashLen, OUT TPML_DIGEST_VALUES *DigestList)
EFI_STATUS EFIAPI HashCompleteAndExtend(IN HASH_HANDLE HashHandle, IN TPMI_DH_PCR PcrIndex, IN VOID *DataToHash, IN UINTN DataToHashLen, OUT TPML_DIGEST_VALUES *DigestList)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
EFI_STATUS EFIAPI Tpm2PcrEvent(IN TPMI_DH_PCR PcrHandle, IN TPM2B_EVENT *EventData, OUT TPML_DIGEST_VALUES *Digests)
EFI_STATUS EFIAPI Tpm2HashSequenceStart(IN TPMI_ALG_HASH HashAlg, OUT TPMI_DH_OBJECT *SequenceHandle)
EFI_STATUS EFIAPI Tpm2SequenceComplete(IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer, OUT TPM2B_DIGEST *Result)
EFI_STATUS EFIAPI Tpm2EventSequenceComplete(IN TPMI_DH_PCR PcrHandle, IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer, OUT TPML_DIGEST_VALUES *Results)
EFI_STATUS EFIAPI Tpm2SequenceUpdate(IN TPMI_DH_OBJECT SequenceHandle, IN TPM2B_MAX_BUFFER *Buffer)
EFI_STATUS EFIAPI Tpm2PcrExtend(IN TPMI_DH_PCR PcrHandle, IN TPML_DIGEST_VALUES *Digests)